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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 6235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6246 void Heap::ClearObjectStats(bool clear_last_time_stats) { | 6246 void Heap::ClearObjectStats(bool clear_last_time_stats) { |
6247 memset(object_counts_, 0, sizeof(object_counts_)); | 6247 memset(object_counts_, 0, sizeof(object_counts_)); |
6248 memset(object_sizes_, 0, sizeof(object_sizes_)); | 6248 memset(object_sizes_, 0, sizeof(object_sizes_)); |
6249 if (clear_last_time_stats) { | 6249 if (clear_last_time_stats) { |
6250 memset(object_counts_last_time_, 0, sizeof(object_counts_last_time_)); | 6250 memset(object_counts_last_time_, 0, sizeof(object_counts_last_time_)); |
6251 memset(object_sizes_last_time_, 0, sizeof(object_sizes_last_time_)); | 6251 memset(object_sizes_last_time_, 0, sizeof(object_sizes_last_time_)); |
6252 } | 6252 } |
6253 } | 6253 } |
6254 | 6254 |
6255 | 6255 |
6256 static base::LazyMutex checkpoint_object_stats_mutex = LAZY_MUTEX_INITIALIZER; | 6256 static base::LazyMutex object_stats_mutex = LAZY_MUTEX_INITIALIZER; |
| 6257 |
| 6258 |
| 6259 static void TraceObjectStat(const char* name, int count, int size) { |
| 6260 if (size > 0) { |
| 6261 PrintF("%40s\tcount= %6d\t size= %6d kb\n", name, count, size); |
| 6262 } |
| 6263 } |
| 6264 |
| 6265 |
| 6266 void Heap::TraceObjectStats() { |
| 6267 base::LockGuard<base::Mutex> lock_guard(object_stats_mutex.Pointer()); |
| 6268 int index; |
| 6269 int count; |
| 6270 int size; |
| 6271 int total_size = 0; |
| 6272 #define TRACE_OBJECT_COUNT(name) \ |
| 6273 count = static_cast<int>(object_counts_[name]); \ |
| 6274 size = static_cast<int>(object_sizes_[name]) / KB; \ |
| 6275 total_size += size; \ |
| 6276 TraceObjectStat(#name, count, size); |
| 6277 INSTANCE_TYPE_LIST(TRACE_OBJECT_COUNT) |
| 6278 #undef TRACE_OBJECT_COUNT |
| 6279 #define TRACE_OBJECT_COUNT(name) \ |
| 6280 index = FIRST_CODE_KIND_SUB_TYPE + Code::name; \ |
| 6281 count = static_cast<int>(object_counts_[index]); \ |
| 6282 size = static_cast<int>(object_sizes_[index]) / KB; \ |
| 6283 TraceObjectStat("CODE_" #name, count, size); |
| 6284 CODE_KIND_LIST(TRACE_OBJECT_COUNT) |
| 6285 #undef TRACE_OBJECT_COUNT |
| 6286 #define TRACE_OBJECT_COUNT(name) \ |
| 6287 index = FIRST_FIXED_ARRAY_SUB_TYPE + name; \ |
| 6288 count = static_cast<int>(object_counts_[index]); \ |
| 6289 size = static_cast<int>(object_sizes_[index]) / KB; \ |
| 6290 TraceObjectStat("FIXED_ARRAY_" #name, count, size); |
| 6291 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(TRACE_OBJECT_COUNT) |
| 6292 #undef TRACE_OBJECT_COUNT |
| 6293 #define TRACE_OBJECT_COUNT(name) \ |
| 6294 index = \ |
| 6295 FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge; \ |
| 6296 count = static_cast<int>(object_counts_[index]); \ |
| 6297 size = static_cast<int>(object_sizes_[index]) / KB; \ |
| 6298 TraceObjectStat("CODE_AGE_" #name, count, size); |
| 6299 CODE_AGE_LIST_COMPLETE(TRACE_OBJECT_COUNT) |
| 6300 #undef TRACE_OBJECT_COUNT |
| 6301 PrintF("Total size= %d kb\n", total_size); |
| 6302 } |
6257 | 6303 |
6258 | 6304 |
6259 void Heap::CheckpointObjectStats() { | 6305 void Heap::CheckpointObjectStats() { |
6260 base::LockGuard<base::Mutex> lock_guard( | 6306 base::LockGuard<base::Mutex> lock_guard(object_stats_mutex.Pointer()); |
6261 checkpoint_object_stats_mutex.Pointer()); | |
6262 Counters* counters = isolate()->counters(); | 6307 Counters* counters = isolate()->counters(); |
6263 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ | 6308 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
6264 counters->count_of_##name()->Increment( \ | 6309 counters->count_of_##name()->Increment( \ |
6265 static_cast<int>(object_counts_[name])); \ | 6310 static_cast<int>(object_counts_[name])); \ |
6266 counters->count_of_##name()->Decrement( \ | 6311 counters->count_of_##name()->Decrement( \ |
6267 static_cast<int>(object_counts_last_time_[name])); \ | 6312 static_cast<int>(object_counts_last_time_[name])); \ |
6268 counters->size_of_##name()->Increment( \ | 6313 counters->size_of_##name()->Increment( \ |
6269 static_cast<int>(object_sizes_[name])); \ | 6314 static_cast<int>(object_sizes_[name])); \ |
6270 counters->size_of_##name()->Decrement( \ | 6315 counters->size_of_##name()->Decrement( \ |
6271 static_cast<int>(object_sizes_last_time_[name])); | 6316 static_cast<int>(object_sizes_last_time_[name])); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6309 static_cast<int>(object_sizes_last_time_[index])); | 6354 static_cast<int>(object_sizes_last_time_[index])); |
6310 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6355 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
6311 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6356 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
6312 | 6357 |
6313 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6358 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
6314 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6359 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
6315 ClearObjectStats(); | 6360 ClearObjectStats(); |
6316 } | 6361 } |
6317 } | 6362 } |
6318 } // namespace v8::internal | 6363 } // namespace v8::internal |
OLD | NEW |