| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains the GPUTrace class. | 5 // This file contains the GPUTrace class. |
| 6 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ | 6 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ |
| 7 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ | 7 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 enum GpuTracerType { | 36 enum GpuTracerType { |
| 37 kTracerTypeInvalid = -1, | 37 kTracerTypeInvalid = -1, |
| 38 | 38 |
| 39 kTracerTypeARBTimer, | 39 kTracerTypeARBTimer, |
| 40 kTracerTypeDisjointTimer | 40 kTracerTypeDisjointTimer |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Marker structure for a Trace. | 43 // Marker structure for a Trace. |
| 44 struct TraceMarker { | 44 struct TraceMarker { |
| 45 TraceMarker(const std::string& name); | 45 TraceMarker(const std::string& category, const std::string& name); |
| 46 ~TraceMarker(); | 46 ~TraceMarker(); |
| 47 | 47 |
| 48 std::string category_; |
| 48 std::string name_; | 49 std::string name_; |
| 49 scoped_refptr<GPUTrace> trace_; | 50 scoped_refptr<GPUTrace> trace_; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 // Traces GPU Commands. | 53 // Traces GPU Commands. |
| 53 class GPUTracer : public base::SupportsWeakPtr<GPUTracer> { | 54 class GPUTracer : public base::SupportsWeakPtr<GPUTracer> { |
| 54 public: | 55 public: |
| 55 explicit GPUTracer(gles2::GLES2Decoder* decoder); | 56 explicit GPUTracer(gles2::GLES2Decoder* decoder); |
| 56 ~GPUTracer(); | 57 ~GPUTracer(); |
| 57 | 58 |
| 58 // Scheduled processing in decoder begins. | 59 // Scheduled processing in decoder begins. |
| 59 bool BeginDecoding(); | 60 bool BeginDecoding(); |
| 60 | 61 |
| 61 // Scheduled processing in decoder ends. | 62 // Scheduled processing in decoder ends. |
| 62 bool EndDecoding(); | 63 bool EndDecoding(); |
| 63 | 64 |
| 64 // Begin a trace marker. | 65 // Begin a trace marker. |
| 65 bool Begin(const std::string& name, GpuTracerSource source); | 66 bool Begin(const std::string& category, const std::string& name, |
| 67 GpuTracerSource source); |
| 66 | 68 |
| 67 // End the last started trace marker. | 69 // End the last started trace marker. |
| 68 bool End(GpuTracerSource source); | 70 bool End(GpuTracerSource source); |
| 69 | 71 |
| 70 bool IsTracing(); | 72 bool IsTracing(); |
| 71 | 73 |
| 72 // Retrieve the name of the current open trace. | 74 // Retrieve the name of the current open trace. |
| 73 // Returns empty string if no current open trace. | 75 // Returns empty string if no current open trace. |
| 76 const std::string& CurrentCategory() const; |
| 74 const std::string& CurrentName() const; | 77 const std::string& CurrentName() const; |
| 75 | 78 |
| 76 private: | 79 private: |
| 77 // Trace Processing. | 80 // Trace Processing. |
| 78 scoped_refptr<GPUTrace> CreateTrace(const std::string& name); | 81 scoped_refptr<GPUTrace> CreateTrace(const std::string& category, |
| 82 const std::string& name); |
| 79 void Process(); | 83 void Process(); |
| 80 void ProcessTraces(); | 84 void ProcessTraces(); |
| 81 | 85 |
| 82 void CalculateTimerOffset(); | 86 void CalculateTimerOffset(); |
| 83 void IssueProcessTask(); | 87 void IssueProcessTask(); |
| 84 | 88 |
| 85 scoped_refptr<Outputter> outputter_; | 89 scoped_refptr<Outputter> outputter_; |
| 86 std::vector<TraceMarker> markers_[NUM_TRACER_SOURCES]; | 90 std::vector<TraceMarker> markers_[NUM_TRACER_SOURCES]; |
| 87 std::deque<scoped_refptr<GPUTrace> > traces_; | 91 std::deque<scoped_refptr<GPUTrace> > traces_; |
| 88 | 92 |
| 89 const unsigned char* gpu_trace_srv_category; | 93 const unsigned char* gpu_trace_srv_category; |
| 90 const unsigned char* gpu_trace_dev_category; | 94 const unsigned char* gpu_trace_dev_category; |
| 91 gles2::GLES2Decoder* decoder_; | 95 gles2::GLES2Decoder* decoder_; |
| 92 | 96 |
| 93 int64 timer_offset_; | 97 int64 timer_offset_; |
| 94 GpuTracerSource last_tracer_source_; | 98 GpuTracerSource last_tracer_source_; |
| 95 | 99 |
| 96 GpuTracerType tracer_type_; | 100 GpuTracerType tracer_type_; |
| 97 bool gpu_timing_synced_; | 101 bool gpu_timing_synced_; |
| 98 bool gpu_executing_; | 102 bool gpu_executing_; |
| 99 bool process_posted_; | 103 bool process_posted_; |
| 100 | 104 |
| 101 DISALLOW_COPY_AND_ASSIGN(GPUTracer); | 105 DISALLOW_COPY_AND_ASSIGN(GPUTracer); |
| 102 }; | 106 }; |
| 103 | 107 |
| 104 class Outputter : public base::RefCounted<Outputter> { | 108 class Outputter : public base::RefCounted<Outputter> { |
| 105 public: | 109 public: |
| 106 virtual void Trace(const std::string& name, | 110 virtual void Trace(const std::string& category, |
| 111 const std::string& name, |
| 107 int64 start_time, | 112 int64 start_time, |
| 108 int64 end_time) = 0; | 113 int64 end_time) = 0; |
| 109 | 114 |
| 110 protected: | 115 protected: |
| 111 virtual ~Outputter() {} | 116 virtual ~Outputter() {} |
| 112 friend class base::RefCounted<Outputter>; | 117 friend class base::RefCounted<Outputter>; |
| 113 }; | 118 }; |
| 114 | 119 |
| 115 class TraceOutputter : public Outputter { | 120 class TraceOutputter : public Outputter { |
| 116 public: | 121 public: |
| 117 static scoped_refptr<TraceOutputter> Create(const std::string& name); | 122 static scoped_refptr<TraceOutputter> Create(const std::string& name); |
| 118 void Trace(const std::string& name, | 123 void Trace(const std::string& category, |
| 124 const std::string& name, |
| 119 int64 start_time, | 125 int64 start_time, |
| 120 int64 end_time) override; | 126 int64 end_time) override; |
| 121 | 127 |
| 122 protected: | 128 protected: |
| 123 friend class base::RefCounted<Outputter>; | 129 friend class base::RefCounted<Outputter>; |
| 124 explicit TraceOutputter(const std::string& name); | 130 explicit TraceOutputter(const std::string& name); |
| 125 ~TraceOutputter() override; | 131 ~TraceOutputter() override; |
| 126 | 132 |
| 127 base::Thread named_thread_; | 133 base::Thread named_thread_; |
| 128 uint64 local_trace_id_; | 134 uint64 local_trace_id_; |
| 129 | 135 |
| 130 DISALLOW_COPY_AND_ASSIGN(TraceOutputter); | 136 DISALLOW_COPY_AND_ASSIGN(TraceOutputter); |
| 131 }; | 137 }; |
| 132 | 138 |
| 133 class GPU_EXPORT GPUTrace | 139 class GPU_EXPORT GPUTrace |
| 134 : public base::RefCounted<GPUTrace> { | 140 : public base::RefCounted<GPUTrace> { |
| 135 public: | 141 public: |
| 136 GPUTrace(scoped_refptr<Outputter> outputter, | 142 GPUTrace(scoped_refptr<Outputter> outputter, |
| 143 const std::string& category, |
| 137 const std::string& name, | 144 const std::string& name, |
| 138 int64 offset, | 145 int64 offset, |
| 139 GpuTracerType tracer_type); | 146 GpuTracerType tracer_type); |
| 140 | 147 |
| 141 bool IsEnabled() { return tracer_type_ != kTracerTypeInvalid; } | 148 bool IsEnabled() { return tracer_type_ != kTracerTypeInvalid; } |
| 149 |
| 150 const std::string& category() { return category_; } |
| 142 const std::string& name() { return name_; } | 151 const std::string& name() { return name_; } |
| 143 | 152 |
| 144 void Start(); | 153 void Start(); |
| 145 void End(); | 154 void End(); |
| 146 bool IsAvailable(); | 155 bool IsAvailable(); |
| 147 void Process(); | 156 void Process(); |
| 148 | 157 |
| 149 private: | 158 private: |
| 150 ~GPUTrace(); | 159 ~GPUTrace(); |
| 151 | 160 |
| 152 void Output(); | 161 void Output(); |
| 153 | 162 |
| 154 friend class base::RefCounted<GPUTrace>; | 163 friend class base::RefCounted<GPUTrace>; |
| 155 | 164 |
| 165 std::string category_; |
| 156 std::string name_; | 166 std::string name_; |
| 157 scoped_refptr<Outputter> outputter_; | 167 scoped_refptr<Outputter> outputter_; |
| 158 | 168 |
| 159 int64 offset_; | 169 int64 offset_; |
| 160 int64 start_time_; | 170 int64 start_time_; |
| 161 int64 end_time_; | 171 int64 end_time_; |
| 162 GpuTracerType tracer_type_; | 172 GpuTracerType tracer_type_; |
| 163 bool end_requested_; | 173 bool end_requested_; |
| 164 | 174 |
| 165 GLuint queries_[2]; | 175 GLuint queries_[2]; |
| 166 | 176 |
| 167 DISALLOW_COPY_AND_ASSIGN(GPUTrace); | 177 DISALLOW_COPY_AND_ASSIGN(GPUTrace); |
| 168 }; | 178 }; |
| 169 | 179 |
| 170 } // namespace gles2 | 180 } // namespace gles2 |
| 171 } // namespace gpu | 181 } // namespace gpu |
| 172 | 182 |
| 173 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ | 183 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ |
| OLD | NEW |