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 30 matching lines...) Expand all Loading... |
41 // the thread-local allocation context tracker has been initialized if | 41 // the thread-local allocation context tracker has been initialized if |
42 // |capture_enabled| returns true. | 42 // |capture_enabled| returns true. |
43 return subtle::Acquire_Load(&capture_enabled_) != 0; | 43 return subtle::Acquire_Load(&capture_enabled_) != 0; |
44 } | 44 } |
45 | 45 |
46 // Returns the thread-local instance, creating one if necessary. Returns | 46 // Returns the thread-local instance, creating one if necessary. Returns |
47 // always a valid instance, unless it is called re-entrantly, in which case | 47 // always a valid instance, unless it is called re-entrantly, in which case |
48 // returns nullptr in the nested calls. | 48 // returns nullptr in the nested calls. |
49 static AllocationContextTracker* GetInstanceForCurrentThread(); | 49 static AllocationContextTracker* GetInstanceForCurrentThread(); |
50 | 50 |
| 51 // Set the thread name in the AllocationContextTracker of the current thread |
| 52 // if capture is enabled. |
| 53 static void SetCurrentThreadName(const char* name); |
| 54 |
51 // Pushes a frame onto the thread-local pseudo stack. | 55 // Pushes a frame onto the thread-local pseudo stack. |
52 void PushPseudoStackFrame(StackFrame frame); | 56 void PushPseudoStackFrame(StackFrame frame); |
53 | 57 |
54 // Pops a frame from the thread-local pseudo stack. | 58 // Pops a frame from the thread-local pseudo stack. |
55 void PopPseudoStackFrame(StackFrame frame); | 59 void PopPseudoStackFrame(StackFrame frame); |
56 | 60 |
57 // Returns a snapshot of the current thread-local context. | 61 // Returns a snapshot of the current thread-local context. |
58 AllocationContext GetContextSnapshot(); | 62 AllocationContext GetContextSnapshot(); |
59 | 63 |
60 ~AllocationContextTracker(); | 64 ~AllocationContextTracker(); |
61 | 65 |
62 private: | 66 private: |
63 AllocationContextTracker(); | 67 AllocationContextTracker(); |
64 | 68 |
65 static subtle::Atomic32 capture_enabled_; | 69 static subtle::Atomic32 capture_enabled_; |
66 | 70 |
67 // The pseudo stack where frames are |TRACE_EVENT| names. | 71 // The pseudo stack where frames are |TRACE_EVENT| names. |
68 std::vector<StackFrame> pseudo_stack_; | 72 std::vector<StackFrame> pseudo_stack_; |
69 | 73 |
| 74 // The thread name is used as the first entry in the pseudo stack. |
| 75 const char* thread_name_; |
| 76 |
70 DISALLOW_COPY_AND_ASSIGN(AllocationContextTracker); | 77 DISALLOW_COPY_AND_ASSIGN(AllocationContextTracker); |
71 }; | 78 }; |
72 | 79 |
73 } // namespace trace_event | 80 } // namespace trace_event |
74 } // namespace base | 81 } // namespace base |
75 | 82 |
76 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ | 83 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_TRACKER_H_ |
OLD | NEW |