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"
22 // Id used to keep trace namespaces separate
23 enum GpuTracerSource
{
24 kTraceGroupMarker
= 0,
29 // Traces GPU Commands.
32 static scoped_ptr
<GPUTracer
> Create(gles2::GLES2Decoder
* decoder
);
37 // Scheduled processing in decoder begins.
38 virtual bool BeginDecoding() = 0;
40 // Scheduled processing in decoder ends.
41 virtual bool EndDecoding() = 0;
43 // Begin a trace marker.
44 virtual bool Begin(const std::string
& name
, GpuTracerSource source
) = 0;
46 // End the last started trace marker.
47 virtual bool End(GpuTracerSource source
) = 0;
49 virtual bool IsTracing() = 0;
51 // Retrieve the name of the current open trace.
52 // Returns empty string if no current open trace.
53 virtual const std::string
& CurrentName() const = 0;
56 DISALLOW_COPY_AND_ASSIGN(GPUTracer
);
59 class Outputter
: public base::RefCounted
<Outputter
> {
61 virtual void Trace(const std::string
& name
,
66 virtual ~Outputter() {}
67 friend class base::RefCounted
<Outputter
>;
70 class TraceOutputter
: public Outputter
{
72 static scoped_refptr
<TraceOutputter
> Create(const std::string
& name
);
73 virtual void Trace(const std::string
& name
,
75 int64 end_time
) OVERRIDE
;
78 friend class base::RefCounted
<Outputter
>;
79 explicit TraceOutputter(const std::string
& name
);
80 virtual ~TraceOutputter();
82 base::Thread named_thread_
;
83 uint64 local_trace_id_
;
85 DISALLOW_COPY_AND_ASSIGN(TraceOutputter
);
88 class GPU_EXPORT Trace
: public base::RefCounted
<Trace
> {
90 explicit Trace(const std::string
& name
) : name_(name
) {}
92 virtual void Start() = 0;
93 virtual void End() = 0;
95 // True if the the results of this query are available.
96 virtual bool IsAvailable() = 0;
98 virtual bool IsProcessable();
99 virtual void Process() = 0;
101 virtual const std::string
& name();
107 friend class base::RefCounted
<Trace
>;
111 DISALLOW_COPY_AND_ASSIGN(Trace
);
114 class GPU_EXPORT GLARBTimerTrace
: public Trace
{
116 GLARBTimerTrace(scoped_refptr
<Outputter
> outputter
,
117 const std::string
& name
,
120 // Implementation of Tracer
121 virtual void Start() OVERRIDE
;
122 virtual void End() OVERRIDE
;
123 virtual bool IsAvailable() OVERRIDE
;
124 virtual void Process() OVERRIDE
;
127 virtual ~GLARBTimerTrace();
131 scoped_refptr
<Outputter
> outputter_
;
140 DISALLOW_COPY_AND_ASSIGN(GLARBTimerTrace
);
146 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_