• 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[] = "cc,devtools";
15 const char kFrameId[] = "frameId";
16 const char kLayerId[] = "layerId";
17 const char kLayerTreeId[] = "layerTreeId";
18 const char kPixelRefId[] = "pixelRefId";
19 
20 const char kImageDecodeTask[] = "ImageDecodeTask";
21 const char kBeginFrame[] = "BeginFrame";
22 const char kActivateLayerTree[] = "ActivateLayerTree";
23 }  // namespace internal
24 
25 const char kRasterTask[] = "RasterTask";
26 const char kPaintSetup[] = "PaintSetup";
27 
28 class ScopedLayerTask {
29  public:
ScopedLayerTask(const char * event_name,int layer_id)30   ScopedLayerTask(const char* event_name, int layer_id)
31     : event_name_(event_name) {
32     TRACE_EVENT_BEGIN1(internal::kCategory, event_name_,
33         internal::kLayerId, layer_id);
34   }
~ScopedLayerTask()35   ~ScopedLayerTask() {
36     TRACE_EVENT_END0(internal::kCategory, event_name_);
37   }
38  private:
39   const char* event_name_;
40 
41   DISALLOW_COPY_AND_ASSIGN(ScopedLayerTask);
42 };
43 
44 class ScopedImageDecodeTask {
45  public:
ScopedImageDecodeTask(void * pixelRef)46   explicit ScopedImageDecodeTask(void* pixelRef) {
47     TRACE_EVENT_BEGIN1(internal::kCategory, internal::kImageDecodeTask,
48         internal::kPixelRefId, reinterpret_cast<uint64>(pixelRef));
49   }
~ScopedImageDecodeTask()50   ~ScopedImageDecodeTask() {
51     TRACE_EVENT_END0(internal::kCategory, internal::kImageDecodeTask);
52   }
53  private:
54   DISALLOW_COPY_AND_ASSIGN(ScopedImageDecodeTask);
55 };
56 
57 class ScopedLayerTreeTask {
58  public:
ScopedLayerTreeTask(const char * event_name,int layer_id,int layer_tree_host_id)59   ScopedLayerTreeTask(const char* event_name,
60                       int layer_id,
61                       int layer_tree_host_id)
62     : event_name_(event_name) {
63     TRACE_EVENT_BEGIN2(internal::kCategory, event_name_,
64         internal::kLayerId, layer_id,
65         internal::kLayerTreeId, layer_tree_host_id);
66   }
~ScopedLayerTreeTask()67   ~ScopedLayerTreeTask() {
68     TRACE_EVENT_END0(internal::kCategory, event_name_);
69   }
70  private:
71   const char* event_name_;
72 
73   DISALLOW_COPY_AND_ASSIGN(ScopedLayerTreeTask);
74 };
75 
76 struct ScopedLayerObjectTracker
77     : public base::debug::TraceScopedTrackableObject<int> {
ScopedLayerObjectTrackerScopedLayerObjectTracker78   explicit ScopedLayerObjectTracker(int layer_id)
79       : base::debug::TraceScopedTrackableObject<int>(
80             internal::kCategory,
81             internal::kLayerId,
82             layer_id) {
83   }
84 
85  private:
86   DISALLOW_COPY_AND_ASSIGN(ScopedLayerObjectTracker);
87 };
88 
didActivateLayerTree(int layer_tree_host_id,int frame_id)89 inline void didActivateLayerTree(int layer_tree_host_id, int frame_id) {
90   TRACE_EVENT_INSTANT2(internal::kCategory,
91                        internal::kActivateLayerTree,
92                        TRACE_EVENT_SCOPE_THREAD,
93                        internal::kLayerTreeId, layer_tree_host_id,
94                        internal::kFrameId, frame_id);
95 }
96 
didBeginFrame(int layer_tree_host_id)97 inline void didBeginFrame(int layer_tree_host_id) {
98   TRACE_EVENT_INSTANT1(internal::kCategory,
99                        internal::kBeginFrame,
100                        TRACE_EVENT_SCOPE_THREAD,
101                        internal::kLayerTreeId, layer_tree_host_id);
102 }
103 
104 }  // namespace devtools_instrumentation
105 }  // namespace cc
106 
107 #endif  // CC_DEBUG_DEVTOOLS_INSTRUMENTATION_H_
108