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

Unified Diff: src/counters.h

Issue 2511093002: [counters] RuntimeStats: fix wrong bookkeeping when dynamically changing counters. (Closed)
Patch Set: merge with master 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/counters.cc » ('j') | test/unittests/counters-unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/counters.h
diff --git a/src/counters.h b/src/counters.h
index 09371e6938101a7f1fbc253a5d461de1271085b1..4b5ec057bf8192ed06d43b9d5ad87c7e3b986033 100644
--- a/src/counters.h
+++ b/src/counters.h
@@ -484,65 +484,51 @@ double AggregatedMemoryHistogram<Histogram>::Aggregate(double current_ms,
value * ((current_ms - last_ms_) / interval_ms);
}
-struct RuntimeCallCounter {
- explicit RuntimeCallCounter(const char* name) : name(name) {}
+class RuntimeCallCounter final {
+ public:
+ explicit RuntimeCallCounter(const char* name) : name_(name) {}
V8_NOINLINE void Reset();
V8_NOINLINE void Dump(v8::tracing::TracedValue* value);
void Add(RuntimeCallCounter* other);
- const char* name;
- int64_t count = 0;
- base::TimeDelta time;
+ const char* name() const { return name_; }
+ int64_t count() const { return count_; }
+ base::TimeDelta time() const { return time_; }
+ void Increment() { count_++; }
+ void Add(base::TimeDelta delta) { time_ += delta; }
+
+ private:
+ const char* name_;
+ int64_t count_ = 0;
+ base::TimeDelta time_;
};
// RuntimeCallTimer is used to keep track of the stack of currently active
// timers used for properly measuring the own time of a RuntimeCallCounter.
-class RuntimeCallTimer {
+class RuntimeCallTimer final {
public:
RuntimeCallCounter* counter() { return counter_; }
- base::ElapsedTimer timer() { return timer_; }
+ void set_counter(RuntimeCallCounter* counter) { counter_ = counter; }
RuntimeCallTimer* parent() const { return parent_.Value(); }
+ void set_parent(RuntimeCallTimer* timer) { parent_.SetValue(timer); }
+ const char* name() const { return counter_->name(); }
- private:
- friend class RuntimeCallStats;
-
- inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent) {
- counter_ = counter;
- parent_.SetValue(parent);
- if (FLAG_runtime_stats !=
- v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) {
- timer_.Start();
- }
- }
+ inline bool IsStarted();
- inline RuntimeCallTimer* Stop() {
- if (!timer_.IsStarted()) return parent();
- base::TimeDelta delta = timer_.Elapsed();
- timer_.Stop();
- counter_->count++;
- counter_->time += delta;
- if (parent()) {
- // Adjust parent timer so that it does not include sub timer's time.
- parent()->counter_->time -= delta;
- }
- return parent();
- }
+ inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent);
+ void Snapshot();
+ inline RuntimeCallTimer* Stop();
- inline void Elapsed() {
- base::TimeDelta delta = timer_.Elapsed();
- counter_->time += delta;
- if (parent()) {
- parent()->counter_->time -= delta;
- parent()->Elapsed();
- }
- timer_.Restart();
- }
-
- const char* name() { return counter_->name; }
+ private:
+ inline void Pause(base::TimeTicks now);
+ inline void Resume(base::TimeTicks now);
+ inline void CommitTimeToCounter();
+ inline base::TimeTicks Now();
RuntimeCallCounter* counter_ = nullptr;
base::AtomicValue<RuntimeCallTimer*> parent_;
- base::ElapsedTimer timer_;
+ base::TimeTicks start_ticks_;
+ base::TimeDelta elapsed_;
};
#define FOR_EACH_API_COUNTER(V) \
@@ -749,6 +735,9 @@ class RuntimeCallTimer {
V(PrototypeObject_DeleteProperty) \
V(RecompileConcurrent) \
V(RecompileSynchronous) \
+ V(TestCounter1) \
+ V(TestCounter2) \
+ V(TestCounter3) \
/* Dummy counter for the unexpected stub miss. */ \
V(UnexpectedStubMiss)
@@ -820,7 +809,7 @@ class RuntimeCallTimer {
V(StoreIC_StoreTransitionDH) \
V(StoreIC_StoreViaSetter)
-class RuntimeCallStats : public ZoneObject {
+class V8_EXPORT_PRIVATE RuntimeCallStats final : public ZoneObject {
public:
typedef RuntimeCallCounter RuntimeCallStats::*CounterId;
@@ -895,6 +884,36 @@ class RuntimeCallStats : public ZoneObject {
CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \
Handler_##counter_name)
+// A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the
+// the time of C++ scope.
+class RuntimeCallTimerScope {
+ public:
+ inline RuntimeCallTimerScope(Isolate* isolate,
+ RuntimeCallStats::CounterId counter_id);
+ // This constructor is here just to avoid calling GetIsolate() when the
+ // stats are disabled and the isolate is not directly available.
+ inline RuntimeCallTimerScope(HeapObject* heap_object,
+ RuntimeCallStats::CounterId counter_id);
+ inline RuntimeCallTimerScope(RuntimeCallStats* stats,
+ RuntimeCallStats::CounterId counter_id);
+
+ inline ~RuntimeCallTimerScope() {
+ if (V8_UNLIKELY(stats_ != nullptr)) {
+ RuntimeCallStats::Leave(stats_, &timer_);
+ }
+ }
+
+ private:
+ V8_INLINE void Initialize(RuntimeCallStats* stats,
+ RuntimeCallStats::CounterId counter_id) {
+ stats_ = stats;
+ RuntimeCallStats::Enter(stats_, &timer_, counter_id);
+ }
+
+ RuntimeCallStats* stats_ = nullptr;
+ RuntimeCallTimer timer_;
+};
+
#define HISTOGRAM_RANGE_LIST(HR) \
/* Generic range histograms */ \
HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \
@@ -1306,36 +1325,6 @@ class Counters {
DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
};
-// A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the
-// the time of C++ scope.
-class RuntimeCallTimerScope {
- public:
- inline RuntimeCallTimerScope(Isolate* isolate,
- RuntimeCallStats::CounterId counter_id);
- // This constructor is here just to avoid calling GetIsolate() when the
- // stats are disabled and the isolate is not directly available.
- inline RuntimeCallTimerScope(HeapObject* heap_object,
- RuntimeCallStats::CounterId counter_id);
- inline RuntimeCallTimerScope(RuntimeCallStats* stats,
- RuntimeCallStats::CounterId counter_id);
-
- inline ~RuntimeCallTimerScope() {
- if (V8_UNLIKELY(stats_ != nullptr)) {
- RuntimeCallStats::Leave(stats_, &timer_);
- }
- }
-
- private:
- V8_INLINE void Initialize(RuntimeCallStats* stats,
- RuntimeCallStats::CounterId counter_id) {
- stats_ = stats;
- RuntimeCallStats::Enter(stats_, &timer_, counter_id);
- }
-
- RuntimeCallStats* stats_ = nullptr;
- RuntimeCallTimer timer_;
-};
-
} // namespace internal
} // namespace v8
« 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