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(void* pixelRef
) {
56 TRACE_EVENT_BEGIN1(internal::kCategory
, internal::kImageDecodeTask
,
57 internal::kPixelRefId
, reinterpret_cast<uint64
>(pixelRef
));
59 ~ScopedImageDecodeTask() {
60 TRACE_EVENT_END0(internal::kCategory
, internal::kImageDecodeTask
);
63 DISALLOW_COPY_AND_ASSIGN(ScopedImageDecodeTask
);
66 class ScopedLayerTreeTask
{
68 ScopedLayerTreeTask(const char* event_name
,
70 int layer_tree_host_id
)
71 : event_name_(event_name
) {
72 TRACE_EVENT_BEGIN2(internal::kCategory
, event_name_
,
73 internal::kLayerId
, layer_id
,
74 internal::kLayerTreeId
, layer_tree_host_id
);
76 ~ScopedLayerTreeTask() {
77 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
80 const char* event_name_
;
82 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTreeTask
);
85 struct ScopedCommitTrace
{
87 explicit ScopedCommitTrace(int layer_tree_host_id
) {
88 TRACE_EVENT_BEGIN1(internal::kCategory
, internal::kCompositeLayers
,
89 internal::kLayerTreeId
, layer_tree_host_id
);
91 ~ScopedCommitTrace() {
92 TRACE_EVENT_END0(internal::kCategory
, internal::kCompositeLayers
);
96 DISALLOW_COPY_AND_ASSIGN(ScopedCommitTrace
);
99 struct ScopedLayerObjectTracker
100 : public base::trace_event::TraceScopedTrackableObject
<int> {
101 explicit ScopedLayerObjectTracker(int layer_id
)
102 : base::trace_event::TraceScopedTrackableObject
<int>(
109 DISALLOW_COPY_AND_ASSIGN(ScopedLayerObjectTracker
);
112 inline void DidActivateLayerTree(int layer_tree_host_id
, int frame_id
) {
113 TRACE_EVENT_INSTANT2(internal::kCategoryFrame
,
114 internal::kActivateLayerTree
,
115 TRACE_EVENT_SCOPE_THREAD
,
116 internal::kLayerTreeId
,
122 inline void DidBeginFrame(int layer_tree_host_id
) {
123 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
124 internal::kBeginFrame
,
125 TRACE_EVENT_SCOPE_THREAD
,
126 internal::kLayerTreeId
,
130 inline void DidDrawFrame(int layer_tree_host_id
) {
131 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
132 internal::kDrawFrame
,
133 TRACE_EVENT_SCOPE_THREAD
,
134 internal::kLayerTreeId
,
138 inline void DidRequestMainThreadFrame(int layer_tree_host_id
) {
139 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
140 internal::kRequestMainThreadFrame
,
141 TRACE_EVENT_SCOPE_THREAD
,
142 internal::kLayerTreeId
,
146 inline scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
147 BeginMainThreadFrameData(int frame_id
) {
148 scoped_refptr
<base::trace_event::TracedValue
> value
=
149 new base::trace_event::TracedValue();
150 value
->SetInteger("frameId", frame_id
);
154 inline void WillBeginMainThreadFrame(int layer_tree_host_id
, int frame_id
) {
155 TRACE_EVENT_INSTANT2(
156 internal::kCategoryFrame
, internal::kBeginMainThreadFrame
,
157 TRACE_EVENT_SCOPE_THREAD
, internal::kLayerTreeId
, layer_tree_host_id
,
158 internal::kData
, BeginMainThreadFrameData(frame_id
));
161 inline scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
162 NeedsBeginFrameData(bool needs_begin_frame
) {
163 scoped_refptr
<base::trace_event::TracedValue
> value
=
164 new base::trace_event::TracedValue();
165 value
->SetInteger("needsBeginFrame", needs_begin_frame
);
169 inline void NeedsBeginFrameChanged(int layer_tree_host_id
, bool new_value
) {
170 TRACE_EVENT_INSTANT2(
171 internal::kCategoryFrame
, internal::kNeedsBeginFrameChanged
,
172 TRACE_EVENT_SCOPE_THREAD
, internal::kLayerTreeId
, layer_tree_host_id
,
173 internal::kData
, NeedsBeginFrameData(new_value
));
176 } // namespace devtools_instrumentation
179 #endif // CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_