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

Unified Diff: base/task_scheduler/task_tracker.cc

Issue 2600023002: Remove worker pool names from TaskScheduler.TaskLatency.* histograms. (Closed)
Patch Set: self-review Created 4 years 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/task_scheduler/task_tracker.cc
diff --git a/base/task_scheduler/task_tracker.cc b/base/task_scheduler/task_tracker.cc
index 07b0d1216db3ab529be9b6b5b754eb132913ae6d..ad1caeee9242ae2ccf9f8c2e43f517b37a9edccb 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,15 @@ 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")}} {}
gab 2017/01/05 19:25:46 // Confirm that all |task_latency_histograms_| hav
fdoray 2017/01/05 20:13:38 Done.
+
TaskTracker::~TaskTracker() = default;
void TaskTracker::Shutdown() {
@@ -220,6 +238,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 +483,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

Powered by Google App Engine
This is Rietveld 408576698