OLD | NEW |
---|---|
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 #ifndef BASE_DEBUG_TASK_ANNOTATOR_H_ | 5 #ifndef BASE_DEBUG_TASK_ANNOTATOR_H_ |
6 #define BASE_DEBUG_TASK_ANNOTATOR_H_ | 6 #define BASE_DEBUG_TASK_ANNOTATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 struct PendingTask; | 15 struct PendingTask; |
15 namespace debug { | 16 namespace debug { |
16 | 17 |
17 // Implements common debug annotations for posted tasks. This includes data | 18 // Implements common debug annotations for posted tasks. This includes data |
18 // such as task origins, queueing durations and memory usage. | 19 // such as task origins, queueing durations and memory usage. |
19 class BASE_EXPORT TaskAnnotator { | 20 class BASE_EXPORT TaskAnnotator { |
20 public: | 21 public: |
21 TaskAnnotator(); | 22 TaskAnnotator(); |
(...skipping 10 matching lines...) Expand all Loading... | |
32 | 33 |
33 private: | 34 private: |
34 // Creates a process-wide unique ID to represent this task in trace events. | 35 // Creates a process-wide unique ID to represent this task in trace events. |
35 // This will be mangled with a Process ID hash to reduce the likelyhood of | 36 // This will be mangled with a Process ID hash to reduce the likelyhood of |
36 // colliding with TaskAnnotator pointers on other processes. | 37 // colliding with TaskAnnotator pointers on other processes. |
37 uint64_t GetTaskTraceID(const PendingTask& task) const; | 38 uint64_t GetTaskTraceID(const PendingTask& task) const; |
38 | 39 |
39 DISALLOW_COPY_AND_ASSIGN(TaskAnnotator); | 40 DISALLOW_COPY_AND_ASSIGN(TaskAnnotator); |
40 }; | 41 }; |
41 | 42 |
43 class ScopedTaskExecutionEvent { | |
44 public: | |
45 ScopedTaskExecutionEvent(const char* file_name, const char* function_name) | |
46 : function_name_(function_name) { | |
47 if (base::trace_event::AllocationContextTracker::capture_enabled()) { | |
Dmitry Skiba
2016/03/15 19:38:31
BTW, since this is inside base too, you can omit b
ssid
2016/03/17 00:11:46
Done.
| |
48 base::trace_event::AllocationContextTracker::SetCurrentTaskFileName( | |
Primiano Tucci (use gerrit)
2016/03/15 16:44:33
why are these inline? Is it for perf reasons?
Tas
ssid
2016/03/17 00:11:46
See TRACE_TASK_EXECUTION below.
TRACE_TASK_EXECUT
| |
49 file_name); | |
50 base::trace_event::AllocationContextTracker::PushPseudoStackFrame( | |
Primiano Tucci (use gerrit)
2016/03/15 16:44:33
Hmm I think that this will screw the pseudo-stack,
ssid
2016/03/17 00:11:47
What I was imagining was, The function that posted
| |
51 function_name_); | |
52 } | |
53 } | |
54 | |
55 ~ScopedTaskExecutionEvent() { | |
56 if (base::trace_event::AllocationContextTracker::capture_enabled()) { | |
57 base::trace_event::AllocationContextTracker::PopPseudoStackFrame( | |
58 function_name_); | |
59 base::trace_event::AllocationContextTracker::SetCurrentTaskFileName( | |
60 nullptr); | |
61 } | |
62 } | |
63 | |
64 private: | |
65 const char* function_name_; | |
66 }; | |
67 | |
42 #define TRACE_TASK_EXECUTION(run_function, task) \ | 68 #define TRACE_TASK_EXECUTION(run_function, task) \ |
43 TRACE_EVENT2("toplevel", (run_function), "src_file", \ | 69 TRACE_EVENT2("toplevel", (run_function), "src_file", \ |
44 (task).posted_from.file_name(), "src_func", \ | 70 (task).posted_from.file_name(), "src_func", \ |
45 (task).posted_from.function_name()); | 71 (task).posted_from.function_name()); \ |
72 base::debug::ScopedTaskExecutionEvent scoped_task_event( \ | |
73 (task).posted_from.file_name(), (task).posted_from.function_name()); | |
46 | 74 |
47 } // namespace debug | 75 } // namespace debug |
48 } // namespace base | 76 } // namespace base |
49 | 77 |
50 #endif // BASE_DEBUG_TASK_ANNOTATOR_H_ | 78 #endif // BASE_DEBUG_TASK_ANNOTATOR_H_ |
OLD | NEW |