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

Side by Side Diff: base/trace_event/pseudo_stack.h

Issue 1340013002: Add thread-local allocation context for tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not allow frame metadata, hook begin/end macros Created 5 years, 3 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
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_TRACE_EVENT_PSEUDO_STACK_H_
6 #define BASE_TRACE_EVENT_PSEUDO_STACK_H_
7
8 #include <vector>
9
10 #include "base/base_export.h"
11 #include "base/trace_event/trace_log.h"
12
13 namespace base {
14 namespace trace_event {
15
16 // The pseudo stack is a thread-local stack, similar to the call stack, where
17 // frames correspond to the |TRACE_EVENT*| macros.
18
19 // Do not access this variable directly, use |*PseudoStackCaptureEnabled|.
20 extern bool BASE_EXPORT g_pseudo_stack_capture_enabled;
21
22 // Globally enables or disables capturing of the pseudo stack for the current
23 // process.
24 void BASE_EXPORT SetPseudoStackCaptureEnabled(bool enabled);
25
26 inline bool BASE_EXPORT GetPseudoStackCaptureEnabled() {
27 // This has no memory barriers for performance reasons. A little lag after
28 // enabling or disabling capturing is not a problem, and pop needs to deal
29 // with underflow either way.
30 return g_pseudo_stack_capture_enabled;
31 }
32
33 // A pseudo stack frame is simply the name of the trace event.
34 typedef const char* PseudoStackFrame;
35
36 // A stack that is kept per thread in TLS to keep track of trace events. Unlike
37 // |std::stack| it allows iterating the stack and it guards for underflow.
38 // Furthermore it has a generation to prevent mixing stacks from different
39 // traces.
40 class BASE_EXPORT PseudoStack {
41 public:
42 typedef std::vector<PseudoStackFrame>::const_reverse_iterator ConstIterator;
43
44 PseudoStack(int32_t generation);
45 ~PseudoStack();
46
47 inline ConstIterator Top() const { return stack_.rbegin(); }
48 inline ConstIterator Bottom() const { return stack_.rend(); }
49
50 inline void Push(PseudoStackFrame frame) { stack_.push_back(frame); }
51 inline void Pop() {
52 if (!stack_.empty())
53 stack_.pop_back();
54 }
55
56 // Returns the thread-local pseudo stack for the current generation, creating
57 // it if it does not exist.
58 static PseudoStack* GetInstance();
59
60 // The pseudo stack is only valid when its generation matches the current
61 // generation. A new generation starts when tracing is enabled, and ends when
62 // tracing is disabled.
63 inline int32_t generation() const { return generation_; }
64
65 private:
66 std::vector<PseudoStackFrame> stack_;
67 const int32_t generation_;
68 };
dsinclair 2015/09/17 14:22:32 DISALLOW_COPY_AND_ASSIGN(PseudoStack);
Ruud van Asseldonk 2015/09/17 15:19:56 Done. Why is it needed though? The default copy co
69
70 } // namespace trace_event
71 } // namespace base
72
73 #endif // BASE_TRACE_EVENT_PSEUDO_STACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698