diff options
-rw-r--r-- | base/message_loop.cc | 5 | ||||
-rw-r--r-- | base/profiler/scoped_profile.cc | 4 | ||||
-rw-r--r-- | base/profiler/tracked_time_unittest.cc | 4 | ||||
-rw-r--r-- | base/threading/worker_pool_posix.cc | 4 | ||||
-rw-r--r-- | base/threading/worker_pool_win.cc | 5 | ||||
-rw-r--r-- | base/tracked_objects.cc | 10 | ||||
-rw-r--r-- | base/tracked_objects.h | 15 |
7 files changed, 35 insertions, 12 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc index f72ded1..c04fa8b 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -491,7 +491,8 @@ void MessageLoop::RunTask(const PendingTask& pending_task) { HistogramEvent(kTaskRunEvent); - tracked_objects::TrackedTime start_time = tracked_objects::ThreadData::Now(); + tracked_objects::TrackedTime start_time = + tracked_objects::ThreadData::NowForStartOfRun(); FOR_EACH_OBSERVER(TaskObserver, task_observers_, WillProcessTask(pending_task.time_posted)); @@ -500,7 +501,7 @@ void MessageLoop::RunTask(const PendingTask& pending_task) { DidProcessTask(pending_task.time_posted)); tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, - start_time, tracked_objects::ThreadData::Now()); + start_time, tracked_objects::ThreadData::NowForEndOfRun()); nestable_tasks_allowed_ = true; } diff --git a/base/profiler/scoped_profile.cc b/base/profiler/scoped_profile.cc index 7bd31fe..71e25dc 100644 --- a/base/profiler/scoped_profile.cc +++ b/base/profiler/scoped_profile.cc @@ -13,7 +13,7 @@ namespace tracked_objects { ScopedProfile::ScopedProfile(const Location& location) : birth_(ThreadData::TallyABirthIfActive(location)), - start_of_run_(ThreadData::Now()) { + start_of_run_(ThreadData::NowForStartOfRun()) { } ScopedProfile::~ScopedProfile() { @@ -24,7 +24,7 @@ void ScopedProfile::StopClockAndTally() { if (!birth_) return; ThreadData::TallyRunInAScopedRegionIfTracking(birth_, start_of_run_, - ThreadData::Now()); + ThreadData::NowForEndOfRun()); birth_ = NULL; } diff --git a/base/profiler/tracked_time_unittest.cc b/base/profiler/tracked_time_unittest.cc index fee4ba6..7474375 100644 --- a/base/profiler/tracked_time_unittest.cc +++ b/base/profiler/tracked_time_unittest.cc @@ -81,6 +81,10 @@ TEST(TrackedTimeTest, TrackedTimerDisabled) { // Since we disabled tracking, we should get a null response. TrackedTime track_now = ThreadData::Now(); EXPECT_TRUE(track_now.is_null()); + track_now = ThreadData::NowForStartOfRun(); + EXPECT_TRUE(track_now.is_null()); + track_now = ThreadData::NowForEndOfRun(); + EXPECT_TRUE(track_now.is_null()); } TEST(TrackedTimeTest, TrackedTimerEnabled) { diff --git a/base/threading/worker_pool_posix.cc b/base/threading/worker_pool_posix.cc index 3ddc08c..886a547 100644 --- a/base/threading/worker_pool_posix.cc +++ b/base/threading/worker_pool_posix.cc @@ -90,13 +90,13 @@ void WorkerThread::ThreadMain() { "src_func", pending_task.posted_from.function_name()); tracked_objects::TrackedTime start_time = - tracked_objects::ThreadData::Now(); + tracked_objects::ThreadData::NowForStartOfRun(); pending_task.task.Run(); tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( pending_task.birth_tally, pending_task.time_posted, - start_time, tracked_objects::ThreadData::Now()); + start_time, tracked_objects::ThreadData::NowForEndOfRun()); } // 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 b73cabd..9444476 100644 --- a/base/threading/worker_pool_win.cc +++ b/base/threading/worker_pool_win.cc @@ -43,13 +43,14 @@ 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::Now(); + tracked_objects::TrackedTime start_time = + tracked_objects::ThreadData::NowForStartOfRun(); pending_task->task.Run(); tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( pending_task->birth_tally, pending_task->time_posted, - start_time, tracked_objects::ThreadData::Now()); + start_time, tracked_objects::ThreadData::NowForEndOfRun()); delete pending_task; return 0; diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc index 6126a45e1..3a86814 100644 --- a/base/tracked_objects.cc +++ b/base/tracked_objects.cc @@ -618,6 +618,16 @@ bool ThreadData::tracking_status() { } // static +TrackedTime ThreadData::NowForStartOfRun() { + return Now(); +} + +// static +TrackedTime ThreadData::NowForEndOfRun() { + return Now(); +} + +// static TrackedTime ThreadData::Now() { if (kTrackAllTaskObjects && tracking_status()) return TrackedTime::Now(); diff --git a/base/tracked_objects.h b/base/tracked_objects.h index 5068e6a..806934f 100644 --- a/base/tracked_objects.h +++ b/base/tracked_objects.h @@ -26,7 +26,7 @@ // across a series of objects so that the counts and times can be rapidly // updated without (usually) having to lock the data, and hence there is usually // very little contention caused by the tracking. The data can be viewed via -// the about:tracking URL, with a variety of sorting and filtering choices. +// the about:profiler URL, with a variety of sorting and filtering choices. // // These classes serve as the basis of a profiler of sorts for the Tasks system. // As a result, design decisions were made to maximize speed, by minimizing @@ -118,7 +118,7 @@ // // The above description tries to define the high performance (run time) // portions of these classes. After gathering statistics, calls instigated -// by visiting about:tracking will assemble and aggregate data for display. The +// by visiting about:profiler will assemble and aggregate data for display. The // following data structures are used for producing such displays. They are // not performance critical, and their only major constraint is that they should // be able to run concurrently with ongoing augmentation of the birth and death @@ -153,7 +153,7 @@ // (example: how many threads are in a specific consecutive set of Snapshots? // What was the total birth count for that set? etc.). Aggregation instances // collect running sums of any set of snapshot instances, and are used to print -// sub-totals in an about:tracking page. +// sub-totals in an about:profiler page. // // TODO(jar): I need to store DataCollections, and provide facilities for taking // the difference between two gathered DataCollections. For now, I'm just @@ -663,6 +663,13 @@ class BASE_EXPORT ThreadData { static bool InitializeAndSetTrackingStatus(bool status); static bool tracking_status(); + // Special versions of Now() for getting times at start and end of a tracked + // run. They are super fast when tracking is disabled, and have some internal + // side effects when we are tracking, so that we can deduce the amount of time + // accumulated outside of execution of tracked runs. + static TrackedTime NowForStartOfRun(); + static TrackedTime NowForEndOfRun(); + // Provide a time function that does nothing (runs fast) when we don't have // the profiler enabled. It will generally be optimized away when it is // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of @@ -722,7 +729,7 @@ class BASE_EXPORT ThreadData { static base::ThreadLocalStorage::Slot tls_index_; // Link to the most recently created instance (starts a null terminated list). - // The list is traversed by about:tracking when it needs to snapshot data. + // The list is traversed by about:profiler when it needs to snapshot data. // This is only accessed while list_lock_ is held. static ThreadData* all_thread_data_list_head_; // Set of ThreadData instances for use with worker threads. When a worker |