1 // Copyright 2013 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.
5 #ifndef CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_
6 #define CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_
8 #include "base/trace_event/trace_event.h"
9 #include "base/trace_event/trace_event_argument.h"
12 namespace devtools_instrumentation
{
15 const char kCategory
[] = TRACE_DISABLED_BY_DEFAULT("devtools.timeline");
16 const char kCategoryFrame
[] =
17 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.frame");
18 const char kData
[] = "data";
19 const char kFrameId
[] = "frameId";
20 const char kLayerId
[] = "layerId";
21 const char kLayerTreeId
[] = "layerTreeId";
22 const char kPixelRefId
[] = "pixelRefId";
24 const char kImageDecodeTask
[] = "ImageDecodeTask";
25 const char kBeginFrame
[] = "BeginFrame";
26 const char kNeedsBeginFrameChanged
[] = "NeedsBeginFrameChanged";
27 const char kActivateLayerTree
[] = "ActivateLayerTree";
28 const char kRequestMainThreadFrame
[] = "RequestMainThreadFrame";
29 const char kBeginMainThreadFrame
[] = "BeginMainThreadFrame";
30 const char kDrawFrame
[] = "DrawFrame";
31 const char kCompositeLayers
[] = "CompositeLayers";
32 } // namespace internal
34 const char kPaintSetup
[] = "PaintSetup";
35 const char kUpdateLayer
[] = "UpdateLayer";
37 class ScopedLayerTask
{
39 ScopedLayerTask(const char* event_name
, int layer_id
)
40 : event_name_(event_name
) {
41 TRACE_EVENT_BEGIN1(internal::kCategory
, event_name_
,
42 internal::kLayerId
, layer_id
);
45 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
48 const char* event_name_
;
50 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTask
);
53 class ScopedImageDecodeTask
{
55 explicit ScopedImageDecodeTask(const void* imagePtr
) {
56 TRACE_EVENT_BEGIN1(internal::kCategory
, internal::kImageDecodeTask
,
57 internal::kPixelRefId
,
58 reinterpret_cast<uint64
>(imagePtr
));
60 ~ScopedImageDecodeTask() {
61 TRACE_EVENT_END0(internal::kCategory
, internal::kImageDecodeTask
);
64 DISALLOW_COPY_AND_ASSIGN(ScopedImageDecodeTask
);
67 class ScopedLayerTreeTask
{
69 ScopedLayerTreeTask(const char* event_name
,
71 int layer_tree_host_id
)
72 : event_name_(event_name
) {
73 TRACE_EVENT_BEGIN2(internal::kCategory
, event_name_
,
74 internal::kLayerId
, layer_id
,
75 internal::kLayerTreeId
, layer_tree_host_id
);
77 ~ScopedLayerTreeTask() {
78 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
81 const char* event_name_
;
83 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTreeTask
);
86 struct ScopedCommitTrace
{
88 explicit ScopedCommitTrace(int layer_tree_host_id
) {
89 TRACE_EVENT_BEGIN1(internal::kCategory
, internal::kCompositeLayers
,
90 internal::kLayerTreeId
, layer_tree_host_id
);
92 ~ScopedCommitTrace() {
93 TRACE_EVENT_END0(internal::kCategory
, internal::kCompositeLayers
);
97 DISALLOW_COPY_AND_ASSIGN(ScopedCommitTrace
);
100 struct ScopedLayerObjectTracker
101 : public base::trace_event::TraceScopedTrackableObject
<int> {
102 explicit ScopedLayerObjectTracker(int layer_id
)
103 : base::trace_event::TraceScopedTrackableObject
<int>(
110 DISALLOW_COPY_AND_ASSIGN(ScopedLayerObjectTracker
);
113 inline void DidActivateLayerTree(int layer_tree_host_id
, int frame_id
) {
114 TRACE_EVENT_INSTANT2(internal::kCategoryFrame
,
115 internal::kActivateLayerTree
,
116 TRACE_EVENT_SCOPE_THREAD
,
117 internal::kLayerTreeId
,
123 inline void DidBeginFrame(int layer_tree_host_id
) {
124 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
125 internal::kBeginFrame
,
126 TRACE_EVENT_SCOPE_THREAD
,
127 internal::kLayerTreeId
,
131 inline void DidDrawFrame(int layer_tree_host_id
) {
132 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
133 internal::kDrawFrame
,
134 TRACE_EVENT_SCOPE_THREAD
,
135 internal::kLayerTreeId
,
139 inline void DidRequestMainThreadFrame(int layer_tree_host_id
) {
140 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
141 internal::kRequestMainThreadFrame
,
142 TRACE_EVENT_SCOPE_THREAD
,
143 internal::kLayerTreeId
,
147 inline scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
148 BeginMainThreadFrameData(int frame_id
) {
149 scoped_refptr
<base::trace_event::TracedValue
> value
=
150 new base::trace_event::TracedValue();
151 value
->SetInteger("frameId", frame_id
);
155 inline void WillBeginMainThreadFrame(int layer_tree_host_id
, int frame_id
) {
156 TRACE_EVENT_INSTANT2(
157 internal::kCategoryFrame
, internal::kBeginMainThreadFrame
,
158 TRACE_EVENT_SCOPE_THREAD
, internal::kLayerTreeId
, layer_tree_host_id
,
159 internal::kData
, BeginMainThreadFrameData(frame_id
));
162 inline scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
163 NeedsBeginFrameData(bool needs_begin_frame
) {
164 scoped_refptr
<base::trace_event::TracedValue
> value
=
165 new base::trace_event::TracedValue();
166 value
->SetInteger("needsBeginFrame", needs_begin_frame
);
170 inline void NeedsBeginFrameChanged(int layer_tree_host_id
, bool new_value
) {
171 TRACE_EVENT_INSTANT2(
172 internal::kCategoryFrame
, internal::kNeedsBeginFrameChanged
,
173 TRACE_EVENT_SCOPE_THREAD
, internal::kLayerTreeId
, layer_tree_host_id
,
174 internal::kData
, NeedsBeginFrameData(new_value
));
177 } // namespace devtools_instrumentation
180 #endif // CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_