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 constexpr RuntimeCallStats::CounterId RuntimeCallStats::counters[]; |
| 294 |
287 // static | 295 // static |
288 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, | 296 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, |
289 CounterId counter_id) { | 297 CounterId counter_id) { |
290 RuntimeCallCounter* counter = &(stats->*counter_id); | 298 RuntimeCallCounter* counter = &(stats->*counter_id); |
| 299 DCHECK(counter->name != NULL); |
291 timer->Start(counter, stats->current_timer_.Value()); | 300 timer->Start(counter, stats->current_timer_.Value()); |
292 stats->current_timer_.SetValue(timer); | 301 stats->current_timer_.SetValue(timer); |
293 } | 302 } |
294 | 303 |
295 // static | 304 // static |
296 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { | 305 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { |
297 if (stats->current_timer_.Value() == timer) { | 306 if (stats->current_timer_.Value() == timer) { |
298 stats->current_timer_.SetValue(timer->Stop()); | 307 stats->current_timer_.SetValue(timer->Stop()); |
299 } else { | 308 } else { |
300 // Must be a Threading cctest. Walk the chain of Timers to find the | 309 // 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 | 310 // buried one that's leaving. We don't care about keeping nested timings |
302 // accurate, just avoid crashing by keeping the chain intact. | 311 // accurate, just avoid crashing by keeping the chain intact. |
303 RuntimeCallTimer* next = stats->current_timer_.Value(); | 312 RuntimeCallTimer* next = stats->current_timer_.Value(); |
304 while (next && next->parent() != timer) next = next->parent(); | 313 while (next->parent() != timer) next = next->parent(); |
305 if (next == nullptr) return; | |
306 next->parent_.SetValue(timer->Stop()); | 314 next->parent_.SetValue(timer->Stop()); |
307 } | 315 } |
308 } | 316 } |
309 | 317 |
| 318 void RuntimeCallStats::Add(RuntimeCallStats* other) { |
| 319 for (const RuntimeCallStats::CounterId counter_id : |
| 320 RuntimeCallStats::counters) { |
| 321 RuntimeCallCounter* counter = &(this->*counter_id); |
| 322 RuntimeCallCounter* other_counter = &(other->*counter_id); |
| 323 counter->Add(other_counter); |
| 324 } |
| 325 } |
| 326 |
310 // static | 327 // static |
311 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, | 328 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, |
312 CounterId counter_id) { | 329 CounterId counter_id) { |
313 RuntimeCallTimer* timer = stats->current_timer_.Value(); | 330 RuntimeCallTimer* timer = stats->current_timer_.Value(); |
314 // When RCS are enabled dynamically there might be no current timer set up. | 331 // When RCS are enabled dynamically there might be no current timer set up. |
315 if (timer == nullptr) return; | 332 if (timer == nullptr) return; |
316 timer->counter_ = &(stats->*counter_id); | 333 timer->counter_ = &(stats->*counter_id); |
317 } | 334 } |
318 | 335 |
319 void RuntimeCallStats::Print(std::ostream& os) { | 336 void RuntimeCallStats::Print(std::ostream& os) { |
320 RuntimeCallStatEntries entries; | 337 RuntimeCallStatEntries entries; |
321 if (current_timer_.Value() != nullptr) { | 338 if (current_timer_.Value() != nullptr) { |
322 current_timer_.Value()->Elapsed(); | 339 current_timer_.Value()->Elapsed(); |
323 } | 340 } |
324 | 341 for (const RuntimeCallStats::CounterId counter_id : |
325 #define PRINT_COUNTER(name) entries.Add(&this->name); | 342 RuntimeCallStats::counters) { |
326 FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) | 343 RuntimeCallCounter* counter = &(this->*counter_id); |
327 #undef PRINT_COUNTER | 344 entries.Add(counter); |
328 | 345 } |
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); | 346 entries.Print(os); |
346 } | 347 } |
347 | 348 |
348 void RuntimeCallStats::Reset() { | 349 void RuntimeCallStats::Reset() { |
349 if (V8_LIKELY(FLAG_runtime_stats == 0)) return; | 350 if (V8_LIKELY(FLAG_runtime_stats == 0)) return; |
350 | 351 |
351 // In tracing, we only what to trace the time spent on top level trace events, | 352 // 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 | 353 // 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 | 354 // counter stack, and then reset counters so that we can dump counters into |
354 // top level trace events accurately. | 355 // top level trace events accurately. |
355 while (current_timer_.Value()) { | 356 while (current_timer_.Value()) { |
356 current_timer_.SetValue(current_timer_.Value()->Stop()); | 357 current_timer_.SetValue(current_timer_.Value()->Stop()); |
357 } | 358 } |
358 | 359 |
359 #define RESET_COUNTER(name) this->name.Reset(); | 360 for (const RuntimeCallStats::CounterId counter_id : |
360 FOR_EACH_MANUAL_COUNTER(RESET_COUNTER) | 361 RuntimeCallStats::counters) { |
361 #undef RESET_COUNTER | 362 RuntimeCallCounter* counter = &(this->*counter_id); |
362 | 363 counter->Reset(); |
363 #define RESET_COUNTER(name, nargs, result_size) this->Runtime_##name.Reset(); | 364 } |
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 | 365 |
379 in_use_ = true; | 366 in_use_ = true; |
380 } | 367 } |
381 | 368 |
382 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { | 369 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { |
383 #define DUMP_COUNTER(name) \ | 370 for (const RuntimeCallStats::CounterId counter_id : |
384 if (this->name.count > 0) this->name.Dump(value); | 371 RuntimeCallStats::counters) { |
385 FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER) | 372 RuntimeCallCounter* counter = &(this->*counter_id); |
386 #undef DUMP_COUNTER | 373 if (counter->count > 0) counter->Dump(value); |
387 | 374 } |
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 | 375 |
408 in_use_ = false; | 376 in_use_ = false; |
409 } | 377 } |
410 | 378 |
411 } // namespace internal | 379 } // namespace internal |
412 } // namespace v8 | 380 } // namespace v8 |
OLD | NEW |