Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/extensions/statistics-extension.cc

Issue 10803008: Expose counters in javascript. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/extensions/statistics-extension.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "statistics-extension.h"
29
30 namespace v8 {
31 namespace internal {
32
33 const char* const StatisticsExtension::kSource =
34 "native function getV8Statistics();";
35
36
37 v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunction(
38 v8::Handle<v8::String> str) {
39 ASSERT(strcmp(*v8::String::AsciiValue(str), "getV8Statistics") == 0);
40 return v8::FunctionTemplate::New(StatisticsExtension::GetCounters);
41 }
42
43
44 v8::Handle<v8::Value> StatisticsExtension::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 ADD_COUNTER(name, caption) \
60 counter = counters->name(); \
61 if (counter->Enabled()) \
62 result->Set(v8::String::New(#name), \
63 v8::Number::New(*counter->GetInternalPointer()));
64
65 STATS_COUNTER_LIST_1(ADD_COUNTER)
66 STATS_COUNTER_LIST_2(ADD_COUNTER)
67 #undef ADD_COUNTER
68 #define ADD_COUNTER(name) \
69 counter = counters->count_of_##name(); \
70 if (counter->Enabled()) \
71 result->Set(v8::String::New("count_of_" #name), \
72 v8::Number::New(*counter->GetInternalPointer())); \
73 counter = counters->size_of_##name(); \
74 if (counter->Enabled()) \
75 result->Set(v8::String::New("size_of_" #name), \
76 v8::Number::New(*counter->GetInternalPointer()));
77
78 INSTANCE_TYPE_LIST(ADD_COUNTER)
79 #undef ADD_COUNTER
80 #define ADD_COUNTER(name) \
81 result->Set(v8::String::New("count_of_CODE_TYPE_" #name), \
82 v8::Number::New( \
83 *counters->count_of_CODE_TYPE_##name()->GetInternalPointer())); \
84 result->Set(v8::String::New("size_of_CODE_TYPE_" #name), \
85 v8::Number::New( \
86 *counters->size_of_CODE_TYPE_##name()->GetInternalPointer()));
87
88 CODE_KIND_LIST(ADD_COUNTER)
89 #undef ADD_COUNTER
90
91 return result;
92 }
93
94
95 void StatisticsExtension::Register() {
96 static StatisticsExtension statistics_extension;
97 static v8::DeclareExtension declaration(&statistics_extension);
98 }
99
100 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/extensions/statistics-extension.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698