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

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

Issue 2386123003: Add heap allocator usage to task profiler. (Closed)
Patch Set: Figure out where the @#$%! corruption is coming from. Move heap tracking to TaskStopwatch." Created 4 years, 2 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 13 matching lines...) Expand all
24 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), 24 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"),
25 queue_function, 25 queue_function,
26 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), 26 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)),
27 TRACE_EVENT_FLAG_FLOW_OUT); 27 TRACE_EVENT_FLAG_FLOW_OUT);
28 } 28 }
29 29
30 void TaskAnnotator::RunTask(const char* queue_function, 30 void TaskAnnotator::RunTask(const char* queue_function,
31 const PendingTask& pending_task) { 31 const PendingTask& pending_task) {
32 ScopedTaskRunActivity task_activity(pending_task); 32 ScopedTaskRunActivity task_activity(pending_task);
33 33
34 base::debug::HeapUsageTracker heap_usage;
Primiano Tucci (use gerrit) 2016/10/13 20:47:44 btw liked Scoped in the name, made it clear that
Sigurður Ásgeirsson 2016/10/14 20:11:35 Yeah, the problem is that the existing instrumenta
34 tracked_objects::TaskStopwatch stopwatch; 35 tracked_objects::TaskStopwatch stopwatch;
35 stopwatch.Start(); 36 stopwatch.Start();
36 tracked_objects::Duration queue_duration = 37 tracked_objects::Duration queue_duration =
37 stopwatch.StartTime() - pending_task.EffectiveTimePosted(); 38 stopwatch.StartTime() - pending_task.EffectiveTimePosted();
38 39
39 TRACE_EVENT_WITH_FLOW1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), 40 TRACE_EVENT_WITH_FLOW1(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"),
40 queue_function, 41 queue_function,
41 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)), 42 TRACE_ID_MANGLE(GetTaskTraceID(pending_task)),
42 TRACE_EVENT_FLAG_FLOW_IN, 43 TRACE_EVENT_FLAG_FLOW_IN,
43 "queue_duration", 44 "queue_duration",
44 queue_duration.InMilliseconds()); 45 queue_duration.InMilliseconds());
45 46
46 // Before running the task, store the program counter where it was posted 47 // Before running the task, store the program counter where it was posted
47 // and deliberately alias it to ensure it is on the stack if the task 48 // and deliberately alias it to ensure it is on the stack if the task
48 // crashes. Be careful not to assume that the variable itself will have the 49 // crashes. Be careful not to assume that the variable itself will have the
49 // expected value when displayed by the optimizer in an optimized build. 50 // expected value when displayed by the optimizer in an optimized build.
50 // Look at a memory dump of the stack. 51 // Look at a memory dump of the stack.
51 const void* program_counter = pending_task.posted_from.program_counter(); 52 const void* program_counter = pending_task.posted_from.program_counter();
52 debug::Alias(&program_counter); 53 debug::Alias(&program_counter);
53 54
54 pending_task.task.Run(); 55 pending_task.task.Run();
55 56
56 stopwatch.Stop(); 57 stopwatch.Stop();
58
Primiano Tucci (use gerrit) 2016/10/13 20:47:44 silly question: what's the point of this scoped He
Sigurður Ásgeirsson 2016/10/14 20:11:35 Good catch - I've moved the HUT into the StopWatch
57 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( 59 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(
58 pending_task, stopwatch); 60 pending_task, stopwatch);
59 } 61 }
60 62
61 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { 63 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const {
62 return (static_cast<uint64_t>(task.sequence_num) << 32) | 64 return (static_cast<uint64_t>(task.sequence_num) << 32) |
63 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >> 65 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >>
64 32); 66 32);
65 } 67 }
66 68
67 } // namespace debug 69 } // namespace debug
68 } // namespace base 70 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698