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 kActivateLayerTree
[] = "ActivateLayerTree";
27 const char kRequestMainThreadFrame
[] = "RequestMainThreadFrame";
28 const char kBeginMainThreadFrame
[] = "BeginMainThreadFrame";
29 const char kDrawFrame
[] = "DrawFrame";
30 const char kCompositeLayers
[] = "CompositeLayers";
31 } // namespace internal
33 const char kPaintSetup
[] = "PaintSetup";
34 const char kUpdateLayer
[] = "UpdateLayer";
36 class ScopedLayerTask
{
38 ScopedLayerTask(const char* event_name
, int layer_id
)
39 : event_name_(event_name
) {
40 TRACE_EVENT_BEGIN1(internal::kCategory
, event_name_
,
41 internal::kLayerId
, layer_id
);
44 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
47 const char* event_name_
;
49 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTask
);
52 class ScopedImageDecodeTask
{
54 explicit ScopedImageDecodeTask(void* pixelRef
) {
55 TRACE_EVENT_BEGIN1(internal::kCategory
, internal::kImageDecodeTask
,
56 internal::kPixelRefId
, reinterpret_cast<uint64
>(pixelRef
));
58 ~ScopedImageDecodeTask() {
59 TRACE_EVENT_END0(internal::kCategory
, internal::kImageDecodeTask
);
62 DISALLOW_COPY_AND_ASSIGN(ScopedImageDecodeTask
);
65 class ScopedLayerTreeTask
{
67 ScopedLayerTreeTask(const char* event_name
,
69 int layer_tree_host_id
)
70 : event_name_(event_name
) {
71 TRACE_EVENT_BEGIN2(internal::kCategory
, event_name_
,
72 internal::kLayerId
, layer_id
,
73 internal::kLayerTreeId
, layer_tree_host_id
);
75 ~ScopedLayerTreeTask() {
76 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
79 const char* event_name_
;
81 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTreeTask
);
84 struct ScopedCommitTrace
{
86 explicit ScopedCommitTrace(int layer_tree_host_id
) {
87 TRACE_EVENT_BEGIN1(internal::kCategory
, internal::kCompositeLayers
,
88 internal::kLayerTreeId
, layer_tree_host_id
);
90 ~ScopedCommitTrace() {
91 TRACE_EVENT_END0(internal::kCategory
, internal::kCompositeLayers
);
95 DISALLOW_COPY_AND_ASSIGN(ScopedCommitTrace
);
98 struct ScopedLayerObjectTracker
99 : public base::trace_event::TraceScopedTrackableObject
<int> {
100 explicit ScopedLayerObjectTracker(int layer_id
)
101 : base::trace_event::TraceScopedTrackableObject
<int>(
108 DISALLOW_COPY_AND_ASSIGN(ScopedLayerObjectTracker
);
111 inline void DidActivateLayerTree(int layer_tree_host_id
, int frame_id
) {
112 TRACE_EVENT_INSTANT2(internal::kCategoryFrame
,
113 internal::kActivateLayerTree
,
114 TRACE_EVENT_SCOPE_THREAD
,
115 internal::kLayerTreeId
,
121 inline void DidBeginFrame(int layer_tree_host_id
) {
122 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
123 internal::kBeginFrame
,
124 TRACE_EVENT_SCOPE_THREAD
,
125 internal::kLayerTreeId
,
129 inline void DidDrawFrame(int layer_tree_host_id
) {
130 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
131 internal::kDrawFrame
,
132 TRACE_EVENT_SCOPE_THREAD
,
133 internal::kLayerTreeId
,
137 inline void DidRequestMainThreadFrame(int layer_tree_host_id
) {
138 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
139 internal::kRequestMainThreadFrame
,
140 TRACE_EVENT_SCOPE_THREAD
,
141 internal::kLayerTreeId
,
145 inline scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
146 BeginMainThreadFrameData(int frame_id
) {
147 scoped_refptr
<base::trace_event::TracedValue
> value
=
148 new base::trace_event::TracedValue();
149 value
->SetInteger("frameId", frame_id
);
153 inline void WillBeginMainThreadFrame(int layer_tree_host_id
, int frame_id
) {
154 TRACE_EVENT_INSTANT2(
155 internal::kCategoryFrame
, internal::kBeginMainThreadFrame
,
156 TRACE_EVENT_SCOPE_THREAD
, internal::kLayerTreeId
, layer_tree_host_id
,
157 internal::kData
, BeginMainThreadFrameData(frame_id
));
160 } // namespace devtools_instrumentation
163 #endif // CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_