OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ | 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ |
6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ | 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/trace_event/heap_profiler_allocation_context.h" | 14 #include "base/trace_event/heap_profiler_allocation_context.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 namespace trace_event { | 17 namespace trace_event { |
18 | 18 |
19 // The allocation context tracker keeps track of thread-local context for heap | 19 // The allocation context tracker keeps track of thread-local context for heap |
20 // profiling. It includes a pseudo stack of trace events. On every allocation | 20 // profiling. It includes a pseudo stack of trace events. On every allocation |
21 // the tracker provides a snapshot of its context in the form of an | 21 // the tracker provides a snapshot of its context in the form of an |
22 // |AllocationContext| that is to be stored together with the allocation | 22 // |AllocationContext| that is to be stored together with the allocation |
23 // details. | 23 // details. |
24 class BASE_EXPORT AllocationContextTracker { | 24 class BASE_EXPORT AllocationContextTracker { |
25 public: | 25 public: |
26 class ScopedTaskExecutionEvent { | |
27 public: | |
28 ScopedTaskExecutionEvent(const char* category_group, | |
29 const char* posted_reason); | |
Primiano Tucci (use gerrit)
2016/03/25 01:56:31
I think these should be called poster_task_file_na
ssid
2016/03/28 18:14:49
calling it context, can change if you prefer to be
| |
30 | |
31 ~ScopedTaskExecutionEvent(); | |
32 | |
33 private: | |
34 const char* category_; | |
35 }; | |
36 | |
26 // Globally enables capturing allocation context. | 37 // Globally enables capturing allocation context. |
27 // TODO(ruuda): Should this be replaced by |EnableCapturing| in the future? | 38 // TODO(ruuda): Should this be replaced by |EnableCapturing| in the future? |
28 // Or at least have something that guards agains enable -> disable -> enable? | 39 // Or at least have something that guards agains enable -> disable -> enable? |
29 static void SetCaptureEnabled(bool enabled); | 40 static void SetCaptureEnabled(bool enabled); |
30 | 41 |
31 // Returns whether capturing allocation context is enabled globally. | 42 // Returns whether capturing allocation context is enabled globally. |
32 inline static bool capture_enabled() { | 43 inline static bool capture_enabled() { |
33 // A little lag after heap profiling is enabled or disabled is fine, it is | 44 // A little lag after heap profiling is enabled or disabled is fine, it is |
34 // more important that the check is as cheap as possible when capturing is | 45 // more important that the check is as cheap as possible when capturing is |
35 // not enabled, so do not issue a memory barrier in the fast path. | 46 // not enabled, so do not issue a memory barrier in the fast path. |
(...skipping 24 matching lines...) Expand all Loading... | |
60 // Returns a snapshot of the current thread-local context. | 71 // Returns a snapshot of the current thread-local context. |
61 AllocationContext GetContextSnapshot(); | 72 AllocationContext GetContextSnapshot(); |
62 | 73 |
63 ~AllocationContextTracker(); | 74 ~AllocationContextTracker(); |
64 | 75 |
65 private: | 76 private: |
66 AllocationContextTracker(); | 77 AllocationContextTracker(); |
67 | 78 |
68 static subtle::Atomic32 capture_enabled_; | 79 static subtle::Atomic32 capture_enabled_; |
69 | 80 |
81 void PushCurrentCategoryName(const char* category); | |
Primiano Tucci (use gerrit)
2016/03/25 01:56:31
I'm a bit confused by the "Category" name here.
Ca
ssid
2016/03/28 18:14:49
Hm it is not exactly task name. To be specific I s
| |
82 void PopCurrentCategoryName(const char* category); | |
83 | |
70 // The pseudo stack where frames are |TRACE_EVENT| names. | 84 // The pseudo stack where frames are |TRACE_EVENT| names. |
71 std::vector<StackFrame> pseudo_stack_; | 85 std::vector<StackFrame> pseudo_stack_; |
72 | 86 |
87 // Category can be nested when tasks are nested. So, a stack is used and the | |
88 // last item is taken for the current allocation. | |
89 std::vector<const char*> categories_; | |
90 | |
73 DISALLOW_COPY_AND_ASSIGN(AllocationContextTracker); | 91 DISALLOW_COPY_AND_ASSIGN(AllocationContextTracker); |
74 }; | 92 }; |
75 | 93 |
76 } // namespace trace_event | 94 } // namespace trace_event |
77 } // namespace base | 95 } // namespace base |
78 | 96 |
79 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ | 97 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ |
OLD | NEW |