Commit 4a24ab21 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[runtime-call-stats] Allow empty RCS stack upon Leave

The stack can be cleared with RuntimeCallStats::Reset() call.
Correctly handle the case by silently exit the running timer scopes.

BUG=chromium:760649

Change-Id: I51ecca5591a7af358f3e50779d0f81cb9d76e502
Reviewed-on: https://chromium-review.googlesource.com/734121Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48847}
parent b3d84990
......@@ -479,7 +479,7 @@ void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
CHECK(stats->IsCalledOnTheSameThread());
RuntimeCallCounter* counter = &(stats->*counter_id);
DCHECK_NOT_NULL(counter->name());
timer->Start(counter, stats->current_timer_.Value());
timer->Start(counter, stats->current_timer());
stats->current_timer_.SetValue(timer);
stats->current_counter_.SetValue(counter);
}
......@@ -487,17 +487,18 @@ void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
// static
void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) {
CHECK(stats->IsCalledOnTheSameThread());
if (stats->current_timer_.Value() != timer) {
RuntimeCallTimer* stack_top = stats->current_timer();
if (stack_top == nullptr) return; // Missing timer is a result of Reset().
if (stack_top != timer) {
// The branch is added to catch a crash crbug.com/760649
RuntimeCallTimer* stack_top = stats->current_timer_.Value();
EmbeddedVector<char, 200> text;
SNPrintF(text, "ERROR: Leaving counter '%s', stack top '%s'.\n",
timer->name(), stack_top ? stack_top->name() : "(null)");
timer->name(), stack_top->name());
USE(text);
CHECK(false);
}
stats->current_timer_.SetValue(timer->Stop());
RuntimeCallTimer* cur_timer = stats->current_timer_.Value();
RuntimeCallTimer* cur_timer = stats->current_timer();
stats->current_counter_.SetValue(cur_timer ? cur_timer->counter() : nullptr);
}
......
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