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

Side by Side Diff: base/task_scheduler/task_traits.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/task_scheduler/task_traits.h ('k') | no next file » | 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_traits.h" 5 #include "base/task_scheduler/task_traits.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <ostream> 9 #include <ostream>
10 10
11 #include "base/logging.h"
12
11 namespace base { 13 namespace base {
12 14
13 // Do not rely on defaults hard-coded below beyond the guarantees described in 15 // Do not rely on defaults hard-coded below beyond the guarantees described in
14 // the header; anything else is subject to change. Tasks should explicitly 16 // the header; anything else is subject to change. Tasks should explicitly
15 // request defaults if the behavior is critical to the task. 17 // request defaults if the behavior is critical to the task.
16 TaskTraits::TaskTraits() 18 TaskTraits::TaskTraits()
17 : with_file_io_(false), 19 : with_file_io_(false),
18 priority_(TaskPriority::BACKGROUND), 20 priority_(TaskPriority::BACKGROUND),
19 shutdown_behavior_(TaskShutdownBehavior::SKIP_ON_SHUTDOWN) {} 21 shutdown_behavior_(TaskShutdownBehavior::SKIP_ON_SHUTDOWN) {}
20 22
21 TaskTraits::~TaskTraits() = default; 23 TaskTraits::~TaskTraits() = default;
22 24
23 TaskTraits& TaskTraits::WithFileIO() { 25 TaskTraits& TaskTraits::WithFileIO() {
24 with_file_io_ = true; 26 with_file_io_ = true;
25 return *this; 27 return *this;
26 } 28 }
27 29
28 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) { 30 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) {
29 priority_ = priority; 31 priority_ = priority;
30 return *this; 32 return *this;
31 } 33 }
32 34
33 TaskTraits& TaskTraits::WithShutdownBehavior( 35 TaskTraits& TaskTraits::WithShutdownBehavior(
34 TaskShutdownBehavior shutdown_behavior) { 36 TaskShutdownBehavior shutdown_behavior) {
35 shutdown_behavior_ = shutdown_behavior; 37 shutdown_behavior_ = shutdown_behavior;
36 return *this; 38 return *this;
37 } 39 }
38 40
39 std::ostream& operator<<(std::ostream& os, const TaskPriority& task_priority) { 41 const char* TaskPriorityToString(TaskPriority task_priority) {
40 switch (task_priority) { 42 switch (task_priority) {
41 case TaskPriority::BACKGROUND: 43 case TaskPriority::BACKGROUND:
42 os << "BACKGROUND"; 44 return "BACKGROUND";
43 break;
44 case TaskPriority::USER_VISIBLE: 45 case TaskPriority::USER_VISIBLE:
45 os << "USER_VISIBLE"; 46 return "USER_VISIBLE";
46 break;
47 case TaskPriority::USER_BLOCKING: 47 case TaskPriority::USER_BLOCKING:
48 os << "USER_BLOCKING"; 48 return "USER_BLOCKING";
49 break;
50 } 49 }
50 NOTREACHED();
51 return "";
52 }
53
54 const char* TaskShutdownBehaviorToString(
55 TaskShutdownBehavior shutdown_behavior) {
56 switch (shutdown_behavior) {
57 case TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN:
58 return "CONTINUE_ON_SHUTDOWN";
59 case TaskShutdownBehavior::SKIP_ON_SHUTDOWN:
60 return "SKIP_ON_SHUTDOWN";
61 case TaskShutdownBehavior::BLOCK_SHUTDOWN:
62 return "BLOCK_SHUTDOWN";
63 }
64 NOTREACHED();
65 return "";
66 }
67
68 const char* ExecutionModeToString(ExecutionMode execution_mode) {
69 switch (execution_mode) {
70 case ExecutionMode::PARALLEL:
71 return "PARALLEL";
72 case ExecutionMode::SEQUENCED:
73 return "SEQUENCED";
74 case ExecutionMode::SINGLE_THREADED:
75 return "SINGLE_THREADED";
76 }
77 NOTREACHED();
78 return "";
79 }
80
81 std::ostream& operator<<(std::ostream& os, const TaskPriority& task_priority) {
82 os << TaskPriorityToString(task_priority);
51 return os; 83 return os;
52 } 84 }
53 85
54 std::ostream& operator<<(std::ostream& os, 86 std::ostream& operator<<(std::ostream& os,
55 const TaskShutdownBehavior& shutdown_behavior) { 87 const TaskShutdownBehavior& shutdown_behavior) {
56 switch (shutdown_behavior) { 88 os << TaskShutdownBehaviorToString(shutdown_behavior);
57 case TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN:
58 os << "CONTINUE_ON_SHUTDOWN";
59 break;
60 case TaskShutdownBehavior::SKIP_ON_SHUTDOWN:
61 os << "SKIP_ON_SHUTDOWN";
62 break;
63 case TaskShutdownBehavior::BLOCK_SHUTDOWN:
64 os << "BLOCK_SHUTDOWN";
65 break;
66 }
67 return os; 89 return os;
68 } 90 }
69 91
92 std::ostream& operator<<(std::ostream& os,
93 const ExecutionMode& execution_mode) {
94 os << ExecutionModeToString(execution_mode);
95 return os;
96 }
97
70 } // namespace base 98 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_traits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698