Commit fdca1bb2 authored by alph's avatar alph Committed by Commit bot

[profiler] Make certain Runtime Call Stats fields atomic.

Make RuntimeCallTimer::parent_ and RuntimeCallStats::current_timer_
fields atomic as they are accessed from the signal handler.

BUG=chromium:660428

Review-Url: https://codereview.chromium.org/2464973002
Cr-Commit-Position: refs/heads/master@{#40709}
parent a3b77d56
......@@ -288,36 +288,36 @@ void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) {
void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
CounterId counter_id) {
RuntimeCallCounter* counter = &(stats->*counter_id);
timer->Start(counter, stats->current_timer_);
stats->current_timer_ = timer;
timer->Start(counter, stats->current_timer_.Value());
stats->current_timer_.SetValue(timer);
}
// static
void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) {
if (stats->current_timer_ == timer) {
stats->current_timer_ = timer->Stop();
if (stats->current_timer_.Value() == timer) {
stats->current_timer_.SetValue(timer->Stop());
} else {
// Must be a Threading cctest. Walk the chain of Timers to find the
// 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_;
while (next->parent_ != timer) next = next->parent_;
next->parent_ = timer->Stop();
RuntimeCallTimer* next = stats->current_timer_.Value();
while (next->parent() != timer) next = next->parent();
next->parent_.SetValue(timer->Stop());
}
}
// static
void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats,
CounterId counter_id) {
DCHECK_NOT_NULL(stats->current_timer_);
DCHECK_NOT_NULL(stats->current_timer_.Value());
RuntimeCallCounter* counter = &(stats->*counter_id);
stats->current_timer_->counter_ = counter;
stats->current_timer_.Value()->counter_ = counter;
}
void RuntimeCallStats::Print(std::ostream& os) {
RuntimeCallStatEntries entries;
if (current_timer_ != NULL) {
current_timer_->Elapsed();
if (current_timer_.Value() != nullptr) {
current_timer_.Value()->Elapsed();
}
#define PRINT_COUNTER(name) entries.Add(&this->name);
......@@ -371,8 +371,8 @@ void RuntimeCallStats::Reset() {
}
void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) {
if (current_timer_ != NULL) {
current_timer_->Elapsed();
if (current_timer_.Value() != nullptr) {
current_timer_.Value()->Elapsed();
}
#define DUMP_COUNTER(name) \
if (this->name.count > 0) this->name.Dump(value);
......
......@@ -7,6 +7,7 @@
#include "include/v8.h"
#include "src/allocation.h"
#include "src/base/atomic-utils.h"
#include "src/base/platform/elapsed-timer.h"
#include "src/base/platform/time.h"
#include "src/builtins/builtins.h"
......@@ -496,17 +497,16 @@ struct RuntimeCallCounter {
// timers used for properly measuring the own time of a RuntimeCallCounter.
class RuntimeCallTimer {
public:
RuntimeCallTimer() {}
RuntimeCallCounter* counter() { return counter_; }
base::ElapsedTimer timer() { return timer_; }
RuntimeCallTimer* parent() const { return parent_; }
RuntimeCallTimer* parent() const { return parent_.Value(); }
private:
friend class RuntimeCallStats;
inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent) {
counter_ = counter;
parent_ = parent;
parent_.SetValue(parent);
timer_.Start();
}
......@@ -515,25 +515,25 @@ class RuntimeCallTimer {
timer_.Stop();
counter_->count++;
counter_->time += delta;
if (parent_ != NULL) {
if (parent()) {
// Adjust parent timer so that it does not include sub timer's time.
parent_->counter_->time -= delta;
parent()->counter_->time -= delta;
}
return parent_;
return parent();
}
inline void Elapsed() {
base::TimeDelta delta = timer_.Elapsed();
counter_->time += delta;
if (parent_ != nullptr) {
parent_->counter_->time -= delta;
parent_->Elapsed();
if (parent()) {
parent()->counter_->time -= delta;
parent()->Elapsed();
}
timer_.Restart();
}
RuntimeCallCounter* counter_ = nullptr;
RuntimeCallTimer* parent_ = nullptr;
base::AtomicValue<RuntimeCallTimer*> parent_;
base::ElapsedTimer timer_;
};
......@@ -842,12 +842,12 @@ class RuntimeCallStats {
in_use_ = false;
}
RuntimeCallTimer* current_timer() { return current_timer_; }
RuntimeCallTimer* current_timer() { return current_timer_.Value(); }
bool InUse() { return in_use_; }
private:
// Counter to track recursive time events.
RuntimeCallTimer* current_timer_ = NULL;
base::AtomicValue<RuntimeCallTimer*> current_timer_;
// Used to track nested tracing scopes.
bool in_use_;
};
......
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