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

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

Issue 10823202: Add heap space sizes and external memory counter to V8 statistics extension. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 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 | « no previous file | src/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 23 matching lines...) Expand all
34 "native function getV8Statistics();"; 34 "native function getV8Statistics();";
35 35
36 36
37 v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunction( 37 v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunction(
38 v8::Handle<v8::String> str) { 38 v8::Handle<v8::String> str) {
39 ASSERT(strcmp(*v8::String::AsciiValue(str), "getV8Statistics") == 0); 39 ASSERT(strcmp(*v8::String::AsciiValue(str), "getV8Statistics") == 0);
40 return v8::FunctionTemplate::New(StatisticsExtension::GetCounters); 40 return v8::FunctionTemplate::New(StatisticsExtension::GetCounters);
41 } 41 }
42 42
43 43
44 static void AddProperty(v8::Local<v8::Object> object, 44 static void AddCounter(v8::Local<v8::Object> object,
45 StatsCounter* counter, 45 StatsCounter* counter,
46 const char* name) { 46 const char* name) {
47 if (counter->Enabled()) { 47 if (counter->Enabled()) {
48 object->Set(v8::String::New(name), 48 object->Set(v8::String::New(name),
49 v8::Number::New(*counter->GetInternalPointer())); 49 v8::Number::New(*counter->GetInternalPointer()));
50 } 50 }
51 } 51 }
52 52
53 static void AddNumber(v8::Local<v8::Object> object,
54 double value,
55 const char* name) {
56 object->Set(v8::String::New(name), v8::Number::New(value));
57 }
58
53 59
54 v8::Handle<v8::Value> StatisticsExtension::GetCounters( 60 v8::Handle<v8::Value> StatisticsExtension::GetCounters(
55 const v8::Arguments& args) { 61 const v8::Arguments& args) {
56 Isolate* isolate = Isolate::Current(); 62 Isolate* isolate = Isolate::Current();
57 Heap* heap = isolate->heap(); 63 Heap* heap = isolate->heap();
58 64
59 if (args.Length() > 0) { // GC if first argument evaluates to true. 65 if (args.Length() > 0) { // GC if first argument evaluates to true.
60 if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) { 66 if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) {
61 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); 67 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension");
62 } 68 }
63 } 69 }
64 70
65 Counters* counters = isolate->counters(); 71 Counters* counters = isolate->counters();
66 v8::Local<v8::Object> result = v8::Object::New(); 72 v8::Local<v8::Object> result = v8::Object::New();
67 73
68 #define ADD_COUNTER(name, caption) \ 74 #define ADD_COUNTER(name, caption) \
69 AddProperty(result, counters->name(), #name); 75 AddCounter(result, counters->name(), #name);
70 76
71 STATS_COUNTER_LIST_1(ADD_COUNTER) 77 STATS_COUNTER_LIST_1(ADD_COUNTER)
72 STATS_COUNTER_LIST_2(ADD_COUNTER) 78 STATS_COUNTER_LIST_2(ADD_COUNTER)
73 #undef ADD_COUNTER 79 #undef ADD_COUNTER
74 #define ADD_COUNTER(name) \ 80 #define ADD_COUNTER(name) \
75 AddProperty(result, counters->count_of_##name(), "count_of_" #name); \ 81 AddCounter(result, counters->count_of_##name(), "count_of_" #name); \
76 AddProperty(result, counters->size_of_##name(), "size_of_" #name); 82 AddCounter(result, counters->size_of_##name(), "size_of_" #name);
77 83
78 INSTANCE_TYPE_LIST(ADD_COUNTER) 84 INSTANCE_TYPE_LIST(ADD_COUNTER)
79 #undef ADD_COUNTER 85 #undef ADD_COUNTER
80 #define ADD_COUNTER(name) \ 86 #define ADD_COUNTER(name) \
81 AddProperty(result, counters->count_of_CODE_TYPE_##name(), \ 87 AddCounter(result, counters->count_of_CODE_TYPE_##name(), \
82 "count_of_CODE_TYPE_" #name); \ 88 "count_of_CODE_TYPE_" #name); \
83 AddProperty(result, counters->size_of_CODE_TYPE_##name(), \ 89 AddCounter(result, counters->size_of_CODE_TYPE_##name(), \
84 "size_of_CODE_TYPE_" #name); 90 "size_of_CODE_TYPE_" #name);
85 91
86 CODE_KIND_LIST(ADD_COUNTER) 92 CODE_KIND_LIST(ADD_COUNTER)
87 #undef ADD_COUNTER 93 #undef ADD_COUNTER
88 #define ADD_COUNTER(name) \ 94 #define ADD_COUNTER(name) \
89 AddProperty(result, counters->count_of_FIXED_ARRAY_##name(), \ 95 AddCounter(result, counters->count_of_FIXED_ARRAY_##name(), \
90 "count_of_FIXED_ARRAY_" #name); \ 96 "count_of_FIXED_ARRAY_" #name); \
91 AddProperty(result, counters->size_of_FIXED_ARRAY_##name(), \ 97 AddCounter(result, counters->size_of_FIXED_ARRAY_##name(), \
92 "size_of_FIXED_ARRAY_" #name); 98 "size_of_FIXED_ARRAY_" #name);
93 99
94 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER) 100 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER)
95 #undef ADD_COUNTER 101 #undef ADD_COUNTER
96 102
103 AddNumber(result, isolate->memory_allocator()->Size(),
104 "total_committed_bytes");
105 AddNumber(result, heap->new_space()->Size(),
106 "new_space_live_bytes");
107 AddNumber(result, heap->new_space()->Available(),
108 "new_space_available_bytes");
109 AddNumber(result, heap->new_space()->CommittedMemory(),
110 "new_space_commited_bytes");
111 AddNumber(result, heap->old_pointer_space()->Size(),
112 "old_pointer_space_live_bytes");
113 AddNumber(result, heap->old_pointer_space()->Available(),
114 "old_pointer_space_available_bytes");
115 AddNumber(result, heap->old_pointer_space()->CommittedMemory(),
116 "old_pointer_space_commited_bytes");
117 AddNumber(result, heap->old_data_space()->Size(),
118 "old_data_space_live_bytes");
119 AddNumber(result, heap->old_data_space()->Available(),
120 "old_data_space_available_bytes");
121 AddNumber(result, heap->old_data_space()->CommittedMemory(),
122 "old_data_space_commited_bytes");
123 AddNumber(result, heap->code_space()->Size(),
124 "code_space_live_bytes");
125 AddNumber(result, heap->code_space()->Available(),
126 "code_space_available_bytes");
127 AddNumber(result, heap->code_space()->CommittedMemory(),
128 "code_space_commited_bytes");
129 AddNumber(result, heap->cell_space()->Size(),
130 "cell_space_live_bytes");
131 AddNumber(result, heap->cell_space()->Available(),
132 "cell_space_available_bytes");
133 AddNumber(result, heap->cell_space()->CommittedMemory(),
134 "cell_space_commited_bytes");
135 AddNumber(result, heap->lo_space()->Size(),
136 "lo_space_live_bytes");
137 AddNumber(result, heap->lo_space()->Available(),
138 "lo_space_available_bytes");
139 AddNumber(result, heap->lo_space()->CommittedMemory(),
140 "lo_space_commited_bytes");
141 AddNumber(result, heap->amount_of_external_allocated_memory(),
142 "amount_of_external_allocated_memory");
Yang 2012/08/07 15:13:04 It seems to me that a macro would save a lot of sp
97 return result; 143 return result;
98 } 144 }
99 145
100 146
101 void StatisticsExtension::Register() { 147 void StatisticsExtension::Register() {
102 static StatisticsExtension statistics_extension; 148 static StatisticsExtension statistics_extension;
103 static v8::DeclareExtension declaration(&statistics_extension); 149 static v8::DeclareExtension declaration(&statistics_extension);
104 } 150 }
105 151
106 } } // namespace v8::internal 152 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698