Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: src/counters.h

Issue 2511093002: [counters] RuntimeStats: fix wrong bookkeeping when dynamically changing counters. (Closed)
Patch Set: merge with master Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/counters.cc » ('j') | test/unittests/counters-unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 void set_counter(RuntimeCallCounter* counter) { counter_ = counter; }
504 RuntimeCallTimer* parent() const { return parent_.Value(); } 512 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();
505 521
506 private: 522 private:
507 friend class RuntimeCallStats; 523 inline void Pause(base::TimeTicks now);
508 524 inline void Resume(base::TimeTicks now);
509 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent) { 525 inline void CommitTimeToCounter();
510 counter_ = counter; 526 inline base::TimeTicks Now();
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; }
542 527
543 RuntimeCallCounter* counter_ = nullptr; 528 RuntimeCallCounter* counter_ = nullptr;
544 base::AtomicValue<RuntimeCallTimer*> parent_; 529 base::AtomicValue<RuntimeCallTimer*> parent_;
545 base::ElapsedTimer timer_; 530 base::TimeTicks start_ticks_;
531 base::TimeDelta elapsed_;
546 }; 532 };
547 533
548 #define FOR_EACH_API_COUNTER(V) \ 534 #define FOR_EACH_API_COUNTER(V) \
549 V(ArrayBuffer_Cast) \ 535 V(ArrayBuffer_Cast) \
550 V(ArrayBuffer_Neuter) \ 536 V(ArrayBuffer_Neuter) \
551 V(ArrayBuffer_New) \ 537 V(ArrayBuffer_New) \
552 V(Array_CloneElementAt) \ 538 V(Array_CloneElementAt) \
553 V(Array_New) \ 539 V(Array_New) \
554 V(BooleanObject_BooleanValue) \ 540 V(BooleanObject_BooleanValue) \
555 V(BooleanObject_New) \ 541 V(BooleanObject_New) \
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 V(PreParseBackgroundNoVariableResolution) \ 728 V(PreParseBackgroundNoVariableResolution) \
743 V(PreParseBackgroundWithVariableResolution) \ 729 V(PreParseBackgroundWithVariableResolution) \
744 V(PreParseNoVariableResolution) \ 730 V(PreParseNoVariableResolution) \
745 V(PreParseWithVariableResolution) \ 731 V(PreParseWithVariableResolution) \
746 V(PropertyCallback) \ 732 V(PropertyCallback) \
747 V(PrototypeMap_TransitionToAccessorProperty) \ 733 V(PrototypeMap_TransitionToAccessorProperty) \
748 V(PrototypeMap_TransitionToDataProperty) \ 734 V(PrototypeMap_TransitionToDataProperty) \
749 V(PrototypeObject_DeleteProperty) \ 735 V(PrototypeObject_DeleteProperty) \
750 V(RecompileConcurrent) \ 736 V(RecompileConcurrent) \
751 V(RecompileSynchronous) \ 737 V(RecompileSynchronous) \
738 V(TestCounter1) \
739 V(TestCounter2) \
740 V(TestCounter3) \
752 /* Dummy counter for the unexpected stub miss. */ \ 741 /* Dummy counter for the unexpected stub miss. */ \
753 V(UnexpectedStubMiss) 742 V(UnexpectedStubMiss)
754 743
755 #define FOR_EACH_HANDLER_COUNTER(V) \ 744 #define FOR_EACH_HANDLER_COUNTER(V) \
756 V(IC_HandlerCacheHit) \ 745 V(IC_HandlerCacheHit) \
757 V(KeyedLoadIC_LoadIndexedStringStub) \ 746 V(KeyedLoadIC_LoadIndexedStringStub) \
758 V(KeyedLoadIC_LoadIndexedInterceptorStub) \ 747 V(KeyedLoadIC_LoadIndexedInterceptorStub) \
759 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \ 748 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \
760 V(KeyedLoadIC_LoadElementDH) \ 749 V(KeyedLoadIC_LoadElementDH) \
761 V(KeyedLoadIC_LoadFastElementStub) \ 750 V(KeyedLoadIC_LoadFastElementStub) \
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 V(StoreIC_StoreFieldStub) \ 802 V(StoreIC_StoreFieldStub) \
814 V(StoreIC_StoreGlobal) \ 803 V(StoreIC_StoreGlobal) \
815 V(StoreIC_StoreGlobalTransition) \ 804 V(StoreIC_StoreGlobalTransition) \
816 V(StoreIC_StoreInterceptorStub) \ 805 V(StoreIC_StoreInterceptorStub) \
817 V(StoreIC_StoreNormal) \ 806 V(StoreIC_StoreNormal) \
818 V(StoreIC_StoreScriptContextFieldStub) \ 807 V(StoreIC_StoreScriptContextFieldStub) \
819 V(StoreIC_StoreTransition) \ 808 V(StoreIC_StoreTransition) \
820 V(StoreIC_StoreTransitionDH) \ 809 V(StoreIC_StoreTransitionDH) \
821 V(StoreIC_StoreViaSetter) 810 V(StoreIC_StoreViaSetter)
822 811
823 class RuntimeCallStats : public ZoneObject { 812 class V8_EXPORT_PRIVATE RuntimeCallStats final : public ZoneObject {
824 public: 813 public:
825 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; 814 typedef RuntimeCallCounter RuntimeCallStats::*CounterId;
826 815
827 #define CALL_RUNTIME_COUNTER(name) \ 816 #define CALL_RUNTIME_COUNTER(name) \
828 RuntimeCallCounter name = RuntimeCallCounter(#name); 817 RuntimeCallCounter name = RuntimeCallCounter(#name);
829 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) 818 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER)
830 #undef CALL_RUNTIME_COUNTER 819 #undef CALL_RUNTIME_COUNTER
831 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ 820 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \
832 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); 821 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name);
833 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) 822 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ 877 if (V8_UNLIKELY(FLAG_runtime_stats)) { \
889 RuntimeCallStats::CorrectCurrentCounterId( \ 878 RuntimeCallStats::CorrectCurrentCounterId( \
890 runtime_call_stats, &RuntimeCallStats::counter_name); \ 879 runtime_call_stats, &RuntimeCallStats::counter_name); \
891 } \ 880 } \
892 } while (false) 881 } while (false)
893 882
894 #define TRACE_HANDLER_STATS(isolate, counter_name) \ 883 #define TRACE_HANDLER_STATS(isolate, counter_name) \
895 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ 884 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \
896 Handler_##counter_name) 885 Handler_##counter_name)
897 886
887 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the
888 // the time of C++ scope.
889 class RuntimeCallTimerScope {
890 public:
891 inline RuntimeCallTimerScope(Isolate* isolate,
892 RuntimeCallStats::CounterId counter_id);
893 // This constructor is here just to avoid calling GetIsolate() when the
894 // stats are disabled and the isolate is not directly available.
895 inline RuntimeCallTimerScope(HeapObject* heap_object,
896 RuntimeCallStats::CounterId counter_id);
897 inline RuntimeCallTimerScope(RuntimeCallStats* stats,
898 RuntimeCallStats::CounterId counter_id);
899
900 inline ~RuntimeCallTimerScope() {
901 if (V8_UNLIKELY(stats_ != nullptr)) {
902 RuntimeCallStats::Leave(stats_, &timer_);
903 }
904 }
905
906 private:
907 V8_INLINE void Initialize(RuntimeCallStats* stats,
908 RuntimeCallStats::CounterId counter_id) {
909 stats_ = stats;
910 RuntimeCallStats::Enter(stats_, &timer_, counter_id);
911 }
912
913 RuntimeCallStats* stats_ = nullptr;
914 RuntimeCallTimer timer_;
915 };
916
898 #define HISTOGRAM_RANGE_LIST(HR) \ 917 #define HISTOGRAM_RANGE_LIST(HR) \
899 /* Generic range histograms */ \ 918 /* Generic range histograms */ \
900 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ 919 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \
901 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ 920 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \
902 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ 921 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \
903 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ 922 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \
904 101) \ 923 101) \
905 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ 924 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \
906 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ 925 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \
907 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ 926 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 1318
1300 RuntimeCallStats runtime_call_stats_; 1319 RuntimeCallStats runtime_call_stats_;
1301 1320
1302 friend class Isolate; 1321 friend class Isolate;
1303 1322
1304 explicit Counters(Isolate* isolate); 1323 explicit Counters(Isolate* isolate);
1305 1324
1306 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); 1325 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
1307 }; 1326 };
1308 1327
1309 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the
1310 // the time of C++ scope.
1311 class RuntimeCallTimerScope {
1312 public:
1313 inline RuntimeCallTimerScope(Isolate* isolate,
1314 RuntimeCallStats::CounterId counter_id);
1315 // This constructor is here just to avoid calling GetIsolate() when the
1316 // stats are disabled and the isolate is not directly available.
1317 inline RuntimeCallTimerScope(HeapObject* heap_object,
1318 RuntimeCallStats::CounterId counter_id);
1319 inline RuntimeCallTimerScope(RuntimeCallStats* stats,
1320 RuntimeCallStats::CounterId counter_id);
1321
1322 inline ~RuntimeCallTimerScope() {
1323 if (V8_UNLIKELY(stats_ != nullptr)) {
1324 RuntimeCallStats::Leave(stats_, &timer_);
1325 }
1326 }
1327
1328 private:
1329 V8_INLINE void Initialize(RuntimeCallStats* stats,
1330 RuntimeCallStats::CounterId counter_id) {
1331 stats_ = stats;
1332 RuntimeCallStats::Enter(stats_, &timer_, counter_id);
1333 }
1334
1335 RuntimeCallStats* stats_ = nullptr;
1336 RuntimeCallTimer timer_;
1337 };
1338
1339 } // namespace internal 1328 } // namespace internal
1340 } // namespace v8 1329 } // namespace v8
1341 1330
1342 #endif // V8_COUNTERS_H_ 1331 #endif // V8_COUNTERS_H_
OLDNEW
« no previous file with comments | « no previous file | src/counters.cc » ('j') | test/unittests/counters-unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698