Commit 21650958 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[runtime] Use methods instead of static functions in RuntimeCallStats.

Bug: chromium:758183
Change-Id: If43122140626207e3f972ccb7d048e012db3ed02
Reviewed-on: https://chromium-review.googlesource.com/796771
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49749}
parent 77672139
......@@ -449,26 +449,24 @@ RuntimeCallStats::RuntimeCallStats() : in_use_(false) {
}
}
// static
void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
void RuntimeCallStats::Enter(RuntimeCallTimer* timer,
RuntimeCallCounterId counter_id) {
DCHECK(stats->IsCalledOnTheSameThread());
RuntimeCallCounter* counter = stats->GetCounter(counter_id);
DCHECK(IsCalledOnTheSameThread());
RuntimeCallCounter* counter = GetCounter(counter_id);
DCHECK_NOT_NULL(counter->name());
timer->Start(counter, stats->current_timer());
stats->current_timer_.SetValue(timer);
stats->current_counter_.SetValue(counter);
timer->Start(counter, current_timer());
current_timer_.SetValue(timer);
current_counter_.SetValue(counter);
}
// static
void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) {
DCHECK(stats->IsCalledOnTheSameThread());
RuntimeCallTimer* stack_top = stats->current_timer();
void RuntimeCallStats::Leave(RuntimeCallTimer* timer) {
DCHECK(IsCalledOnTheSameThread());
RuntimeCallTimer* stack_top = current_timer();
if (stack_top == nullptr) return; // Missing timer is a result of Reset().
CHECK(stack_top == timer);
stats->current_timer_.SetValue(timer->Stop());
RuntimeCallTimer* cur_timer = stats->current_timer();
stats->current_counter_.SetValue(cur_timer ? cur_timer->counter() : nullptr);
current_timer_.SetValue(timer->Stop());
RuntimeCallTimer* cur_timer = current_timer();
current_counter_.SetValue(cur_timer ? cur_timer->counter() : nullptr);
}
void RuntimeCallStats::Add(RuntimeCallStats* other) {
......@@ -479,15 +477,13 @@ void RuntimeCallStats::Add(RuntimeCallStats* other) {
// static
void RuntimeCallStats::CorrectCurrentCounterId(
RuntimeCallStats* stats, RuntimeCallCounterId counter_id) {
DCHECK(stats->IsCalledOnTheSameThread());
// When RCS are enabled dynamically there might be no stats or timer set up.
if (stats == nullptr) return;
RuntimeCallTimer* timer = stats->current_timer_.Value();
RuntimeCallCounterId counter_id) {
DCHECK(IsCalledOnTheSameThread());
RuntimeCallTimer* timer = current_timer();
if (timer == nullptr) return;
RuntimeCallCounter* counter = stats->GetCounter(counter_id);
RuntimeCallCounter* counter = GetCounter(counter_id);
timer->set_counter(counter);
stats->current_counter_.SetValue(counter);
current_counter_.SetValue(counter);
}
bool RuntimeCallStats::IsCalledOnTheSameThread() {
......
......@@ -950,20 +950,18 @@ class RuntimeCallStats final : public ZoneObject {
// Starting measuring the time for a function. This will establish the
// connection to the parent counter for properly calculating the own times.
V8_EXPORT_PRIVATE static void Enter(RuntimeCallStats* stats,
RuntimeCallTimer* timer,
RuntimeCallCounterId counter_id);
V8_EXPORT_PRIVATE void Enter(RuntimeCallTimer* timer,
RuntimeCallCounterId counter_id);
// Leave a scope for a measured runtime function. This will properly add
// the time delta to the current_counter and subtract the delta from its
// parent.
V8_EXPORT_PRIVATE static void Leave(RuntimeCallStats* stats,
RuntimeCallTimer* timer);
V8_EXPORT_PRIVATE void Leave(RuntimeCallTimer* timer);
// Set counter id for the innermost measurement. It can be used to refine
// event kind when a runtime entry counter is too generic.
V8_EXPORT_PRIVATE static void CorrectCurrentCounterId(
RuntimeCallStats* stats, RuntimeCallCounterId counter_id);
V8_EXPORT_PRIVATE void CorrectCurrentCounterId(
RuntimeCallCounterId counter_id);
V8_EXPORT_PRIVATE void Reset();
// Add all entries from another stats object.
......@@ -1000,9 +998,8 @@ class RuntimeCallStats final : public ZoneObject {
#define CHANGE_CURRENT_RUNTIME_COUNTER(runtime_call_stats, counter_id) \
do { \
if (V8_UNLIKELY(FLAG_runtime_stats)) { \
RuntimeCallStats::CorrectCurrentCounterId(runtime_call_stats, \
counter_id); \
if (V8_UNLIKELY(FLAG_runtime_stats) && runtime_call_stats) { \
runtime_call_stats->CorrectCurrentCounterId(counter_id); \
} \
} while (false)
......@@ -1025,12 +1022,12 @@ class RuntimeCallTimerScope {
RuntimeCallCounterId counter_id) {
if (V8_LIKELY(!FLAG_runtime_stats || stats == nullptr)) return;
stats_ = stats;
RuntimeCallStats::Enter(stats_, &timer_, counter_id);
stats_->Enter(&timer_, counter_id);
}
inline ~RuntimeCallTimerScope() {
if (V8_UNLIKELY(stats_ != nullptr)) {
RuntimeCallStats::Leave(stats_, &timer_);
stats_->Leave(&timer_);
}
}
......@@ -1554,7 +1551,7 @@ RuntimeCallTimerScope::RuntimeCallTimerScope(Isolate* isolate,
RuntimeCallCounterId counter_id) {
if (V8_LIKELY(!FLAG_runtime_stats)) return;
stats_ = isolate->counters()->runtime_call_stats();
RuntimeCallStats::Enter(stats_, &timer_, counter_id);
stats_->Enter(&timer_, counter_id);
}
} // namespace internal
......
......@@ -37,8 +37,7 @@ GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope)
// TODO(cbruni): remove once we fully moved to a trace-based system.
if (V8_LIKELY(!FLAG_runtime_stats)) return;
runtime_stats_ = tracer_->heap_->isolate()->counters()->runtime_call_stats();
RuntimeCallStats::Enter(runtime_stats_, &timer_,
GCTracer::RCSCounterFromScope(scope));
runtime_stats_->Enter(&timer_, GCTracer::RCSCounterFromScope(scope));
}
GCTracer::Scope::~Scope() {
......@@ -46,7 +45,7 @@ GCTracer::Scope::~Scope() {
scope_, tracer_->heap_->MonotonicallyIncreasingTimeInMs() - start_time_);
// TODO(cbruni): remove once we fully moved to a trace-based system.
if (V8_LIKELY(runtime_stats_ == nullptr)) return;
RuntimeCallStats::Leave(runtime_stats_, &timer_);
runtime_stats_->Leave(&timer_);
}
const char* GCTracer::Scope::Name(ScopeId id) {
......
......@@ -2717,8 +2717,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
: RuntimeCallCounterId::
kPreParseBackgroundNoVariableResolution;
}
RuntimeCallStats::CorrectCurrentCounterId(runtime_call_stats_,
counter_id);
if (runtime_call_stats_) {
runtime_call_stats_->CorrectCurrentCounterId(counter_id);
}
}
}
......
......@@ -302,7 +302,7 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimer) {
RuntimeCallTimer timer;
Sleep(50);
RuntimeCallStats::Enter(stats(), &timer, counter_id());
stats()->Enter(&timer, counter_id());
EXPECT_EQ(counter(), timer.counter());
EXPECT_EQ(nullptr, timer.parent());
EXPECT_TRUE(timer.IsStarted());
......@@ -310,7 +310,7 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimer) {
Sleep(100);
RuntimeCallStats::Leave(stats(), &timer);
stats()->Leave(&timer);
Sleep(50);
EXPECT_FALSE(timer.IsStarted());
EXPECT_EQ(1, counter()->count());
......@@ -321,7 +321,7 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimerSubTimer) {
RuntimeCallTimer timer;
RuntimeCallTimer timer2;
RuntimeCallStats::Enter(stats(), &timer, counter_id());
stats()->Enter(&timer, counter_id());
EXPECT_TRUE(timer.IsStarted());
EXPECT_FALSE(timer2.IsStarted());
EXPECT_EQ(counter(), timer.counter());
......@@ -330,7 +330,7 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimerSubTimer) {
Sleep(50);
RuntimeCallStats::Enter(stats(), &timer2, counter_id2());
stats()->Enter(&timer2, counter_id2());
// timer 1 is paused, while timer 2 is active.
EXPECT_TRUE(timer2.IsStarted());
EXPECT_EQ(counter(), timer.counter());
......@@ -340,7 +340,7 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimerSubTimer) {
EXPECT_EQ(&timer2, stats()->current_timer());
Sleep(100);
RuntimeCallStats::Leave(stats(), &timer2);
stats()->Leave(&timer2);
// The subtimer subtracts its time from the parent timer.
EXPECT_TRUE(timer.IsStarted());
......@@ -353,7 +353,7 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimerSubTimer) {
Sleep(100);
RuntimeCallStats::Leave(stats(), &timer);
stats()->Leave(&timer);
EXPECT_FALSE(timer.IsStarted());
EXPECT_EQ(1, counter()->count());
EXPECT_EQ(1, counter2()->count());
......@@ -366,13 +366,13 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimerRecursive) {
RuntimeCallTimer timer;
RuntimeCallTimer timer2;
RuntimeCallStats::Enter(stats(), &timer, counter_id());
stats()->Enter(&timer, counter_id());
EXPECT_EQ(counter(), timer.counter());
EXPECT_EQ(nullptr, timer.parent());
EXPECT_TRUE(timer.IsStarted());
EXPECT_EQ(&timer, stats()->current_timer());
RuntimeCallStats::Enter(stats(), &timer2, counter_id());
stats()->Enter(&timer2, counter_id());
EXPECT_EQ(counter(), timer2.counter());
EXPECT_EQ(nullptr, timer.parent());
EXPECT_EQ(&timer, timer2.parent());
......@@ -381,7 +381,7 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimerRecursive) {
Sleep(50);
RuntimeCallStats::Leave(stats(), &timer2);
stats()->Leave(&timer2);
EXPECT_EQ(nullptr, timer.parent());
EXPECT_FALSE(timer2.IsStarted());
EXPECT_TRUE(timer.IsStarted());
......@@ -390,7 +390,7 @@ TEST_F(RuntimeCallStatsTest, RuntimeCallTimerRecursive) {
Sleep(100);
RuntimeCallStats::Leave(stats(), &timer);
stats()->Leave(&timer);
EXPECT_FALSE(timer.IsStarted());
EXPECT_EQ(2, counter()->count());
EXPECT_EQ(150, counter()->time().InMicroseconds());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment