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

Side by Side Diff: src/counters.h

Issue 2511093002: [counters] RuntimeStats: fix wrong bookkeeping when dynamically changing counters. (Closed)
Patch Set: moar tests Created 4 years, 1 month 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
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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 int num_buckets, Isolate* isolate) 242 int num_buckets, Isolate* isolate)
243 : Histogram(name, min, max, num_buckets, isolate), 243 : Histogram(name, min, max, num_buckets, isolate),
244 resolution_(resolution) {} 244 resolution_(resolution) {}
245 245
246 // Start the timer. 246 // Start the timer.
247 void Start(); 247 void Start();
248 248
249 // Stop the timer and record the results. 249 // Stop the timer and record the results.
250 void Stop(); 250 void Stop();
251 251
252 // Returns true if the timer is running. 252 // Returns true if the timer is runnibase::ng.
Igor Sheludko 2016/11/18 18:56:27 Spurious change.
Camillo Bruni 2016/11/21 10:50:03 done.
253 bool Running() { 253 bool Running() {
254 return Enabled() && timer_.IsStarted(); 254 return Enabled() && timer_.IsStarted();
255 } 255 }
256 256
257 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed. 257 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed.
258 #ifdef DEBUG 258 #ifdef DEBUG
259 base::ElapsedTimer* timer() { return &timer_; } 259 base::ElapsedTimer* timer() { return &timer_; }
260 #endif 260 #endif
261 261
262 private: 262 private:
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 counter_ = counter; 510 inline RuntimeCallTimer* Stop();
511 parent_.SetValue(parent); 511 // Synchronize the currently active timer stack. Walk up the stack by stopping
512 if (FLAG_runtime_stats != 512 // and restarting each timer.
513 v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) { 513 inline void Snapshot();
514 timer_.Start(); 514 inline void Subtract(base::TimeDelta delta);
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 515
541 const char* name() { return counter_->name; } 516 const char* name() { return counter_->name; }
542 517
543 RuntimeCallCounter* counter_ = nullptr; 518 RuntimeCallCounter* counter_ = nullptr;
544 base::AtomicValue<RuntimeCallTimer*> parent_; 519 base::AtomicValue<RuntimeCallTimer*> parent_;
545 base::ElapsedTimer timer_; 520 base::ElapsedTimer timer_;
546 }; 521 };
547 522
548 #define FOR_EACH_API_COUNTER(V) \ 523 #define FOR_EACH_API_COUNTER(V) \
549 V(ArrayBuffer_Cast) \ 524 V(ArrayBuffer_Cast) \
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 V(PreParseBackgroundNoVariableResolution) \ 714 V(PreParseBackgroundNoVariableResolution) \
740 V(PreParseBackgroundWithVariableResolution) \ 715 V(PreParseBackgroundWithVariableResolution) \
741 V(PreParseNoVariableResolution) \ 716 V(PreParseNoVariableResolution) \
742 V(PreParseWithVariableResolution) \ 717 V(PreParseWithVariableResolution) \
743 V(PropertyCallback) \ 718 V(PropertyCallback) \
744 V(PrototypeMap_TransitionToAccessorProperty) \ 719 V(PrototypeMap_TransitionToAccessorProperty) \
745 V(PrototypeMap_TransitionToDataProperty) \ 720 V(PrototypeMap_TransitionToDataProperty) \
746 V(PrototypeObject_DeleteProperty) \ 721 V(PrototypeObject_DeleteProperty) \
747 V(RecompileConcurrent) \ 722 V(RecompileConcurrent) \
748 V(RecompileSynchronous) \ 723 V(RecompileSynchronous) \
724 V(TestCounter1) \
725 V(TestCounter2) \
749 /* Dummy counter for the unexpected stub miss. */ \ 726 /* Dummy counter for the unexpected stub miss. */ \
750 V(UnexpectedStubMiss) 727 V(UnexpectedStubMiss)
751 728
752 #define FOR_EACH_HANDLER_COUNTER(V) \ 729 #define FOR_EACH_HANDLER_COUNTER(V) \
753 V(IC_HandlerCacheHit) \ 730 V(IC_HandlerCacheHit) \
754 V(KeyedLoadIC_LoadIndexedStringStub) \ 731 V(KeyedLoadIC_LoadIndexedStringStub) \
755 V(KeyedLoadIC_LoadIndexedInterceptorStub) \ 732 V(KeyedLoadIC_LoadIndexedInterceptorStub) \
756 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \ 733 V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub) \
757 V(KeyedLoadIC_LoadElementDH) \ 734 V(KeyedLoadIC_LoadElementDH) \
758 V(KeyedLoadIC_LoadFastElementStub) \ 735 V(KeyedLoadIC_LoadFastElementStub) \
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ 862 if (V8_UNLIKELY(FLAG_runtime_stats)) { \
886 RuntimeCallStats::CorrectCurrentCounterId( \ 863 RuntimeCallStats::CorrectCurrentCounterId( \
887 runtime_call_stats, &RuntimeCallStats::counter_name); \ 864 runtime_call_stats, &RuntimeCallStats::counter_name); \
888 } \ 865 } \
889 } while (false) 866 } while (false)
890 867
891 #define TRACE_HANDLER_STATS(isolate, counter_name) \ 868 #define TRACE_HANDLER_STATS(isolate, counter_name) \
892 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ 869 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \
893 Handler_##counter_name) 870 Handler_##counter_name)
894 871
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
895 #define HISTOGRAM_RANGE_LIST(HR) \ 902 #define HISTOGRAM_RANGE_LIST(HR) \
896 /* Generic range histograms */ \ 903 /* Generic range histograms */ \
897 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ 904 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \
898 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ 905 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) \ 906 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \
900 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ 907 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \
901 101) \ 908 101) \
902 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ 909 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \
903 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ 910 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \
904 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ 911 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 1303
1297 RuntimeCallStats runtime_call_stats_; 1304 RuntimeCallStats runtime_call_stats_;
1298 1305
1299 friend class Isolate; 1306 friend class Isolate;
1300 1307
1301 explicit Counters(Isolate* isolate); 1308 explicit Counters(Isolate* isolate);
1302 1309
1303 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); 1310 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
1304 }; 1311 };
1305 1312
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 1313 } // namespace internal
1337 } // namespace v8 1314 } // namespace v8
1338 1315
1339 #endif // V8_COUNTERS_H_ 1316 #endif // V8_COUNTERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698