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

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

Issue 1956333002: Change the base class of BlameContext into AsyncEnabledStateObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ThreadSafeObserver
Patch Set: Add note on thread safety for Enter() and Leave() Created 4 years, 7 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
« no previous file with comments | « no previous file | base/trace_event/blame_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_BLAME_CONTEXT_H_ 5 #ifndef BASE_TRACE_EVENT_BLAME_CONTEXT_H_
6 #define BASE_TRACE_EVENT_BLAME_CONTEXT_H_ 6 #define BASE_TRACE_EVENT_BLAME_CONTEXT_H_
7 7
8 #include <inttypes.h> 8 #include <inttypes.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/threading/thread_checker.h"
12 #include "base/trace_event/trace_log.h" 13 #include "base/trace_event/trace_log.h"
13 14
14 namespace base { 15 namespace base {
15 namespace trace_event { 16 namespace trace_event {
16 class TracedValue; 17 class TracedValue;
17 } 18 }
18 19
19 namespace trace_event { 20 namespace trace_event {
20 21
21 // A blame context represents a logical unit to which we want to attribute 22 // A blame context represents a logical unit to which we want to attribute
22 // different costs (e.g., CPU, network, or memory usage). An example of a blame 23 // different costs (e.g., CPU, network, or memory usage). An example of a blame
23 // context is an <iframe> element on a web page. Different subsystems can 24 // context is an <iframe> element on a web page. Different subsystems can
24 // "enter" and "leave" blame contexts to indicate that they are doing work which 25 // "enter" and "leave" blame contexts to indicate that they are doing work which
25 // should be accounted against this blame context. 26 // should be accounted against this blame context.
26 // 27 //
27 // A blame context can optionally have a parent context, forming a blame context 28 // A blame context can optionally have a parent context, forming a blame context
28 // tree. When work is attributed to a particular blame context, it is considered 29 // tree. When work is attributed to a particular blame context, it is considered
29 // to count against all of that context's children too. This is useful when work 30 // to count against all of that context's children too. This is useful when work
30 // cannot be exactly attributed into a more specific context. For example, 31 // cannot be exactly attributed into a more specific context. For example,
31 // Javascript garbage collection generally needs to inspect all objects on a 32 // Javascript garbage collection generally needs to inspect all objects on a
32 // page instead looking at each <iframe> individually. In this case the work 33 // page instead looking at each <iframe> individually. In this case the work
33 // should be attributed to a blame context which is the parent of all <iframe> 34 // should be attributed to a blame context which is the parent of all <iframe>
34 // blame contexts. 35 // blame contexts.
35 class BASE_EXPORT BlameContext 36 class BASE_EXPORT BlameContext
36 : public trace_event::TraceLog::EnabledStateObserver { 37 : public trace_event::TraceLog::AsyncEnabledStateObserver {
37 public: 38 public:
38 // Construct a blame context belonging to the blame context tree |name|, using 39 // Construct a blame context belonging to the blame context tree |name|, using
39 // the tracing category |category|, identified by |id| from the |scope| 40 // the tracing category |category|, identified by |id| from the |scope|
40 // namespace. |type| identifies the type of this object snapshot in the blame 41 // namespace. |type| identifies the type of this object snapshot in the blame
41 // context tree. |parent_context| is the parent of this blame context or 42 // context tree. |parent_context| is the parent of this blame context or
42 // null. Note that all strings must have application lifetime. 43 // null. Note that all strings must have application lifetime.
43 // 44 //
44 // For example, a blame context which represents a specific <iframe> in a 45 // For example, a blame context which represents a specific <iframe> in a
45 // browser frame tree could be specified with: 46 // browser frame tree could be specified with:
46 // 47 //
(...skipping 21 matching lines...) Expand all
68 const char* scope, 69 const char* scope,
69 int64_t id, 70 int64_t id,
70 const BlameContext* parent_context); 71 const BlameContext* parent_context);
71 ~BlameContext() override; 72 ~BlameContext() override;
72 73
73 // Initialize the blame context, automatically taking a snapshot if tracing is 74 // Initialize the blame context, automatically taking a snapshot if tracing is
74 // enabled. Must be called before any other methods on this class. 75 // enabled. Must be called before any other methods on this class.
75 void Initialize(); 76 void Initialize();
76 77
77 // Indicate that the current thread is now doing work which should count 78 // Indicate that the current thread is now doing work which should count
78 // against this blame context. 79 // against this blame context. This function is allowed to be called in a
80 // thread different from where the blame context was created; However, any
81 // client doing that must be fully responsible for ensuring thready safety.
79 void Enter(); 82 void Enter();
80 83
81 // Leave and stop doing work for a previously entered blame context. If 84 // Leave and stop doing work for a previously entered blame context. If
82 // another blame context belongin to the same tree was entered prior to this 85 // another blame context belongin to the same tree was entered prior to this
83 // one, it becomes the active blame context for this thread again. 86 // one, it becomes the active blame context for this thread again. Similar
87 // to Enter(), this function can be called in a thread different from where
88 // the blame context was created, and the same requirement on thread safety
89 // must be satisfied.
84 void Leave(); 90 void Leave();
85 91
86 // Record a snapshot of the blame context. This is normally only needed if a 92 // Record a snapshot of the blame context. This is normally only needed if a
87 // blame context subclass defines custom properties (see AsValueInto) and one 93 // blame context subclass defines custom properties (see AsValueInto) and one
88 // or more of those properties have changed. 94 // or more of those properties have changed.
89 void TakeSnapshot(); 95 void TakeSnapshot();
90 96
91 const char* category() const { return category_; } 97 const char* category() const { return category_; }
92 const char* name() const { return name_; } 98 const char* name() const { return name_; }
93 const char* type() const { return type_; } 99 const char* type() const { return type_; }
(...skipping 19 matching lines...) Expand all
113 const char* name_; 119 const char* name_;
114 const char* type_; 120 const char* type_;
115 const char* scope_; 121 const char* scope_;
116 const int64_t id_; 122 const int64_t id_;
117 123
118 const char* parent_scope_; 124 const char* parent_scope_;
119 const int64_t parent_id_; 125 const int64_t parent_id_;
120 126
121 const unsigned char* category_group_enabled_; 127 const unsigned char* category_group_enabled_;
122 128
129 ThreadChecker thread_checker_;
130 WeakPtrFactory<BlameContext> weak_factory_;
131
123 DISALLOW_COPY_AND_ASSIGN(BlameContext); 132 DISALLOW_COPY_AND_ASSIGN(BlameContext);
124 }; 133 };
125 134
126 } // namespace trace_event 135 } // namespace trace_event
127 } // namespace base 136 } // namespace base
128 137
129 #endif // BASE_TRACE_EVENT_BLAME_CONTEXT_H_ 138 #endif // BASE_TRACE_EVENT_BLAME_CONTEXT_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/blame_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698