| 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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // Returns the thread-local instance, creating one if necessary. Returns | 63 // Returns the thread-local instance, creating one if necessary. Returns |
| 64 // always a valid instance, unless it is called re-entrantly, in which case | 64 // always a valid instance, unless it is called re-entrantly, in which case |
| 65 // returns nullptr in the nested calls. | 65 // returns nullptr in the nested calls. |
| 66 static AllocationContextTracker* GetInstanceForCurrentThread(); | 66 static AllocationContextTracker* GetInstanceForCurrentThread(); |
| 67 | 67 |
| 68 // Set the thread name in the AllocationContextTracker of the current thread | 68 // Set the thread name in the AllocationContextTracker of the current thread |
| 69 // if capture is enabled. | 69 // if capture is enabled. |
| 70 static void SetCurrentThreadName(const char* name); | 70 static void SetCurrentThreadName(const char* name); |
| 71 | 71 |
| 72 // Starts and ends a new ignore scope between which the allocations are | 72 // Starts and ends a new ignore scope between which the allocations are |
| 73 // ignored in the heap profiler. A dummy context that short circuits to | 73 // ignored by the heap profiler. GetContextSnapshot() returns false when |
| 74 // "tracing_overhead" is returned for these allocations. | 74 // allocations are ignored. |
| 75 void begin_ignore_scope() { ignore_scope_depth_++; } | 75 void begin_ignore_scope() { ignore_scope_depth_++; } |
| 76 void end_ignore_scope() { | 76 void end_ignore_scope() { |
| 77 if (ignore_scope_depth_) | 77 if (ignore_scope_depth_) |
| 78 ignore_scope_depth_--; | 78 ignore_scope_depth_--; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Pushes a frame onto the thread-local pseudo stack. | 81 // Pushes a frame onto the thread-local pseudo stack. |
| 82 void PushPseudoStackFrame(PseudoStackFrame stack_frame); | 82 void PushPseudoStackFrame(PseudoStackFrame stack_frame); |
| 83 | 83 |
| 84 // Pops a frame from the thread-local pseudo stack. | 84 // Pops a frame from the thread-local pseudo stack. |
| 85 void PopPseudoStackFrame(PseudoStackFrame stack_frame); | 85 void PopPseudoStackFrame(PseudoStackFrame stack_frame); |
| 86 | 86 |
| 87 // Push and pop current task's context. A stack is used to support nested | 87 // Push and pop current task's context. A stack is used to support nested |
| 88 // tasks and the top of the stack will be used in allocation context. | 88 // tasks and the top of the stack will be used in allocation context. |
| 89 void PushCurrentTaskContext(const char* context); | 89 void PushCurrentTaskContext(const char* context); |
| 90 void PopCurrentTaskContext(const char* context); | 90 void PopCurrentTaskContext(const char* context); |
| 91 | 91 |
| 92 // Returns a snapshot of the current thread-local context. | 92 // Fills a snapshot of the current thread-local context. Doesn't fill and |
| 93 AllocationContext GetContextSnapshot(); | 93 // returns false if allocations are being ignored. |
| 94 bool GetContextSnapshot(AllocationContext* snapshot); |
| 94 | 95 |
| 95 ~AllocationContextTracker(); | 96 ~AllocationContextTracker(); |
| 96 | 97 |
| 97 private: | 98 private: |
| 98 AllocationContextTracker(); | 99 AllocationContextTracker(); |
| 99 | 100 |
| 100 static subtle::Atomic32 capture_mode_; | 101 static subtle::Atomic32 capture_mode_; |
| 101 | 102 |
| 102 // The pseudo stack where frames are |TRACE_EVENT| names. | 103 // The pseudo stack where frames are |TRACE_EVENT| names. |
| 103 std::vector<PseudoStackFrame> pseudo_stack_; | 104 std::vector<PseudoStackFrame> pseudo_stack_; |
| 104 | 105 |
| 105 // The thread name is used as the first entry in the pseudo stack. | 106 // The thread name is used as the first entry in the pseudo stack. |
| 106 const char* thread_name_; | 107 const char* thread_name_; |
| 107 | 108 |
| 108 // Stack of tasks' contexts. Context serves as a different dimension than | 109 // Stack of tasks' contexts. Context serves as a different dimension than |
| 109 // pseudo stack to cluster allocations. | 110 // pseudo stack to cluster allocations. |
| 110 std::vector<const char*> task_contexts_; | 111 std::vector<const char*> task_contexts_; |
| 111 | 112 |
| 112 uint32_t ignore_scope_depth_; | 113 uint32_t ignore_scope_depth_; |
| 113 | 114 |
| 114 DISALLOW_COPY_AND_ASSIGN(AllocationContextTracker); | 115 DISALLOW_COPY_AND_ASSIGN(AllocationContextTracker); |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 } // namespace trace_event | 118 } // namespace trace_event |
| 118 } // namespace base | 119 } // namespace base |
| 119 | 120 |
| 120 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ | 121 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ |
| OLD | NEW |