1 /**************************************************************************
3 * Copyright 2011-2012 Jose Fonseca
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
37 #include "trace_model.hpp"
38 #include "trace_parser.hpp"
39 #include "trace_profiler.hpp"
50 extern trace::Parser parser;
51 extern trace::Profiler profiler;
55 * Similar to alloca(), but implemented with malloc.
70 /* Always return valid address, even when size is zero */
71 size = std::max(size, sizeof(uintptr_t));
73 uintptr_t * buf = static_cast<uintptr_t *>(malloc(sizeof(uintptr_t) + size));
79 next = reinterpret_cast<uintptr_t>(buf);
80 assert((next & 1) == 0);
82 return static_cast<void *>(&buf[1]);
86 * Allocate an array with the same dimensions as the specified value.
89 alloc(const trace::Value *value, size_t size) {
90 const trace::Array *array = dynamic_cast<const trace::Array *>(value);
92 return alloc(array->size() * size);
94 const trace::Null *null = dynamic_cast<const trace::Null *>(value);
103 * Prevent this pointer from being automatically freed.
109 reinterpret_cast<uintptr_t *>(ptr)[-1] |= 1;
116 uintptr_t temp = *reinterpret_cast<uintptr_t *>(next);
118 bool bind = temp & 1;
122 free(reinterpret_cast<void *>(next));
132 * Output verbosity when retracing files.
134 extern int verbosity;
142 * Add profiling data to the dump when retracing.
144 extern bool profiling;
145 extern bool profilingCpuTimes;
146 extern bool profilingGpuTimes;
147 extern bool profilingPixelsDrawn;
152 extern bool dumpingState;
157 DRIVER_HARDWARE, // force hardware
164 extern Driver driver;
165 extern const char *driverModule;
167 extern bool doubleBuffer;
168 extern bool coreProfile;
170 extern unsigned frameNo;
171 extern unsigned callNo;
174 std::ostream &warning(trace::Call &call);
177 void ignore(trace::Call &call);
178 void unsupported(trace::Call &call);
181 typedef void (*Callback)(trace::Call &call);
189 struct stringComparer {
190 bool operator() (const char *a, const char *b) const {
191 return strcmp(a, b) < 0;
196 extern const Entry stdc_callbacks[];
201 typedef std::map<const char *, Callback, stringComparer> Map;
204 std::vector<Callback> callbacks;
208 addCallbacks(stdc_callbacks);
211 virtual ~Retracer() {}
213 void addCallback(const Entry *entry);
214 void addCallbacks(const Entry *entries);
216 void retrace(trace::Call &call);
223 virtual image::Image *
229 dumpState(std::ostream &os) {
235 extern Dumper *dumper;
242 addCallbacks(retrace::Retracer &retracer);
245 frameComplete(trace::Call &call);
250 flushRendering(void);
259 } /* namespace retrace */
261 #endif /* _RETRACE_HPP_ */