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/alias.h" | 7 #include "base/debug/alias.h" |
| 8 #include "base/pending_task.h" | 8 #include "base/pending_task.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "base/tracked_objects.h" | 10 #include "base/tracked_objects.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 TRACE_EVENT_FLOW_END1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), | 37 TRACE_EVENT_FLOW_END1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), |
| 38 queue_function, | 38 queue_function, |
| 39 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), | 39 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), |
| 40 "queue_duration", | 40 "queue_duration", |
| 41 queue_duration.InMilliseconds()); | 41 queue_duration.InMilliseconds()); |
| 42 | 42 |
| 43 // When tracing memory for posted tasks it's more valuable to attribute the | 43 // When tracing memory for posted tasks it's more valuable to attribute the |
| 44 // memory allocations to the source function than generically to the task | 44 // memory allocations to the source function than generically to the task |
| 45 // runner. | 45 // runner. |
| 46 TRACE_EVENT_WITH_MEMORY_TAG2( | 46 TRACE_EVENT_WITH_MEMORY_TAG2( |
| 47 "toplevel", | 47 "toplevel", pending_task.posted_from.function_name(), |
|
Sami
2015/02/27 18:22:33
Wanna pull this out to a separate patch? We may wa
| |
| 48 run_function, | |
| 49 pending_task.posted_from.function_name(), // Name for memory tracking. | 48 pending_task.posted_from.function_name(), // Name for memory tracking. |
| 50 "src_file", | 49 "src_file", pending_task.posted_from.file_name(), "src_func", |
| 51 pending_task.posted_from.file_name(), | |
| 52 "src_func", | |
| 53 pending_task.posted_from.function_name()); | 50 pending_task.posted_from.function_name()); |
| 54 | 51 |
| 55 // Before running the task, store the program counter where it was posted | 52 // Before running the task, store the program counter where it was posted |
| 56 // and deliberately alias it to ensure it is on the stack if the task | 53 // and deliberately alias it to ensure it is on the stack if the task |
| 57 // crashes. Be careful not to assume that the variable itself will have the | 54 // crashes. Be careful not to assume that the variable itself will have the |
| 58 // expected value when displayed by the optimizer in an optimized build. | 55 // expected value when displayed by the optimizer in an optimized build. |
| 59 // Look at a memory dump of the stack. | 56 // Look at a memory dump of the stack. |
| 60 const void* program_counter = pending_task.posted_from.program_counter(); | 57 const void* program_counter = pending_task.posted_from.program_counter(); |
| 61 debug::Alias(&program_counter); | 58 debug::Alias(&program_counter); |
| 62 | 59 |
| 63 pending_task.task.Run(); | 60 pending_task.task.Run(); |
| 64 | 61 |
| 65 stopwatch.Stop(); | 62 stopwatch.Stop(); |
| 66 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( | 63 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( |
| 67 pending_task, stopwatch); | 64 pending_task, stopwatch); |
| 68 } | 65 } |
| 69 | 66 |
| 70 uint64 TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { | 67 uint64 TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { |
| 71 return (static_cast<uint64>(task.sequence_num) << 32) | | 68 return (static_cast<uint64>(task.sequence_num) << 32) | |
| 72 ((static_cast<uint64>(reinterpret_cast<intptr_t>(this)) << 32) >> 32); | 69 ((static_cast<uint64>(reinterpret_cast<intptr_t>(this)) << 32) >> 32); |
| 73 } | 70 } |
| 74 | 71 |
| 75 } // namespace debug | 72 } // namespace debug |
| 76 } // namespace base | 73 } // namespace base |
| OLD | NEW |