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

Side by Side Diff: src/counters.h

Issue 2511093002: [counters] RuntimeStats: fix wrong bookkeeping when dynamically changing counters. (Closed)
Patch Set: formatting 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 488 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 inline void Elapsed();
512 if (FLAG_runtime_stats != 512 inline void Subtract(base::TimeDelta delta);
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 513
541 const char* name() { return counter_->name; } 514 const char* name() { return counter_->name; }
542 515
543 RuntimeCallCounter* counter_ = nullptr; 516 RuntimeCallCounter* counter_ = nullptr;
544 base::AtomicValue<RuntimeCallTimer*> parent_; 517 base::AtomicValue<RuntimeCallTimer*> parent_;
545 base::ElapsedTimer timer_; 518 base::ElapsedTimer timer_;
546 }; 519 };
547 520
548 #define FOR_EACH_API_COUNTER(V) \ 521 #define FOR_EACH_API_COUNTER(V) \
549 V(ArrayBuffer_Cast) \ 522 V(ArrayBuffer_Cast) \
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ 858 if (V8_UNLIKELY(FLAG_runtime_stats)) { \
886 RuntimeCallStats::CorrectCurrentCounterId( \ 859 RuntimeCallStats::CorrectCurrentCounterId( \
887 runtime_call_stats, &RuntimeCallStats::counter_name); \ 860 runtime_call_stats, &RuntimeCallStats::counter_name); \
888 } \ 861 } \
889 } while (false) 862 } while (false)
890 863
891 #define TRACE_HANDLER_STATS(isolate, counter_name) \ 864 #define TRACE_HANDLER_STATS(isolate, counter_name) \
892 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \ 865 CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \
893 Handler_##counter_name) 866 Handler_##counter_name)
894 867
868 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the
869 // the time of C++ scope.
870 class RuntimeCallTimerScope {
871 public:
872 inline RuntimeCallTimerScope(Isolate* isolate,
873 RuntimeCallStats::CounterId counter_id);
874 // This constructor is here just to avoid calling GetIsolate() when the
875 // stats are disabled and the isolate is not directly available.
876 inline RuntimeCallTimerScope(HeapObject* heap_object,
877 RuntimeCallStats::CounterId counter_id);
878 inline RuntimeCallTimerScope(RuntimeCallStats* stats,
879 RuntimeCallStats::CounterId counter_id);
880
881 inline ~RuntimeCallTimerScope() {
882 if (V8_UNLIKELY(stats_ != nullptr)) {
883 RuntimeCallStats::Leave(stats_, &timer_);
884 }
885 }
886
887 private:
888 V8_INLINE void Initialize(RuntimeCallStats* stats,
889 RuntimeCallStats::CounterId counter_id) {
890 stats_ = stats;
891 RuntimeCallStats::Enter(stats_, &timer_, counter_id);
892 }
893
894 RuntimeCallStats* stats_ = nullptr;
895 RuntimeCallTimer timer_;
896 };
897
895 #define HISTOGRAM_RANGE_LIST(HR) \ 898 #define HISTOGRAM_RANGE_LIST(HR) \
896 /* Generic range histograms */ \ 899 /* Generic range histograms */ \
897 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ 900 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \
898 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ 901 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) \ 902 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \
900 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ 903 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \
901 101) \ 904 101) \
902 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ 905 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \
903 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ 906 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \
904 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ 907 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 1299
1297 RuntimeCallStats runtime_call_stats_; 1300 RuntimeCallStats runtime_call_stats_;
1298 1301
1299 friend class Isolate; 1302 friend class Isolate;
1300 1303
1301 explicit Counters(Isolate* isolate); 1304 explicit Counters(Isolate* isolate);
1302 1305
1303 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); 1306 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
1304 }; 1307 };
1305 1308
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 1309 } // namespace internal
1337 } // namespace v8 1310 } // namespace v8
1338 1311
1339 #endif // V8_COUNTERS_H_ 1312 #endif // V8_COUNTERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698