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.
69 /* Always return valid address, even when size is zero */
70 size = std::max(size, sizeof(uintptr_t));
72 uintptr_t * buf = static_cast<uintptr_t *>(malloc(sizeof(uintptr_t) + size));
78 next = reinterpret_cast<uintptr_t>(buf);
79 assert((next & 1) == 0);
81 return static_cast<void *>(&buf[1]);
87 return static_cast<T *>(alloc(sizeof(T) * n));
91 * Allocate an array with the same dimensions as the specified value.
95 alloc(const trace::Value *value) {
96 const trace::Array *array = dynamic_cast<const trace::Array *>(value);
98 return alloc<T>(array->size());
100 const trace::Null *null = dynamic_cast<const trace::Null *>(value);
109 * Prevent this pointer from being automatically freed.
115 reinterpret_cast<uintptr_t *>(ptr)[-1] |= 1;
122 uintptr_t temp = *reinterpret_cast<uintptr_t *>(next);
124 bool bind = temp & 1;
128 free(reinterpret_cast<void *>(next));
138 * Output verbosity when retracing files.
140 extern int verbosity;
148 * Add profiling data to the dump when retracing.
150 extern bool profiling;
151 extern bool profilingCpuTimes;
152 extern bool profilingGpuTimes;
153 extern bool profilingPixelsDrawn;
158 extern bool dumpingState;
161 extern bool doubleBuffer;
162 extern bool coreProfile;
164 extern unsigned frameNo;
165 extern unsigned callNo;
168 std::ostream &warning(trace::Call &call);
171 void ignore(trace::Call &call);
172 void unsupported(trace::Call &call);
175 typedef void (*Callback)(trace::Call &call);
183 struct stringComparer {
184 bool operator() (const char *a, const char *b) const {
185 return strcmp(a, b) < 0;
190 extern const Entry stdc_callbacks[];
195 typedef std::map<const char *, Callback, stringComparer> Map;
198 std::vector<Callback> callbacks;
202 addCallbacks(stdc_callbacks);
205 virtual ~Retracer() {}
207 void addCallback(const Entry *entry);
208 void addCallbacks(const Entry *entries);
210 void retrace(trace::Call &call);
218 addCallbacks(retrace::Retracer &retracer);
221 frameComplete(trace::Call &call);
227 dumpState(std::ostream &os);
230 flushRendering(void);
239 } /* namespace retrace */
241 #endif /* _RETRACE_HPP_ */