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 kPaintSetup
[] = "PaintSetup";
30 const char kUpdateLayer
[] = "UpdateLayer";
32 class ScopedLayerTask
{
34 ScopedLayerTask(const char* event_name
, int layer_id
)
35 : event_name_(event_name
) {
36 TRACE_EVENT_BEGIN1(internal::kCategory
, event_name_
,
37 internal::kLayerId
, layer_id
);
40 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
43 const char* event_name_
;
45 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTask
);
48 class ScopedImageDecodeTask
{
50 explicit ScopedImageDecodeTask(void* pixelRef
) {
51 TRACE_EVENT_BEGIN1(internal::kCategory
, internal::kImageDecodeTask
,
52 internal::kPixelRefId
, reinterpret_cast<uint64
>(pixelRef
));
54 ~ScopedImageDecodeTask() {
55 TRACE_EVENT_END0(internal::kCategory
, internal::kImageDecodeTask
);
58 DISALLOW_COPY_AND_ASSIGN(ScopedImageDecodeTask
);
61 class ScopedLayerTreeTask
{
63 ScopedLayerTreeTask(const char* event_name
,
65 int layer_tree_host_id
)
66 : event_name_(event_name
) {
67 TRACE_EVENT_BEGIN2(internal::kCategory
, event_name_
,
68 internal::kLayerId
, layer_id
,
69 internal::kLayerTreeId
, layer_tree_host_id
);
71 ~ScopedLayerTreeTask() {
72 TRACE_EVENT_END0(internal::kCategory
, event_name_
);
75 const char* event_name_
;
77 DISALLOW_COPY_AND_ASSIGN(ScopedLayerTreeTask
);
80 struct ScopedLayerObjectTracker
81 : public base::debug::TraceScopedTrackableObject
<int> {
82 explicit ScopedLayerObjectTracker(int layer_id
)
83 : base::debug::TraceScopedTrackableObject
<int>(
90 DISALLOW_COPY_AND_ASSIGN(ScopedLayerObjectTracker
);
93 inline void DidActivateLayerTree(int layer_tree_host_id
, int frame_id
) {
94 TRACE_EVENT_INSTANT2(internal::kCategoryFrame
,
95 internal::kActivateLayerTree
,
96 TRACE_EVENT_SCOPE_THREAD
,
97 internal::kLayerTreeId
,
103 inline void DidBeginFrame(int layer_tree_host_id
) {
104 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
105 internal::kBeginFrame
,
106 TRACE_EVENT_SCOPE_THREAD
,
107 internal::kLayerTreeId
,
111 inline void DidDrawFrame(int layer_tree_host_id
) {
112 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
113 internal::kDrawFrame
,
114 TRACE_EVENT_SCOPE_THREAD
,
115 internal::kLayerTreeId
,
119 inline void DidRequestMainThreadFrame(int layer_tree_host_id
) {
120 TRACE_EVENT_INSTANT1(internal::kCategoryFrame
,
121 internal::kRequestMainThreadFrame
,
122 TRACE_EVENT_SCOPE_THREAD
,
123 internal::kLayerTreeId
,
127 } // namespace devtools_instrumentation
130 #endif // CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_