| 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/counters.h" | 5 #include "src/counters.h" |
| 6 | 6 |
| 7 #include <iomanip> | 7 #include <iomanip> |
| 8 | 8 |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 time = base::TimeDelta(); | 277 time = base::TimeDelta(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { | 280 void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { |
| 281 value->BeginArray(name); | 281 value->BeginArray(name); |
| 282 value->AppendLongInteger(count); | 282 value->AppendLongInteger(count); |
| 283 value->AppendLongInteger(time.InMicroseconds()); | 283 value->AppendLongInteger(time.InMicroseconds()); |
| 284 value->EndArray(); | 284 value->EndArray(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 void RuntimeCallCounter::Add(RuntimeCallCounter* other) { |
| 288 count += other->count; |
| 289 time += other->time; |
| 290 } |
| 291 |
| 292 // static |
| 293 const RuntimeCallStats::CounterId RuntimeCallStats::counters[] = { |
| 294 #define CALL_RUNTIME_COUNTER(name) &RuntimeCallStats::name, |
| 295 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) // |
| 296 #undef CALL_RUNTIME_COUNTER |
| 297 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ |
| 298 &RuntimeCallStats::Runtime_##name, // |
| 299 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) // |
| 300 #undef CALL_RUNTIME_COUNTER |
| 301 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Builtin_##name, |
| 302 BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) // |
| 303 #undef CALL_BUILTIN_COUNTER |
| 304 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::API_##name, |
| 305 FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) // |
| 306 #undef CALL_BUILTIN_COUNTER |
| 307 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Handler_##name, |
| 308 FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) |
| 309 #undef CALL_BUILTIN_COUNTER |
| 310 }; |
| 311 |
| 287 // static | 312 // static |
| 288 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, | 313 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, |
| 289 CounterId counter_id) { | 314 CounterId counter_id) { |
| 290 RuntimeCallCounter* counter = &(stats->*counter_id); | 315 RuntimeCallCounter* counter = &(stats->*counter_id); |
| 316 DCHECK(counter->name != NULL); |
| 291 timer->Start(counter, stats->current_timer_.Value()); | 317 timer->Start(counter, stats->current_timer_.Value()); |
| 292 stats->current_timer_.SetValue(timer); | 318 stats->current_timer_.SetValue(timer); |
| 293 } | 319 } |
| 294 | 320 |
| 295 // static | 321 // static |
| 296 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { | 322 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { |
| 297 if (stats->current_timer_.Value() == timer) { | 323 if (stats->current_timer_.Value() == timer) { |
| 298 stats->current_timer_.SetValue(timer->Stop()); | 324 stats->current_timer_.SetValue(timer->Stop()); |
| 299 } else { | 325 } else { |
| 300 // Must be a Threading cctest. Walk the chain of Timers to find the | 326 // Must be a Threading cctest. Walk the chain of Timers to find the |
| 301 // buried one that's leaving. We don't care about keeping nested timings | 327 // buried one that's leaving. We don't care about keeping nested timings |
| 302 // accurate, just avoid crashing by keeping the chain intact. | 328 // accurate, just avoid crashing by keeping the chain intact. |
| 303 RuntimeCallTimer* next = stats->current_timer_.Value(); | 329 RuntimeCallTimer* next = stats->current_timer_.Value(); |
| 304 while (next && next->parent() != timer) next = next->parent(); | 330 while (next->parent() != timer) next = next->parent(); |
| 305 if (next == nullptr) return; | |
| 306 next->parent_.SetValue(timer->Stop()); | 331 next->parent_.SetValue(timer->Stop()); |
| 307 } | 332 } |
| 308 } | 333 } |
| 309 | 334 |
| 335 void RuntimeCallStats::Add(RuntimeCallStats* other) { |
| 336 for (const RuntimeCallStats::CounterId counter_id : |
| 337 RuntimeCallStats::counters) { |
| 338 RuntimeCallCounter* counter = &(this->*counter_id); |
| 339 RuntimeCallCounter* other_counter = &(other->*counter_id); |
| 340 counter->Add(other_counter); |
| 341 } |
| 342 } |
| 343 |
| 310 // static | 344 // static |
| 311 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, | 345 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, |
| 312 CounterId counter_id) { | 346 CounterId counter_id) { |
| 313 RuntimeCallTimer* timer = stats->current_timer_.Value(); | 347 RuntimeCallTimer* timer = stats->current_timer_.Value(); |
| 314 // When RCS are enabled dynamically there might be no current timer set up. | 348 // When RCS are enabled dynamically there might be no current timer set up. |
| 315 if (timer == nullptr) return; | 349 if (timer == nullptr) return; |
| 316 timer->counter_ = &(stats->*counter_id); | 350 timer->counter_ = &(stats->*counter_id); |
| 317 } | 351 } |
| 318 | 352 |
| 319 void RuntimeCallStats::Print(std::ostream& os) { | 353 void RuntimeCallStats::Print(std::ostream& os) { |
| 320 RuntimeCallStatEntries entries; | 354 RuntimeCallStatEntries entries; |
| 321 if (current_timer_.Value() != nullptr) { | 355 if (current_timer_.Value() != nullptr) { |
| 322 current_timer_.Value()->Elapsed(); | 356 current_timer_.Value()->Elapsed(); |
| 323 } | 357 } |
| 324 | 358 for (const RuntimeCallStats::CounterId counter_id : |
| 325 #define PRINT_COUNTER(name) entries.Add(&this->name); | 359 RuntimeCallStats::counters) { |
| 326 FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) | 360 RuntimeCallCounter* counter = &(this->*counter_id); |
| 327 #undef PRINT_COUNTER | 361 entries.Add(counter); |
| 328 | 362 } |
| 329 #define PRINT_COUNTER(name, nargs, ressize) entries.Add(&this->Runtime_##name); | |
| 330 FOR_EACH_INTRINSIC(PRINT_COUNTER) | |
| 331 #undef PRINT_COUNTER | |
| 332 | |
| 333 #define PRINT_COUNTER(name) entries.Add(&this->Builtin_##name); | |
| 334 BUILTIN_LIST_C(PRINT_COUNTER) | |
| 335 #undef PRINT_COUNTER | |
| 336 | |
| 337 #define PRINT_COUNTER(name) entries.Add(&this->API_##name); | |
| 338 FOR_EACH_API_COUNTER(PRINT_COUNTER) | |
| 339 #undef PRINT_COUNTER | |
| 340 | |
| 341 #define PRINT_COUNTER(name) entries.Add(&this->Handler_##name); | |
| 342 FOR_EACH_HANDLER_COUNTER(PRINT_COUNTER) | |
| 343 #undef PRINT_COUNTER | |
| 344 | |
| 345 entries.Print(os); | 363 entries.Print(os); |
| 346 } | 364 } |
| 347 | 365 |
| 348 void RuntimeCallStats::Reset() { | 366 void RuntimeCallStats::Reset() { |
| 349 if (V8_LIKELY(FLAG_runtime_stats == 0)) return; | 367 if (V8_LIKELY(FLAG_runtime_stats == 0)) return; |
| 350 | 368 |
| 351 // In tracing, we only what to trace the time spent on top level trace events, | 369 // In tracing, we only what to trace the time spent on top level trace events, |
| 352 // if runtime counter stack is not empty, we should clear the whole runtime | 370 // if runtime counter stack is not empty, we should clear the whole runtime |
| 353 // counter stack, and then reset counters so that we can dump counters into | 371 // counter stack, and then reset counters so that we can dump counters into |
| 354 // top level trace events accurately. | 372 // top level trace events accurately. |
| 355 while (current_timer_.Value()) { | 373 while (current_timer_.Value()) { |
| 356 current_timer_.SetValue(current_timer_.Value()->Stop()); | 374 current_timer_.SetValue(current_timer_.Value()->Stop()); |
| 357 } | 375 } |
| 358 | 376 |
| 359 #define RESET_COUNTER(name) this->name.Reset(); | 377 for (const RuntimeCallStats::CounterId counter_id : |
| 360 FOR_EACH_MANUAL_COUNTER(RESET_COUNTER) | 378 RuntimeCallStats::counters) { |
| 361 #undef RESET_COUNTER | 379 RuntimeCallCounter* counter = &(this->*counter_id); |
| 362 | 380 counter->Reset(); |
| 363 #define RESET_COUNTER(name, nargs, result_size) this->Runtime_##name.Reset(); | 381 } |
| 364 FOR_EACH_INTRINSIC(RESET_COUNTER) | |
| 365 #undef RESET_COUNTER | |
| 366 | |
| 367 #define RESET_COUNTER(name) this->Builtin_##name.Reset(); | |
| 368 BUILTIN_LIST_C(RESET_COUNTER) | |
| 369 #undef RESET_COUNTER | |
| 370 | |
| 371 #define RESET_COUNTER(name) this->API_##name.Reset(); | |
| 372 FOR_EACH_API_COUNTER(RESET_COUNTER) | |
| 373 #undef RESET_COUNTER | |
| 374 | |
| 375 #define RESET_COUNTER(name) this->Handler_##name.Reset(); | |
| 376 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) | |
| 377 #undef RESET_COUNTER | |
| 378 | 382 |
| 379 in_use_ = true; | 383 in_use_ = true; |
| 380 } | 384 } |
| 381 | 385 |
| 382 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { | 386 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { |
| 383 #define DUMP_COUNTER(name) \ | 387 for (const RuntimeCallStats::CounterId counter_id : |
| 384 if (this->name.count > 0) this->name.Dump(value); | 388 RuntimeCallStats::counters) { |
| 385 FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER) | 389 RuntimeCallCounter* counter = &(this->*counter_id); |
| 386 #undef DUMP_COUNTER | 390 if (counter->count > 0) counter->Dump(value); |
| 387 | 391 } |
| 388 #define DUMP_COUNTER(name, nargs, result_size) \ | |
| 389 if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(value); | |
| 390 FOR_EACH_INTRINSIC(DUMP_COUNTER) | |
| 391 #undef DUMP_COUNTER | |
| 392 | |
| 393 #define DUMP_COUNTER(name) \ | |
| 394 if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(value); | |
| 395 BUILTIN_LIST_C(DUMP_COUNTER) | |
| 396 #undef DUMP_COUNTER | |
| 397 | |
| 398 #define DUMP_COUNTER(name) \ | |
| 399 if (this->API_##name.count > 0) this->API_##name.Dump(value); | |
| 400 FOR_EACH_API_COUNTER(DUMP_COUNTER) | |
| 401 #undef DUMP_COUNTER | |
| 402 | |
| 403 #define DUMP_COUNTER(name) \ | |
| 404 if (this->Handler_##name.count > 0) this->Handler_##name.Dump(value); | |
| 405 FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER) | |
| 406 #undef DUMP_COUNTER | |
| 407 | 392 |
| 408 in_use_ = false; | 393 in_use_ = false; |
| 409 } | 394 } |
| 410 | 395 |
| 411 } // namespace internal | 396 } // namespace internal |
| 412 } // namespace v8 | 397 } // namespace v8 |
| OLD | NEW |