Performance histograms for extension content verification
[chromium-blink-merge.git] / gpu / command_buffer / service / gpu_tracer.h
blob7daea897db644060e2aa669fa87d6c865cf21a6b
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_
9 #include <string>
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"
19 namespace gpu {
20 namespace gles2 {
22 // Id used to keep trace namespaces separate
23 enum GpuTracerSource {
24 kTraceGroupMarker = 0,
25 kTraceCHROMIUM = 1,
26 kTraceDecoder = 2,
29 // Traces GPU Commands.
30 class GPUTracer {
31 public:
32 static scoped_ptr<GPUTracer> Create(gles2::GLES2Decoder* decoder);
34 GPUTracer();
35 virtual ~GPUTracer();
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;
55 private:
56 DISALLOW_COPY_AND_ASSIGN(GPUTracer);
59 class Outputter : public base::RefCounted<Outputter> {
60 public:
61 virtual void Trace(const std::string& name,
62 int64 start_time,
63 int64 end_time) = 0;
65 protected:
66 virtual ~Outputter() {}
67 friend class base::RefCounted<Outputter>;
70 class TraceOutputter : public Outputter {
71 public:
72 static scoped_refptr<TraceOutputter> Create(const std::string& name);
73 virtual void Trace(const std::string& name,
74 int64 start_time,
75 int64 end_time) OVERRIDE;
77 protected:
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> {
89 public:
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();
103 protected:
104 virtual ~Trace() {}
106 private:
107 friend class base::RefCounted<Trace>;
109 std::string name_;
111 DISALLOW_COPY_AND_ASSIGN(Trace);
114 class GPU_EXPORT GLARBTimerTrace : public Trace {
115 public:
116 GLARBTimerTrace(scoped_refptr<Outputter> outputter,
117 const std::string& name,
118 int64 offset);
120 // Implementation of Tracer
121 virtual void Start() OVERRIDE;
122 virtual void End() OVERRIDE;
123 virtual bool IsAvailable() OVERRIDE;
124 virtual void Process() OVERRIDE;
126 private:
127 virtual ~GLARBTimerTrace();
129 void Output();
131 scoped_refptr<Outputter> outputter_;
133 int64 offset_;
134 int64 start_time_;
135 int64 end_time_;
136 bool end_requested_;
138 GLuint queries_[2];
140 DISALLOW_COPY_AND_ASSIGN(GLARBTimerTrace);
143 } // namespace gles2
144 } // namespace gpu
146 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_