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

Side by Side Diff: base/task_scheduler/task_tracker.cc

Issue 2600023002: Remove worker pool names from TaskScheduler.TaskLatency.* histograms. (Closed)
Patch Set: self-review (add const) Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/task_tracker.h" 5 #include "base/task_scheduler/task_tracker.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string>
8 9
9 #include "base/callback.h" 10 #include "base/callback.h"
10 #include "base/debug/task_annotator.h" 11 #include "base/debug/task_annotator.h"
11 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
15 #include "base/sequence_token.h" 16 #include "base/sequence_token.h"
16 #include "base/synchronization/condition_variable.h" 17 #include "base/synchronization/condition_variable.h"
17 #include "base/task_scheduler/scoped_set_task_priority_for_current_thread.h" 18 #include "base/task_scheduler/scoped_set_task_priority_for_current_thread.h"
18 #include "base/threading/sequenced_task_runner_handle.h" 19 #include "base/threading/sequenced_task_runner_handle.h"
19 #include "base/threading/thread_restrictions.h" 20 #include "base/threading/thread_restrictions.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h"
21 #include "base/trace_event/trace_event.h" 23 #include "base/trace_event/trace_event.h"
22 #include "base/values.h" 24 #include "base/values.h"
23 25
24 namespace base { 26 namespace base {
25 namespace internal { 27 namespace internal {
26 28
27 namespace { 29 namespace {
28 30
29 constexpr char kParallelExecutionMode[] = "parallel"; 31 constexpr char kParallelExecutionMode[] = "parallel";
30 constexpr char kSequencedExecutionMode[] = "sequenced"; 32 constexpr char kSequencedExecutionMode[] = "sequenced";
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 JSONWriter::Write(dict, &tmp); 66 JSONWriter::Write(dict, &tmp);
65 out->append(tmp); 67 out->append(tmp);
66 } 68 }
67 69
68 const char kQueueFunctionName[] = "base::PostTask"; 70 const char kQueueFunctionName[] = "base::PostTask";
69 71
70 // This name conveys that a Task is run by the task scheduler without revealing 72 // This name conveys that a Task is run by the task scheduler without revealing
71 // its implementation details. 73 // its implementation details.
72 const char kRunFunctionName[] = "TaskSchedulerRunTask"; 74 const char kRunFunctionName[] = "TaskSchedulerRunTask";
73 75
76 HistogramBase* GetTaskLatencyHistogram(const char* suffix) {
77 // Mimics the UMA_HISTOGRAM_TIMES macro.
78 return Histogram::FactoryTimeGet(
79 std::string("TaskScheduler.TaskLatency.") + suffix,
80 TimeDelta::FromMilliseconds(1), TimeDelta::FromSeconds(10), 50,
81 HistogramBase::kUmaTargetedHistogramFlag);
82 }
83
74 // Upper bound for the 84 // Upper bound for the
75 // TaskScheduler.BlockShutdownTasksPostedDuringShutdown histogram. 85 // TaskScheduler.BlockShutdownTasksPostedDuringShutdown histogram.
76 const HistogramBase::Sample kMaxBlockShutdownTasksPostedDuringShutdown = 1000; 86 const HistogramBase::Sample kMaxBlockShutdownTasksPostedDuringShutdown = 1000;
77 87
78 void RecordNumBlockShutdownTasksPostedDuringShutdown( 88 void RecordNumBlockShutdownTasksPostedDuringShutdown(
79 HistogramBase::Sample value) { 89 HistogramBase::Sample value) {
80 UMA_HISTOGRAM_CUSTOM_COUNTS( 90 UMA_HISTOGRAM_CUSTOM_COUNTS(
81 "TaskScheduler.BlockShutdownTasksPostedDuringShutdown", value, 1, 91 "TaskScheduler.BlockShutdownTasksPostedDuringShutdown", value, 1,
82 kMaxBlockShutdownTasksPostedDuringShutdown, 50); 92 kMaxBlockShutdownTasksPostedDuringShutdown, 50);
83 } 93 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // blocking task or the second thread will win and 177 // blocking task or the second thread will win and
168 // IncrementNumTasksBlockingShutdown() will know that shutdown has started. 178 // IncrementNumTasksBlockingShutdown() will know that shutdown has started.
169 subtle::Atomic32 bits_ = 0; 179 subtle::Atomic32 bits_ = 0;
170 180
171 DISALLOW_COPY_AND_ASSIGN(State); 181 DISALLOW_COPY_AND_ASSIGN(State);
172 }; 182 };
173 183
174 TaskTracker::TaskTracker() 184 TaskTracker::TaskTracker()
175 : state_(new State), 185 : state_(new State),
176 flush_cv_(flush_lock_.CreateConditionVariable()), 186 flush_cv_(flush_lock_.CreateConditionVariable()),
177 shutdown_lock_(&flush_lock_) {} 187 shutdown_lock_(&flush_lock_),
188 task_latency_histograms_{
189 {GetTaskLatencyHistogram("BackgroundTaskPriority"),
190 GetTaskLatencyHistogram("BackgroundTaskPriority.MayBlock")},
191 {GetTaskLatencyHistogram("UserVisibleTaskPriority"),
192 GetTaskLatencyHistogram("UserVisibleTaskPriority.MayBlock")},
193 {GetTaskLatencyHistogram("UserBlockingTaskPriority"),
194 GetTaskLatencyHistogram("UserBlockingTaskPriority.MayBlock")}} {
195 // Confirm that all |task_latency_histograms_| have been initialized above.
196 DCHECK(*(&task_latency_histograms_[static_cast<int>(TaskPriority::HIGHEST) +
197 1][0] -
198 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
199 }
200
178 TaskTracker::~TaskTracker() = default; 201 TaskTracker::~TaskTracker() = default;
179 202
180 void TaskTracker::Shutdown() { 203 void TaskTracker::Shutdown() {
181 PerformShutdown(); 204 PerformShutdown();
182 DCHECK(IsShutdownComplete()); 205 DCHECK(IsShutdownComplete());
183 206
184 // Unblock Flush() when shutdown completes. 207 // Unblock Flush() when shutdown completes.
185 AutoSchedulerLock auto_lock(flush_lock_); 208 AutoSchedulerLock auto_lock(flush_lock_);
186 flush_cv_->Signal(); 209 flush_cv_->Signal();
187 } 210 }
(...skipping 25 matching lines...) Expand all
213 const SequenceToken& sequence_token) { 236 const SequenceToken& sequence_token) {
214 DCHECK(task); 237 DCHECK(task);
215 DCHECK(sequence_token.IsValid()); 238 DCHECK(sequence_token.IsValid());
216 239
217 const TaskShutdownBehavior shutdown_behavior = 240 const TaskShutdownBehavior shutdown_behavior =
218 task->traits.shutdown_behavior(); 241 task->traits.shutdown_behavior();
219 const bool can_run_task = BeforeRunTask(shutdown_behavior); 242 const bool can_run_task = BeforeRunTask(shutdown_behavior);
220 const bool is_delayed = !task->delayed_run_time.is_null(); 243 const bool is_delayed = !task->delayed_run_time.is_null();
221 244
222 if (can_run_task) { 245 if (can_run_task) {
246 RecordTaskLatencyHistogram(task.get());
247
223 const bool previous_singleton_allowed = 248 const bool previous_singleton_allowed =
224 ThreadRestrictions::SetSingletonAllowed( 249 ThreadRestrictions::SetSingletonAllowed(
225 task->traits.shutdown_behavior() != 250 task->traits.shutdown_behavior() !=
226 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); 251 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN);
227 const bool previous_io_allowed = 252 const bool previous_io_allowed =
228 ThreadRestrictions::SetIOAllowed(task->traits.may_block()); 253 ThreadRestrictions::SetIOAllowed(task->traits.may_block());
229 const bool previous_wait_allowed = ThreadRestrictions::SetWaitAllowed( 254 const bool previous_wait_allowed = ThreadRestrictions::SetWaitAllowed(
230 task->traits.with_base_sync_primitives()); 255 task->traits.with_base_sync_primitives());
231 256
232 { 257 {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 void TaskTracker::DecrementNumPendingUndelayedTasks() { 481 void TaskTracker::DecrementNumPendingUndelayedTasks() {
457 const auto new_num_pending_undelayed_tasks = 482 const auto new_num_pending_undelayed_tasks =
458 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); 483 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
459 DCHECK_GE(new_num_pending_undelayed_tasks, 0); 484 DCHECK_GE(new_num_pending_undelayed_tasks, 0);
460 if (new_num_pending_undelayed_tasks == 0) { 485 if (new_num_pending_undelayed_tasks == 0) {
461 AutoSchedulerLock auto_lock(flush_lock_); 486 AutoSchedulerLock auto_lock(flush_lock_);
462 flush_cv_->Signal(); 487 flush_cv_->Signal();
463 } 488 }
464 } 489 }
465 490
491 void TaskTracker::RecordTaskLatencyHistogram(Task* task) {
492 const TimeDelta task_latency = TimeTicks::Now() - task->sequenced_time;
493 task_latency_histograms_[static_cast<int>(task->traits.priority())]
494 [task->traits.may_block() ||
495 task->traits.with_base_sync_primitives()
496 ? 1
497 : 0]
498 ->AddTime(task_latency);
499 }
500
466 } // namespace internal 501 } // namespace internal
467 } // namespace base 502 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698