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
3 // found in the LICENSE file.
5 // This file contains the GPUTrace class.
6 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_
7 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
16 #include "gpu/gpu_export.h"
17 #include "ui/gl/gl_bindings.h"
25 // Id used to keep trace namespaces separate
26 enum GpuTracerSource
{
27 kTraceGroupInvalid
= -1,
29 kTraceGroupMarker
= 0,
36 // Marker structure for a Trace.
38 TraceMarker(const std::string
& name
);
42 scoped_refptr
<GPUTrace
> trace_
;
45 // Traces GPU Commands.
46 class GPUTracer
: public base::SupportsWeakPtr
<GPUTracer
> {
48 explicit GPUTracer(gles2::GLES2Decoder
* decoder
);
51 // Scheduled processing in decoder begins.
54 // Scheduled processing in decoder ends.
57 // Begin a trace marker.
58 bool Begin(const std::string
& name
, GpuTracerSource source
);
60 // End the last started trace marker.
61 bool End(GpuTracerSource source
);
65 // Retrieve the name of the current open trace.
66 // Returns empty string if no current open trace.
67 const std::string
& CurrentName() const;
71 scoped_refptr
<GPUTrace
> CreateTrace(const std::string
& name
);
75 void CalculateTimerOffset();
76 void IssueProcessTask();
78 scoped_refptr
<Outputter
> outputter_
;
79 std::vector
<TraceMarker
> markers_
[NUM_TRACER_SOURCES
];
80 std::deque
<scoped_refptr
<GPUTrace
> > traces_
;
82 const unsigned char* gpu_trace_srv_category
;
83 const unsigned char* gpu_trace_dev_category
;
84 gles2::GLES2Decoder
* decoder_
;
87 GpuTracerSource last_tracer_source_
;
90 bool gpu_timing_synced_
;
94 DISALLOW_COPY_AND_ASSIGN(GPUTracer
);
97 class Outputter
: public base::RefCounted
<Outputter
> {
99 virtual void Trace(const std::string
& name
,
104 virtual ~Outputter() {}
105 friend class base::RefCounted
<Outputter
>;
108 class TraceOutputter
: public Outputter
{
110 static scoped_refptr
<TraceOutputter
> Create(const std::string
& name
);
111 virtual void Trace(const std::string
& name
,
113 int64 end_time
) OVERRIDE
;
116 friend class base::RefCounted
<Outputter
>;
117 explicit TraceOutputter(const std::string
& name
);
118 virtual ~TraceOutputter();
120 base::Thread named_thread_
;
121 uint64 local_trace_id_
;
123 DISALLOW_COPY_AND_ASSIGN(TraceOutputter
);
126 class GPU_EXPORT GPUTrace
127 : public base::RefCounted
<GPUTrace
> {
129 explicit GPUTrace(const std::string
& name
);
130 GPUTrace(scoped_refptr
<Outputter
> outputter
,
131 const std::string
& name
,
134 bool IsEnabled() { return enabled_
; }
135 const std::string
& name() { return name_
; }
147 friend class base::RefCounted
<GPUTrace
>;
150 scoped_refptr
<Outputter
> outputter_
;
160 DISALLOW_COPY_AND_ASSIGN(GPUTrace
);
166 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_