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 #ifndef V8_COUNTERS_H_ | 5 #ifndef V8_COUNTERS_H_ |
6 #define V8_COUNTERS_H_ | 6 #define V8_COUNTERS_H_ |
7 | 7 |
8 #include "include/v8.h" | 8 #include "include/v8.h" |
9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
10 #include "src/base/atomic-utils.h" | 10 #include "src/base/atomic-utils.h" |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 double current_value) { | 477 double current_value) { |
478 double interval_ms = current_ms - start_ms_; | 478 double interval_ms = current_ms - start_ms_; |
479 double value = (current_value + last_value_) / 2; | 479 double value = (current_value + last_value_) / 2; |
480 // The aggregate_value_ is the average for [start_ms_; last_ms_]. | 480 // The aggregate_value_ is the average for [start_ms_; last_ms_]. |
481 // The value is the average for [last_ms_; current_ms]. | 481 // The value is the average for [last_ms_; current_ms]. |
482 // Return the weighted average of the aggregate_value_ and the value. | 482 // Return the weighted average of the aggregate_value_ and the value. |
483 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) + | 483 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) + |
484 value * ((current_ms - last_ms_) / interval_ms); | 484 value * ((current_ms - last_ms_) / interval_ms); |
485 } | 485 } |
486 | 486 |
487 struct RuntimeCallCounter { | 487 class RuntimeCallCounter final { |
488 explicit RuntimeCallCounter(const char* name) : name(name) {} | 488 public: |
| 489 explicit RuntimeCallCounter(const char* name) : name_(name) {} |
489 V8_NOINLINE void Reset(); | 490 V8_NOINLINE void Reset(); |
490 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); | 491 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); |
491 void Add(RuntimeCallCounter* other); | 492 void Add(RuntimeCallCounter* other); |
492 | 493 |
493 const char* name; | 494 const char* name() const { return name_; } |
494 int64_t count = 0; | 495 int64_t count() const { return count_; } |
495 base::TimeDelta time; | 496 base::TimeDelta time() const { return time_; } |
| 497 void Increment() { count_++; } |
| 498 void Add(base::TimeDelta delta) { time_ += delta; } |
| 499 |
| 500 private: |
| 501 const char* name_; |
| 502 int64_t count_ = 0; |
| 503 base::TimeDelta time_; |
496 }; | 504 }; |
497 | 505 |
498 // RuntimeCallTimer is used to keep track of the stack of currently active | 506 // RuntimeCallTimer is used to keep track of the stack of currently active |
499 // timers used for properly measuring the own time of a RuntimeCallCounter. | 507 // timers used for properly measuring the own time of a RuntimeCallCounter. |
500 class RuntimeCallTimer { | 508 class RuntimeCallTimer final { |
501 public: | 509 public: |
502 RuntimeCallCounter* counter() { return counter_; } | 510 RuntimeCallCounter* counter() { return counter_; } |
503 base::ElapsedTimer timer() { return timer_; } | 511 base::ElapsedTimer timer() const { return timer_; } |
504 RuntimeCallTimer* parent() const { return parent_.Value(); } | 512 RuntimeCallTimer* parent() const { return parent_.Value(); } |
| 513 const char* name() const { return counter_->name(); } |
505 | 514 |
506 private: | 515 private: |
507 friend class RuntimeCallStats; | 516 friend class RuntimeCallStats; |
508 | 517 |
509 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent) { | 518 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent); |
510 counter_ = counter; | 519 inline RuntimeCallTimer* Stop(); |
511 parent_.SetValue(parent); | 520 base::TimeDelta Restart(base::TimeTicks now) { return timer_.Restart(now); } |
512 if (FLAG_runtime_stats != | 521 // Synchronize the currently active timer stack. Walk up the stack by stopping |
513 v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) { | 522 // and restarting each timer. |
514 timer_.Start(); | 523 void Snapshot(); |
515 } | 524 void SubtractSubtime(base::TimeDelta delta) { subtime_ += delta; } |
| 525 void AddAndSubmitResults(base::TimeDelta delta) { |
| 526 counter_->Add(delta - subtime_); |
| 527 subtime_ = base::TimeDelta(); |
516 } | 528 } |
517 | 529 |
518 inline RuntimeCallTimer* Stop() { | |
519 if (!timer_.IsStarted()) return parent(); | |
520 base::TimeDelta delta = timer_.Elapsed(); | |
521 timer_.Stop(); | |
522 counter_->count++; | |
523 counter_->time += delta; | |
524 if (parent()) { | |
525 // Adjust parent timer so that it does not include sub timer's time. | |
526 parent()->counter_->time -= delta; | |
527 } | |
528 return parent(); | |
529 } | |
530 | |
531 inline void Elapsed() { | |
532 base::TimeDelta delta = timer_.Elapsed(); | |
533 counter_->time += delta; | |
534 if (parent()) { | |
535 parent()->counter_->time -= delta; | |
536 parent()->Elapsed(); | |
537 } | |
538 timer_.Restart(); | |
539 } | |
540 | |
541 const char* name() { return counter_->name; } | |
542 | |
543 RuntimeCallCounter* counter_ = nullptr; | 530 RuntimeCallCounter* counter_ = nullptr; |
544 base::AtomicValue<RuntimeCallTimer*> parent_; | 531 base::AtomicValue<RuntimeCallTimer*> parent_; |
545 base::ElapsedTimer timer_; | 532 base::ElapsedTimer timer_; |
| 533 // Time spent in subtimers which only gets committed to the counter once this |
| 534 // RuntimeCallTimer stops, otherwise we might miscount time when we |
| 535 // dynamically change the RuntimeCallTimer counter_. |
| 536 base::TimeDelta subtime_; |
546 }; | 537 }; |
547 | 538 |
548 #define FOR_EACH_API_COUNTER(V) \ | 539 #define FOR_EACH_API_COUNTER(V) \ |
549 V(ArrayBuffer_Cast) \ | 540 V(ArrayBuffer_Cast) \ |
550 V(ArrayBuffer_Neuter) \ | 541 V(ArrayBuffer_Neuter) \ |
551 V(ArrayBuffer_New) \ | 542 V(ArrayBuffer_New) \ |
552 V(Array_CloneElementAt) \ | 543 V(Array_CloneElementAt) \ |
553 V(Array_New) \ | 544 V(Array_New) \ |
554 V(BooleanObject_BooleanValue) \ | 545 V(BooleanObject_BooleanValue) \ |
555 V(BooleanObject_New) \ | 546 V(BooleanObject_New) \ |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 V(PreParseBackgroundNoVariableResolution) \ | 730 V(PreParseBackgroundNoVariableResolution) \ |
740 V(PreParseBackgroundWithVariableResolution) \ | 731 V(PreParseBackgroundWithVariableResolution) \ |
741 V(PreParseNoVariableResolution) \ | 732 V(PreParseNoVariableResolution) \ |
742 V(PreParseWithVariableResolution) \ | 733 V(PreParseWithVariableResolution) \ |
743 V(PropertyCallback) \ | 734 V(PropertyCallback) \ |
744 V(PrototypeMap_TransitionToAccessorProperty) \ | 735 V(PrototypeMap_TransitionToAccessorProperty) \ |
745 V(PrototypeMap_TransitionToDataProperty) \ | 736 V(PrototypeMap_TransitionToDataProperty) \ |
746 V(PrototypeObject_DeleteProperty) \ | 737 V(PrototypeObject_DeleteProperty) \ |
747 V(RecompileConcurrent) \ | 738 V(RecompileConcurrent) \ |
748 V(RecompileSynchronous) \ | 739 V(RecompileSynchronous) \ |
| 740 V(TestCounter1) \ |
| 741 V(TestCounter2) \ |
| 742 V(TestCounter3) \ |
749 /* Dummy counter for the unexpected stub miss. */ \ | 743 /* Dummy counter for the unexpected stub miss. */ \ |
750 V(UnexpectedStubMiss) | 744 V(UnexpectedStubMiss) |
751 | 745 |
752 #define FOR_EACH_HANDLER_COUNTER(V) \ | 746 #define FOR_EACH_HANDLER_COUNTER(V) \ |
753 V(IC_HandlerCacheHit) \ | 747 V(IC_HandlerCacheHit) \ |
754 V(KeyedLoadIC_LoadIndexedStringStub) \ | 748 V(KeyedLoadIC_LoadIndexedStringStub) \ |
755 V(KeyedLoadIC_LoadIndexedInterceptorStub) \ | 749 V(KeyedLoadIC_LoadIndexedInterceptorStub) \ |
756 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \ | 750 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \ |
757 V(KeyedLoadIC_LoadElementDH) \ | 751 V(KeyedLoadIC_LoadElementDH) \ |
758 V(KeyedLoadIC_LoadFastElementStub) \ | 752 V(KeyedLoadIC_LoadFastElementStub) \ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 V(StoreIC_StoreFieldStub) \ | 804 V(StoreIC_StoreFieldStub) \ |
811 V(StoreIC_StoreGlobal) \ | 805 V(StoreIC_StoreGlobal) \ |
812 V(StoreIC_StoreGlobalTransition) \ | 806 V(StoreIC_StoreGlobalTransition) \ |
813 V(StoreIC_StoreInterceptorStub) \ | 807 V(StoreIC_StoreInterceptorStub) \ |
814 V(StoreIC_StoreNormal) \ | 808 V(StoreIC_StoreNormal) \ |
815 V(StoreIC_StoreScriptContextFieldStub) \ | 809 V(StoreIC_StoreScriptContextFieldStub) \ |
816 V(StoreIC_StoreTransition) \ | 810 V(StoreIC_StoreTransition) \ |
817 V(StoreIC_StoreTransitionDH) \ | 811 V(StoreIC_StoreTransitionDH) \ |
818 V(StoreIC_StoreViaSetter) | 812 V(StoreIC_StoreViaSetter) |
819 | 813 |
820 class RuntimeCallStats : public ZoneObject { | 814 class V8_EXPORT_PRIVATE RuntimeCallStats final : public ZoneObject { |
821 public: | 815 public: |
822 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; | 816 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; |
823 | 817 |
824 #define CALL_RUNTIME_COUNTER(name) \ | 818 #define CALL_RUNTIME_COUNTER(name) \ |
825 RuntimeCallCounter name = RuntimeCallCounter(#name); | 819 RuntimeCallCounter name = RuntimeCallCounter(#name); |
826 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) | 820 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) |
827 #undef CALL_RUNTIME_COUNTER | 821 #undef CALL_RUNTIME_COUNTER |
828 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ | 822 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ |
829 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); | 823 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); |
830 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) | 824 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ | 879 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ |
886 RuntimeCallStats::CorrectCurrentCounterId( \ | 880 RuntimeCallStats::CorrectCurrentCounterId( \ |
887 runtime_call_stats, &RuntimeCallStats::counter_name); \ | 881 runtime_call_stats, &RuntimeCallStats::counter_name); \ |
888 } \ | 882 } \ |
889 } while (false) | 883 } while (false) |
890 | 884 |
891 #define TRACE_HANDLER_STATS(isolate, counter_name) \ | 885 #define TRACE_HANDLER_STATS(isolate, counter_name) \ |
892 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ | 886 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ |
893 Handler_##counter_name) | 887 Handler_##counter_name) |
894 | 888 |
| 889 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the |
| 890 // the time of C++ scope. |
| 891 class RuntimeCallTimerScope { |
| 892 public: |
| 893 inline RuntimeCallTimerScope(Isolate* isolate, |
| 894 RuntimeCallStats::CounterId counter_id); |
| 895 // This constructor is here just to avoid calling GetIsolate() when the |
| 896 // stats are disabled and the isolate is not directly available. |
| 897 inline RuntimeCallTimerScope(HeapObject* heap_object, |
| 898 RuntimeCallStats::CounterId counter_id); |
| 899 inline RuntimeCallTimerScope(RuntimeCallStats* stats, |
| 900 RuntimeCallStats::CounterId counter_id); |
| 901 |
| 902 inline ~RuntimeCallTimerScope() { |
| 903 if (V8_UNLIKELY(stats_ != nullptr)) { |
| 904 RuntimeCallStats::Leave(stats_, &timer_); |
| 905 } |
| 906 } |
| 907 |
| 908 private: |
| 909 V8_INLINE void Initialize(RuntimeCallStats* stats, |
| 910 RuntimeCallStats::CounterId counter_id) { |
| 911 stats_ = stats; |
| 912 RuntimeCallStats::Enter(stats_, &timer_, counter_id); |
| 913 } |
| 914 |
| 915 RuntimeCallStats* stats_ = nullptr; |
| 916 RuntimeCallTimer timer_; |
| 917 }; |
| 918 |
895 #define HISTOGRAM_RANGE_LIST(HR) \ | 919 #define HISTOGRAM_RANGE_LIST(HR) \ |
896 /* Generic range histograms */ \ | 920 /* Generic range histograms */ \ |
897 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ | 921 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ |
898 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ | 922 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ |
899 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ | 923 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ |
900 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ | 924 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ |
901 101) \ | 925 101) \ |
902 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ | 926 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ |
903 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ | 927 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ |
904 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ | 928 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 | 1320 |
1297 RuntimeCallStats runtime_call_stats_; | 1321 RuntimeCallStats runtime_call_stats_; |
1298 | 1322 |
1299 friend class Isolate; | 1323 friend class Isolate; |
1300 | 1324 |
1301 explicit Counters(Isolate* isolate); | 1325 explicit Counters(Isolate* isolate); |
1302 | 1326 |
1303 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1327 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
1304 }; | 1328 }; |
1305 | 1329 |
1306 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the | |
1307 // the time of C++ scope. | |
1308 class RuntimeCallTimerScope { | |
1309 public: | |
1310 inline RuntimeCallTimerScope(Isolate* isolate, | |
1311 RuntimeCallStats::CounterId counter_id); | |
1312 // This constructor is here just to avoid calling GetIsolate() when the | |
1313 // stats are disabled and the isolate is not directly available. | |
1314 inline RuntimeCallTimerScope(HeapObject* heap_object, | |
1315 RuntimeCallStats::CounterId counter_id); | |
1316 inline RuntimeCallTimerScope(RuntimeCallStats* stats, | |
1317 RuntimeCallStats::CounterId counter_id); | |
1318 | |
1319 inline ~RuntimeCallTimerScope() { | |
1320 if (V8_UNLIKELY(stats_ != nullptr)) { | |
1321 RuntimeCallStats::Leave(stats_, &timer_); | |
1322 } | |
1323 } | |
1324 | |
1325 private: | |
1326 V8_INLINE void Initialize(RuntimeCallStats* stats, | |
1327 RuntimeCallStats::CounterId counter_id) { | |
1328 stats_ = stats; | |
1329 RuntimeCallStats::Enter(stats_, &timer_, counter_id); | |
1330 } | |
1331 | |
1332 RuntimeCallStats* stats_ = nullptr; | |
1333 RuntimeCallTimer timer_; | |
1334 }; | |
1335 | |
1336 } // namespace internal | 1330 } // namespace internal |
1337 } // namespace v8 | 1331 } // namespace v8 |
1338 | 1332 |
1339 #endif // V8_COUNTERS_H_ | 1333 #endif // V8_COUNTERS_H_ |
OLD | NEW |