Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / base / debug / task_annotator.cc
blobb74d390938d75867af4f52d379774ae6fe265667
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/debug/task_annotator.h"
7 #include "base/debug/alias.h"
8 #include "base/pending_task.h"
9 #include "base/trace_event/trace_event.h"
10 #include "base/tracked_objects.h"
12 namespace base {
13 namespace debug {
15 TaskAnnotator::TaskAnnotator() {
18 TaskAnnotator::~TaskAnnotator() {
21 void TaskAnnotator::DidQueueTask(const char* queue_function,
22 const PendingTask& pending_task) {
23 TRACE_EVENT_FLOW_BEGIN0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"),
24 queue_function,
25 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)));
28 void TaskAnnotator::RunTask(const char* queue_function,
29 const PendingTask& pending_task) {
30 tracked_objects::TaskStopwatch stopwatch;
31 stopwatch.Start();
32 tracked_objects::Duration queue_duration =
33 stopwatch.StartTime() - pending_task.EffectiveTimePosted();
35 TRACE_EVENT_FLOW_END1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"),
36 queue_function,
37 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)),
38 "queue_duration",
39 queue_duration.InMilliseconds());
41 // Before running the task, store the program counter where it was posted
42 // and deliberately alias it to ensure it is on the stack if the task
43 // crashes. Be careful not to assume that the variable itself will have the
44 // expected value when displayed by the optimizer in an optimized build.
45 // Look at a memory dump of the stack.
46 const void* program_counter = pending_task.posted_from.program_counter();
47 debug::Alias(&program_counter);
49 pending_task.task.Run();
51 stopwatch.Stop();
52 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(
53 pending_task, stopwatch);
56 uint64 TaskAnnotator::GetTaskTraceID(const PendingTask& task) const {
57 return (static_cast<uint64>(task.sequence_num) << 32) |
58 ((static_cast<uint64>(reinterpret_cast<intptr_t>(this)) << 32) >> 32);
61 } // namespace debug
62 } // namespace base