OLD | NEW |
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 Loading... |
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::Utf8Value(str), "getV8Statistics") == 0); | 39 ASSERT(strcmp(*v8::String::Utf8Value(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 AddCounter(v8::Local<v8::Object> object, | 44 static void AddCounter(v8::Isolate* isolate, |
| 45 v8::Local<v8::Object> object, |
45 StatsCounter* counter, | 46 StatsCounter* counter, |
46 const char* name) { | 47 const char* name) { |
47 if (counter->Enabled()) { | 48 if (counter->Enabled()) { |
48 object->Set(v8::String::New(name), | 49 object->Set(v8::String::NewFromUtf8(isolate, name), |
49 v8::Number::New(*counter->GetInternalPointer())); | 50 v8::Number::New(*counter->GetInternalPointer())); |
50 } | 51 } |
51 } | 52 } |
52 | 53 |
53 static void AddNumber(v8::Local<v8::Object> object, | 54 static void AddNumber(v8::Isolate* isolate, |
| 55 v8::Local<v8::Object> object, |
54 intptr_t value, | 56 intptr_t value, |
55 const char* name) { | 57 const char* name) { |
56 object->Set(v8::String::New(name), | 58 object->Set(v8::String::NewFromUtf8(isolate, name), |
57 v8::Number::New(static_cast<double>(value))); | 59 v8::Number::New(static_cast<double>(value))); |
58 } | 60 } |
59 | 61 |
60 | 62 |
61 static void AddNumber64(v8::Local<v8::Object> object, | 63 static void AddNumber64(v8::Isolate* isolate, |
| 64 v8::Local<v8::Object> object, |
62 int64_t value, | 65 int64_t value, |
63 const char* name) { | 66 const char* name) { |
64 object->Set(v8::String::New(name), | 67 object->Set(v8::String::NewFromUtf8(isolate, name), |
65 v8::Number::New(static_cast<double>(value))); | 68 v8::Number::New(static_cast<double>(value))); |
66 } | 69 } |
67 | 70 |
68 | 71 |
69 void StatisticsExtension::GetCounters( | 72 void StatisticsExtension::GetCounters( |
70 const v8::FunctionCallbackInfo<v8::Value>& args) { | 73 const v8::FunctionCallbackInfo<v8::Value>& args) { |
71 Isolate* isolate = reinterpret_cast<Isolate*>(args.GetIsolate()); | 74 Isolate* isolate = reinterpret_cast<Isolate*>(args.GetIsolate()); |
72 Heap* heap = isolate->heap(); | 75 Heap* heap = isolate->heap(); |
73 | 76 |
74 if (args.Length() > 0) { // GC if first argument evaluates to true. | 77 if (args.Length() > 0) { // GC if first argument evaluates to true. |
75 if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) { | 78 if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) { |
76 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); | 79 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); |
77 } | 80 } |
78 } | 81 } |
79 | 82 |
80 Counters* counters = isolate->counters(); | 83 Counters* counters = isolate->counters(); |
81 v8::Local<v8::Object> result = v8::Object::New(); | 84 v8::Local<v8::Object> result = v8::Object::New(); |
82 | 85 |
83 #define ADD_COUNTER(name, caption) \ | 86 #define ADD_COUNTER(name, caption) \ |
84 AddCounter(result, counters->name(), #name); | 87 AddCounter(args.GetIsolate(), result, counters->name(), #name); |
85 | 88 |
86 STATS_COUNTER_LIST_1(ADD_COUNTER) | 89 STATS_COUNTER_LIST_1(ADD_COUNTER) |
87 STATS_COUNTER_LIST_2(ADD_COUNTER) | 90 STATS_COUNTER_LIST_2(ADD_COUNTER) |
88 #undef ADD_COUNTER | 91 #undef ADD_COUNTER |
89 #define ADD_COUNTER(name) \ | 92 #define ADD_COUNTER(name) \ |
90 AddCounter(result, counters->count_of_##name(), "count_of_" #name); \ | 93 AddCounter(args.GetIsolate(), result, counters->count_of_##name(), \ |
91 AddCounter(result, counters->size_of_##name(), "size_of_" #name); | 94 "count_of_" #name); \ |
| 95 AddCounter(args.GetIsolate(), result, counters->size_of_##name(), \ |
| 96 "size_of_" #name); |
92 | 97 |
93 INSTANCE_TYPE_LIST(ADD_COUNTER) | 98 INSTANCE_TYPE_LIST(ADD_COUNTER) |
94 #undef ADD_COUNTER | 99 #undef ADD_COUNTER |
95 #define ADD_COUNTER(name) \ | 100 #define ADD_COUNTER(name) \ |
96 AddCounter(result, counters->count_of_CODE_TYPE_##name(), \ | 101 AddCounter(args.GetIsolate(), result, counters->count_of_CODE_TYPE_##name(), \ |
97 "count_of_CODE_TYPE_" #name); \ | 102 "count_of_CODE_TYPE_" #name); \ |
98 AddCounter(result, counters->size_of_CODE_TYPE_##name(), \ | 103 AddCounter(args.GetIsolate(), result, counters->size_of_CODE_TYPE_##name(), \ |
99 "size_of_CODE_TYPE_" #name); | 104 "size_of_CODE_TYPE_" #name); |
100 | 105 |
101 CODE_KIND_LIST(ADD_COUNTER) | 106 CODE_KIND_LIST(ADD_COUNTER) |
102 #undef ADD_COUNTER | 107 #undef ADD_COUNTER |
103 #define ADD_COUNTER(name) \ | 108 #define ADD_COUNTER(name) \ |
104 AddCounter(result, counters->count_of_FIXED_ARRAY_##name(), \ | 109 AddCounter(args.GetIsolate(), result, \ |
105 "count_of_FIXED_ARRAY_" #name); \ | 110 counters->count_of_FIXED_ARRAY_##name(), \ |
106 AddCounter(result, counters->size_of_FIXED_ARRAY_##name(), \ | 111 "count_of_FIXED_ARRAY_" #name); \ |
| 112 AddCounter(args.GetIsolate(), result, \ |
| 113 counters->size_of_FIXED_ARRAY_##name(), \ |
107 "size_of_FIXED_ARRAY_" #name); | 114 "size_of_FIXED_ARRAY_" #name); |
108 | 115 |
109 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER) | 116 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER) |
110 #undef ADD_COUNTER | 117 #undef ADD_COUNTER |
111 | 118 |
112 AddNumber(result, isolate->memory_allocator()->Size(), | 119 AddNumber(args.GetIsolate(), result, isolate->memory_allocator()->Size(), |
113 "total_committed_bytes"); | 120 "total_committed_bytes"); |
114 AddNumber(result, heap->new_space()->Size(), | 121 AddNumber(args.GetIsolate(), result, heap->new_space()->Size(), |
115 "new_space_live_bytes"); | 122 "new_space_live_bytes"); |
116 AddNumber(result, heap->new_space()->Available(), | 123 AddNumber(args.GetIsolate(), result, heap->new_space()->Available(), |
117 "new_space_available_bytes"); | 124 "new_space_available_bytes"); |
118 AddNumber(result, heap->new_space()->CommittedMemory(), | 125 AddNumber(args.GetIsolate(), result, heap->new_space()->CommittedMemory(), |
119 "new_space_commited_bytes"); | 126 "new_space_commited_bytes"); |
120 AddNumber(result, heap->old_pointer_space()->Size(), | 127 AddNumber(args.GetIsolate(), result, heap->old_pointer_space()->Size(), |
121 "old_pointer_space_live_bytes"); | 128 "old_pointer_space_live_bytes"); |
122 AddNumber(result, heap->old_pointer_space()->Available(), | 129 AddNumber(args.GetIsolate(), result, heap->old_pointer_space()->Available(), |
123 "old_pointer_space_available_bytes"); | 130 "old_pointer_space_available_bytes"); |
124 AddNumber(result, heap->old_pointer_space()->CommittedMemory(), | 131 AddNumber(args.GetIsolate(), result, |
| 132 heap->old_pointer_space()->CommittedMemory(), |
125 "old_pointer_space_commited_bytes"); | 133 "old_pointer_space_commited_bytes"); |
126 AddNumber(result, heap->old_data_space()->Size(), | 134 AddNumber(args.GetIsolate(), result, heap->old_data_space()->Size(), |
127 "old_data_space_live_bytes"); | 135 "old_data_space_live_bytes"); |
128 AddNumber(result, heap->old_data_space()->Available(), | 136 AddNumber(args.GetIsolate(), result, heap->old_data_space()->Available(), |
129 "old_data_space_available_bytes"); | 137 "old_data_space_available_bytes"); |
130 AddNumber(result, heap->old_data_space()->CommittedMemory(), | 138 AddNumber(args.GetIsolate(), result, |
| 139 heap->old_data_space()->CommittedMemory(), |
131 "old_data_space_commited_bytes"); | 140 "old_data_space_commited_bytes"); |
132 AddNumber(result, heap->code_space()->Size(), | 141 AddNumber(args.GetIsolate(), result, heap->code_space()->Size(), |
133 "code_space_live_bytes"); | 142 "code_space_live_bytes"); |
134 AddNumber(result, heap->code_space()->Available(), | 143 AddNumber(args.GetIsolate(), result, heap->code_space()->Available(), |
135 "code_space_available_bytes"); | 144 "code_space_available_bytes"); |
136 AddNumber(result, heap->code_space()->CommittedMemory(), | 145 AddNumber(args.GetIsolate(), result, heap->code_space()->CommittedMemory(), |
137 "code_space_commited_bytes"); | 146 "code_space_commited_bytes"); |
138 AddNumber(result, heap->cell_space()->Size(), | 147 AddNumber(args.GetIsolate(), result, heap->cell_space()->Size(), |
139 "cell_space_live_bytes"); | 148 "cell_space_live_bytes"); |
140 AddNumber(result, heap->cell_space()->Available(), | 149 AddNumber(args.GetIsolate(), result, heap->cell_space()->Available(), |
141 "cell_space_available_bytes"); | 150 "cell_space_available_bytes"); |
142 AddNumber(result, heap->cell_space()->CommittedMemory(), | 151 AddNumber(args.GetIsolate(), result, heap->cell_space()->CommittedMemory(), |
143 "cell_space_commited_bytes"); | 152 "cell_space_commited_bytes"); |
144 AddNumber(result, heap->property_cell_space()->Size(), | 153 AddNumber(args.GetIsolate(), result, heap->property_cell_space()->Size(), |
145 "property_cell_space_live_bytes"); | 154 "property_cell_space_live_bytes"); |
146 AddNumber(result, heap->property_cell_space()->Available(), | 155 AddNumber(args.GetIsolate(), result, heap->property_cell_space()->Available(), |
147 "property_cell_space_available_bytes"); | 156 "property_cell_space_available_bytes"); |
148 AddNumber(result, heap->property_cell_space()->CommittedMemory(), | 157 AddNumber(args.GetIsolate(), result, |
| 158 heap->property_cell_space()->CommittedMemory(), |
149 "property_cell_space_commited_bytes"); | 159 "property_cell_space_commited_bytes"); |
150 AddNumber(result, heap->lo_space()->Size(), | 160 AddNumber(args.GetIsolate(), result, heap->lo_space()->Size(), |
151 "lo_space_live_bytes"); | 161 "lo_space_live_bytes"); |
152 AddNumber(result, heap->lo_space()->Available(), | 162 AddNumber(args.GetIsolate(), result, heap->lo_space()->Available(), |
153 "lo_space_available_bytes"); | 163 "lo_space_available_bytes"); |
154 AddNumber(result, heap->lo_space()->CommittedMemory(), | 164 AddNumber(args.GetIsolate(), result, heap->lo_space()->CommittedMemory(), |
155 "lo_space_commited_bytes"); | 165 "lo_space_commited_bytes"); |
156 AddNumber64(result, heap->amount_of_external_allocated_memory(), | 166 AddNumber64(args.GetIsolate(), result, |
| 167 heap->amount_of_external_allocated_memory(), |
157 "amount_of_external_allocated_memory"); | 168 "amount_of_external_allocated_memory"); |
158 args.GetReturnValue().Set(result); | 169 args.GetReturnValue().Set(result); |
159 } | 170 } |
160 | 171 |
161 | 172 |
162 void StatisticsExtension::Register() { | 173 void StatisticsExtension::Register() { |
163 static StatisticsExtension statistics_extension; | 174 static StatisticsExtension statistics_extension; |
164 static v8::DeclareExtension declaration(&statistics_extension); | 175 static v8::DeclareExtension declaration(&statistics_extension); |
165 } | 176 } |
166 | 177 |
167 } } // namespace v8::internal | 178 } } // namespace v8::internal |
OLD | NEW |