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_TRACED_BLAME_CONTEXT_H_ | |
6 #define BASE_TRACE_EVENT_TRACED_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/blame_context.h" | |
13 #include "base/trace_event/trace_event.h" | |
14 | |
15 namespace base { | |
16 namespace trace_event { | |
17 class TracedValue; | |
18 } | |
19 | |
20 namespace trace_event { | |
21 | |
22 // A blame context implementation which records enter and leave events to the | |
23 // trace log. A traced blame context can optionally have a parent context, | |
24 // forming a blame context tree. When work is attributed to a particular blame | |
25 // context, it is considered to count against all of that context's children | |
26 // too. This is useful when work cannot be exactly attributed into a more | |
27 // specific context. For example, Javascript garbage collection generally needs | |
28 // to inspect all objects on a page instead looking at each <iframe> | |
29 // individually. In this case the work should be attributed to a blame context | |
30 // which is the parent of all <iframe> blame contexts. | |
31 class BASE_EXPORT TracedBlameContext | |
32 : public BlameContext, | |
33 public trace_event::TraceLog::EnabledStateObserver { | |
34 public: | |
35 // Construct a blame context belonging to the blame context tree |name|, using | |
36 // to the tracing category |category|, identified by |id| from to the |scope| | |
danakj
2016/03/16 18:29:50
"using the tracing"
"from the |scope|"
Sami
2016/03/17 12:27:13
Argh, looks like these got mangled somewhere in du
| |
37 // namespace. |type| identifies the type of this object snapshot in the blame | |
38 // context tree. This blame context will not have a parent. Note that all | |
39 // strings must have application lifetime. | |
40 TracedBlameContext(const char* category, | |
41 const char* name, | |
42 const char* type, | |
43 const char* scope, | |
44 int64_t id); | |
45 | |
46 // Construct a blame context belonging to the blame context tree|name|, using | |
danakj
2016/03/16 18:29:50
"tree |name|"
Sami
2016/03/17 12:27:13
Done.
| |
47 // to the tracing category |category|, identified by |id| from to the |scope| | |
danakj
2016/03/16 18:29:50
"using the tracing"
"from the |scope|"
Sami
2016/03/17 12:27:13
Done.
| |
48 // namespace. |type| identifies the type of this object snapshot in the blame | |
49 // context tree. |parent_context| identifies the parent for this blame | |
50 // context. It must belong to the same blame context tree as this context, | |
51 // i.e., |name| must equal |parent_context.name()|. Note that all strings must | |
52 // have application lifetime. | |
53 TracedBlameContext(const char* category, | |
54 const char* name, | |
55 const char* type, | |
56 const char* scope, | |
57 int64_t id, | |
58 const TracedBlameContext& parent_context); | |
59 | |
60 // BlameContext implementation: | |
61 void Enter() override; | |
danakj
2016/03/16 18:29:50
I'd still like to see us do this without virtuals,
Sami
2016/03/17 12:27:13
Looks like it all fits together, thanks for the su
| |
62 void Leave() override; | |
63 | |
64 // Record a snapshot of the blame context. This is normally only needed if a | |
65 // blame context subclass defines custom properties (see AsValueInto) and one | |
66 // or more of those properties have changed. | |
67 void TakeSnapshot(); | |
68 | |
69 const char* category() const { return category_; } | |
70 const char* name() const { return name_; } | |
71 const char* type() const { return type_; } | |
72 const char* scope() const { return scope_; } | |
73 int64_t id() const { return id_; } | |
74 | |
75 // trace_event::TraceLog::EnabledStateObserver implementation: | |
76 void OnTraceLogEnabled() override; | |
77 void OnTraceLogDisabled() override; | |
78 | |
79 protected: | |
80 ~TracedBlameContext() override; | |
81 | |
82 // Serialize the properties of this blame context into |state|. Subclasses can | |
83 // override this method to record additional properties (e.g, the URL for an | |
84 // <iframe> blame context). Note that an overridden implementation must still | |
85 // call this base method. | |
86 virtual void AsValueInto(trace_event::TracedValue* state); | |
87 | |
88 private: | |
89 void Initialize(); | |
90 | |
91 // The following string pointers have application lifetime. | |
92 const char* category_; | |
93 const char* name_; | |
94 const char* type_; | |
95 const char* scope_; | |
96 const int64_t id_; | |
97 | |
98 const char* parent_scope_; | |
99 const int64_t parent_id_; | |
100 | |
101 const unsigned char* category_group_enabled_; | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(TracedBlameContext); | |
104 }; | |
105 | |
106 } // namespace trace_event | |
107 } // namespace base | |
108 | |
109 #endif // BASE_TRACE_EVENT_BLAME_CONTEXT_H_ | |
OLD | NEW |