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

Side by Side Diff: base/debug/task_annotator.cc

Issue 1044413002: Record async "task backtraces" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't duplicate the posted_from in stacktrace. Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « base/BUILD.gn ('k') | base/message_loop/incoming_task_queue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/activity_tracker.h"
8 #include "base/debug/alias.h" 8 #include "base/debug/alias.h"
9 #include "base/pending_task.h" 9 #include "base/pending_task.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 23 matching lines...) Expand all
34 tracked_objects::TaskStopwatch stopwatch; 34 tracked_objects::TaskStopwatch stopwatch;
35 stopwatch.Start(); 35 stopwatch.Start();
36 tracked_objects::Duration queue_duration = 36 tracked_objects::Duration queue_duration =
37 stopwatch.StartTime() - pending_task->EffectiveTimePosted(); 37 stopwatch.StartTime() - pending_task->EffectiveTimePosted();
38 38
39 TRACE_EVENT_WITH_FLOW1( 39 TRACE_EVENT_WITH_FLOW1(
40 TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), queue_function, 40 TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), queue_function,
41 TRACE_ID_MANGLE(GetTaskTraceID(*pending_task)), TRACE_EVENT_FLAG_FLOW_IN, 41 TRACE_ID_MANGLE(GetTaskTraceID(*pending_task)), TRACE_EVENT_FLAG_FLOW_IN,
42 "queue_duration", queue_duration.InMilliseconds()); 42 "queue_duration", queue_duration.InMilliseconds());
43 43
44 // Before running the task, store the program counter where it was posted 44 // Before running the task, store the task backtrace with the chain of
45 // and deliberately alias it to ensure it is on the stack if the task 45 // PostTasks that resulted in this call and deliberately alias it to ensure
46 // crashes. Be careful not to assume that the variable itself will have the 46 // it is on the stack if the task crashes. Be careful not to assume that the
47 // expected value when displayed by the optimizer in an optimized build. 47 // variable itself will have the expected value when displayed by the
48 // Look at a memory dump of the stack. 48 // optimizer in an optimized build. Look at a memory dump of the stack.
49 const void* program_counter = pending_task->posted_from.program_counter(); 49 const void* task_backtrace[arraysize(pending_task->task_backtrace) + 1];
50 debug::Alias(&program_counter); 50 task_backtrace[0] = pending_task->posted_from.program_counter();
51 memcpy(&task_backtrace[1], &pending_task->task_backtrace[0],
52 sizeof(task_backtrace));
danakj 2017/02/08 23:40:28 The compiler disagrees with me, you want size of p
danakj 2017/02/08 23:41:04 Possibly consider using std::array and STL things
awong 2017/02/09 00:23:38 EEk. Good catch. STLed everything.
53 debug::Alias(&task_backtrace);
51 54
52 std::move(pending_task->task).Run(); 55 std::move(pending_task->task).Run();
53 56
54 stopwatch.Stop(); 57 stopwatch.Stop();
55 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(*pending_task, 58 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(*pending_task,
56 stopwatch); 59 stopwatch);
57 } 60 }
58 61
59 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { 62 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const {
60 return (static_cast<uint64_t>(task.sequence_num) << 32) | 63 return (static_cast<uint64_t>(task.sequence_num) << 32) |
61 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >> 64 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >>
62 32); 65 32);
63 } 66 }
64 67
65 } // namespace debug 68 } // namespace debug
66 } // namespace base 69 } // namespace base
OLDNEW
« no previous file with comments | « base/BUILD.gn ('k') | base/message_loop/incoming_task_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698