Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/sequence_token.h" | 15 #include "base/sequence_token.h" |
| 16 #include "base/synchronization/condition_variable.h" | 16 #include "base/synchronization/condition_variable.h" |
| 17 #include "base/threading/sequenced_task_runner_handle.h" | 17 #include "base/threading/sequenced_task_runner_handle.h" |
| 18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 namespace internal { | 24 namespace internal { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 constexpr char kParallelExecutionMode[] = "parallel"; | |
| 29 constexpr char kSequencedExecutionMode[] = "sequenced"; | |
| 30 constexpr char kSingleThreadExecutionMode[] = "single thread"; | |
| 31 | |
| 28 // An immutable copy of a scheduler task's info required by tracing. | 32 // An immutable copy of a scheduler task's info required by tracing. |
| 29 class TaskTracingInfo : public trace_event::ConvertableToTraceFormat { | 33 class TaskTracingInfo : public trace_event::ConvertableToTraceFormat { |
| 30 public: | 34 public: |
| 31 TaskTracingInfo(const TaskTraits& task_traits, | 35 TaskTracingInfo(const TaskTraits& task_traits, |
| 32 ExecutionMode execution_mode, | 36 const char* execution_mode, |
| 33 const SequenceToken& sequence_token) | 37 const SequenceToken& sequence_token) |
| 34 : task_traits_(task_traits), | 38 : task_traits_(task_traits), |
| 35 execution_mode_(execution_mode), | 39 execution_mode_(execution_mode), |
| 36 sequence_token_(sequence_token) {} | 40 sequence_token_(sequence_token) {} |
| 37 | 41 |
| 38 // trace_event::ConvertableToTraceFormat implementation. | 42 // trace_event::ConvertableToTraceFormat implementation. |
| 39 void AppendAsTraceFormat(std::string* out) const override; | 43 void AppendAsTraceFormat(std::string* out) const override; |
| 40 | 44 |
| 41 private: | 45 private: |
| 42 const TaskTraits task_traits_; | 46 const TaskTraits task_traits_; |
| 43 const ExecutionMode execution_mode_; | 47 const char* execution_mode_; |
|
gab
2016/10/31 19:10:11
const char* const
fdoray
2016/10/31 19:44:52
Done.
| |
| 44 const SequenceToken sequence_token_; | 48 const SequenceToken sequence_token_; |
| 45 | 49 |
| 46 DISALLOW_COPY_AND_ASSIGN(TaskTracingInfo); | 50 DISALLOW_COPY_AND_ASSIGN(TaskTracingInfo); |
| 47 }; | 51 }; |
| 48 | 52 |
| 49 void TaskTracingInfo::AppendAsTraceFormat(std::string* out) const { | 53 void TaskTracingInfo::AppendAsTraceFormat(std::string* out) const { |
| 50 DictionaryValue dict; | 54 DictionaryValue dict; |
| 51 | 55 |
| 52 dict.SetString("task_priority", | 56 dict.SetString("task_priority", |
| 53 base::TaskPriorityToString(task_traits_.priority())); | 57 base::TaskPriorityToString(task_traits_.priority())); |
| 54 dict.SetString("execution_mode", | 58 dict.SetString("execution_mode", execution_mode_); |
| 55 base::ExecutionModeToString(execution_mode_)); | 59 if (execution_mode_ != kParallelExecutionMode) |
| 56 if (execution_mode_ != ExecutionMode::PARALLEL) | |
| 57 dict.SetInteger("sequence_token", sequence_token_.ToInternalValue()); | 60 dict.SetInteger("sequence_token", sequence_token_.ToInternalValue()); |
| 58 | 61 |
| 59 std::string tmp; | 62 std::string tmp; |
| 60 JSONWriter::Write(dict, &tmp); | 63 JSONWriter::Write(dict, &tmp); |
| 61 out->append(tmp); | 64 out->append(tmp); |
| 62 } | 65 } |
| 63 | 66 |
| 64 const char kQueueFunctionName[] = "base::PostTask"; | 67 const char kQueueFunctionName[] = "base::PostTask"; |
| 65 | 68 |
| 66 // This name conveys that a Task is run by the task scheduler without revealing | 69 // This name conveys that a Task is run by the task scheduler without revealing |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 if (task->sequenced_task_runner_ref) { | 239 if (task->sequenced_task_runner_ref) { |
| 237 sequenced_task_runner_handle.reset( | 240 sequenced_task_runner_handle.reset( |
| 238 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); | 241 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); |
| 239 } else if (task->single_thread_task_runner_ref) { | 242 } else if (task->single_thread_task_runner_ref) { |
| 240 single_thread_task_runner_handle.reset( | 243 single_thread_task_runner_handle.reset( |
| 241 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref)); | 244 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref)); |
| 242 } | 245 } |
| 243 | 246 |
| 244 TRACE_TASK_EXECUTION(kRunFunctionName, *task); | 247 TRACE_TASK_EXECUTION(kRunFunctionName, *task); |
| 245 | 248 |
| 246 const ExecutionMode execution_mode = | 249 const char* execution_mode = |
|
gab
2016/10/31 19:10:11
const char* const
fdoray
2016/10/31 19:44:52
Done.
| |
| 247 task->single_thread_task_runner_ref | 250 task->single_thread_task_runner_ref |
| 248 ? ExecutionMode::SINGLE_THREADED | 251 ? kSingleThreadExecutionMode |
| 249 : (task->sequenced_task_runner_ref ? ExecutionMode::SEQUENCED | 252 : (task->sequenced_task_runner_ref ? kSequencedExecutionMode |
| 250 : ExecutionMode::PARALLEL); | 253 : kParallelExecutionMode); |
| 251 // TODO(gab): In a better world this would be tacked on as an extra arg | 254 // TODO(gab): In a better world this would be tacked on as an extra arg |
| 252 // to the trace event generated above. This is not possible however until | 255 // to the trace event generated above. This is not possible however until |
| 253 // http://crbug.com/652692 is resolved. | 256 // http://crbug.com/652692 is resolved. |
| 254 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", | 257 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", |
| 255 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, | 258 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, |
| 256 sequence_token)); | 259 sequence_token)); |
| 257 | 260 |
| 258 PerformRunTask(std::move(task)); | 261 PerformRunTask(std::move(task)); |
| 259 } | 262 } |
| 260 | 263 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); | 442 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); |
| 440 DCHECK_GE(new_num_pending_undelayed_tasks, 0); | 443 DCHECK_GE(new_num_pending_undelayed_tasks, 0); |
| 441 if (new_num_pending_undelayed_tasks == 0) { | 444 if (new_num_pending_undelayed_tasks == 0) { |
| 442 AutoSchedulerLock auto_lock(flush_lock_); | 445 AutoSchedulerLock auto_lock(flush_lock_); |
| 443 flush_cv_->Signal(); | 446 flush_cv_->Signal(); |
| 444 } | 447 } |
| 445 } | 448 } |
| 446 | 449 |
| 447 } // namespace internal | 450 } // namespace internal |
| 448 } // namespace base | 451 } // namespace base |
| OLD | NEW |