Chromium Code Reviews| 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_event.h" | |
| 13 | |
| 14 namespace base { | |
| 15 namespace trace_event { | |
| 16 class TracedValue; | |
| 17 } | |
| 18 | |
| 19 namespace trace_event { | |
| 20 | |
| 21 // Abstract blame context base class which can be used for attributing work. | |
| 22 class BASE_EXPORT BlameContextBase { | |
|
danakj
2016/03/14 18:43:59
What's the goal of having this base class?
| |
| 23 public: | |
| 24 // Indicate that the current thread is now doing work which should count | |
| 25 // against this blame context. | |
| 26 virtual void Enter() = 0; | |
| 27 | |
| 28 // Leave and stop doing work for a previously entered blame context. If | |
| 29 // another blame context of the same type was entered prior to this one, it | |
| 30 // becomes the active blame context for this thread again. | |
| 31 virtual void Leave() = 0; | |
| 32 | |
| 33 protected: | |
| 34 BlameContextBase() {} | |
| 35 virtual ~BlameContextBase() {} | |
| 36 | |
| 37 DISALLOW_COPY_AND_ASSIGN(BlameContextBase); | |
| 38 }; | |
| 39 | |
| 40 // A blame context represents a logical unit to which we want to attribute | |
| 41 // different costs (e.g., CPU, network, or memory usage). An example of a blame | |
| 42 // context is an <iframe> element on a web page. Different subsystems can | |
| 43 // "enter" and "leave" blame contexts to indicate that they are doing work which | |
| 44 // should be accounted against this blame context. | |
| 45 // | |
| 46 // Each blame context can optionally have a parent context, forming a blame | |
| 47 // context tree. When work is attributed to a particular blame context, it | |
| 48 // is considered to count against all of that context's children too. This is | |
| 49 // useful when work cannot be exactly attributed into a more specific context. | |
| 50 // For example, Javascript garbage collection generally needs to inspect all | |
| 51 // objects on a page instead looking at each <iframe> individually. In this case | |
| 52 // the work should be attributed to a blame context which is the parent of all | |
| 53 // <iframe> blame contexts. | |
| 54 class BASE_EXPORT BlameContext | |
| 55 : public BlameContextBase, | |
| 56 public trace_event::TraceLog::EnabledStateObserver { | |
| 57 public: | |
| 58 // Construct a blame context belonging to the blame context tree |name|, using | |
| 59 // to the tracing category |category|, identified by |id| from to the |scope| | |
| 60 // namespace. |type| identifies the type of this object snapshot in the blame | |
| 61 // context tree. This blame context will not have a parent. Note that all | |
| 62 // strings must have application lifetime. | |
| 63 BlameContext(const char* category, | |
| 64 const char* name, | |
| 65 const char* type, | |
| 66 const char* scope, | |
| 67 int64_t id); | |
| 68 | |
| 69 // Construct a blame context belonging to the blame context tree|name|, using | |
| 70 // to the tracing category |category|, identified by |id| from to the |scope| | |
| 71 // namespace. |type| identifies the type of this object snapshot in the blame | |
| 72 // context tree. |parent_context| identifies the parent for this blame | |
| 73 // context. It must belong to the same blame context tree as this context, | |
| 74 // i.e., |name| must equal |parent_context.name()|. Note that all strings must | |
| 75 // have application lifetime. | |
| 76 BlameContext(const char* category, | |
| 77 const char* name, | |
| 78 const char* type, | |
| 79 const char* scope, | |
| 80 int64_t id, | |
| 81 const BlameContext& parent_context); | |
| 82 | |
| 83 // BlameContextBase implementation: | |
| 84 void Enter() override; | |
| 85 void Leave() override; | |
| 86 | |
| 87 // Record a snapshot of the blame context. This is normally only needed if a | |
| 88 // blame context subclass defines custom properties (see AsValueInto) and one | |
| 89 // or more of those properties have changed. | |
| 90 void TakeSnapshot(); | |
| 91 | |
| 92 const char* category() const { return category_; } | |
| 93 const char* name() const { return name_; } | |
| 94 const char* type() const { return type_; } | |
| 95 const char* scope() const { return scope_; } | |
| 96 int64_t id() const { return id_; } | |
| 97 | |
| 98 // trace_event::TraceLog::EnabledStateObserver implementation: | |
| 99 void OnTraceLogEnabled() override; | |
| 100 void OnTraceLogDisabled() override; | |
| 101 | |
| 102 protected: | |
| 103 ~BlameContext() override; | |
| 104 | |
| 105 // Serialize the properties of this blame context into |state|. Subclasses can | |
| 106 // override this method to record additional properties (e.g, the URL for an | |
| 107 // <iframe> blame context). Note that an overridden implementation must still | |
| 108 // call this base method. | |
| 109 virtual void AsValueInto(trace_event::TracedValue* state); | |
| 110 | |
| 111 private: | |
| 112 void Initialize(); | |
| 113 | |
| 114 // The following string pointers have application lifetime. | |
| 115 const char* category_; | |
| 116 const char* name_; | |
| 117 const char* type_; | |
| 118 const char* scope_; | |
| 119 const int64_t id_; | |
| 120 | |
| 121 const char* parent_scope_; | |
| 122 const int64_t parent_id_; | |
| 123 | |
| 124 const unsigned char* category_group_enabled_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(BlameContext); | |
| 127 }; | |
| 128 | |
| 129 } // namespace trace_event | |
| 130 } // namespace base | |
| 131 | |
| 132 #endif // BASE_TRACE_EVENT_BLAME_CONTEXT_H_ | |
| OLD | NEW |