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

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

Issue 1776673002: base: Add blame context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unprotect destructor. Created 4 years, 9 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 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
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.
Primiano Tucci (use gerrit) 2016/03/21 14:26:29 Maybe an example of how the actual args to the cto
Sami 2016/03/21 15:05:09 Good idea, added.
43 BlameContext(const char* category,
44 const char* name,
45 const char* type,
46 const char* scope,
47 int64_t id);
Primiano Tucci (use gerrit) 2016/03/21 14:26:29 if this is expected to be overridden, I wonder if
Sami 2016/03/21 15:05:09 Agreed, I've now combined them (although there was
48
49 // Construct a blame context belonging to the blame context tree |name|, using
Primiano Tucci (use gerrit) 2016/03/21 14:26:29 I'd probably not duplicate this comment, and in th
Sami 2016/03/21 15:05:09 Done.
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 ~BlameContext() override;
63
64 // Indicate that the current thread is now doing work which should count
65 // against this blame context.
66 void Enter();
67
68 // Leave and stop doing work for a previously entered blame context. If
69 // another blame context belongin to the same tree was entered prior to this
70 // one, it becomes the active blame context for this thread again.
71 void Leave();
72
73 // Record a snapshot of the blame context. This is normally only needed if a
74 // blame context subclass defines custom properties (see AsValueInto) and one
75 // or more of those properties have changed.
76 void TakeSnapshot();
77
78 const char* category() const { return category_; }
79 const char* name() const { return name_; }
80 const char* type() const { return type_; }
81 const char* scope() const { return scope_; }
82 int64_t id() const { return id_; }
83
84 // trace_event::TraceLog::EnabledStateObserver implementation:
85 void OnTraceLogEnabled() override;
86 void OnTraceLogDisabled() override;
87
88 protected:
89 // Serialize the properties of this blame context into |state|. Subclasses can
90 // override this method to record additional properties (e.g, the URL for an
91 // <iframe> blame context). Note that an overridden implementation must still
92 // call this base method.
93 virtual void AsValueInto(trace_event::TracedValue* state);
94
95 private:
96 void Initialize();
97
98 // The following string pointers have application lifetime.
99 const char* category_;
100 const char* name_;
101 const char* type_;
102 const char* scope_;
103 const int64_t id_;
104
105 const char* parent_scope_;
106 const int64_t parent_id_;
107
108 const unsigned char* category_group_enabled_;
109
110 DISALLOW_COPY_AND_ASSIGN(BlameContext);
111 };
112
113 } // namespace trace_event
114 } // namespace base
115
116 #endif // BASE_TRACE_EVENT_BLAME_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698