Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/debug/task_annotator.h" | 5 #include "base/debug/task_annotator.h" |
| 6 | 6 |
| 7 #include "base/debug/activity_tracker.h" | |
| 7 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
| 8 #include "base/pending_task.h" | 9 #include "base/pending_task.h" |
| 9 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 10 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 namespace debug { | 14 namespace debug { |
| 14 | 15 |
| 15 TaskAnnotator::TaskAnnotator() { | 16 TaskAnnotator::TaskAnnotator() { |
| 16 } | 17 } |
| 17 | 18 |
| 18 TaskAnnotator::~TaskAnnotator() { | 19 TaskAnnotator::~TaskAnnotator() { |
| 19 } | 20 } |
| 20 | 21 |
| 21 void TaskAnnotator::DidQueueTask(const char* queue_function, | 22 void TaskAnnotator::DidQueueTask(const char* queue_function, |
| 22 const PendingTask& pending_task) { | 23 const PendingTask& pending_task) { |
| 23 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), | 24 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), |
| 24 queue_function, | 25 queue_function, |
| 25 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), | 26 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), |
| 26 TRACE_EVENT_FLAG_FLOW_OUT); | 27 TRACE_EVENT_FLAG_FLOW_OUT); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void TaskAnnotator::RunTask(const char* queue_function, | 30 void TaskAnnotator::RunTask(const char* queue_function, |
| 30 const PendingTask& pending_task) { | 31 const PendingTask& pending_task) { |
| 32 ScopedTaskActivity activity(pending_task); | |
| 33 | |
| 31 tracked_objects::TaskStopwatch stopwatch; | 34 tracked_objects::TaskStopwatch stopwatch; |
| 32 stopwatch.Start(); | 35 stopwatch.Start(); |
| 33 tracked_objects::Duration queue_duration = | 36 tracked_objects::Duration queue_duration = |
| 34 stopwatch.StartTime() - pending_task.EffectiveTimePosted(); | 37 stopwatch.StartTime() - pending_task.EffectiveTimePosted(); |
| 35 | 38 |
| 36 TRACE_EVENT_WITH_FLOW1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), | 39 TRACE_EVENT_WITH_FLOW1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), |
| 37 queue_function, | 40 queue_function, |
| 38 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), | 41 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), |
| 39 TRACE_EVENT_FLAG_FLOW_IN, | 42 TRACE_EVENT_FLAG_FLOW_IN, |
| 40 "queue_duration", | 43 "queue_duration", |
| 41 queue_duration.InMilliseconds()); | 44 queue_duration.InMilliseconds()); |
| 42 | 45 |
| 43 // Before running the task, store the program counter where it was posted | 46 // Before running the task, store the program counter where it was posted |
| 44 // and deliberately alias it to ensure it is on the stack if the task | 47 // and deliberately alias it to ensure it is on the stack if the task |
| 45 // crashes. Be careful not to assume that the variable itself will have the | 48 // crashes. Be careful not to assume that the variable itself will have the |
| 46 // expected value when displayed by the optimizer in an optimized build. | 49 // expected value when displayed by the optimizer in an optimized build. |
| 47 // Look at a memory dump of the stack. | 50 // Look at a memory dump of the stack. |
| 48 const void* program_counter = pending_task.posted_from.program_counter(); | 51 const void* program_counter = pending_task.posted_from.program_counter(); |
|
Sigurður Ásgeirsson
2016/05/20 13:16:53
can we subsume some or all of the stuff here - que
bcwhite
2016/05/20 19:19:19
Dunno. Something to consider once we know what it
| |
| 49 debug::Alias(&program_counter); | 52 debug::Alias(&program_counter); |
| 50 | 53 |
| 51 pending_task.task.Run(); | 54 pending_task.task.Run(); |
| 52 | 55 |
| 53 stopwatch.Stop(); | 56 stopwatch.Stop(); |
| 54 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( | 57 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( |
| 55 pending_task, stopwatch); | 58 pending_task, stopwatch); |
| 56 } | 59 } |
| 57 | 60 |
| 58 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { | 61 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { |
| 59 return (static_cast<uint64_t>(task.sequence_num) << 32) | | 62 return (static_cast<uint64_t>(task.sequence_num) << 32) | |
| 60 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >> | 63 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >> |
| 61 32); | 64 32); |
| 62 } | 65 } |
| 63 | 66 |
| 64 } // namespace debug | 67 } // namespace debug |
| 65 } // namespace base | 68 } // namespace base |
| OLD | NEW |