| 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 // timers used for properly measuring the own time of a RuntimeCallCounter. | 499 // timers used for properly measuring the own time of a RuntimeCallCounter. |
| 500 class RuntimeCallTimer { | 500 class RuntimeCallTimer { |
| 501 public: | 501 public: |
| 502 RuntimeCallCounter* counter() { return counter_; } | 502 RuntimeCallCounter* counter() { return counter_; } |
| 503 base::ElapsedTimer timer() { return timer_; } | 503 base::ElapsedTimer timer() { return timer_; } |
| 504 RuntimeCallTimer* parent() const { return parent_.Value(); } | 504 RuntimeCallTimer* parent() const { return parent_.Value(); } |
| 505 | 505 |
| 506 private: | 506 private: |
| 507 friend class RuntimeCallStats; | 507 friend class RuntimeCallStats; |
| 508 | 508 |
| 509 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent); | 509 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent) { |
| 510 inline RuntimeCallTimer* Stop(); | 510 counter_ = counter; |
| 511 // Synchronize the currently active timer stack. Walk up the stack by stopping | 511 parent_.SetValue(parent); |
| 512 // and restarting each timer. | 512 if (FLAG_runtime_stats != |
| 513 inline void Snapshot(); | 513 v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) { |
| 514 inline void Subtract(base::TimeDelta delta); | 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 } |
| 515 | 540 |
| 516 const char* name() { return counter_->name; } | 541 const char* name() { return counter_->name; } |
| 517 | 542 |
| 518 RuntimeCallCounter* counter_ = nullptr; | 543 RuntimeCallCounter* counter_ = nullptr; |
| 519 base::AtomicValue<RuntimeCallTimer*> parent_; | 544 base::AtomicValue<RuntimeCallTimer*> parent_; |
| 520 base::ElapsedTimer timer_; | 545 base::ElapsedTimer timer_; |
| 521 }; | 546 }; |
| 522 | 547 |
| 523 #define FOR_EACH_API_COUNTER(V) \ | 548 #define FOR_EACH_API_COUNTER(V) \ |
| 524 V(ArrayBuffer_Cast) \ | 549 V(ArrayBuffer_Cast) \ |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 V(PreParseBackgroundNoVariableResolution) \ | 739 V(PreParseBackgroundNoVariableResolution) \ |
| 715 V(PreParseBackgroundWithVariableResolution) \ | 740 V(PreParseBackgroundWithVariableResolution) \ |
| 716 V(PreParseNoVariableResolution) \ | 741 V(PreParseNoVariableResolution) \ |
| 717 V(PreParseWithVariableResolution) \ | 742 V(PreParseWithVariableResolution) \ |
| 718 V(PropertyCallback) \ | 743 V(PropertyCallback) \ |
| 719 V(PrototypeMap_TransitionToAccessorProperty) \ | 744 V(PrototypeMap_TransitionToAccessorProperty) \ |
| 720 V(PrototypeMap_TransitionToDataProperty) \ | 745 V(PrototypeMap_TransitionToDataProperty) \ |
| 721 V(PrototypeObject_DeleteProperty) \ | 746 V(PrototypeObject_DeleteProperty) \ |
| 722 V(RecompileConcurrent) \ | 747 V(RecompileConcurrent) \ |
| 723 V(RecompileSynchronous) \ | 748 V(RecompileSynchronous) \ |
| 724 V(TestCounter1) \ | |
| 725 V(TestCounter2) \ | |
| 726 /* Dummy counter for the unexpected stub miss. */ \ | 749 /* Dummy counter for the unexpected stub miss. */ \ |
| 727 V(UnexpectedStubMiss) | 750 V(UnexpectedStubMiss) |
| 728 | 751 |
| 729 #define FOR_EACH_HANDLER_COUNTER(V) \ | 752 #define FOR_EACH_HANDLER_COUNTER(V) \ |
| 730 V(IC_HandlerCacheHit) \ | 753 V(IC_HandlerCacheHit) \ |
| 731 V(KeyedLoadIC_LoadIndexedStringStub) \ | 754 V(KeyedLoadIC_LoadIndexedStringStub) \ |
| 732 V(KeyedLoadIC_LoadIndexedInterceptorStub) \ | 755 V(KeyedLoadIC_LoadIndexedInterceptorStub) \ |
| 733 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \ | 756 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \ |
| 734 V(KeyedLoadIC_LoadElementDH) \ | 757 V(KeyedLoadIC_LoadElementDH) \ |
| 735 V(KeyedLoadIC_LoadFastElementStub) \ | 758 V(KeyedLoadIC_LoadFastElementStub) \ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 V(StoreIC_StoreFieldStub) \ | 810 V(StoreIC_StoreFieldStub) \ |
| 788 V(StoreIC_StoreGlobal) \ | 811 V(StoreIC_StoreGlobal) \ |
| 789 V(StoreIC_StoreGlobalTransition) \ | 812 V(StoreIC_StoreGlobalTransition) \ |
| 790 V(StoreIC_StoreInterceptorStub) \ | 813 V(StoreIC_StoreInterceptorStub) \ |
| 791 V(StoreIC_StoreNormal) \ | 814 V(StoreIC_StoreNormal) \ |
| 792 V(StoreIC_StoreScriptContextFieldStub) \ | 815 V(StoreIC_StoreScriptContextFieldStub) \ |
| 793 V(StoreIC_StoreTransition) \ | 816 V(StoreIC_StoreTransition) \ |
| 794 V(StoreIC_StoreTransitionDH) \ | 817 V(StoreIC_StoreTransitionDH) \ |
| 795 V(StoreIC_StoreViaSetter) | 818 V(StoreIC_StoreViaSetter) |
| 796 | 819 |
| 797 class V8_EXPORT_PRIVATE RuntimeCallStats : public ZoneObject { | 820 class RuntimeCallStats : public ZoneObject { |
| 798 public: | 821 public: |
| 799 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; | 822 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; |
| 800 | 823 |
| 801 #define CALL_RUNTIME_COUNTER(name) \ | 824 #define CALL_RUNTIME_COUNTER(name) \ |
| 802 RuntimeCallCounter name = RuntimeCallCounter(#name); | 825 RuntimeCallCounter name = RuntimeCallCounter(#name); |
| 803 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) | 826 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) |
| 804 #undef CALL_RUNTIME_COUNTER | 827 #undef CALL_RUNTIME_COUNTER |
| 805 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ | 828 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ |
| 806 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); | 829 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); |
| 807 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... |
| 862 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ | 885 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ |
| 863 RuntimeCallStats::CorrectCurrentCounterId( \ | 886 RuntimeCallStats::CorrectCurrentCounterId( \ |
| 864 runtime_call_stats, &RuntimeCallStats::counter_name); \ | 887 runtime_call_stats, &RuntimeCallStats::counter_name); \ |
| 865 } \ | 888 } \ |
| 866 } while (false) | 889 } while (false) |
| 867 | 890 |
| 868 #define TRACE_HANDLER_STATS(isolate, counter_name) \ | 891 #define TRACE_HANDLER_STATS(isolate, counter_name) \ |
| 869 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ | 892 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ |
| 870 Handler_##counter_name) | 893 Handler_##counter_name) |
| 871 | 894 |
| 872 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the | |
| 873 // the time of C++ scope. | |
| 874 class RuntimeCallTimerScope { | |
| 875 public: | |
| 876 inline RuntimeCallTimerScope(Isolate* isolate, | |
| 877 RuntimeCallStats::CounterId counter_id); | |
| 878 // This constructor is here just to avoid calling GetIsolate() when the | |
| 879 // stats are disabled and the isolate is not directly available. | |
| 880 inline RuntimeCallTimerScope(HeapObject* heap_object, | |
| 881 RuntimeCallStats::CounterId counter_id); | |
| 882 inline RuntimeCallTimerScope(RuntimeCallStats* stats, | |
| 883 RuntimeCallStats::CounterId counter_id); | |
| 884 | |
| 885 inline ~RuntimeCallTimerScope() { | |
| 886 if (V8_UNLIKELY(stats_ != nullptr)) { | |
| 887 RuntimeCallStats::Leave(stats_, &timer_); | |
| 888 } | |
| 889 } | |
| 890 | |
| 891 private: | |
| 892 V8_INLINE void Initialize(RuntimeCallStats* stats, | |
| 893 RuntimeCallStats::CounterId counter_id) { | |
| 894 stats_ = stats; | |
| 895 RuntimeCallStats::Enter(stats_, &timer_, counter_id); | |
| 896 } | |
| 897 | |
| 898 RuntimeCallStats* stats_ = nullptr; | |
| 899 RuntimeCallTimer timer_; | |
| 900 }; | |
| 901 | |
| 902 #define HISTOGRAM_RANGE_LIST(HR) \ | 895 #define HISTOGRAM_RANGE_LIST(HR) \ |
| 903 /* Generic range histograms */ \ | 896 /* Generic range histograms */ \ |
| 904 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ | 897 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ |
| 905 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) \ |
| 906 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) \ |
| 907 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ | 900 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ |
| 908 101) \ | 901 101) \ |
| 909 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ | 902 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ |
| 910 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ | 903 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ |
| 911 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... |
| 1303 | 1296 |
| 1304 RuntimeCallStats runtime_call_stats_; | 1297 RuntimeCallStats runtime_call_stats_; |
| 1305 | 1298 |
| 1306 friend class Isolate; | 1299 friend class Isolate; |
| 1307 | 1300 |
| 1308 explicit Counters(Isolate* isolate); | 1301 explicit Counters(Isolate* isolate); |
| 1309 | 1302 |
| 1310 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1303 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
| 1311 }; | 1304 }; |
| 1312 | 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 |
| 1313 } // namespace internal | 1336 } // namespace internal |
| 1314 } // namespace v8 | 1337 } // namespace v8 |
| 1315 | 1338 |
| 1316 #endif // V8_COUNTERS_H_ | 1339 #endif // V8_COUNTERS_H_ |
| OLD | NEW |