Index: base/trace_event/traced_blame_context.h |
diff --git a/base/trace_event/traced_blame_context.h b/base/trace_event/traced_blame_context.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6bba24add192b85fc8e68c0998a467f70f2e5a8f |
--- /dev/null |
+++ b/base/trace_event/traced_blame_context.h |
@@ -0,0 +1,109 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef BASE_TRACE_EVENT_TRACED_BLAME_CONTEXT_H_ |
+#define BASE_TRACE_EVENT_TRACED_BLAME_CONTEXT_H_ |
+ |
+#include <inttypes.h> |
+ |
+#include "base/base_export.h" |
+#include "base/macros.h" |
+#include "base/trace_event/blame_context.h" |
+#include "base/trace_event/trace_event.h" |
+ |
+namespace base { |
+namespace trace_event { |
+class TracedValue; |
+} |
+ |
+namespace trace_event { |
+ |
+// A blame context implementation which records enter and leave events to the |
+// trace log. A traced blame context can optionally have a parent context, |
+// forming a blame context tree. When work is attributed to a particular blame |
+// context, it is considered to count against all of that context's children |
+// too. This is useful when work cannot be exactly attributed into a more |
+// specific context. For example, Javascript garbage collection generally needs |
+// to inspect all objects on a page instead looking at each <iframe> |
+// individually. In this case the work should be attributed to a blame context |
+// which is the parent of all <iframe> blame contexts. |
+class BASE_EXPORT TracedBlameContext |
+ : public BlameContext, |
+ public trace_event::TraceLog::EnabledStateObserver { |
+ public: |
+ // Construct a blame context belonging to the blame context tree |name|, using |
+ // 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
|
+ // namespace. |type| identifies the type of this object snapshot in the blame |
+ // context tree. This blame context will not have a parent. Note that all |
+ // strings must have application lifetime. |
+ TracedBlameContext(const char* category, |
+ const char* name, |
+ const char* type, |
+ const char* scope, |
+ int64_t id); |
+ |
+ // 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.
|
+ // 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.
|
+ // namespace. |type| identifies the type of this object snapshot in the blame |
+ // context tree. |parent_context| identifies the parent for this blame |
+ // context. It must belong to the same blame context tree as this context, |
+ // i.e., |name| must equal |parent_context.name()|. Note that all strings must |
+ // have application lifetime. |
+ TracedBlameContext(const char* category, |
+ const char* name, |
+ const char* type, |
+ const char* scope, |
+ int64_t id, |
+ const TracedBlameContext& parent_context); |
+ |
+ // BlameContext implementation: |
+ 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
|
+ void Leave() override; |
+ |
+ // Record a snapshot of the blame context. This is normally only needed if a |
+ // blame context subclass defines custom properties (see AsValueInto) and one |
+ // or more of those properties have changed. |
+ void TakeSnapshot(); |
+ |
+ const char* category() const { return category_; } |
+ const char* name() const { return name_; } |
+ const char* type() const { return type_; } |
+ const char* scope() const { return scope_; } |
+ int64_t id() const { return id_; } |
+ |
+ // trace_event::TraceLog::EnabledStateObserver implementation: |
+ void OnTraceLogEnabled() override; |
+ void OnTraceLogDisabled() override; |
+ |
+ protected: |
+ ~TracedBlameContext() override; |
+ |
+ // Serialize the properties of this blame context into |state|. Subclasses can |
+ // override this method to record additional properties (e.g, the URL for an |
+ // <iframe> blame context). Note that an overridden implementation must still |
+ // call this base method. |
+ virtual void AsValueInto(trace_event::TracedValue* state); |
+ |
+ private: |
+ void Initialize(); |
+ |
+ // The following string pointers have application lifetime. |
+ const char* category_; |
+ const char* name_; |
+ const char* type_; |
+ const char* scope_; |
+ const int64_t id_; |
+ |
+ const char* parent_scope_; |
+ const int64_t parent_id_; |
+ |
+ const unsigned char* category_group_enabled_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TracedBlameContext); |
+}; |
+ |
+} // namespace trace_event |
+} // namespace base |
+ |
+#endif // BASE_TRACE_EVENT_BLAME_CONTEXT_H_ |