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

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 Created 3 years, 12 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")}} {}
gab 2017/01/05 19:25:46 // Confirm that all |task_latency_histograms_| hav
fdoray 2017/01/05 20:13:38 Done.
195
178 TaskTracker::~TaskTracker() = default; 196 TaskTracker::~TaskTracker() = default;
179 197
180 void TaskTracker::Shutdown() { 198 void TaskTracker::Shutdown() {
181 PerformShutdown(); 199 PerformShutdown();
182 DCHECK(IsShutdownComplete()); 200 DCHECK(IsShutdownComplete());
183 201
184 // Unblock Flush() when shutdown completes. 202 // Unblock Flush() when shutdown completes.
185 AutoSchedulerLock auto_lock(flush_lock_); 203 AutoSchedulerLock auto_lock(flush_lock_);
186 flush_cv_->Signal(); 204 flush_cv_->Signal();
187 } 205 }
(...skipping 25 matching lines...) Expand all
213 const SequenceToken& sequence_token) { 231 const SequenceToken& sequence_token) {
214 DCHECK(task); 232 DCHECK(task);
215 DCHECK(sequence_token.IsValid()); 233 DCHECK(sequence_token.IsValid());
216 234
217 const TaskShutdownBehavior shutdown_behavior = 235 const TaskShutdownBehavior shutdown_behavior =
218 task->traits.shutdown_behavior(); 236 task->traits.shutdown_behavior();
219 const bool can_run_task = BeforeRunTask(shutdown_behavior); 237 const bool can_run_task = BeforeRunTask(shutdown_behavior);
220 const bool is_delayed = !task->delayed_run_time.is_null(); 238 const bool is_delayed = !task->delayed_run_time.is_null();
221 239
222 if (can_run_task) { 240 if (can_run_task) {
241 RecordTaskLatencyHistogram(task.get());
242
223 const bool previous_singleton_allowed = 243 const bool previous_singleton_allowed =
224 ThreadRestrictions::SetSingletonAllowed( 244 ThreadRestrictions::SetSingletonAllowed(
225 task->traits.shutdown_behavior() != 245 task->traits.shutdown_behavior() !=
226 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); 246 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN);
227 const bool previous_io_allowed = 247 const bool previous_io_allowed =
228 ThreadRestrictions::SetIOAllowed(task->traits.may_block()); 248 ThreadRestrictions::SetIOAllowed(task->traits.may_block());
229 const bool previous_wait_allowed = ThreadRestrictions::SetWaitAllowed( 249 const bool previous_wait_allowed = ThreadRestrictions::SetWaitAllowed(
230 task->traits.with_base_sync_primitives()); 250 task->traits.with_base_sync_primitives());
231 251
232 { 252 {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 void TaskTracker::DecrementNumPendingUndelayedTasks() { 476 void TaskTracker::DecrementNumPendingUndelayedTasks() {
457 const auto new_num_pending_undelayed_tasks = 477 const auto new_num_pending_undelayed_tasks =
458 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); 478 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
459 DCHECK_GE(new_num_pending_undelayed_tasks, 0); 479 DCHECK_GE(new_num_pending_undelayed_tasks, 0);
460 if (new_num_pending_undelayed_tasks == 0) { 480 if (new_num_pending_undelayed_tasks == 0) {
461 AutoSchedulerLock auto_lock(flush_lock_); 481 AutoSchedulerLock auto_lock(flush_lock_);
462 flush_cv_->Signal(); 482 flush_cv_->Signal();
463 } 483 }
464 } 484 }
465 485
486 void TaskTracker::RecordTaskLatencyHistogram(Task* task) {
487 const TimeDelta task_latency = TimeTicks::Now() - task->sequenced_time;
488 task_latency_histograms_[static_cast<int>(task->traits.priority())]
489 [task->traits.may_block() ||
490 task->traits.with_base_sync_primitives()
491 ? 1
492 : 0]
493 ->AddTime(task_latency);
494 }
495
466 } // namespace internal 496 } // namespace internal
467 } // namespace base 497 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698