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

Unified Diff: base/task_scheduler/task_tracker.cc

Issue 2356393002: Add ExecutionMode/SequenceToken and TaskPriority as arguments of TaskScheduler tasks in tracing (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sequence_token_unittest.cc ('k') | base/trace_event/common/trace_event_common.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/task_tracker.cc
diff --git a/base/task_scheduler/task_tracker.cc b/base/task_scheduler/task_tracker.cc
index 1d28f2dab0ba95d944a0679641f96d97cc04a635..8d7b5afc02da5636a460a27cba30ebddc59a4533 100644
--- a/base/task_scheduler/task_tracker.cc
+++ b/base/task_scheduler/task_tracker.cc
@@ -8,7 +8,9 @@
#include "base/callback.h"
#include "base/debug/task_annotator.h"
+#include "base/json/json_writer.h"
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/sequence_token.h"
#include "base/synchronization/condition_variable.h"
@@ -16,12 +18,82 @@
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
+#include "base/trace_event/trace_event_impl.h"
+#include "base/values.h"
namespace base {
namespace internal {
namespace {
+// An immutable copy of a scheduler task's info required by tracing.
+class TaskTracingInfo : public trace_event::ConvertableToTraceFormat {
+ public:
+ TaskTracingInfo(const TaskTraits& task_traits,
+ ExecutionMode execution_mode,
+ const SequenceToken& sequence_token)
+ : task_traits_(task_traits),
+ execution_mode_(execution_mode),
+ sequence_token_(sequence_token) {}
+
+ // Overridden from trace_event::ConvertableToTraceFormat:
+ void AppendAsTraceFormat(std::string* out) const override;
+
+ private:
+ const TaskTraits task_traits_;
+ const ExecutionMode execution_mode_;
+ const SequenceToken sequence_token_;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskTracingInfo);
+};
+
+void TaskTracingInfo::AppendAsTraceFormat(std::string* out) const {
+ DictionaryValue dict;
+
+ bool task_scheduler_tracing_enabled = false;
+ TRACE_EVENT_CATEGORY_GROUP_ENABLED(
+ TRACE_DISABLED_BY_DEFAULT("taskscheduler"),
+ &task_scheduler_tracing_enabled);
+ if (task_scheduler_tracing_enabled) {
+ const char* priority_str = nullptr;
+ switch (task_traits_.priority()) {
+ case TaskPriority::BACKGROUND:
+ priority_str = "BACKGROUND";
+ break;
+ case TaskPriority::USER_VISIBLE:
+ priority_str = "USER_VISIBLE";
+ break;
+ case TaskPriority::USER_BLOCKING:
+ priority_str = "USER_BLOCKING";
+ break;
+ }
+ dict.SetString("TaskPriority", priority_str);
+
+ const char* execution_mode_str = nullptr;
+ switch (execution_mode_) {
+ case ExecutionMode::PARALLEL:
+ execution_mode_str = "PARALLEL";
+ break;
+ case ExecutionMode::SEQUENCED:
+ execution_mode_str = "SEQUENCED";
+ break;
+ case ExecutionMode::SINGLE_THREADED:
+ execution_mode_str = "SINGLE_THREADED";
+ break;
+ }
+ dict.SetString("ExecutionMode", execution_mode_str);
+
+ if (execution_mode_ != ExecutionMode::PARALLEL)
+ dict.SetString("SequenceToken", sequence_token_.ToString());
+ }
+
+ // Even when the taskscheduler tracing category is disabled, a valid (empty)
+ // JSON object still needs to be emitted.
+ std::string tmp;
+ JSONWriter::Write(dict, &tmp);
+ out->append(tmp);
+}
+
const char kQueueFunctionName[] = "base::PostTask";
// This name conveys that a Task is run by the task scheduler without revealing
@@ -201,7 +273,15 @@ bool TaskTracker::RunTask(const Task* task,
new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref));
}
- TRACE_TASK_EXECUTION(kRunFunctionName, *task);
+ ExecutionMode execution_mode =
+ task->single_thread_task_runner_ref
+ ? ExecutionMode::SINGLE_THREADED
+ : (task->sequenced_task_runner_ref ? ExecutionMode::SEQUENCED
+ : ExecutionMode::PARALLEL);
+
+ TRACE_TASK_EXECUTION1(kRunFunctionName, *task, "TaskSchedulerInfo",
+ MakeUnique<TaskTracingInfo>(
+ task->traits, execution_mode, sequence_token));
debug::TaskAnnotator task_annotator;
task_annotator.RunTask(kQueueFunctionName, *task);
« no previous file with comments | « base/sequence_token_unittest.cc ('k') | base/trace_event/common/trace_event_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698