| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/extensions/statistics-extension.h" | 5 #include "src/extensions/statistics-extension.h" |
| 6 | 6 |
| 7 namespace v8 { | 7 namespace v8 { |
| 8 namespace internal { | 8 namespace internal { |
| 9 | 9 |
| 10 const char* const StatisticsExtension::kSource = | 10 const char* const StatisticsExtension::kSource = |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 if (args.Length() > 0) { // GC if first argument evaluates to true. | 55 if (args.Length() > 0) { // GC if first argument evaluates to true. |
| 56 if (args[0]->IsBoolean() && | 56 if (args[0]->IsBoolean() && |
| 57 args[0]->ToBoolean(args.GetIsolate())->Value()) { | 57 args[0]->ToBoolean(args.GetIsolate())->Value()) { |
| 58 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); | 58 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 Counters* counters = isolate->counters(); | 62 Counters* counters = isolate->counters(); |
| 63 v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate()); | 63 v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate()); |
| 64 | 64 |
| 65 #define ADD_COUNTER(name, caption) \ | 65 struct StatisticsCounter { |
| 66 AddCounter(args.GetIsolate(), result, counters->name(), #name); | 66 v8::internal::StatsCounter* counter; |
| 67 const char* name; |
| 68 }; |
| 69 const StatisticsCounter counter_list[] = { |
| 70 #define ADD_COUNTER(name, caption) \ |
| 71 { counters->name(), #name } \ |
| 72 , |
| 67 | 73 |
| 68 STATS_COUNTER_LIST_1(ADD_COUNTER) | 74 STATS_COUNTER_LIST_1(ADD_COUNTER) STATS_COUNTER_LIST_2(ADD_COUNTER) |
| 69 STATS_COUNTER_LIST_2(ADD_COUNTER) | |
| 70 #undef ADD_COUNTER | 75 #undef ADD_COUNTER |
| 71 #define ADD_COUNTER(name) \ | 76 #define ADD_COUNTER(name) \ |
| 72 AddCounter(args.GetIsolate(), result, counters->count_of_##name(), \ | 77 { counters->count_of_##name(), "count_of_" #name } \ |
| 73 "count_of_" #name); \ | 78 , {counters->size_of_##name(), "size_of_" #name}, |
| 74 AddCounter(args.GetIsolate(), result, counters->size_of_##name(), \ | |
| 75 "size_of_" #name); | |
| 76 | 79 |
| 77 INSTANCE_TYPE_LIST(ADD_COUNTER) | 80 INSTANCE_TYPE_LIST(ADD_COUNTER) |
| 78 #undef ADD_COUNTER | 81 #undef ADD_COUNTER |
| 79 #define ADD_COUNTER(name) \ | 82 #define ADD_COUNTER(name) \ |
| 80 AddCounter(args.GetIsolate(), result, counters->count_of_CODE_TYPE_##name(), \ | 83 { counters->count_of_CODE_TYPE_##name(), "count_of_CODE_TYPE_" #name } \ |
| 81 "count_of_CODE_TYPE_" #name); \ | 84 , {counters->size_of_CODE_TYPE_##name(), "size_of_CODE_TYPE_" #name}, |
| 82 AddCounter(args.GetIsolate(), result, counters->size_of_CODE_TYPE_##name(), \ | |
| 83 "size_of_CODE_TYPE_" #name); | |
| 84 | 85 |
| 85 CODE_KIND_LIST(ADD_COUNTER) | 86 CODE_KIND_LIST(ADD_COUNTER) |
| 86 #undef ADD_COUNTER | 87 #undef ADD_COUNTER |
| 87 #define ADD_COUNTER(name) \ | 88 #define ADD_COUNTER(name) \ |
| 88 AddCounter(args.GetIsolate(), result, \ | 89 { counters->count_of_FIXED_ARRAY_##name(), "count_of_FIXED_ARRAY_" #name } \ |
| 89 counters->count_of_FIXED_ARRAY_##name(), \ | 90 , {counters->size_of_FIXED_ARRAY_##name(), "size_of_FIXED_ARRAY_" #name}, |
| 90 "count_of_FIXED_ARRAY_" #name); \ | |
| 91 AddCounter(args.GetIsolate(), result, \ | |
| 92 counters->size_of_FIXED_ARRAY_##name(), \ | |
| 93 "size_of_FIXED_ARRAY_" #name); | |
| 94 | 91 |
| 95 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER) | 92 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER) |
| 96 #undef ADD_COUNTER | 93 #undef ADD_COUNTER |
| 94 }; // End counter_list array. |
| 97 | 95 |
| 98 AddNumber(args.GetIsolate(), result, isolate->memory_allocator()->Size(), | 96 for (size_t i = 0; i < arraysize(counter_list); i++) { |
| 99 "total_committed_bytes"); | 97 AddCounter(args.GetIsolate(), result, counter_list[i].counter, |
| 100 AddNumber(args.GetIsolate(), result, heap->new_space()->Size(), | 98 counter_list[i].name); |
| 101 "new_space_live_bytes"); | 99 } |
| 102 AddNumber(args.GetIsolate(), result, heap->new_space()->Available(), | 100 |
| 103 "new_space_available_bytes"); | 101 struct StatisticNumber { |
| 104 AddNumber(args.GetIsolate(), result, heap->new_space()->CommittedMemory(), | 102 intptr_t number; |
| 105 "new_space_commited_bytes"); | 103 const char* name; |
| 106 AddNumber(args.GetIsolate(), result, heap->old_pointer_space()->Size(), | 104 }; |
| 107 "old_pointer_space_live_bytes"); | 105 |
| 108 AddNumber(args.GetIsolate(), result, heap->old_pointer_space()->Available(), | 106 const StatisticNumber numbers[] = { |
| 109 "old_pointer_space_available_bytes"); | 107 {isolate->memory_allocator()->Size(), "total_committed_bytes"}, |
| 110 AddNumber(args.GetIsolate(), result, | 108 {heap->new_space()->Size(), "new_space_live_bytes"}, |
| 111 heap->old_pointer_space()->CommittedMemory(), | 109 {heap->new_space()->Available(), "new_space_available_bytes"}, |
| 112 "old_pointer_space_commited_bytes"); | 110 {heap->new_space()->CommittedMemory(), "new_space_commited_bytes"}, |
| 113 AddNumber(args.GetIsolate(), result, heap->old_data_space()->Size(), | 111 {heap->old_pointer_space()->Size(), "old_pointer_space_live_bytes"}, |
| 114 "old_data_space_live_bytes"); | 112 {heap->old_pointer_space()->Available(), |
| 115 AddNumber(args.GetIsolate(), result, heap->old_data_space()->Available(), | 113 "old_pointer_space_available_bytes"}, |
| 116 "old_data_space_available_bytes"); | 114 {heap->old_pointer_space()->CommittedMemory(), |
| 117 AddNumber(args.GetIsolate(), result, | 115 "old_pointer_space_commited_bytes"}, |
| 118 heap->old_data_space()->CommittedMemory(), | 116 {heap->old_data_space()->Size(), "old_data_space_live_bytes"}, |
| 119 "old_data_space_commited_bytes"); | 117 {heap->old_data_space()->Available(), "old_data_space_available_bytes"}, |
| 120 AddNumber(args.GetIsolate(), result, heap->code_space()->Size(), | 118 {heap->old_data_space()->CommittedMemory(), |
| 121 "code_space_live_bytes"); | 119 "old_data_space_commited_bytes"}, |
| 122 AddNumber(args.GetIsolate(), result, heap->code_space()->Available(), | 120 {heap->code_space()->Size(), "code_space_live_bytes"}, |
| 123 "code_space_available_bytes"); | 121 {heap->code_space()->Available(), "code_space_available_bytes"}, |
| 124 AddNumber(args.GetIsolate(), result, heap->code_space()->CommittedMemory(), | 122 {heap->code_space()->CommittedMemory(), "code_space_commited_bytes"}, |
| 125 "code_space_commited_bytes"); | 123 {heap->cell_space()->Size(), "cell_space_live_bytes"}, |
| 126 AddNumber(args.GetIsolate(), result, heap->cell_space()->Size(), | 124 {heap->cell_space()->Available(), "cell_space_available_bytes"}, |
| 127 "cell_space_live_bytes"); | 125 {heap->cell_space()->CommittedMemory(), "cell_space_commited_bytes"}, |
| 128 AddNumber(args.GetIsolate(), result, heap->cell_space()->Available(), | 126 {heap->property_cell_space()->Size(), "property_cell_space_live_bytes"}, |
| 129 "cell_space_available_bytes"); | 127 {heap->property_cell_space()->Available(), |
| 130 AddNumber(args.GetIsolate(), result, heap->cell_space()->CommittedMemory(), | 128 "property_cell_space_available_bytes"}, |
| 131 "cell_space_commited_bytes"); | 129 {heap->property_cell_space()->CommittedMemory(), |
| 132 AddNumber(args.GetIsolate(), result, heap->property_cell_space()->Size(), | 130 "property_cell_space_commited_bytes"}, |
| 133 "property_cell_space_live_bytes"); | 131 {heap->lo_space()->Size(), "lo_space_live_bytes"}, |
| 134 AddNumber(args.GetIsolate(), result, heap->property_cell_space()->Available(), | 132 {heap->lo_space()->Available(), "lo_space_available_bytes"}, |
| 135 "property_cell_space_available_bytes"); | 133 {heap->lo_space()->CommittedMemory(), "lo_space_commited_bytes"}, |
| 136 AddNumber(args.GetIsolate(), result, | 134 }; |
| 137 heap->property_cell_space()->CommittedMemory(), | 135 |
| 138 "property_cell_space_commited_bytes"); | 136 for (size_t i = 0; i < arraysize(numbers); i++) { |
| 139 AddNumber(args.GetIsolate(), result, heap->lo_space()->Size(), | 137 AddNumber(args.GetIsolate(), result, numbers[i].number, numbers[i].name); |
| 140 "lo_space_live_bytes"); | 138 } |
| 141 AddNumber(args.GetIsolate(), result, heap->lo_space()->Available(), | 139 |
| 142 "lo_space_available_bytes"); | |
| 143 AddNumber(args.GetIsolate(), result, heap->lo_space()->CommittedMemory(), | |
| 144 "lo_space_commited_bytes"); | |
| 145 AddNumber64(args.GetIsolate(), result, | 140 AddNumber64(args.GetIsolate(), result, |
| 146 heap->amount_of_external_allocated_memory(), | 141 heap->amount_of_external_allocated_memory(), |
| 147 "amount_of_external_allocated_memory"); | 142 "amount_of_external_allocated_memory"); |
| 148 args.GetReturnValue().Set(result); | 143 args.GetReturnValue().Set(result); |
| 149 } | 144 } |
| 150 | 145 |
| 151 } } // namespace v8::internal | 146 } } // namespace v8::internal |
| OLD | NEW |