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/debug/trace_event.h"
11 namespace devtools_instrumentation
{
14 const char kCategory
[] = TRACE_DISABLED_BY_DEFAULT("devtools.timeline");
15 const char kCategoryFrame
[] =
16 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.frame");
17 const char kFrameId
[] = "frameId";
18 const char kLayerId
[] = "layerId";
19 const char kLayerTreeId
[] = "layerTreeId";
20 const char kPixelRefId
[] = "pixelRefId";
22 const char kImageDecodeTask
[] = "ImageDecodeTask";
23 const char kBeginFrame
[] = "BeginFrame";
24 const char kActivateLayerTree
[] = "ActivateLayerTree";
25 const char kRequestMainThreadFrame
[] = "RequestMainThreadFrame";
26 const char kDrawFrame
[] = "DrawFrame";
27 } // namespace internal
29 const char kRasterTask
[] = "RasterTask";
30 const char kPaintSetup
[] = "PaintSetup";
31 const char kUpdateLayer
[] = "UpdateLayer";
33 class ScopedLayerTask
{
35 ScopedLayerTask(const char* event_name
, int layer_id
)
36 : event_name_(event_name
) {
37 TRACE_EVENT_BEGIN1(internal::kCategory
, event_name_
,
38 internal::kLayerId
, layer_id
);
41 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
44 const char* event_name_
;
46 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTask
);
49 class ScopedImageDecodeTask
{
51 explicit ScopedImageDecodeTask(void* pixelRef
) {
52 TRACE_EVENT_BEGIN1(internal::kCategory
, internal::kImageDecodeTask
,
53 internal::kPixelRefId
, reinterpret_cast<uint64
>(pixelRef
));
55 ~ScopedImageDecodeTask() {
56 TRACE_EVENT_END0(internal::kCategory
, internal::kImageDecodeTask
);
59 DISALLOW_COPY_AND_ASSIGN(ScopedImageDecodeTask
);
62 class ScopedLayerTreeTask
{
64 ScopedLayerTreeTask(const char* event_name
,
66 int layer_tree_host_id
)
67 : event_name_(event_name
) {
68 TRACE_EVENT_BEGIN2(internal::kCategory
, event_name_
,
69 internal::kLayerId
, layer_id
,
70 internal::kLayerTreeId
, layer_tree_host_id
);
72 ~ScopedLayerTreeTask() {
73 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
76 const char* event_name_
;
78 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTreeTask
);
81 struct ScopedLayerObjectTracker
82 : public base::debug::TraceScopedTrackableObject
<int> {
83 explicit ScopedLayerObjectTracker(int layer_id
)
84 : base::debug::TraceScopedTrackableObject
<int>(
91 DISALLOW_COPY_AND_ASSIGN(ScopedLayerObjectTracker
);
94 inline void DidActivateLayerTree(int layer_tree_host_id
, int frame_id
) {
95 TRACE_EVENT_INSTANT2(internal::kCategoryFrame
,
96 internal::kActivateLayerTree
,
97 TRACE_EVENT_SCOPE_THREAD
,
98 internal::kLayerTreeId
,
104 inline void DidBeginFrame(int layer_tree_host_id
) {
105 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
106 internal::kBeginFrame
,
107 TRACE_EVENT_SCOPE_THREAD
,
108 internal::kLayerTreeId
,
112 inline void DidDrawFrame(int layer_tree_host_id
) {
113 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
114 internal::kDrawFrame
,
115 TRACE_EVENT_SCOPE_THREAD
,
116 internal::kLayerTreeId
,
120 inline void DidRequestMainThreadFrame(int layer_tree_host_id
) {
121 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
122 internal::kRequestMainThreadFrame
,
123 TRACE_EVENT_SCOPE_THREAD
,
124 internal::kLayerTreeId
,
128 } // namespace devtools_instrumentation
131 #endif // CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_