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

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: More wording fixes. 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 <array>
8
7 #include "base/debug/activity_tracker.h" 9 #include "base/debug/activity_tracker.h"
8 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
9 #include "base/pending_task.h" 11 #include "base/pending_task.h"
10 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
11 #include "base/tracked_objects.h" 13 #include "base/tracked_objects.h"
12 14
13 namespace base { 15 namespace base {
14 namespace debug { 16 namespace debug {
15 17
16 TaskAnnotator::TaskAnnotator() { 18 TaskAnnotator::TaskAnnotator() {
(...skipping 17 matching lines...) Expand all
34 tracked_objects::TaskStopwatch stopwatch; 36 tracked_objects::TaskStopwatch stopwatch;
35 stopwatch.Start(); 37 stopwatch.Start();
36 tracked_objects::Duration queue_duration = 38 tracked_objects::Duration queue_duration =
37 stopwatch.StartTime() - pending_task->EffectiveTimePosted(); 39 stopwatch.StartTime() - pending_task->EffectiveTimePosted();
38 40
39 TRACE_EVENT_WITH_FLOW1( 41 TRACE_EVENT_WITH_FLOW1(
40 TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), queue_function, 42 TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), queue_function,
41 TRACE_ID_MANGLE(GetTaskTraceID(*pending_task)), TRACE_EVENT_FLAG_FLOW_IN, 43 TRACE_ID_MANGLE(GetTaskTraceID(*pending_task)), TRACE_EVENT_FLAG_FLOW_IN,
42 "queue_duration", queue_duration.InMilliseconds()); 44 "queue_duration", queue_duration.InMilliseconds());
43 45
44 // Before running the task, store the program counter where it was posted 46 // 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 47 // 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 48 // 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. 49 // variable itself will have the expected value when displayed by the
48 // Look at a memory dump of the stack. 50 // optimizer in an optimized build. Look at a memory dump of the stack.
49 const void* program_counter = pending_task->posted_from.program_counter(); 51 static constexpr int kStackTaskTraceSnapshotSize =
50 debug::Alias(&program_counter); 52 std::tuple_size<decltype(pending_task->task_backtrace)>::value + 1;
53 std::array<const void*, kStackTaskTraceSnapshotSize> task_backtrace;
54 task_backtrace[0] = pending_task->posted_from.program_counter();
55 std::copy(pending_task->task_backtrace.begin(),
56 pending_task->task_backtrace.end(), task_backtrace.begin() + 1);
57 debug::Alias(&task_backtrace);
51 58
52 std::move(pending_task->task).Run(); 59 std::move(pending_task->task).Run();
53 60
54 stopwatch.Stop(); 61 stopwatch.Stop();
55 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(*pending_task, 62 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(*pending_task,
56 stopwatch); 63 stopwatch);
57 } 64 }
58 65
59 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { 66 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const {
60 return (static_cast<uint64_t>(task.sequence_num) << 32) | 67 return (static_cast<uint64_t>(task.sequence_num) << 32) |
61 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >> 68 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >>
62 32); 69 32);
63 } 70 }
64 71
65 } // namespace debug 72 } // namespace debug
66 } // namespace base 73 } // 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