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

Unified Diff: base/tracked_objects.cc

Issue 445413003: Creating a framework for suppressing pollution of the profiler data (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months 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
Index: base/tracked_objects.cc
diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc
index 56b44c10b2c389fbb053bee442769c0eda51941a..ea0d2ae1f653941879062ea91eb51f42b5f8ee0b 100644
--- a/base/tracked_objects.cc
+++ b/base/tracked_objects.cc
@@ -269,7 +269,8 @@ ThreadData::ThreadData(const std::string& suggested_name)
: next_(NULL),
next_retired_worker_(NULL),
worker_thread_number_(0),
- incarnation_count_for_pool_(-1) {
+ incarnation_count_for_pool_(-1),
+ current_stopwatch_(NULL) {
DCHECK_GE(suggested_name.size(), 0u);
thread_name_ = suggested_name;
PushToHeadOfList(); // Which sets real incarnation_count_for_pool_.
@@ -279,7 +280,8 @@ ThreadData::ThreadData(int thread_number)
: next_(NULL),
next_retired_worker_(NULL),
worker_thread_number_(thread_number),
- incarnation_count_for_pool_(-1) {
+ incarnation_count_for_pool_(-1),
+ current_stopwatch_(NULL) {
CHECK_GT(thread_number, 0);
base::StringAppendF(&thread_name_, "WorkerThread-%d", thread_number);
PushToHeadOfList(); // Which sets real incarnation_count_for_pool_.
@@ -434,7 +436,9 @@ Births* ThreadData::TallyABirth(const Location& location) {
void ThreadData::TallyADeath(const Births& birth,
int32 queue_duration,
- int32 run_duration) {
+ const TaskStopwatch& stopwatch) {
+ int32 run_duration = stopwatch.TaskDurationMs();
jar (doing other things) 2014/08/08 01:34:48 I don't think "run_duration" is always millisecond
vadimt 2014/08/08 20:39:34 Not sure I dotally got it. So, I'm listing some fa
+
// Stir in some randomness, plus add constant in case durations are zero.
const int32 kSomePrimeNumber = 2147483647;
random_number_ += queue_duration + run_duration + kSomePrimeNumber;
@@ -481,8 +485,7 @@ Births* ThreadData::TallyABirthIfActive(const Location& location) {
// static
void ThreadData::TallyRunOnNamedThreadIfTracking(
const base::TrackingInfo& completed_task,
- const TrackedTime& start_of_run,
- const TrackedTime& end_of_run) {
+ const TaskStopwatch& stopwatch) {
if (!kTrackAllTaskObjects)
return; // Not compiled in.
@@ -501,23 +504,20 @@ void ThreadData::TallyRunOnNamedThreadIfTracking(
// get a time value since we "weren't tracking" and we were trying to be
// efficient by not calling for a genuine time value. For simplicity, we'll
// use a default zero duration when we can't calculate a true value.
+ TrackedTime start_of_run = stopwatch.StartTime();
int32 queue_duration = 0;
- int32 run_duration = 0;
if (!start_of_run.is_null()) {
queue_duration = (start_of_run - completed_task.EffectiveTimePosted())
.InMilliseconds();
- if (!end_of_run.is_null())
- run_duration = (end_of_run - start_of_run).InMilliseconds();
}
- current_thread_data->TallyADeath(*birth, queue_duration, run_duration);
+ current_thread_data->TallyADeath(*birth, queue_duration, stopwatch);
}
// static
void ThreadData::TallyRunOnWorkerThreadIfTracking(
const Births* birth,
const TrackedTime& time_posted,
- const TrackedTime& start_of_run,
- const TrackedTime& end_of_run) {
+ const TaskStopwatch& stopwatch) {
if (!kTrackAllTaskObjects)
return; // Not compiled in.
@@ -540,21 +540,18 @@ void ThreadData::TallyRunOnWorkerThreadIfTracking(
if (!current_thread_data)
return;
+ TrackedTime start_of_run = stopwatch.StartTime();
int32 queue_duration = 0;
- int32 run_duration = 0;
if (!start_of_run.is_null()) {
queue_duration = (start_of_run - time_posted).InMilliseconds();
- if (!end_of_run.is_null())
jar (doing other things) 2014/08/08 01:34:48 There seems to be a bunch of code dealing with the
vadimt 2014/08/08 20:39:34 I preserved all nullness checks: (1) You can see t
- run_duration = (end_of_run - start_of_run).InMilliseconds();
}
- current_thread_data->TallyADeath(*birth, queue_duration, run_duration);
+ current_thread_data->TallyADeath(*birth, queue_duration, stopwatch);
}
// static
void ThreadData::TallyRunInAScopedRegionIfTracking(
const Births* birth,
- const TrackedTime& start_of_run,
- const TrackedTime& end_of_run) {
+ const TaskStopwatch& stopwatch) {
if (!kTrackAllTaskObjects)
return; // Not compiled in.
@@ -569,10 +566,7 @@ void ThreadData::TallyRunInAScopedRegionIfTracking(
return;
int32 queue_duration = 0;
- int32 run_duration = 0;
- if (!start_of_run.is_null() && !end_of_run.is_null())
- run_duration = (end_of_run - start_of_run).InMilliseconds();
- current_thread_data->TallyADeath(*birth, queue_duration, run_duration);
+ current_thread_data->TallyADeath(*birth, queue_duration, stopwatch);
}
// static
@@ -858,6 +852,93 @@ void ThreadData::ShutdownSingleThreadedCleanup(bool leak) {
}
//------------------------------------------------------------------------------
+TaskStopwatch::TaskStopwatch()
+ : current_thread_data_(NULL),
+ nested_stopwatches_duration_ms_(0),
+ parent_stopwatch_(NULL) {
+#ifndef NDEBUG
+ state_ = CREATED;
+ running_child_ = NULL;
+#endif
+}
+
+TaskStopwatch::~TaskStopwatch() {
+#ifndef NDEBUG
+ DCHECK(state_ != RUNNING);
+ DCHECK(running_child_ == NULL);
+#endif
+}
+
+void TaskStopwatch::Start(const TrackedTime& start_time) {
+#ifndef NDEBUG
+ DCHECK(state_ != RUNNING);
+ state_ = RUNNING;
+ DCHECK(running_child_ == NULL);
+#endif
+
+ nested_stopwatches_duration_ms_ = 0;
jar (doing other things) 2014/08/08 01:34:48 Given that you said that stopwatches could be star
vadimt 2014/08/08 20:39:34 Stopwatches indeed can be reused i.e.: Start Stop
+ start_time_ = start_time;
+ wallclock_duration_ms_ = 0;
+ current_thread_data_ = ThreadData::Get();
jar (doing other things) 2014/08/08 01:34:48 This is a TLS access, and hence plausibly expensiv
vadimt 2014/08/08 20:39:34 Ah, OK. I assumed that TLS is cheap (like you get
+ if (current_thread_data_) {
+ parent_stopwatch_ = current_thread_data_->current_stopwatch_;
+#ifndef NDEBUG
+ if (parent_stopwatch_) {
+ DCHECK(parent_stopwatch_->state_ == RUNNING);
+ DCHECK(parent_stopwatch_->running_child_ == NULL);
+ parent_stopwatch_->running_child_ = this;
+ }
+#endif
+ current_thread_data_->current_stopwatch_ = this;
+ }
+}
+
+void TaskStopwatch::Stop(const TrackedTime& end_time) {
+#ifndef NDEBUG
+ DCHECK(state_ == RUNNING);
+ state_ = STOPPED;
+ DCHECK(running_child_ == NULL);
+#endif
+
+ if (!start_time_.is_null() && !end_time.is_null()) {
+ wallclock_duration_ms_ = (end_time - start_time_).InMilliseconds();
+ }
+
+ if (current_thread_data_) {
+ DCHECK(current_thread_data_->current_stopwatch_ == this);
+ current_thread_data_->current_stopwatch_ = parent_stopwatch_;
+
+ if (parent_stopwatch_) {
+#ifndef NDEBUG
+ DCHECK(parent_stopwatch_->state_ == RUNNING);
+ DCHECK(parent_stopwatch_->running_child_ == this);
+ parent_stopwatch_->running_child_ = NULL;
+#endif
+ parent_stopwatch_->nested_stopwatches_duration_ms_ +=
+ wallclock_duration_ms_;
+ parent_stopwatch_ = NULL;
+ }
+
+ current_thread_data_ = NULL;
+ }
+}
+
+TrackedTime TaskStopwatch::StartTime() const {
+#ifndef NDEBUG
+ DCHECK(state_ != CREATED);
+#endif
+ return start_time_;
+}
+
+int32 TaskStopwatch::TaskDurationMs() const {
+#ifndef NDEBUG
+ DCHECK(state_ == STOPPED);
+#endif
+
+ return wallclock_duration_ms_ - nested_stopwatches_duration_ms_;
+}
+
+//------------------------------------------------------------------------------
TaskSnapshot::TaskSnapshot() {
}

Powered by Google App Engine
This is Rietveld 408576698