• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_
6 #define CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_
7 
8 #include "base/debug/trace_event.h"
9 
10 namespace cc {
11 namespace devtools_instrumentation {
12 
13 namespace internal {
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";
21 
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
28 
29 const char kRasterTask[] = "RasterTask";
30 const char kPaintSetup[] = "PaintSetup";
31 const char kUpdateLayer[] = "UpdateLayer";
32 
33 class ScopedLayerTask {
34  public:
ScopedLayerTask(const char * event_name,int layer_id)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);
39   }
~ScopedLayerTask()40   ~ScopedLayerTask() {
41     TRACE_EVENT_END0(internal::kCategory, event_name_);
42   }
43  private:
44   const char* event_name_;
45 
46   DISALLOW_COPY_AND_ASSIGN(ScopedLayerTask);
47 };
48 
49 class ScopedImageDecodeTask {
50  public:
ScopedImageDecodeTask(void * pixelRef)51   explicit ScopedImageDecodeTask(void* pixelRef) {
52     TRACE_EVENT_BEGIN1(internal::kCategory, internal::kImageDecodeTask,
53         internal::kPixelRefId, reinterpret_cast<uint64>(pixelRef));
54   }
~ScopedImageDecodeTask()55   ~ScopedImageDecodeTask() {
56     TRACE_EVENT_END0(internal::kCategory, internal::kImageDecodeTask);
57   }
58  private:
59   DISALLOW_COPY_AND_ASSIGN(ScopedImageDecodeTask);
60 };
61 
62 class ScopedLayerTreeTask {
63  public:
ScopedLayerTreeTask(const char * event_name,int layer_id,int layer_tree_host_id)64   ScopedLayerTreeTask(const char* event_name,
65                       int layer_id,
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);
71   }
~ScopedLayerTreeTask()72   ~ScopedLayerTreeTask() {
73     TRACE_EVENT_END0(internal::kCategory, event_name_);
74   }
75  private:
76   const char* event_name_;
77 
78   DISALLOW_COPY_AND_ASSIGN(ScopedLayerTreeTask);
79 };
80 
81 struct ScopedLayerObjectTracker
82     : public base::debug::TraceScopedTrackableObject<int> {
ScopedLayerObjectTrackerScopedLayerObjectTracker83   explicit ScopedLayerObjectTracker(int layer_id)
84       : base::debug::TraceScopedTrackableObject<int>(
85             internal::kCategory,
86             internal::kLayerId,
87             layer_id) {
88   }
89 
90  private:
91   DISALLOW_COPY_AND_ASSIGN(ScopedLayerObjectTracker);
92 };
93 
DidActivateLayerTree(int layer_tree_host_id,int frame_id)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,
99                        layer_tree_host_id,
100                        internal::kFrameId,
101                        frame_id);
102 }
103 
DidBeginFrame(int layer_tree_host_id)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,
109                        layer_tree_host_id);
110 }
111 
DidDrawFrame(int layer_tree_host_id)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,
117                        layer_tree_host_id);
118 }
119 
DidRequestMainThreadFrame(int layer_tree_host_id)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,
125                        layer_tree_host_id);
126 }
127 
128 }  // namespace devtools_instrumentation
129 }  // namespace cc
130 
131 #endif  // CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_
132