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

Unified 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:fdoray#10 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/task_scheduler/task_traits.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..b4ef586a6b2bbf1c6969b6b3a715e19fd0adf69a 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,48 @@
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.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:
danakj 2016/10/05 23:26:52 nit: normally written as "trace_event::Convertable
gab 2016/10/06 19:13:53 Done.
+ 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;
+
+ dict.SetString("TaskPriority",
+ base::TaskPriorityToString(task_traits_.priority()));
+ dict.SetString("ExecutionMode", base::ExecutionModeToString(execution_mode_));
+ if (execution_mode_ != ExecutionMode::PARALLEL)
+ dict.SetInteger("SequenceToken", sequence_token_.ToInternalValue());
+
+ 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
@@ -203,6 +241,18 @@ bool TaskTracker::RunTask(const Task* task,
TRACE_TASK_EXECUTION(kRunFunctionName, *task);
+ const ExecutionMode execution_mode =
+ task->single_thread_task_runner_ref
+ ? ExecutionMode::SINGLE_THREADED
+ : (task->sequenced_task_runner_ref ? ExecutionMode::SEQUENCED
+ : ExecutionMode::PARALLEL);
+ // TODO(gab): In a better world this would be tacked on as an extra arg
+ // to the trace event generated above. This is not possible however until
+ // http://crbug.com/652692 is resolved.
+ TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info",
+ 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/task_scheduler/task_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698