OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/heap/object-stats.h" |
| 6 |
| 7 #include "src/counters.h" |
| 8 #include "src/heap/heap-inl.h" |
| 9 #include "src/isolate.h" |
| 10 #include "src/utils.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 |
| 15 static base::LazyMutex object_stats_mutex = LAZY_MUTEX_INITIALIZER; |
| 16 |
| 17 |
| 18 void ObjectStats::ClearObjectStats(bool clear_last_time_stats) { |
| 19 memset(object_counts_, 0, sizeof(object_counts_)); |
| 20 memset(object_sizes_, 0, sizeof(object_sizes_)); |
| 21 if (clear_last_time_stats) { |
| 22 memset(object_counts_last_time_, 0, sizeof(object_counts_last_time_)); |
| 23 memset(object_sizes_last_time_, 0, sizeof(object_sizes_last_time_)); |
| 24 } |
| 25 } |
| 26 |
| 27 |
| 28 void ObjectStats::TraceObjectStat(const char* name, int count, int size, |
| 29 double time) { |
| 30 int ms_count = heap()->ms_count(); |
| 31 PrintIsolate(isolate(), |
| 32 "heap:%p, time:%f, gc:%d, type:%s, count:%d, size:%d\n", |
| 33 static_cast<void*>(heap()), time, ms_count, name, count, size); |
| 34 } |
| 35 |
| 36 |
| 37 void ObjectStats::TraceObjectStats() { |
| 38 base::LockGuard<base::Mutex> lock_guard(object_stats_mutex.Pointer()); |
| 39 int index; |
| 40 int count; |
| 41 int size; |
| 42 int total_size = 0; |
| 43 double time = isolate()->time_millis_since_init(); |
| 44 #define TRACE_OBJECT_COUNT(name) \ |
| 45 count = static_cast<int>(object_counts_[name]); \ |
| 46 size = static_cast<int>(object_sizes_[name]) / KB; \ |
| 47 total_size += size; \ |
| 48 TraceObjectStat(#name, count, size, time); |
| 49 INSTANCE_TYPE_LIST(TRACE_OBJECT_COUNT) |
| 50 #undef TRACE_OBJECT_COUNT |
| 51 #define TRACE_OBJECT_COUNT(name) \ |
| 52 index = FIRST_CODE_KIND_SUB_TYPE + Code::name; \ |
| 53 count = static_cast<int>(object_counts_[index]); \ |
| 54 size = static_cast<int>(object_sizes_[index]) / KB; \ |
| 55 TraceObjectStat("*CODE_" #name, count, size, time); |
| 56 CODE_KIND_LIST(TRACE_OBJECT_COUNT) |
| 57 #undef TRACE_OBJECT_COUNT |
| 58 #define TRACE_OBJECT_COUNT(name) \ |
| 59 index = FIRST_FIXED_ARRAY_SUB_TYPE + name; \ |
| 60 count = static_cast<int>(object_counts_[index]); \ |
| 61 size = static_cast<int>(object_sizes_[index]) / KB; \ |
| 62 TraceObjectStat("*FIXED_ARRAY_" #name, count, size, time); |
| 63 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(TRACE_OBJECT_COUNT) |
| 64 #undef TRACE_OBJECT_COUNT |
| 65 #define TRACE_OBJECT_COUNT(name) \ |
| 66 index = \ |
| 67 FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge; \ |
| 68 count = static_cast<int>(object_counts_[index]); \ |
| 69 size = static_cast<int>(object_sizes_[index]) / KB; \ |
| 70 TraceObjectStat("*CODE_AGE_" #name, count, size, time); |
| 71 CODE_AGE_LIST_COMPLETE(TRACE_OBJECT_COUNT) |
| 72 #undef TRACE_OBJECT_COUNT |
| 73 } |
| 74 |
| 75 |
| 76 void ObjectStats::CheckpointObjectStats() { |
| 77 base::LockGuard<base::Mutex> lock_guard(object_stats_mutex.Pointer()); |
| 78 Counters* counters = isolate()->counters(); |
| 79 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
| 80 counters->count_of_##name()->Increment( \ |
| 81 static_cast<int>(object_counts_[name])); \ |
| 82 counters->count_of_##name()->Decrement( \ |
| 83 static_cast<int>(object_counts_last_time_[name])); \ |
| 84 counters->size_of_##name()->Increment( \ |
| 85 static_cast<int>(object_sizes_[name])); \ |
| 86 counters->size_of_##name()->Decrement( \ |
| 87 static_cast<int>(object_sizes_last_time_[name])); |
| 88 INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 89 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 90 int index; |
| 91 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
| 92 index = FIRST_CODE_KIND_SUB_TYPE + Code::name; \ |
| 93 counters->count_of_CODE_TYPE_##name()->Increment( \ |
| 94 static_cast<int>(object_counts_[index])); \ |
| 95 counters->count_of_CODE_TYPE_##name()->Decrement( \ |
| 96 static_cast<int>(object_counts_last_time_[index])); \ |
| 97 counters->size_of_CODE_TYPE_##name()->Increment( \ |
| 98 static_cast<int>(object_sizes_[index])); \ |
| 99 counters->size_of_CODE_TYPE_##name()->Decrement( \ |
| 100 static_cast<int>(object_sizes_last_time_[index])); |
| 101 CODE_KIND_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 102 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 103 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
| 104 index = FIRST_FIXED_ARRAY_SUB_TYPE + name; \ |
| 105 counters->count_of_FIXED_ARRAY_##name()->Increment( \ |
| 106 static_cast<int>(object_counts_[index])); \ |
| 107 counters->count_of_FIXED_ARRAY_##name()->Decrement( \ |
| 108 static_cast<int>(object_counts_last_time_[index])); \ |
| 109 counters->size_of_FIXED_ARRAY_##name()->Increment( \ |
| 110 static_cast<int>(object_sizes_[index])); \ |
| 111 counters->size_of_FIXED_ARRAY_##name()->Decrement( \ |
| 112 static_cast<int>(object_sizes_last_time_[index])); |
| 113 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 114 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 115 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
| 116 index = \ |
| 117 FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge; \ |
| 118 counters->count_of_CODE_AGE_##name()->Increment( \ |
| 119 static_cast<int>(object_counts_[index])); \ |
| 120 counters->count_of_CODE_AGE_##name()->Decrement( \ |
| 121 static_cast<int>(object_counts_last_time_[index])); \ |
| 122 counters->size_of_CODE_AGE_##name()->Increment( \ |
| 123 static_cast<int>(object_sizes_[index])); \ |
| 124 counters->size_of_CODE_AGE_##name()->Decrement( \ |
| 125 static_cast<int>(object_sizes_last_time_[index])); |
| 126 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 127 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 128 |
| 129 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 130 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 131 ClearObjectStats(); |
| 132 } |
| 133 |
| 134 |
| 135 Isolate* ObjectStats::isolate() { return heap()->isolate(); } |
| 136 |
| 137 } // namespace internal |
| 138 } // namespace v8 |
OLD | NEW |