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

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: Now with unittests! 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
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[4];
danakj 2017/02/08 18:06:22 can you static assert that this is the same size a
awong 2017/02/08 23:20:38 good idea. done. Actually did better and just tied
50 debug::Alias(&program_counter); 50 memcpy(&task_backtrace[0], &pending_task->task_backtrace[0],
51 sizeof(task_backtrace));
52 debug::Alias(&task_backtrace);
51 53
52 std::move(pending_task->task).Run(); 54 std::move(pending_task->task).Run();
53 55
54 stopwatch.Stop(); 56 stopwatch.Stop();
55 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(*pending_task, 57 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(*pending_task,
56 stopwatch); 58 stopwatch);
57 } 59 }
58 60
59 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { 61 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const {
60 return (static_cast<uint64_t>(task.sequence_num) << 32) | 62 return (static_cast<uint64_t>(task.sequence_num) << 32) |
61 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >> 63 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >>
62 32); 64 32);
63 } 65 }
64 66
65 } // namespace debug 67 } // namespace debug
66 } // namespace base 68 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698