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

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

Issue 2392903002: Add a task_scheduler tracing category which will record an extra event per task. (Closed)
Patch Set: review:danakj#19 Created 4 years, 2 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
« no previous file with comments | « base/sequence_token_unittest.cc ('k') | base/task_scheduler/task_traits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/debug/task_annotator.h" 10 #include "base/debug/task_annotator.h"
11 #include "base/json/json_writer.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h"
12 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
13 #include "base/sequence_token.h" 15 #include "base/sequence_token.h"
14 #include "base/synchronization/condition_variable.h" 16 #include "base/synchronization/condition_variable.h"
15 #include "base/threading/sequenced_task_runner_handle.h" 17 #include "base/threading/sequenced_task_runner_handle.h"
16 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
17 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
21 #include "base/values.h"
19 22
20 namespace base { 23 namespace base {
21 namespace internal { 24 namespace internal {
22 25
23 namespace { 26 namespace {
24 27
28 // An immutable copy of a scheduler task's info required by tracing.
29 class TaskTracingInfo : public trace_event::ConvertableToTraceFormat {
30 public:
31 TaskTracingInfo(const TaskTraits& task_traits,
32 ExecutionMode execution_mode,
33 const SequenceToken& sequence_token)
34 : task_traits_(task_traits),
35 execution_mode_(execution_mode),
36 sequence_token_(sequence_token) {}
37
38 // trace_event::ConvertableToTraceFormat implementation.
39 void AppendAsTraceFormat(std::string* out) const override;
40
41 private:
42 const TaskTraits task_traits_;
43 const ExecutionMode execution_mode_;
44 const SequenceToken sequence_token_;
45
46 DISALLOW_COPY_AND_ASSIGN(TaskTracingInfo);
47 };
48
49 void TaskTracingInfo::AppendAsTraceFormat(std::string* out) const {
50 DictionaryValue dict;
51
52 dict.SetString("task_priority",
53 base::TaskPriorityToString(task_traits_.priority()));
54 dict.SetString("execution_mode",
55 base::ExecutionModeToString(execution_mode_));
56 if (execution_mode_ != ExecutionMode::PARALLEL)
57 dict.SetInteger("sequence_token", sequence_token_.ToInternalValue());
58
59 std::string tmp;
60 JSONWriter::Write(dict, &tmp);
61 out->append(tmp);
62 }
63
25 const char kQueueFunctionName[] = "base::PostTask"; 64 const char kQueueFunctionName[] = "base::PostTask";
26 65
27 // This name conveys that a Task is run by the task scheduler without revealing 66 // This name conveys that a Task is run by the task scheduler without revealing
28 // its implementation details. 67 // its implementation details.
29 const char kRunFunctionName[] = "TaskSchedulerRunTask"; 68 const char kRunFunctionName[] = "TaskSchedulerRunTask";
30 69
31 // Upper bound for the 70 // Upper bound for the
32 // TaskScheduler.BlockShutdownTasksPostedDuringShutdown histogram. 71 // TaskScheduler.BlockShutdownTasksPostedDuringShutdown histogram.
33 const HistogramBase::Sample kMaxBlockShutdownTasksPostedDuringShutdown = 1000; 72 const HistogramBase::Sample kMaxBlockShutdownTasksPostedDuringShutdown = 1000;
34 73
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (task->sequenced_task_runner_ref) { 235 if (task->sequenced_task_runner_ref) {
197 sequenced_task_runner_handle.reset( 236 sequenced_task_runner_handle.reset(
198 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); 237 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref));
199 } else if (task->single_thread_task_runner_ref) { 238 } else if (task->single_thread_task_runner_ref) {
200 single_thread_task_runner_handle.reset( 239 single_thread_task_runner_handle.reset(
201 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref)); 240 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref));
202 } 241 }
203 242
204 TRACE_TASK_EXECUTION(kRunFunctionName, *task); 243 TRACE_TASK_EXECUTION(kRunFunctionName, *task);
205 244
245 const ExecutionMode execution_mode =
246 task->single_thread_task_runner_ref
247 ? ExecutionMode::SINGLE_THREADED
248 : (task->sequenced_task_runner_ref ? ExecutionMode::SEQUENCED
249 : ExecutionMode::PARALLEL);
250 // TODO(gab): In a better world this would be tacked on as an extra arg
251 // to the trace event generated above. This is not possible however until
252 // http://crbug.com/652692 is resolved.
253 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info",
254 MakeUnique<TaskTracingInfo>(task->traits, execution_mode,
255 sequence_token));
256
206 debug::TaskAnnotator task_annotator; 257 debug::TaskAnnotator task_annotator;
207 task_annotator.RunTask(kQueueFunctionName, *task); 258 task_annotator.RunTask(kQueueFunctionName, *task);
208 } 259 }
209 260
210 AfterRunTask(shutdown_behavior); 261 AfterRunTask(shutdown_behavior);
211 } 262 }
212 263
213 if (task->delayed_run_time.is_null()) 264 if (task->delayed_run_time.is_null())
214 DecrementNumPendingUndelayedTasks(); 265 DecrementNumPendingUndelayedTasks();
215 266
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); 435 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
385 DCHECK_GE(new_num_pending_undelayed_tasks, 0); 436 DCHECK_GE(new_num_pending_undelayed_tasks, 0);
386 if (new_num_pending_undelayed_tasks == 0) { 437 if (new_num_pending_undelayed_tasks == 0) {
387 AutoSchedulerLock auto_lock(flush_lock_); 438 AutoSchedulerLock auto_lock(flush_lock_);
388 flush_cv_->Signal(); 439 flush_cv_->Signal();
389 } 440 }
390 } 441 }
391 442
392 } // namespace internal 443 } // namespace internal
393 } // namespace base 444 } // namespace base
OLDNEW
« no previous file with comments | « base/sequence_token_unittest.cc ('k') | base/task_scheduler/task_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698