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

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: Created 5 years, 8 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/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // runner. 45 // runner.
46 TRACE_EVENT_WITH_MEMORY_TAG2( 46 TRACE_EVENT_WITH_MEMORY_TAG2(
47 "toplevel", 47 "toplevel",
48 run_function, 48 run_function,
49 pending_task.posted_from.function_name(), // Name for memory tracking. 49 pending_task.posted_from.function_name(), // Name for memory tracking.
50 "src_file", 50 "src_file",
51 pending_task.posted_from.file_name(), 51 pending_task.posted_from.file_name(),
52 "src_func", 52 "src_func",
53 pending_task.posted_from.function_name()); 53 pending_task.posted_from.function_name());
54 54
55 // Before running the task, store the program counter where it was posted 55 // Before running the task, store the task backtrace with the chain of
56 // and deliberately alias it to ensure it is on the stack if the task 56 // PostTasks that resulted in this call and deliberately alias it to ensure
57 // crashes. Be careful not to assume that the variable itself will have the 57 // it is on the stack if the task crashes. Be careful not to assume that the
58 // expected value when displayed by the optimizer in an optimized build. 58 // variable itself will have the expected value when displayed by the
59 // Look at a memory dump of the stack. 59 // optimizer in an optimized build. Look at a memory dump of the stack.
60 const void* program_counter = pending_task.posted_from.program_counter(); 60 const void* task_backtrace[4];
61 debug::Alias(&program_counter); 61 memcpy(&task_backtrace[0], &pending_task.task_backtrace[0],
62 sizeof(task_backtrace));
63 debug::Alias(&task_backtrace);
62 64
63 pending_task.task.Run(); 65 pending_task.task.Run();
64 66
65 stopwatch.Stop(); 67 stopwatch.Stop();
66 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( 68 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(
67 pending_task, stopwatch); 69 pending_task, stopwatch);
68 } 70 }
69 71
70 uint64 TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { 72 uint64 TaskAnnotator::GetTaskTraceID(const PendingTask& task) const {
71 return (static_cast<uint64>(task.sequence_num) << 32) | 73 return (static_cast<uint64>(task.sequence_num) << 32) |
72 ((static_cast<uint64>(reinterpret_cast<intptr_t>(this)) << 32) >> 32); 74 ((static_cast<uint64>(reinterpret_cast<intptr_t>(this)) << 32) >> 32);
73 } 75 }
74 76
75 } // namespace debug 77 } // namespace debug
76 } // namespace base 78 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/message_loop/incoming_task_queue.cc » ('j') | base/threading/worker_pool_posix.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698