 Chromium Code Reviews
 Chromium Code Reviews Issue 2600023002:
  Remove worker pool names from TaskScheduler.TaskLatency.* histograms.  (Closed)
    
  
    Issue 2600023002:
  Remove worker pool names from TaskScheduler.TaskLatency.* histograms.  (Closed) 
  | Index: base/task_scheduler/task_tracker.cc | 
| diff --git a/base/task_scheduler/task_tracker.cc b/base/task_scheduler/task_tracker.cc | 
| index 07b0d1216db3ab529be9b6b5b754eb132913ae6d..da21d5ea8ef510c33636cc993b34e3501aa09101 100644 | 
| --- a/base/task_scheduler/task_tracker.cc | 
| +++ b/base/task_scheduler/task_tracker.cc | 
| @@ -5,6 +5,7 @@ | 
| #include "base/task_scheduler/task_tracker.h" | 
| #include <limits> | 
| +#include <string> | 
| #include "base/callback.h" | 
| #include "base/debug/task_annotator.h" | 
| @@ -18,6 +19,7 @@ | 
| #include "base/threading/sequenced_task_runner_handle.h" | 
| #include "base/threading/thread_restrictions.h" | 
| #include "base/threading/thread_task_runner_handle.h" | 
| +#include "base/time/time.h" | 
| #include "base/trace_event/trace_event.h" | 
| #include "base/values.h" | 
| @@ -71,6 +73,14 @@ const char kQueueFunctionName[] = "base::PostTask"; | 
| // its implementation details. | 
| const char kRunFunctionName[] = "TaskSchedulerRunTask"; | 
| +HistogramBase* GetTaskLatencyHistogram(const char* suffix) { | 
| + // Mimics the UMA_HISTOGRAM_TIMES macro. | 
| + return Histogram::FactoryTimeGet( | 
| + std::string("TaskScheduler.TaskLatency.") + suffix, | 
| + TimeDelta::FromMilliseconds(1), TimeDelta::FromSeconds(10), 50, | 
| + HistogramBase::kUmaTargetedHistogramFlag); | 
| +} | 
| + | 
| // Upper bound for the | 
| // TaskScheduler.BlockShutdownTasksPostedDuringShutdown histogram. | 
| const HistogramBase::Sample kMaxBlockShutdownTasksPostedDuringShutdown = 1000; | 
| @@ -174,7 +184,20 @@ class TaskTracker::State { | 
| TaskTracker::TaskTracker() | 
| : state_(new State), | 
| flush_cv_(flush_lock_.CreateConditionVariable()), | 
| - shutdown_lock_(&flush_lock_) {} | 
| + shutdown_lock_(&flush_lock_), | 
| + task_latency_histograms_{ | 
| + {GetTaskLatencyHistogram("BackgroundTaskPriority"), | 
| + GetTaskLatencyHistogram("BackgroundTaskPriority.MayBlock")}, | 
| + {GetTaskLatencyHistogram("UserVisibleTaskPriority"), | 
| + GetTaskLatencyHistogram("UserVisibleTaskPriority.MayBlock")}, | 
| + {GetTaskLatencyHistogram("UserBlockingTaskPriority"), | 
| + GetTaskLatencyHistogram("UserBlockingTaskPriority.MayBlock")}} { | 
| + // Confirm that all |task_latency_histograms_| have been initialized above. | 
| + DCHECK(*(&task_latency_histograms_[static_cast<int>(TaskPriority::HIGHEST) + | 
| + 1][0] - | 
| + 1)); | 
| 
gab
2017/01/05 22:16:36
This is git cl format? Looks terrible..!
 
fdoray
2017/01/05 22:31:58
Yes. And there is a presubmit check to verify that
 | 
| +} | 
| + | 
| TaskTracker::~TaskTracker() = default; | 
| void TaskTracker::Shutdown() { | 
| @@ -220,6 +243,8 @@ bool TaskTracker::RunTask(std::unique_ptr<Task> task, | 
| const bool is_delayed = !task->delayed_run_time.is_null(); | 
| if (can_run_task) { | 
| + RecordTaskLatencyHistogram(task.get()); | 
| + | 
| const bool previous_singleton_allowed = | 
| ThreadRestrictions::SetSingletonAllowed( | 
| task->traits.shutdown_behavior() != | 
| @@ -463,5 +488,15 @@ void TaskTracker::DecrementNumPendingUndelayedTasks() { | 
| } | 
| } | 
| +void TaskTracker::RecordTaskLatencyHistogram(Task* task) { | 
| + const TimeDelta task_latency = TimeTicks::Now() - task->sequenced_time; | 
| + task_latency_histograms_[static_cast<int>(task->traits.priority())] | 
| + [task->traits.may_block() || | 
| + task->traits.with_base_sync_primitives() | 
| + ? 1 | 
| + : 0] | 
| + ->AddTime(task_latency); | 
| +} | 
| + | 
| } // namespace internal | 
| } // namespace base |