Commit 1f96226b authored by lpy's avatar lpy Committed by Commit bot

[Tracing] Fix inaccurate time accumulation in runtime statistics.

In tracing we collect runtime statistics data based on top level trace events,
in this patch we force to clear the whole runtime statistics stack when we
enter top level trace events.

Review-Url: https://codereview.chromium.org/2483583002
Cr-Commit-Position: refs/heads/master@{#40867}
parent da3e2225
......@@ -301,7 +301,8 @@ void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) {
// buried one that's leaving. We don't care about keeping nested timings
// accurate, just avoid crashing by keeping the chain intact.
RuntimeCallTimer* next = stats->current_timer_.Value();
while (next->parent() != timer) next = next->parent();
while (next && next->parent() != timer) next = next->parent();
if (next == nullptr) return;
next->parent_.SetValue(timer->Stop());
}
}
......@@ -347,6 +348,14 @@ void RuntimeCallStats::Print(std::ostream& os) {
void RuntimeCallStats::Reset() {
if (V8_LIKELY(FLAG_runtime_stats == 0)) return;
// In tracing, we only what to trace the time spent on top level trace events,
// if runtime counter stack is not empty, we should clear the whole runtime
// counter stack, and then reset counters so that we can dump counters into
// top level trace events accurately.
while (current_timer_.Value()) {
current_timer_.SetValue(current_timer_.Value()->Stop());
}
#define RESET_COUNTER(name) this->name.Reset();
FOR_EACH_MANUAL_COUNTER(RESET_COUNTER)
#undef RESET_COUNTER
......@@ -371,9 +380,6 @@ void RuntimeCallStats::Reset() {
}
void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) {
if (current_timer_.Value() != nullptr) {
current_timer_.Value()->Elapsed();
}
#define DUMP_COUNTER(name) \
if (this->name.count > 0) this->name.Dump(value);
FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER)
......
......@@ -45,7 +45,7 @@ void CallStatsScopedTracer::Initialize(v8::internal::Isolate* isolate,
p_data_ = &data_;
RuntimeCallStats* table = isolate->counters()->runtime_call_stats();
has_parent_scope_ = table->InUse();
if (!has_parent_scope_ && table->current_timer() == NULL) table->Reset();
if (!has_parent_scope_) table->Reset();
v8::internal::tracing::AddTraceEvent(
TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name,
v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
......
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