]> git.cworth.org Git - apitrace/blob - retrace/retrace.hpp
Extend profiling tool to support Vsize and Rss memory usage profile per call
[apitrace] / retrace / retrace.hpp
1 /**************************************************************************
2  *
3  * Copyright 2011-2012 Jose Fonseca
4  * Copyright (C) 2013 Intel Corporation. All rights reversed.
5  * Author: Shuang He <shuang.he@intel.com>
6  * All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  *
26  **************************************************************************/
27
28 #ifndef _RETRACE_HPP_
29 #define _RETRACE_HPP_
30
31 #include <assert.h>
32 #include <string.h>
33
34 #include <list>
35 #include <map>
36 #include <ostream>
37
38 #include "trace_model.hpp"
39 #include "trace_parser.hpp"
40 #include "trace_profiler.hpp"
41
42 #include "scoped_allocator.hpp"
43
44
45 namespace image {
46     class Image;
47 }
48
49
50 namespace retrace {
51
52
53 extern trace::Parser parser;
54 extern trace::Profiler profiler;
55
56
57 class ScopedAllocator : public ::ScopedAllocator
58 {
59 public:
60     /**
61      * Allocate an array with the same dimensions as the specified value.
62      */
63     inline void *
64     alloc(const trace::Value *value, size_t size) {
65         const trace::Array *array = dynamic_cast<const trace::Array *>(value);
66         if (array) {
67             return ::ScopedAllocator::alloc(array->size() * size);
68         }
69         const trace::Null *null = dynamic_cast<const trace::Null *>(value);
70         if (null) {
71             return NULL;
72         }
73         assert(0);
74         return NULL;
75     }
76
77 };
78
79
80 /**
81  * Output verbosity when retracing files.
82  */
83 extern int verbosity;
84
85 /**
86  * Debugging checks.
87  */
88 extern bool debug;
89
90 /**
91  * Add profiling data to the dump when retracing.
92  */
93 extern bool profiling;
94 extern bool profilingCpuTimes;
95 extern bool profilingGpuTimes;
96 extern bool profilingPixelsDrawn;
97 extern bool profilingMemoryUsage;
98
99 /**
100  * State dumping.
101  */
102 extern bool dumpingState;
103
104
105 enum Driver {
106     DRIVER_DEFAULT,
107     DRIVER_HARDWARE, // force hardware
108     DRIVER_SOFTWARE,
109     DRIVER_REFERENCE,
110     DRIVER_NULL,
111     DRIVER_MODULE,
112 };
113
114 extern Driver driver;
115 extern const char *driverModule;
116
117 extern bool doubleBuffer;
118 extern bool coreProfile;
119
120 extern unsigned frameNo;
121 extern unsigned callNo;
122
123
124 std::ostream &warning(trace::Call &call);
125
126
127 void ignore(trace::Call &call);
128 void unsupported(trace::Call &call);
129
130
131 typedef void (*Callback)(trace::Call &call);
132
133 struct Entry {
134     const char *name;
135     Callback callback;
136 };
137
138
139 struct stringComparer {
140   bool operator() (const char *a, const  char *b) const {
141     return strcmp(a, b) < 0;
142   }
143 };
144
145
146 extern const Entry stdc_callbacks[];
147
148
149 class Retracer
150 {
151     typedef std::map<const char *, Callback, stringComparer> Map;
152     Map map;
153
154     std::vector<Callback> callbacks;
155
156 public:
157     Retracer() {
158         addCallbacks(stdc_callbacks);
159     }
160
161     virtual ~Retracer() {}
162
163     void addCallback(const Entry *entry);
164     void addCallbacks(const Entry *entries);
165
166     void retrace(trace::Call &call);
167 };
168
169
170 class Dumper
171 {
172 public:
173     virtual image::Image *
174     getSnapshot(void) {
175         return NULL;
176     }
177
178     virtual bool
179     dumpState(std::ostream &os) {
180         return false;
181     }
182 };
183
184
185 extern Dumper *dumper;
186
187
188 void
189 setUp(void);
190
191 void
192 addCallbacks(retrace::Retracer &retracer);
193
194 void
195 frameComplete(trace::Call &call);
196
197
198
199 void
200 flushRendering(void);
201
202 void
203 waitForInput(void);
204
205 void
206 cleanUp(void);
207
208
209 } /* namespace retrace */
210
211 #endif /* _RETRACE_HPP_ */