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 class RuntimeCallCounter final { | 487 struct RuntimeCallCounter { |
488 public: | 488 explicit RuntimeCallCounter(const char* name) : name(name) {} |
489 explicit RuntimeCallCounter(const char* name) : name_(name) {} | |
490 V8_NOINLINE void Reset(); | 489 V8_NOINLINE void Reset(); |
491 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); | 490 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); |
492 void Add(RuntimeCallCounter* other); | 491 void Add(RuntimeCallCounter* other); |
493 | 492 |
494 const char* name() const { return name_; } | 493 const char* name; |
495 int64_t count() const { return count_; } | 494 int64_t count = 0; |
496 base::TimeDelta time() const { return time_; } | 495 base::TimeDelta 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_; | |
504 }; | 496 }; |
505 | 497 |
506 // RuntimeCallTimer is used to keep track of the stack of currently active | 498 // RuntimeCallTimer is used to keep track of the stack of currently active |
507 // timers used for properly measuring the own time of a RuntimeCallCounter. | 499 // timers used for properly measuring the own time of a RuntimeCallCounter. |
508 class RuntimeCallTimer final { | 500 class RuntimeCallTimer { |
509 public: | 501 public: |
510 RuntimeCallCounter* counter() { return counter_; } | 502 RuntimeCallCounter* counter() { return counter_; } |
511 void set_counter(RuntimeCallCounter* counter) { counter_ = counter; } | 503 base::ElapsedTimer timer() { return timer_; } |
512 RuntimeCallTimer* parent() const { return parent_.Value(); } | 504 RuntimeCallTimer* parent() const { return parent_.Value(); } |
513 void set_parent(RuntimeCallTimer* timer) { parent_.SetValue(timer); } | |
514 const char* name() const { return counter_->name(); } | |
515 | |
516 inline bool IsStarted(); | |
517 | |
518 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent); | |
519 void Snapshot(); | |
520 inline RuntimeCallTimer* Stop(); | |
521 | 505 |
522 private: | 506 private: |
523 inline void Pause(base::TimeTicks now); | 507 friend class RuntimeCallStats; |
524 inline void Resume(base::TimeTicks now); | 508 |
525 inline void CommitTimeToCounter(); | 509 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent) { |
526 inline base::TimeTicks Now(); | 510 counter_ = counter; |
| 511 parent_.SetValue(parent); |
| 512 if (FLAG_runtime_stats != |
| 513 v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) { |
| 514 timer_.Start(); |
| 515 } |
| 516 } |
| 517 |
| 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; } |
527 | 542 |
528 RuntimeCallCounter* counter_ = nullptr; | 543 RuntimeCallCounter* counter_ = nullptr; |
529 base::AtomicValue<RuntimeCallTimer*> parent_; | 544 base::AtomicValue<RuntimeCallTimer*> parent_; |
530 base::TimeTicks start_ticks_; | 545 base::ElapsedTimer timer_; |
531 base::TimeDelta elapsed_; | |
532 }; | 546 }; |
533 | 547 |
534 #define FOR_EACH_API_COUNTER(V) \ | 548 #define FOR_EACH_API_COUNTER(V) \ |
535 V(ArrayBuffer_Cast) \ | 549 V(ArrayBuffer_Cast) \ |
536 V(ArrayBuffer_Neuter) \ | 550 V(ArrayBuffer_Neuter) \ |
537 V(ArrayBuffer_New) \ | 551 V(ArrayBuffer_New) \ |
538 V(Array_CloneElementAt) \ | 552 V(Array_CloneElementAt) \ |
539 V(Array_New) \ | 553 V(Array_New) \ |
540 V(BooleanObject_BooleanValue) \ | 554 V(BooleanObject_BooleanValue) \ |
541 V(BooleanObject_New) \ | 555 V(BooleanObject_New) \ |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 V(PreParseBackgroundNoVariableResolution) \ | 739 V(PreParseBackgroundNoVariableResolution) \ |
726 V(PreParseBackgroundWithVariableResolution) \ | 740 V(PreParseBackgroundWithVariableResolution) \ |
727 V(PreParseNoVariableResolution) \ | 741 V(PreParseNoVariableResolution) \ |
728 V(PreParseWithVariableResolution) \ | 742 V(PreParseWithVariableResolution) \ |
729 V(PropertyCallback) \ | 743 V(PropertyCallback) \ |
730 V(PrototypeMap_TransitionToAccessorProperty) \ | 744 V(PrototypeMap_TransitionToAccessorProperty) \ |
731 V(PrototypeMap_TransitionToDataProperty) \ | 745 V(PrototypeMap_TransitionToDataProperty) \ |
732 V(PrototypeObject_DeleteProperty) \ | 746 V(PrototypeObject_DeleteProperty) \ |
733 V(RecompileConcurrent) \ | 747 V(RecompileConcurrent) \ |
734 V(RecompileSynchronous) \ | 748 V(RecompileSynchronous) \ |
735 V(TestCounter1) \ | |
736 V(TestCounter2) \ | |
737 V(TestCounter3) \ | |
738 /* Dummy counter for the unexpected stub miss. */ \ | 749 /* Dummy counter for the unexpected stub miss. */ \ |
739 V(UnexpectedStubMiss) | 750 V(UnexpectedStubMiss) |
740 | 751 |
741 #define FOR_EACH_HANDLER_COUNTER(V) \ | 752 #define FOR_EACH_HANDLER_COUNTER(V) \ |
742 V(IC_HandlerCacheHit) \ | 753 V(IC_HandlerCacheHit) \ |
743 V(KeyedLoadIC_LoadIndexedStringStub) \ | 754 V(KeyedLoadIC_LoadIndexedStringStub) \ |
744 V(KeyedLoadIC_LoadIndexedInterceptorStub) \ | 755 V(KeyedLoadIC_LoadIndexedInterceptorStub) \ |
745 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \ | 756 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \ |
746 V(KeyedLoadIC_LoadElementDH) \ | 757 V(KeyedLoadIC_LoadElementDH) \ |
747 V(KeyedLoadIC_LoadFastElementStub) \ | 758 V(KeyedLoadIC_LoadFastElementStub) \ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 V(StoreIC_StoreFieldStub) \ | 810 V(StoreIC_StoreFieldStub) \ |
800 V(StoreIC_StoreGlobal) \ | 811 V(StoreIC_StoreGlobal) \ |
801 V(StoreIC_StoreGlobalTransition) \ | 812 V(StoreIC_StoreGlobalTransition) \ |
802 V(StoreIC_StoreInterceptorStub) \ | 813 V(StoreIC_StoreInterceptorStub) \ |
803 V(StoreIC_StoreNormal) \ | 814 V(StoreIC_StoreNormal) \ |
804 V(StoreIC_StoreScriptContextFieldStub) \ | 815 V(StoreIC_StoreScriptContextFieldStub) \ |
805 V(StoreIC_StoreTransition) \ | 816 V(StoreIC_StoreTransition) \ |
806 V(StoreIC_StoreTransitionDH) \ | 817 V(StoreIC_StoreTransitionDH) \ |
807 V(StoreIC_StoreViaSetter) | 818 V(StoreIC_StoreViaSetter) |
808 | 819 |
809 class V8_EXPORT_PRIVATE RuntimeCallStats final : public ZoneObject { | 820 class RuntimeCallStats : public ZoneObject { |
810 public: | 821 public: |
811 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; | 822 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; |
812 | 823 |
813 #define CALL_RUNTIME_COUNTER(name) \ | 824 #define CALL_RUNTIME_COUNTER(name) \ |
814 RuntimeCallCounter name = RuntimeCallCounter(#name); | 825 RuntimeCallCounter name = RuntimeCallCounter(#name); |
815 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) | 826 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) |
816 #undef CALL_RUNTIME_COUNTER | 827 #undef CALL_RUNTIME_COUNTER |
817 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ | 828 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ |
818 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); | 829 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); |
819 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) | 830 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ | 885 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ |
875 RuntimeCallStats::CorrectCurrentCounterId( \ | 886 RuntimeCallStats::CorrectCurrentCounterId( \ |
876 runtime_call_stats, &RuntimeCallStats::counter_name); \ | 887 runtime_call_stats, &RuntimeCallStats::counter_name); \ |
877 } \ | 888 } \ |
878 } while (false) | 889 } while (false) |
879 | 890 |
880 #define TRACE_HANDLER_STATS(isolate, counter_name) \ | 891 #define TRACE_HANDLER_STATS(isolate, counter_name) \ |
881 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ | 892 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ |
882 Handler_##counter_name) | 893 Handler_##counter_name) |
883 | 894 |
884 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the | |
885 // the time of C++ scope. | |
886 class RuntimeCallTimerScope { | |
887 public: | |
888 inline RuntimeCallTimerScope(Isolate* isolate, | |
889 RuntimeCallStats::CounterId counter_id); | |
890 // This constructor is here just to avoid calling GetIsolate() when the | |
891 // stats are disabled and the isolate is not directly available. | |
892 inline RuntimeCallTimerScope(HeapObject* heap_object, | |
893 RuntimeCallStats::CounterId counter_id); | |
894 inline RuntimeCallTimerScope(RuntimeCallStats* stats, | |
895 RuntimeCallStats::CounterId counter_id); | |
896 | |
897 inline ~RuntimeCallTimerScope() { | |
898 if (V8_UNLIKELY(stats_ != nullptr)) { | |
899 RuntimeCallStats::Leave(stats_, &timer_); | |
900 } | |
901 } | |
902 | |
903 private: | |
904 V8_INLINE void Initialize(RuntimeCallStats* stats, | |
905 RuntimeCallStats::CounterId counter_id) { | |
906 stats_ = stats; | |
907 RuntimeCallStats::Enter(stats_, &timer_, counter_id); | |
908 } | |
909 | |
910 RuntimeCallStats* stats_ = nullptr; | |
911 RuntimeCallTimer timer_; | |
912 }; | |
913 | |
914 #define HISTOGRAM_RANGE_LIST(HR) \ | 895 #define HISTOGRAM_RANGE_LIST(HR) \ |
915 /* Generic range histograms */ \ | 896 /* Generic range histograms */ \ |
916 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ | 897 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ |
917 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ | 898 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ |
918 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ | 899 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ |
919 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ | 900 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ |
920 101) \ | 901 101) \ |
921 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ | 902 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ |
922 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ | 903 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ |
923 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ | 904 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 | 1296 |
1316 RuntimeCallStats runtime_call_stats_; | 1297 RuntimeCallStats runtime_call_stats_; |
1317 | 1298 |
1318 friend class Isolate; | 1299 friend class Isolate; |
1319 | 1300 |
1320 explicit Counters(Isolate* isolate); | 1301 explicit Counters(Isolate* isolate); |
1321 | 1302 |
1322 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1303 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
1323 }; | 1304 }; |
1324 | 1305 |
| 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 |
1325 } // namespace internal | 1336 } // namespace internal |
1326 } // namespace v8 | 1337 } // namespace v8 |
1327 | 1338 |
1328 #endif // V8_COUNTERS_H_ | 1339 #endif // V8_COUNTERS_H_ |
OLD | NEW |