From 12f0f7db8095f1a5e40fb7227b217ddfc1724116 Mon Sep 17 00:00:00 2001 From: vadimt Date: Mon, 15 Sep 2014 12:19:38 -0700 Subject: Creating a framework for suppressing pollution of the profiler data and applying for know cases of pollution. See the bug. The CL introduces TaskStopwatch that has to be used to measure run time for tasks. It takes care of double-counting run time in the nested-tasks case by subtracting run time of nested tasks from their parents. TaskStopwatch can be also used for subtracting other nested intervals, such as the time while a nested message pump runs. ThreadData::TallyADeath now takes a stopwatch parameter instead of start_time and end_time. This helps avoid mistakes when the interval passed up to the parent for exclusion is different from the interval for the current task duration. BUG=401560 Review URL: https://codereview.chromium.org/445413003 Cr-Commit-Position: refs/heads/master@{#294865} --- base/threading/sequenced_worker_pool.cc | 10 +++++----- base/threading/worker_pool_posix.cc | 8 ++++---- base/threading/worker_pool_win.cc | 11 +++++++---- 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'base/threading') diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc index 532f26e..38b2998 100644 --- a/base/threading/sequenced_worker_pool.cc +++ b/base/threading/sequenced_worker_pool.cc @@ -755,13 +755,13 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { this_worker->set_running_task_info( SequenceToken(task.sequence_token_id), task.shutdown_behavior); - tracked_objects::TrackedTime start_time = - tracked_objects::ThreadData::NowForStartOfRun(task.birth_tally); - + tracked_objects::ThreadData::PrepareForStartOfRun(task.birth_tally); + tracked_objects::TaskStopwatch stopwatch; task.task.Run(); + stopwatch.Stop(); - tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(task, - start_time, tracked_objects::ThreadData::NowForEndOfRun()); + tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( + task, stopwatch); // Make sure our task is erased outside the lock for the // same reason we do this with delete_these_oustide_lock. diff --git a/base/threading/worker_pool_posix.cc b/base/threading/worker_pool_posix.cc index f00d799..167d20f 100644 --- a/base/threading/worker_pool_posix.cc +++ b/base/threading/worker_pool_posix.cc @@ -95,14 +95,14 @@ void WorkerThread::ThreadMain() { "src_file", pending_task.posted_from.file_name(), "src_func", pending_task.posted_from.function_name()); - TrackedTime start_time = - tracked_objects::ThreadData::NowForStartOfRun(pending_task.birth_tally); - + tracked_objects::ThreadData::PrepareForStartOfRun(pending_task.birth_tally); + tracked_objects::TaskStopwatch stopwatch; pending_task.task.Run(); + stopwatch.Stop(); tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( pending_task.birth_tally, TrackedTime(pending_task.time_posted), - start_time, tracked_objects::ThreadData::NowForEndOfRun()); + stopwatch); } // The WorkerThread is non-joinable, so it deletes itself. diff --git a/base/threading/worker_pool_win.cc b/base/threading/worker_pool_win.cc index fa11dc5..8fc7324 100644 --- a/base/threading/worker_pool_win.cc +++ b/base/threading/worker_pool_win.cc @@ -25,17 +25,20 @@ DWORD CALLBACK WorkItemCallback(void* param) { "src_file", pending_task->posted_from.file_name(), "src_func", pending_task->posted_from.function_name()); - tracked_objects::TrackedTime start_time = - tracked_objects::ThreadData::NowForStartOfRun(pending_task->birth_tally); + tracked_objects::ThreadData::PrepareForStartOfRun(pending_task->birth_tally); g_worker_pool_running_on_this_thread.Get().Set(true); + + tracked_objects::TaskStopwatch stopwatch; pending_task->task.Run(); + stopwatch.Stop(); + g_worker_pool_running_on_this_thread.Get().Set(false); tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( pending_task->birth_tally, - tracked_objects::TrackedTime(pending_task->time_posted), start_time, - tracked_objects::ThreadData::NowForEndOfRun()); + tracked_objects::TrackedTime(pending_task->time_posted), + stopwatch); delete pending_task; return 0; -- cgit v1.1