Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 #include "counters-extension.h" | |
|
rossberg
2012/07/18 12:23:39
Can we perhaps call that "stats"?
| |
| 29 | |
| 30 namespace v8 { | |
| 31 namespace internal { | |
| 32 | |
| 33 const char* const CountersExtension::kSource = | |
| 34 "native function getV8Counters();"; | |
| 35 | |
| 36 | |
| 37 v8::Handle<v8::FunctionTemplate> CountersExtension::GetNativeFunction( | |
| 38 v8::Handle<v8::String> str) { | |
| 39 ASSERT(strcmp(*v8::String::AsciiValue(str), "getPerformanceCounters") == 0); | |
| 40 return v8::FunctionTemplate::New(CountersExtension::GetCounters); | |
| 41 } | |
| 42 | |
| 43 | |
| 44 v8::Handle<v8::Value> CountersExtension::GetCounters( | |
| 45 const v8::Arguments& args) { | |
| 46 Isolate* isolate = Isolate::Current(); | |
| 47 Heap* heap = isolate->heap(); | |
| 48 if (args.Length() > 0) { // GC if first argument evaluates to true. | |
| 49 if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) { | |
| 50 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 Counters* counters = isolate->counters(); | |
| 55 v8::Local<v8::Object> result = v8::Object::New(); | |
| 56 | |
| 57 StatsCounter* counter = NULL; | |
| 58 | |
| 59 #define STR(s) #s | |
|
rossberg
2012/07/18 12:23:39
As discussed offline, you could get rid of this on
| |
| 60 #define ADD_COUNTER(name, caption) \ | |
| 61 counter = counters->name(); \ | |
| 62 if (counter->Enabled()) \ | |
| 63 result->Set(v8::String::New(STR(name)), \ | |
| 64 v8::Number::New(static_cast<double>(*counter->GetInternalPointer()))); | |
|
rossberg
2012/07/18 12:23:39
Is the cast necessary? (here and below)
| |
| 65 | |
| 66 STATS_COUNTER_LIST_1(ADD_COUNTER) | |
| 67 STATS_COUNTER_LIST_2(ADD_COUNTER) | |
| 68 #undef ADD_COUNTER | |
| 69 #define ADD_COUNTER(name) \ | |
| 70 counter = counters->count_of_##name(); \ | |
| 71 if (counter->Enabled()) \ | |
| 72 result->Set(v8::String::New(STR(count_of_##name)), \ | |
| 73 v8::Number::New(static_cast<double>(*counter->GetInternalPointer()))); \ | |
| 74 counter = counters->size_of_##name(); \ | |
| 75 if (counter->Enabled()) \ | |
| 76 result->Set(v8::String::New(STR(size_of_##name)), \ | |
| 77 v8::Number::New(static_cast<double>(*counter->GetInternalPointer()))); | |
| 78 | |
| 79 INSTANCE_TYPE_LIST(ADD_COUNTER) | |
| 80 #undef ADD_COUNTER | |
| 81 #define ADD_COUNTER(name) \ | |
| 82 result->Set(v8::String::New(STR(count_of_CODE_TYPE_##name)), \ | |
| 83 v8::Number::New(static_cast<double>( \ | |
| 84 *counters->count_of_CODE_TYPE_##name()->GetInternalPointer()))); \ | |
| 85 result->Set(v8::String::New(STR(size_of_CODE_TYPE_##name)), \ | |
| 86 v8::Number::New(static_cast<double>( \ | |
| 87 *counters->size_of_CODE_TYPE_##name()->GetInternalPointer()))); | |
| 88 | |
| 89 CODE_KIND_LIST(ADD_COUNTER) | |
| 90 #undef ADD_COUNTER | |
| 91 #undef STR | |
| 92 | |
| 93 return result; | |
| 94 } | |
| 95 | |
| 96 | |
| 97 void CountersExtension::Register() { | |
| 98 static CountersExtension counters_extension; | |
| 99 static v8::DeclareExtension declaration(&counters_extension); | |
| 100 } | |
| 101 | |
| 102 } } // namespace v8::internal | |
| OLD | NEW |