OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_TRACE_EVENT_BLAME_CONTEXT_H_ | |
6 #define BASE_TRACE_EVENT_BLAME_CONTEXT_H_ | |
7 | |
8 #include <inttypes.h> | |
9 | |
10 #include "base/base_export.h" | |
11 #include "base/macros.h" | |
12 #include "base/trace_event/trace_log.h" | |
13 | |
14 namespace base { | |
15 namespace trace_event { | |
16 class TracedValue; | |
17 } | |
18 | |
19 namespace trace_event { | |
20 | |
21 // 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 // 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 // should be accounted against this blame context. | |
26 // | |
27 // 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 // 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 // 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 // should be attributed to a blame context which is the parent of all <iframe> | |
34 // blame contexts. | |
35 class BASE_EXPORT BlameContext | |
danakj
2016/03/18 21:34:56
Yay concrete class
| |
36 : public trace_event::TraceLog::EnabledStateObserver { | |
37 public: | |
38 // Construct a blame context belonging to the blame context tree |name|, using | |
39 // the tracing category |category|, identified by |id| from the |scope| | |
40 // namespace. |type| identifies the type of this object snapshot in the blame | |
41 // context tree. This blame context will not have a parent. Note that all | |
42 // strings must have application lifetime. | |
43 BlameContext(const char* category, | |
44 const char* name, | |
45 const char* type, | |
46 const char* scope, | |
47 int64_t id); | |
48 | |
49 // Construct a blame context belonging to the blame context tree |name|, using | |
50 // the tracing category |category|, identified by |id| from the |scope| | |
51 // namespace. |type| identifies the type of this object snapshot in the blame | |
52 // context tree. |parent_context| identifies the parent for this blame | |
53 // context. It must belong to the same blame context tree as this context, | |
54 // i.e., |name| must equal |parent_context.name()|. Note that all strings must | |
55 // have application lifetime. | |
56 BlameContext(const char* category, | |
57 const char* name, | |
58 const char* type, | |
59 const char* scope, | |
60 int64_t id, | |
61 const BlameContext& parent_context); | |
62 | |
63 // Indicate that the current thread is now doing work which should count | |
64 // against this blame context. | |
65 void Enter(); | |
66 | |
67 // Leave and stop doing work for a previously entered blame context. If | |
68 // another blame context belongin to the same tree was entered prior to this | |
69 // one, it becomes the active blame context for this thread again. | |
70 void Leave(); | |
71 | |
72 // Record a snapshot of the blame context. This is normally only needed if a | |
73 // blame context subclass defines custom properties (see AsValueInto) and one | |
74 // or more of those properties have changed. | |
75 void TakeSnapshot(); | |
76 | |
77 const char* category() const { return category_; } | |
78 const char* name() const { return name_; } | |
79 const char* type() const { return type_; } | |
80 const char* scope() const { return scope_; } | |
81 int64_t id() const { return id_; } | |
82 | |
83 // trace_event::TraceLog::EnabledStateObserver implementation: | |
84 void OnTraceLogEnabled() override; | |
85 void OnTraceLogDisabled() override; | |
86 | |
87 protected: | |
88 ~BlameContext() override; | |
89 | |
90 // Serialize the properties of this blame context into |state|. Subclasses can | |
91 // override this method to record additional properties (e.g, the URL for an | |
92 // <iframe> blame context). Note that an overridden implementation must still | |
93 // call this base method. | |
94 virtual void AsValueInto(trace_event::TracedValue* state); | |
95 | |
96 private: | |
97 void Initialize(); | |
98 | |
99 // The following string pointers have application lifetime. | |
100 const char* category_; | |
101 const char* name_; | |
102 const char* type_; | |
103 const char* scope_; | |
104 const int64_t id_; | |
105 | |
106 const char* parent_scope_; | |
107 const int64_t parent_id_; | |
108 | |
109 const unsigned char* category_group_enabled_; | |
110 | |
111 DISALLOW_COPY_AND_ASSIGN(BlameContext); | |
112 }; | |
113 | |
114 } // namespace trace_event | |
115 } // namespace base | |
116 | |
117 #endif // BASE_TRACE_EVENT_BLAME_CONTEXT_H_ | |
OLD | NEW |