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_DEBUG_BLAME_CONTEXT_H_ | |
| 6 #define BASE_DEBUG_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 debug { | |
| 20 | |
| 21 // Abstract blame context base class which can be used for attributing work. | |
| 22 class BASE_EXPORT BlameContextBase { | |
| 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 | |
|
chiniforooshan
2016/03/10 16:18:55
Oh, does this attributing work to all children wor
Sami
2016/03/10 17:59:02
I commented on the doc but I'll repeat it here too
| |
| 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 of type |name|, belonging to the tracing category | |
| 59 // |category|, identified by |id| from to the |scope| namespace. This blame | |
| 60 // context will not have a parent. Note that all strings must have application | |
| 61 // lifetime. | |
| 62 BlameContext(const char* category, | |
| 63 const char* name, | |
| 64 const char* scope, | |
| 65 int64_t id); | |
| 66 | |
| 67 // Construct a blame context of type |name|, belonging to the tracing category | |
| 68 // |category|, identified by |id| from to the |scope| namespace. | |
| 69 // |parent_context| identifies the parent for this blame context. It must | |
| 70 // belong to the same blame context tree as this context, i.e., |name| must | |
| 71 // equal |parent_context.name()|. Note that all strings must have application | |
| 72 // lifetime. | |
| 73 BlameContext(const char* category, | |
| 74 const char* name, | |
| 75 const char* scope, | |
| 76 int64_t id, | |
| 77 const BlameContext& parent_context); | |
| 78 | |
| 79 // BlameContextBase implementation: | |
| 80 void Enter() override; | |
| 81 void Leave() override; | |
| 82 | |
| 83 // Record a snapshot of the blame context. This is normally only needed if a | |
| 84 // blame context subclass defines custom properties (see AsValueInto) and one | |
| 85 // or more of those properties have changed. | |
| 86 void TakeSnapshot(); | |
| 87 | |
| 88 const char* category() const { return category_; } | |
| 89 const char* name() const { return name_; } | |
| 90 const char* scope() const { return scope_; } | |
| 91 int64_t id() const { return id_; } | |
| 92 | |
| 93 // trace_event::TraceLog::EnabledStateObserver implementation: | |
| 94 void OnTraceLogEnabled() override; | |
| 95 void OnTraceLogDisabled() override; | |
| 96 | |
| 97 protected: | |
| 98 ~BlameContext() override; | |
| 99 | |
| 100 // Serialize the properties of this blame context into |state|. Subclasses can | |
| 101 // override this method to record additional properties (e.g, the URL for an | |
| 102 // <iframe> blame context). Note that an overridden implementation must still | |
| 103 // call this base method. | |
| 104 virtual void AsValueInto(trace_event::TracedValue* state); | |
| 105 | |
| 106 private: | |
| 107 void Initialize(); | |
| 108 | |
| 109 // The following string pointers have application lifetime. | |
| 110 const char* category_; | |
| 111 const char* name_; | |
| 112 const char* scope_; | |
| 113 const int64_t id_; | |
| 114 | |
| 115 const char* parent_scope_; | |
| 116 const int64_t parent_id_; | |
| 117 | |
| 118 const unsigned char* category_group_enabled_; | |
| 119 | |
| 120 DISALLOW_COPY_AND_ASSIGN(BlameContext); | |
| 121 }; | |
| 122 | |
| 123 } // namespace debug | |
| 124 } // namespace base | |
| 125 | |
| 126 #endif // BASE_DEBUG_BLAME_CONTEXT_H_ | |
| OLD | NEW |