def dump_arg_instance(self, function, arg): if function.name in self.draw_function_names and arg.name == 'indices': print ' GLint __element_array_buffer = 0;' print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' print ' if (!__element_array_buffer) {' print ' Trace::LiteralBlob((const void *)%s, count*__gl_type_size(type));' % (arg.name) print ' } else {' print ' Trace::LiteralOpaque((const void *)%s);' % (arg.name) print ' }' return # Several GL state functions take GLenum symbolic names as # integer/floats; so dump the symbolic name whenever possible if arg.type in (glapi.GLint, glapi.GLfloat) and arg.name == 'param': assert arg.index > 0 assert function.args[arg.index - 1].name == 'pname' assert function.args[arg.index - 1].type == glapi.GLenum print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name dump_instance(glapi.GLenum, arg.name) print ' } else {' Tracer.dump_arg_instance(self, function, arg) print ' }' return Tracer.dump_arg_instance(self, function, arg)
def header(self, api): print ''' static HINSTANCE g_hDll = NULL; static PROC __getPublicProcAddress(LPCSTR lpProcName) { if (!g_hDll) { char szDll[MAX_PATH] = {0}; if (!GetSystemDirectoryA(szDll, MAX_PATH)) { return NULL; } strcat(szDll, "\\\\%s"); g_hDll = LoadLibraryA(szDll); if (!g_hDll) { return NULL; } } return GetProcAddress(g_hDll, lpProcName); } ''' % self.dllname dispatcher = Dispatcher() dispatcher.dispatch_api(api) Tracer.header(self, api)
def header(self, api): for module in api.modules: dispatcher = DllDispatcher() dispatcher.dispatchModule(module) Tracer.header(self, api)
def traceApi(self, api): if self.getProcAddressFunctionNames: # Generate a function to wrap proc addresses getProcAddressFunction = api.getFunctionByName(self.getProcAddressFunctionNames[0]) argType = getProcAddressFunction.args[0].type retType = getProcAddressFunction.type print 'static %s _wrapProcAddress(%s procName, %s procPtr);' % (retType, argType, retType) print Tracer.traceApi(self, api) print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType) print ' if (!procPtr) {' print ' return procPtr;' print ' }' for function in api.functions: ptype = function_pointer_type(function) pvalue = function_pointer_value(function) print ' if (strcmp("%s", (const char *)procName) == 0) {' % function.name print ' %s = (%s)procPtr;' % (pvalue, ptype) print ' return (%s)&%s;' % (retType, function.name,) print ' }' print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);' print ' return procPtr;' print '}' print else: Tracer.traceApi(self, api)
def wrapRet(self, function, instance): Tracer.wrapRet(self, function, instance) # Replace function addresses with ours if function.name in self.getProcAddressFunctionNames: print ' %s = _wrapProcAddress(%s, %s);' % (instance, function.args[0].name, instance) # Keep track of buffer mappings if function.name in ('glMapBuffer', 'glMapBufferARB'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' print ' mapping->map = %s;' % (instance) print ' mapping->length = 0;' print ' __glGetBufferParameteriv(target, GL_BUFFER_SIZE, &mapping->length);' print ' mapping->write = (access != GL_READ_ONLY);' print ' mapping->explicit_flush = false;' print ' }' if function.name == 'glMapBufferRange': print ' if (access & GL_MAP_WRITE_BIT) {' print ' __checkBufferMapRange = true;' print ' }' print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' print ' mapping->map = %s;' % (instance) print ' mapping->length = length;' print ' mapping->write = access & GL_MAP_WRITE_BIT;' print ' mapping->explicit_flush = access & GL_MAP_FLUSH_EXPLICIT_BIT;' print ' }'
def traceApi(self, api): if self.getProcAddressFunctionNames: # Generate a function to wrap proc addresses getProcAddressFunction = api.getFunctionByName( self.getProcAddressFunctionNames[0]) argType = getProcAddressFunction.args[0].type retType = getProcAddressFunction.type print 'static %s _wrapProcAddress(%s procName, %s procPtr);' % ( retType, argType, retType) print Tracer.traceApi(self, api) print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % ( retType, argType, retType) print ' if (!procPtr) {' print ' return procPtr;' print ' }' for function in api.getAllFunctions(): ptype = function_pointer_type(function) pvalue = function_pointer_value(function) print ' if (strcmp("%s", (const char *)procName) == 0) {' % function.name print ' %s = (%s)procPtr;' % (pvalue, ptype) print ' return (%s)&%s;' % ( retType, function.name, ) print ' }' print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);' print ' return procPtr;' print '}' print else: Tracer.traceApi(self, api)
def wrapRet(self, function, instance): Tracer.wrapRet(self, function, instance) # Replace function addresses with ours if function.name in self.getProcAddressFunctionNames: print ' %s = _wrapProcAddress(%s, %s);' % ( instance, function.args[0].name, instance) # Keep track of buffer mappings if function.name in ('glMapBuffer', 'glMapBufferARB'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' print ' mapping->map = %s;' % (instance) print ' mapping->length = 0;' print ' _glGetBufferParameteriv(target, GL_BUFFER_SIZE, &mapping->length);' print ' mapping->write = (access != GL_READ_ONLY);' print ' mapping->explicit_flush = false;' print ' }' if function.name == 'glMapBufferRange': print ' if (access & GL_MAP_WRITE_BIT) {' print ' _checkBufferMapRange = true;' print ' }' print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' print ' mapping->map = %s;' % (instance) print ' mapping->length = length;' print ' mapping->write = access & GL_MAP_WRITE_BIT;' print ' mapping->explicit_flush = access & GL_MAP_FLUSH_EXPLICIT_BIT;' print ' }'
def header(self, api): print ''' static HMODULE g_hDll = NULL; static PROC _getPublicProcAddress(LPCSTR lpProcName) { if (!g_hDll) { char szDll[MAX_PATH] = {0}; if (!GetSystemDirectoryA(szDll, MAX_PATH)) { return NULL; } strcat(szDll, "\\\\%s"); g_hDll = LoadLibraryA(szDll); if (!g_hDll) { return NULL; } } return GetProcAddress(g_hDll, lpProcName); } ''' % self.dllname dispatcher = Dispatcher() dispatcher.dispatchApi(api) Tracer.header(self, api)
def header(self, api): print r'#include "dlltrace.hpp"' print for module in api.modules: dispatcher = DllDispatcher() dispatcher.dispatchModule(module) Tracer.header(self, api)
def header(self, api): print(r'#include "dlltrace.hpp"') print() for module in api.modules: dispatcher = DllDispatcher() dispatcher.dispatchModule(module) Tracer.header(self, api)
def doInvokeFunction(self, function): if function.name in self.getProcAddressFunctionNames: nameArg = function.args[0].name Tracer.doInvokeFunction(self, function) # Replace function addresses with ours # XXX: Doing this here instead of wrapRet means that the trace will # contain the addresses of the wrapper functions, and not the real # functions, but in practice this should make no difference. print " _result = _wrapProcAddress(%s, _result);" % (nameArg,) else: Tracer.doInvokeFunction(self, function)
def dump_arg_instance(self, function, arg): if function.name in self.draw_function_names and arg.name == 'indices': print ' GLint __element_array_buffer = 0;' print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' print ' if (!__element_array_buffer) {' print ' Trace::LiteralBlob((const void *)%s, count*__gl_type_size(type));' % (arg.name) print ' } else {' print ' Trace::LiteralOpaque((const void *)%s);' % (arg.name) print ' }' return Tracer.dump_arg_instance(self, function, arg)
def __init__(self, node, rationale, **kw): ResourceAgent.__init__(self, node) Trader.__init__(self, rationale, **kw) self.trace = Tracer(node) self.trace = self.trace.add('%-12s' % self) self.listen_process = None self.quote_timeouts = dict()
def start_on_node(self, node): self.node = node self.regions.add(self.node.region) self.trace = Tracer(node) self.trace = self.trace.add('%-12s' % self) self.trace = self.trace.add('j%-5d' % self.job.id) self.trace and self.trace("starting on %s" % node) self.start()
def serializeArgValue(self, function, arg): if function.name in self.draw_function_names and arg.name == 'indices': print ' GLint _element_array_buffer = 0;' print ' _glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &_element_array_buffer);' print ' if (!_element_array_buffer) {' if isinstance(arg.type, stdapi.Array): print ' trace::localWriter.beginArray(%s);' % arg.type.length print ' for(GLsizei i = 0; i < %s; ++i) {' % arg.type.length print ' trace::localWriter.beginElement();' print ' trace::localWriter.writeBlob(%s[i], count[i]*_gl_type_size(type));' % ( arg.name) print ' trace::localWriter.endElement();' print ' }' print ' trace::localWriter.endArray();' else: print ' trace::localWriter.writeBlob(%s, count*_gl_type_size(type));' % ( arg.name) print ' } else {' Tracer.serializeArgValue(self, function, arg) print ' }' return # Recognize offsets instead of blobs when a PBO is bound if function.name in self.unpack_function_names \ and (isinstance(arg.type, stdapi.Blob) \ or (isinstance(arg.type, stdapi.Const) \ and isinstance(arg.type.type, stdapi.Blob))): print ' {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' GLint _unpack_buffer = 0;' print ' if (ctx->profile == gltrace::PROFILE_COMPAT)' print ' _glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &_unpack_buffer);' print ' if (_unpack_buffer) {' print ' trace::localWriter.writePointer((uintptr_t)%s);' % arg.name print ' } else {' Tracer.serializeArgValue(self, function, arg) print ' }' print ' }' return # Several GL state functions take GLenum symbolic names as # integer/floats; so dump the symbolic name whenever possible if function.name.startswith('gl') \ and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \ and arg.name == 'param': assert arg.index > 0 assert function.args[arg.index - 1].name == 'pname' assert function.args[arg.index - 1].type == glapi.GLenum print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name self.serializeValue(glapi.GLenum, arg.name) print ' } else {' Tracer.serializeArgValue(self, function, arg) print ' }' return Tracer.serializeArgValue(self, function, arg)
def run(events): T = Tracer() for e in events: with T["event"]: if len(e.Muon) > 1: with T["event/dimuon"]: for m1, m2 in e.Muon.pairs(): with T["event/dimuon/pair"]: if m1.q * m2.q < 0 and m1.p < 1000 and m2.p < 1000: # Cuts with T["event/dimuon/pair/opposite"]: M12 = math.sqrt(2*m1.pt*m2.pt*(math.cosh(m1.eta-m2.eta) - math.cos(m1.phi-m2.phi))) if M12 < 140 and M12 > 60: with T["event/dimuon/pair/opposite/mass_in_range"]: yield (M12, m1.p, m2.p) sys.stderr.write(T.formatStats()+"\n")
def __init__(self, region, node, registry, sync_time, others): self.region = region self.node = node self.registry = registry self.sync_time = sync_time self.others = others self.listen_process = None self.trace = Tracer(node).add("bkr%-9s" % region)
class Seller(ResourceAgent, Trader): def __init__(self, node, rationale, **kw): ResourceAgent.__init__(self, node) Trader.__init__(self, rationale, **kw) self.trace = Tracer(node) self.trace = self.trace.add('%-12s' % self) self.listen_process = None self.quote_timeouts = dict() def start(self): self.listen_process = ListenProcess(self) activate(self.listen_process, self.listen_process.listen()) def set_quote_timeout(self, quote, trace): trace and trace("setting rationale timeout %s" % (id, )) p = RationaleTimeout() p.start(p.timeout(self, quote.id, quote, self.quote_timeout, trace)) self.quote_timeouts[quote.id] = p def cancel_quote_timeout(self, id, trace): if id in self.quote_timeouts: trace and trace("cancelling rationale timeout %s" % (id, )) process = self.quote_timeouts[id] cancel_process(process) del self.quote_timeouts[id] elif id in self.timedout: trace and trace("rationale timeout already fired %s" % (id, )) elif trace: trace("WARNING: unknown quote timeout cancelled %s" % (id, )) def process_quote_timeout(self, id, quote, trace): if id in self.quote_timeouts: trace and trace("observing failed quote %s" % (id, )) self.rationale.observe(quote, False) self.timedout.add(id) del self.quote_timeouts[id] elif id in self.timedout: trace("WARNING: quote timeout already timed out %s" % (id, )) else: trace("WARNING: unknown quote timeout firing %s" % (id, )) # utility function def create_quote(self): self.price = self.rationale.quote() return Ask(None, self, self.resource.free, self.price) def create_accept(self, quote): return Ask(quote.buyer, self, quote.job, quote.price) def viable_quote(self, q): return (self.active and self.bid and q.price >= self.price and q.size <= self.node.resource.free)
def serializeArgValue(self, function, arg): if function.name in self.draw_function_names and arg.name == 'indices': print ' GLint __element_array_buffer = 0;' print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' print ' if (!__element_array_buffer) {' if isinstance(arg.type, stdapi.Array): print ' trace::localWriter.beginArray(%s);' % arg.type.length print ' for(GLsizei i = 0; i < %s; ++i) {' % arg.type.length print ' trace::localWriter.beginElement();' print ' trace::localWriter.writeBlob(%s[i], count[i]*__gl_type_size(type));' % (arg.name) print ' trace::localWriter.endElement();' print ' }' print ' trace::localWriter.endArray();' else: print ' trace::localWriter.writeBlob(%s, count*__gl_type_size(type));' % (arg.name) print ' } else {' Tracer.serializeArgValue(self, function, arg) print ' }' return # Recognize offsets instead of blobs when a PBO is bound if function.name in self.unpack_function_names \ and (isinstance(arg.type, stdapi.Blob) \ or (isinstance(arg.type, stdapi.Const) \ and isinstance(arg.type.type, stdapi.Blob))): print ' {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' GLint __unpack_buffer = 0;' print ' if (ctx->profile == gltrace::PROFILE_COMPAT)' print ' __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);' print ' if (__unpack_buffer) {' print ' trace::localWriter.writeOpaque(%s);' % arg.name print ' } else {' Tracer.serializeArgValue(self, function, arg) print ' }' print ' }' return # Several GL state functions take GLenum symbolic names as # integer/floats; so dump the symbolic name whenever possible if function.name.startswith('gl') \ and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \ and arg.name == 'param': assert arg.index > 0 assert function.args[arg.index - 1].name == 'pname' assert function.args[arg.index - 1].type == glapi.GLenum print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name self.serializeValue(glapi.GLenum, arg.name) print ' } else {' Tracer.serializeArgValue(self, function, arg) print ' }' return Tracer.serializeArgValue(self, function, arg)
def wrap_ret(self, function, instance): Tracer.wrap_ret(self, function, instance) if function.name in ("glMapBuffer", "glMapBufferARB"): print " struct buffer_mapping *mapping = get_buffer_mapping(target);" print " if (mapping) {" print " mapping->map = %s;" % (instance) print " mapping->length = 0;" print " __glGetBufferParameteriv(target, GL_BUFFER_SIZE, &mapping->length);" print " mapping->write = (access != GL_READ_ONLY);" print " }" if function.name == "glMapBufferRange": print " struct buffer_mapping *mapping = get_buffer_mapping(target);" print " if (mapping) {" print " mapping->map = %s;" % (instance) print " mapping->length = length;" print " mapping->write = access & GL_MAP_WRITE_BIT;" print " }"
def wrap_ret(self, function, instance): Tracer.wrap_ret(self, function, instance) if function.name in ('glMapBuffer', 'glMapBufferARB'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' print ' mapping->map = %s;' % (instance) print ' mapping->length = 0;' print ' __glGetBufferParameteriv(target, GL_BUFFER_SIZE, &mapping->length);' print ' mapping->write = (access != GL_READ_ONLY);' print ' }' if function.name == 'glMapBufferRange': print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' print ' mapping->map = %s;' % (instance) print ' mapping->length = length;' print ' mapping->write = access & GL_MAP_WRITE_BIT;' print ' }'
def traceApi(self, api): if self.getProcAddressFunctionNames: # Generate a function to wrap proc addresses getProcAddressFunction = api.getFunctionByName(self.getProcAddressFunctionNames[0]) argType = getProcAddressFunction.args[0].type retType = getProcAddressFunction.type print 'static %s _wrapProcAddress(%s procName, %s procPtr);' % (retType, argType, retType) print Tracer.traceApi(self, api) print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType) # Provide fallback functions to missing debug functions print ' if (!procPtr) {' else_ = '' for function_name in self.debug_functions: if self.api.getFunctionByName(function_name): print ' %sif (strcmp("%s", (const char *)procName) == 0) {' % (else_, function_name) print ' return (%s)&%s;' % (retType, function_name) print ' }' else_ = 'else ' print ' %s{' % else_ print ' return NULL;' print ' }' print ' }' for function in api.getAllFunctions(): ptype = function_pointer_type(function) pvalue = function_pointer_value(function) print ' if (strcmp("%s", (const char *)procName) == 0) {' % function.name print ' %s = (%s)procPtr;' % (pvalue, ptype) print ' return (%s)&%s;' % (retType, function.name,) print ' }' print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);' print ' return procPtr;' print '}' print else: Tracer.traceApi(self, api)
def invokeFunction(self, function): # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the # driver if function.name in self.marker_functions: return if function.name in self.getProcAddressFunctionNames: else_ = '' for marker_function in self.marker_functions: if self.api.getFunctionByName(marker_function): print ' %sif (strcmp("%s", (const char *)%s) == 0) {' % (else_, marker_function, function.args[0].name) print ' _result = (%s)&%s;' % (function.type, marker_function) print ' }' else_ = 'else ' print ' %s{' % else_ Tracer.invokeFunction(self, function) print ' _result = _wrapProcAddress(%s, _result);' % (function.args[0].name) print ' }' return # Override GL extensions if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): Tracer.invokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override') return Tracer.invokeFunction(self, function)
def invokeFunction(self, function): if function.name in ('glLinkProgram', 'glLinkProgramARB'): # These functions have been dispatched already return # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the # driver if function.name in self.marker_functions: return if function.name in ('glXGetProcAddress', 'glXGetProcAddressARB', 'wglGetProcAddress'): else_ = '' for marker_function in self.marker_functions: if self.api.getFunctionByName(marker_function): print ' %sif (strcmp("%s", (const char *)%s) == 0) {' % ( else_, marker_function, function.args[0].name) print ' _result = (%s)&%s;' % (function.type, marker_function) print ' }' else_ = 'else ' print ' %s{' % else_ Tracer.invokeFunction(self, function) print ' }' return # Override GL extensions if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): Tracer.invokeFunction(self, function, prefix='gltrace::_', suffix='_override') return Tracer.invokeFunction(self, function)
def serializeArgValue(self, function, arg): # Recognize offsets instead of blobs when a PBO is bound if function.name in self.unpack_function_names \ and (isinstance(arg.type, stdapi.Blob) \ or (isinstance(arg.type, stdapi.Const) \ and isinstance(arg.type.type, stdapi.Blob))): print ' {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' GLint _unpack_buffer = 0;' print ' if (ctx->profile == gltrace::PROFILE_COMPAT)' print ' _glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &_unpack_buffer);' print ' if (_unpack_buffer) {' print ' trace::localWriter.writePointer((uintptr_t)%s);' % arg.name print ' } else {' Tracer.serializeArgValue(self, function, arg) print ' }' print ' }' return # Several GL state functions take GLenum symbolic names as # integer/floats; so dump the symbolic name whenever possible if function.name.startswith('gl') \ and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \ and arg.name == 'param': assert arg.index > 0 assert function.args[arg.index - 1].name == 'pname' assert function.args[arg.index - 1].type == glapi.GLenum print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name self.serializeValue(glapi.GLenum, arg.name) print ' } else {' Tracer.serializeArgValue(self, function, arg) print ' }' return Tracer.serializeArgValue(self, function, arg)
def invokeFunction(self, function): if function.name in ('glLinkProgram', 'glLinkProgramARB'): # These functions have been dispatched already return # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the # driver if function.name in self.marker_functions: return if function.name in ('glXGetProcAddress', 'glXGetProcAddressARB', 'wglGetProcAddress'): else_ = '' for marker_function in self.marker_functions: if self.api.get_function_by_name(marker_function): print ' %sif (strcmp("%s", (const char *)%s) == 0) {' % (else_, marker_function, function.args[0].name) print ' __result = (%s)&%s;' % (function.type, marker_function) print ' }' else_ = 'else ' print ' %s{' % else_ Tracer.invokeFunction(self, function) print ' }' return # Override GL extensions if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): Tracer.invokeFunction(self, function, prefix = 'gltrace::__', suffix = '_override') return Tracer.invokeFunction(self, function)
def dispatch_function(self, function): if function.name in ('glLinkProgram', 'glLinkProgramARB'): # These functions have been dispatched already return # We implement the GREMEDY extensions, not the driver if function.name in self.gremedy_functions: return if function.name in ('glXGetProcAddress', 'glXGetProcAddressARB', 'wglGetProcAddress'): if_ = 'if' for gremedy_function in self.gremedy_functions: print ' %s (strcmp("%s", (const char *)%s) == 0) {' % (if_, gremedy_function, function.args[0].name) print ' __result = (%s)&%s;' % (function.type, gremedy_function) print ' }' if_ = 'else if' print ' else {' Tracer.dispatch_function(self, function) print ' }' return # Override GL extensions if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): Tracer.dispatch_function(self, function, prefix = 'gltrace::__', suffix = '_override') return Tracer.dispatch_function(self, function)
def main() -> None: asyncio.set_event_loop(uvloop.new_event_loop()) http_session = Client() bakery_client = bakery.HttpClient("http://localhost:8000/bakery", client=http_session) bakery_service = bakery.Service() staff_room = staffroom.service.Service() shopfront_service = shopfront.service.Service(bakery=bakery_client, staff_room=staff_room) unknotter_service = unknotter.service.Service() exporter = unknotter.exporter.Exporter(unknotter=unknotter_service) set_exporter(exporter) tracer = Tracer() opentracing.set_global_tracer(tracer) bakery_blueprint = bakery.blueprint.factory(bakery=bakery_service) shopfront_blueprint = shopfront.blueprint.factory( shopfront=shopfront_service) shopfront_blueprint = shopfront.blueprint.factory( shopfront=shopfront_service) unknotter_blueprint = unknotter.blueprint.factory( unknotter=unknotter_service) app = Sanic() app.blueprint(bakery_blueprint, url_prefix="/bakery") app.blueprint(shopfront_blueprint, url_prefix="/shopfront") app.blueprint(unknotter_blueprint, url_prefix="/unknotter") server = app.create_server(host="127.0.0.1", port=8000, return_asyncio_server=True, debug=True) _ = asyncio.ensure_future(server) loop = asyncio.get_event_loop() signal(SIGINT, lambda s, f: loop.stop()) try: loop.run_forever() except Exception: loop.stop()
def doInvokeFunction(self, function): # Same as invokeFunction() but called both when trace is enabled or disabled. # # Used to modify the behavior of GL entry-points. # Override GL extensions if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): Tracer.doInvokeFunction(self, function, prefix='gltrace::_', suffix='_override') return # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the # driver if function.name in self.marker_functions: return # We may be faking KHR_debug, so ensure the pointer queries result is # always zeroed to prevent dereference of unitialized pointers if function.name == 'glGetPointerv': print ' if (params &&' print ' (pname == GL_DEBUG_CALLBACK_FUNCTION ||' print ' pname == GL_DEBUG_CALLBACK_USER_PARAM)) {' print ' *params = NULL;' print ' }' if function.name in self.getProcAddressFunctionNames: else_ = '' for marker_function in self.marker_functions: if self.api.getFunctionByName(marker_function): print ' %sif (strcmp("%s", (const char *)%s) == 0) {' % ( else_, marker_function, function.args[0].name) print ' _result = (%s)&%s;' % (function.type, marker_function) print ' }' else_ = 'else ' print ' %s{' % else_ Tracer.doInvokeFunction(self, function) # Replace function addresses with ours # XXX: Doing this here instead of wrapRet means that the trace will # contain the addresses of the wrapper functions, and not the real # functions, but in practice this should make no difference. if function.name in self.getProcAddressFunctionNames: print ' _result = _wrapProcAddress(%s, _result);' % ( function.args[0].name, ) print ' }' return Tracer.doInvokeFunction(self, function)
def doInvokeFunction(self, function): # Same as invokeFunction() but called both when trace is enabled or disabled. # # Used to modify the behavior of GL entry-points. # Override GL extensions if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override') return # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the # driver if function.name in self.marker_functions: return # We may be faking KHR_debug, so ensure the pointer queries result is # always zeroed to prevent dereference of unitialized pointers if function.name == 'glGetPointerv': print ' if (params &&' print ' (pname == GL_DEBUG_CALLBACK_FUNCTION ||' print ' pname == GL_DEBUG_CALLBACK_USER_PARAM)) {' print ' *params = NULL;' print ' }' if function.name in self.getProcAddressFunctionNames: else_ = '' for marker_function in self.marker_functions: if self.api.getFunctionByName(marker_function): print ' %sif (strcmp("%s", (const char *)%s) == 0) {' % (else_, marker_function, function.args[0].name) print ' _result = (%s)&%s;' % (function.type, marker_function) print ' }' else_ = 'else ' print ' %s{' % else_ Tracer.doInvokeFunction(self, function) # Replace function addresses with ours # XXX: Doing this here instead of wrapRet means that the trace will # contain the addresses of the wrapper functions, and not the real # functions, but in practice this should make no difference. if function.name in self.getProcAddressFunctionNames: print ' _result = _wrapProcAddress(%s, _result);' % (function.args[0].name,) print ' }' return Tracer.doInvokeFunction(self, function)
class MdsResourceAgent(ResourceAgent): def __init__(self, node, update_time): ResourceAgent.__init__(self, node) self.update_time = update_time self.update_process = None self.listen_process = None self.trace = Tracer(self.node).add("ragent%-6s" % node.id) def accept(self, value): if self.listen_process: self.listen_process.signal("accept", value) else: self.trace("WARNING: no listen process for accept") @property def broker(self): return self.node.broker def start(self): self.update_process = ResourceUpdateProcess(self) self.update_process.start(self.update_process.update()) self.listen_process = ResourceListenProcess(self) self.listen_process.start(self.listen_process.listen()) # accept received def accept_received(self, alloc): job = alloc.jagent.job trace = self.trace.add("j%-5s" % job.id) if self.resource.can_allocate(job): trace and trace("accept from %s, starting" % alloc.jagent) self.confirm_and_start_job(job, alloc.jagent, alloc) else: trace and trace("accept from %s, busy, rejecting" % alloc.jagent) self.send_reject(alloc.jagent, alloc) def __str__(self): return "ragent%d" % self.node.id
def doInvokeFunction(self, function): # Same as invokeFunction() but called both when trace is enabled or disabled. # # Used to modify the behavior of GL entry-points. # Override GL extensions if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override') return # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the # driver if function.name in self.marker_functions: return if function.name in self.getProcAddressFunctionNames: else_ = '' for marker_function in self.marker_functions: if self.api.getFunctionByName(marker_function): print ' %sif (strcmp("%s", (const char *)%s) == 0) {' % (else_, marker_function, function.args[0].name) print ' _result = (%s)&%s;' % (function.type, marker_function) print ' }' else_ = 'else ' print ' %s{' % else_ Tracer.doInvokeFunction(self, function) # Replace function addresses with ours # XXX: Doing this here instead of wrapRet means that the trace will # contain the addresses of the wrapper functions, and not the real # functions, but in practice this should make no difference. if function.name in self.getProcAddressFunctionNames: print ' _result = _wrapProcAddress(%s, _result);' % (function.args[0].name,) print ' }' return Tracer.doInvokeFunction(self, function)
def getRoute(address): t = Tracer(address) return t.run()
def traceFunctionImplBody(self, function): # Defer tracing of user array pointers... if function.name in self.array_pointer_function_names: print ' GLint _array_buffer = 0;' print ' _glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &_array_buffer);' print ' if (!_array_buffer) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' ctx->user_arrays = true;' if function.name == "glVertexAttribPointerARB": print ' ctx->user_arrays_arb = true;' if function.name == "glVertexAttribPointerNV": print ' ctx->user_arrays_nv = true;' self.invokeFunction(function) # And also break down glInterleavedArrays into the individual calls if function.name == 'glInterleavedArrays': print # Initialize the enable flags for camelcase_name, uppercase_name in self.arrays: flag_name = '_' + uppercase_name.lower() print ' GLboolean %s = GL_FALSE;' % flag_name print # Switch for the interleaved formats print ' switch (format) {' for format in self.interleaved_formats: print ' case %s:' % format for camelcase_name, uppercase_name in self.arrays: flag_name = '_' + uppercase_name.lower() if format.find('_' + uppercase_name[0]) >= 0: print ' %s = GL_TRUE;' % flag_name print ' break;' print ' default:' print ' return;' print ' }' print # Emit fake glEnableClientState/glDisableClientState flags for camelcase_name, uppercase_name in self.arrays: flag_name = '_' + uppercase_name.lower() enable_name = 'GL_%s_ARRAY' % uppercase_name # Emit a fake function print ' {' print ' static const trace::FunctionSig &_sig = %s ? _glEnableClientState_sig : _glDisableClientState_sig;' % flag_name print ' unsigned _call = trace::localWriter.beginEnter(&_sig);' print ' trace::localWriter.beginArg(0);' self.serializeValue(glapi.GLenum, enable_name) print ' trace::localWriter.endArg();' print ' trace::localWriter.endEnter();' print ' trace::localWriter.beginLeave(_call);' print ' trace::localWriter.endLeave();' print ' }' print ' return;' print ' }' # ... to the draw calls if function.name in self.draw_function_names: print ' if (_need_user_arrays()) {' arg_names = ', '.join([arg.name for arg in function.args[1:]]) print ' GLuint _count = _%s_count(%s);' % (function.name, arg_names) print ' _trace_user_arrays(_count);' print ' }' # Emit a fake memcpy on buffer uploads if function.name == 'glBufferParameteriAPPLE': print ' if (pname == GL_BUFFER_FLUSHING_UNMAP_APPLE && param == GL_FALSE) {' print ' _checkBufferFlushingUnmapAPPLE = true;' print ' }' if function.name in ('glUnmapBuffer', 'glUnmapBufferARB'): if function.name.endswith('ARB'): suffix = 'ARB' else: suffix = '' print ' GLint access = 0;' print ' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS, &access);' % suffix print ' if (access != GL_READ_ONLY) {' print ' GLvoid *map = NULL;' print ' _glGetBufferPointerv%s(target, GL_BUFFER_MAP_POINTER, &map);' % suffix print ' if (map) {' print ' GLint length = -1;' print ' bool flush = true;' print ' if (_checkBufferMapRange) {' print ' _glGetBufferParameteriv%s(target, GL_BUFFER_MAP_LENGTH, &length);' % suffix print ' GLint access_flags = 0;' print ' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);' print ' flush = flush && !(access_flags & GL_MAP_FLUSH_EXPLICIT_BIT);' print ' if (length == -1) {' print ' // Mesa drivers refuse GL_BUFFER_MAP_LENGTH without GL 3.0 up-to' print ' // http://cgit.freedesktop.org/mesa/mesa/commit/?id=ffee498fb848b253a7833373fe5430f8c7ca0c5f' print ' static bool warned = false;' print ' if (!warned) {' print ' os::log("apitrace: warning: glGetBufferParameteriv%s(GL_BUFFER_MAP_LENGTH) failed\\n");' % suffix print ' warned = true;' print ' }' print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' print ' length = mapping->length;' print ' flush = flush && !mapping->explicit_flush;' print ' } else {' print ' length = 0;' print ' flush = false;' print ' }' print ' }' print ' } else {' print ' length = 0;' print ' _glGetBufferParameteriv%s(target, GL_BUFFER_SIZE, &length);' % suffix print ' }' print ' if (_checkBufferFlushingUnmapAPPLE) {' print ' GLint flushing_unmap = GL_TRUE;' print ' _glGetBufferParameteriv%s(target, GL_BUFFER_FLUSHING_UNMAP_APPLE, &flushing_unmap);' % suffix print ' flush = flush && flushing_unmap;' print ' }' print ' if (flush && length > 0) {' self.emit_memcpy('map', 'map', 'length') print ' }' print ' }' print ' }' if function.name == 'glUnmapBufferOES': print ' GLint access = 0;' print ' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_OES, &access);' print ' if (access == GL_WRITE_ONLY_OES) {' print ' GLvoid *map = NULL;' print ' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER_OES, &map);' print ' GLint size = 0;' print ' _glGetBufferParameteriv(target, GL_BUFFER_SIZE, &size);' print ' if (map && size > 0) {' self.emit_memcpy('map', 'map', 'size') self.shadowBufferMethod('bufferSubData(0, size, map)') print ' }' print ' }' if function.name == 'glUnmapNamedBufferEXT': print ' GLint access_flags = 0;' print ' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);' print ' if ((access_flags & GL_MAP_WRITE_BIT) && !(access_flags & GL_MAP_FLUSH_EXPLICIT_BIT)) {' print ' GLvoid *map = NULL;' print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);' print ' GLint length = 0;' print ' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);' print ' if (map && length > 0) {' self.emit_memcpy('map', 'map', 'length') print ' }' print ' }' if function.name == 'glFlushMappedBufferRange': print ' GLvoid *map = NULL;' print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);' print ' if (map && length > 0) {' self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'length') print ' }' if function.name == 'glFlushMappedBufferRangeAPPLE': print ' GLvoid *map = NULL;' print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);' print ' if (map && size > 0) {' self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'size') print ' }' if function.name == 'glFlushMappedNamedBufferRangeEXT': print ' GLvoid *map = NULL;' print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);' print ' if (map && length > 0) {' self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'length') print ' }' # Don't leave vertex attrib locations to chance. Instead emit fake # glBindAttribLocation calls to ensure that the same locations will be # used when retracing. Trying to remap locations after the fact would # be an herculian task given that vertex attrib locations appear in # many entry-points, including non-shader related ones. if function.name == 'glLinkProgram': Tracer.invokeFunction(self, function) print ' GLint active_attributes = 0;' print ' _glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);' print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLchar name[256];' # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 print ' _glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);' print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" print ' GLint location = _glGetAttribLocation(program, name);' print ' if (location >= 0) {' bind_function = glapi.glapi.getFunctionByName('glBindAttribLocation') self.fake_call(bind_function, ['program', 'location', 'name']) print ' }' print ' }' print ' }' if function.name == 'glLinkProgramARB': Tracer.invokeFunction(self, function) print ' GLint active_attributes = 0;' print ' _glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);' print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLcharARB name[256];' # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 print ' _glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);' print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" print ' GLint location = _glGetAttribLocationARB(programObj, name);' print ' if (location >= 0) {' bind_function = glapi.glapi.getFunctionByName('glBindAttribLocationARB') self.fake_call(bind_function, ['programObj', 'location', 'name']) print ' }' print ' }' print ' }' self.shadowBufferProlog(function) Tracer.traceFunctionImplBody(self, function)
def footer(self, api): Tracer.footer(self, api) # A simple state tracker to track the pointer values # update the state print 'static void __trace_user_arrays(GLuint maxindex)' print '{' print ' gltrace::Context *ctx = gltrace::getContext();' for camelcase_name, uppercase_name in self.arrays: # in which profile is the array available? profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)'; function_name = 'gl%sPointer' % camelcase_name enable_name = 'GL_%s_ARRAY' % uppercase_name binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name function = api.get_function_by_name(function_name) print ' // %s' % function.prototype() print ' if (%s) {' % profile_check self.array_trace_prolog(api, uppercase_name) self.array_prolog(api, uppercase_name) print ' if (__glIsEnabled(%s)) {' % enable_name print ' GLint __binding = 0;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' # Get the arguments via glGet* for arg in function.args: arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper()) arg_get_function, arg_type = TypeGetter().visit(arg.type) print ' %s %s = 0;' % (arg_type, arg.name) print ' __%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name) arg_names = ', '.join([arg.name for arg in function.args[:-1]]) print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) # Emit a fake function self.array_trace_intermezzo(api, uppercase_name) print ' unsigned __call = trace::localWriter.beginEnter(&__%s_sig);' % (function.name,) for arg in function.args: assert not arg.output print ' trace::localWriter.beginArg(%u);' % (arg.index,) if arg.name != 'pointer': self.serializeValue(arg.type, arg.name) else: print ' trace::localWriter.writeBlob((const void *)%s, __size);' % (arg.name) print ' trace::localWriter.endArg();' print ' trace::localWriter.endEnter();' print ' trace::localWriter.beginLeave(__call);' print ' trace::localWriter.endLeave();' print ' }' print ' }' self.array_epilog(api, uppercase_name) self.array_trace_epilog(api, uppercase_name) print ' }' print # Samething, but for glVertexAttribPointer* # # Some variants of glVertexAttribPointer alias conventional and generic attributes: # - glVertexAttribPointer: no # - glVertexAttribPointerARB: implementation dependent # - glVertexAttribPointerNV: yes # # This means that the implementations of these functions do not always # alias, and they need to be considered independently. # print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == gltrace::PROFILE_ES1)' print ' return;' print print ' vertex_attrib __vertex_attrib = __get_vertex_attrib();' print for suffix in ['', 'ARB', 'NV']: if suffix: SUFFIX = '_' + suffix else: SUFFIX = suffix function_name = 'glVertexAttribPointer' + suffix function = api.get_function_by_name(function_name) print ' // %s' % function.prototype() print ' if (__vertex_attrib == VERTEX_ATTRIB%s) {' % SUFFIX if suffix == 'NV': print ' GLint __max_vertex_attribs = 16;' else: print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' if suffix == 'NV': print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' else: print ' __glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED%s, &__enabled);' % (suffix, SUFFIX) print ' if (__enabled) {' print ' GLint __binding = 0;' if suffix != 'NV': # It doesn't seem possible to use VBOs with NV_vertex_program. print ' __glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING%s, &__binding);' % (suffix, SUFFIX) print ' if (!__binding) {' # Get the arguments via glGet* for arg in function.args[1:]: if suffix == 'NV': arg_get_enum = 'GL_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX) else: arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX) arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False, suffix).visit(arg.type) print ' %s %s = 0;' % (arg_type, arg.name) print ' __%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name) arg_names = ', '.join([arg.name for arg in function.args[1:-1]]) print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) # Emit a fake function print ' unsigned __call = trace::localWriter.beginEnter(&__%s_sig);' % (function.name,) for arg in function.args: assert not arg.output print ' trace::localWriter.beginArg(%u);' % (arg.index,) if arg.name != 'pointer': self.serializeValue(arg.type, arg.name) else: print ' trace::localWriter.writeBlob((const void *)%s, __size);' % (arg.name) print ' trace::localWriter.endArg();' print ' trace::localWriter.endEnter();' print ' trace::localWriter.beginLeave(__call);' print ' trace::localWriter.endLeave();' print ' }' print ' }' print ' }' print ' }' print print '}' print
def footer(self, api): Tracer.footer(self, api) self.state_tracker_impl(api)
def header(self, api): Tracer.header(self, api) print '#include "gltrace.hpp"' print # Which glVertexAttrib* variant to use print 'enum vertex_attrib {' print ' VERTEX_ATTRIB,' print ' VERTEX_ATTRIB_ARB,' print ' VERTEX_ATTRIB_NV,' print '};' print print 'gltrace::Context *' print 'gltrace::getContext(void)' print '{' print ' // TODO return the context set by other APIs (GLX, EGL, and etc.)' print ' static gltrace::Context __ctx = { gltrace::PROFILE_COMPAT, false, false, false };' print ' return &__ctx;' print '}' print print 'static vertex_attrib __get_vertex_attrib(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' if (ctx->user_arrays_arb || ctx->user_arrays_nv) {' print ' GLboolean __vertex_program = GL_FALSE;' print ' __glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &__vertex_program);' print ' if (__vertex_program) {' print ' if (ctx->user_arrays_nv) {' print ' GLint __vertex_program_binding_nv = 0;' print ' __glGetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &__vertex_program_binding_nv);' print ' if (__vertex_program_binding_nv) {' print ' return VERTEX_ATTRIB_NV;' print ' }' print ' }' print ' return VERTEX_ATTRIB_ARB;' print ' }' print ' }' print ' return VERTEX_ATTRIB;' print '}' print # Whether we need user arrays print 'static inline bool __need_user_arrays(void)' print '{' print ' gltrace::Context *ctx = gltrace::getContext();' print ' if (!ctx->user_arrays) {' print ' return false;' print ' }' print for camelcase_name, uppercase_name in self.arrays: # in which profile is the array available? profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)'; function_name = 'gl%sPointer' % camelcase_name enable_name = 'GL_%s_ARRAY' % uppercase_name binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name print ' // %s' % function_name print ' if (%s) {' % profile_check self.array_prolog(api, uppercase_name) print ' if (__glIsEnabled(%s)) {' % enable_name print ' GLint __binding = 0;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print ' }' print print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == gltrace::PROFILE_ES1)' print ' return false;' print print ' vertex_attrib __vertex_attrib = __get_vertex_attrib();' print print ' // glVertexAttribPointer' print ' if (__vertex_attrib == VERTEX_ATTRIB) {' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerARB' print ' if (__vertex_attrib == VERTEX_ATTRIB_ARB) {' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerNV' print ' if (__vertex_attrib == VERTEX_ATTRIB_NV) {' print ' for (GLint index = 0; index < 16; ++index) {' print ' GLint __enabled = 0;' print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' print ' if (__enabled) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void __trace_user_arrays(GLuint maxindex);' print print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping __%s_mapping;' % target.lower(); print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & __%s_mapping;' % target.lower() print ' default:' print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '__gl_param_size(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is not None: print ' case %s: return %u;' % (name, count) print ' case GL_COMPRESSED_TEXTURE_FORMATS: {' print ' GLint num_compressed_texture_formats = 0;' print ' __glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num_compressed_texture_formats);' print ' return num_compressed_texture_formats;' print ' }' print ' default:' print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;' print ' }' print '}' print # states such as GL_UNPACK_ROW_LENGTH are not available in GLES print 'static inline bool' print 'can_unpack_subimage(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' return (ctx->profile == gltrace::PROFILE_COMPAT);' print '}' print
class Broker(object): def __init__(self, region, node, registry, sync_time, others): self.region = region self.node = node self.registry = registry self.sync_time = sync_time self.others = others self.listen_process = None self.trace = Tracer(node).add("bkr%-9s" % region) def __str__(self): return "broker %d" % self.region def start(self): self.listen_process = BrokerListenProcess(self) self.listen_process.start(self.listen_process.listen()) self.update_process = BrokerUpdateProcess(self) self.update_process.start(self.update_process.update()) def allocate(self, allocation): trace = self.trace.add("j%-5s" % allocation.jagent.job.id) trace and trace("alloc request from %s" % allocation.jagent) states = self.registry.get_resources(allocation) # return the best system wide fit states.sort(key=lambda x: x.free) if states: state = states[0] alloc = Allocation(allocation.jagent, state.agent) msg = AllocationResponse(alloc) msg.send_msg(self.node, alloc.jagent.node) trace and trace("returning alloc %s" % alloc) state.free -= allocation.job.size else: trace and trace("no valid allocations") def update(self, state): self.trace and self.trace("updating state for %s" % state.agent) self.registry.update_state(state) @property def other_brokers(self): for other in self.others.itervalues(): if other is not self: yield other def send_sync(self): states = SyncDict(self) for agent, state in self.registry.states.iteritems(): states[agent] = ResourceState(agent, state.free) for other in self.other_brokers: self.trace and self.trace("sending sync to %s" % other) msg = SyncMessage(states) msg.send_msg(self.node, other.node) def sync(self, states): self.trace and self.trace("syncing states from %s" % states.broker) #print "xxx" #print "----" #for state in self.registry.states.itervalues(): # print state.agent, state.free #print "----" for state in states.itervalues(): #print state.agent, state.free self.registry.update_state(state)
def dispatch_function(self, function): if function.name in ('glLinkProgram', 'glLinkProgramARB'): # These functions have been dispatched already return Tracer.dispatch_function(self, function)
def trace_function_impl_body(self, function): # Defer tracing of user array pointers... if function.name in self.array_pointer_function_names: print ' GLint __array_buffer = 0;' print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' print ' if (!__array_buffer) {' print ' __user_arrays = true;' self.dispatch_function(function) # And also break down glInterleavedArrays into the individual calls if function.name == 'glInterleavedArrays': print # Initialize the enable flags for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() print ' GLboolean %s = GL_FALSE;' % flag_name print # Switch for the interleaved formats print ' switch (format) {' for format in self.interleaved_formats: print ' case %s:' % format for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() if format.find('_' + uppercase_name[0]) >= 0: print ' %s = GL_TRUE;' % flag_name print ' break;' print ' default:' print ' return;' print ' }' print # Emit fake glEnableClientState/glDisableClientState flags for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() enable_name = 'GL_%s_ARRAY' % uppercase_name # Emit a fake function print ' {' print ' static const Trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name print ' unsigned __call = Trace::BeginEnter(__sig);' print ' Trace::BeginArg(0);' dump_instance(glapi.GLenum, enable_name) print ' Trace::EndArg();' print ' Trace::EndEnter();' print ' Trace::BeginLeave(__call);' print ' Trace::EndLeave();' print ' }' print ' return;' print ' }' # ... to the draw calls if function.name in self.draw_function_names: print ' if (__need_user_arrays()) {' arg_names = ', '.join([arg.name for arg in function.args[1:]]) print ' GLuint maxindex = __%s_maxindex(%s);' % ( function.name, arg_names) print ' __trace_user_arrays(maxindex);' print ' }' # Emit a fake memcpy on buffer uploads if function.name in ( 'glUnmapBuffer', 'glUnmapBufferARB', ): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping && mapping->write && !mapping->explicit_flush) {' self.emit_memcpy('mapping->map', 'mapping->map', 'mapping->length') print ' }' if function.name in ('glFlushMappedBufferRange', 'glFlushMappedBufferRangeAPPLE'): # TODO: avoid copying [0, offset] bytes print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' if function.name.endswith('APPLE'): print ' GLsizeiptr length = size;' print ' mapping->explicit_flush = true;' print ' //assert(offset + length <= mapping->length);' self.emit_memcpy('mapping->map', 'mapping->map', 'offset + length') print ' }' # FIXME: glFlushMappedNamedBufferRangeEXT # Don't leave vertex attrib locations to chance. Instead emit fake # glBindAttribLocation calls to ensure that the same locations will be # used when retracing. Trying to remap locations after the fact would # be an herculian task given that vertex attrib locations appear in # many entry-points, including non-shader related ones. if function.name == 'glLinkProgram': Tracer.dispatch_function(self, function) print ' GLint active_attributes = 0;' print ' __glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);' print ' for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLchar name[256];' # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 print ' __glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);' print ' GLint location = __glGetAttribLocation(program, name);' print ' if (location >= 0) {' bind_function = glapi.glapi.get_function_by_name( 'glBindAttribLocation') self.fake_call(bind_function, ['program', 'location', 'name']) print ' }' print ' }' if function.name == 'glLinkProgramARB': Tracer.dispatch_function(self, function) print ' GLint active_attributes = 0;' print ' __glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);' print ' for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLcharARB name[256];' # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 print ' __glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);' print ' GLint location = __glGetAttribLocationARB(programObj, name);' print ' if (location >= 0) {' bind_function = glapi.glapi.get_function_by_name( 'glBindAttribLocationARB') self.fake_call(bind_function, ['programObj', 'location', 'name']) print ' }' print ' }' Tracer.trace_function_impl_body(self, function)
def trace_function_impl_body(self, function): # Defer tracing of user array pointers... if function.name in self.array_pointer_function_names: print ' GLint __array_buffer = 0;' print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' print ' if (!__array_buffer) {' print ' __user_arrays = true;' self.dispatch_function(function) print ' return;' print ' }' # ... to the draw calls if function.name in self.draw_function_names: print ' if (__need_user_arrays()) {' arg_names = ', '.join([arg.name for arg in function.args[1:]]) print ' GLuint maxindex = __%s_maxindex(%s);' % (function.name, arg_names) print ' __trace_user_arrays(maxindex);' print ' }' # And also break down glInterleavedArrays into the individual calls if function.name == 'glInterleavedArrays': print ' GLint __array_buffer = 0;' print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' print ' if (!__array_buffer) {' print ' __user_arrays = true;' self.dispatch_function(function) print # Initialize the enable flags for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() print ' GLboolean %s = GL_FALSE;' % flag_name print # Swicth for the interleaved formats print ' switch (format) {' for format in self.interleaved_formats: print ' case %s:' % format for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() if format.find('_' + uppercase_name[0]) >= 0: print ' %s = GL_TRUE;' % flag_name print ' break;' print ' default:' print ' return;' print ' }' print # Emit fake glEnableClientState/glDisableClientState flags for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() enable_name = 'GL_%s_ARRAY' % uppercase_name # Emit a fake function print ' {' print ' static const Trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name print ' unsigned __call = Trace::BeginEnter(__sig);' print ' Trace::BeginArg(0);' dump_instance(glapi.GLenum, enable_name) print ' Trace::EndArg();' print ' Trace::EndEnter();' print ' Trace::BeginLeave(__call);' print ' Trace::EndLeave();' print ' }' print ' return;' print ' }' # Emit a fake memcpy on if function.name in ('glUnmapBuffer', 'glUnmapBufferARB'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping && mapping->write) {' print ' unsigned __call = Trace::BeginEnter(__memcpy_sig);' print ' Trace::BeginArg(0);' print ' Trace::LiteralOpaque(mapping->map);' print ' Trace::EndArg();' print ' Trace::BeginArg(1);' print ' Trace::LiteralBlob(mapping->map, mapping->length);' print ' Trace::EndArg();' print ' Trace::BeginArg(2);' print ' Trace::LiteralUInt(mapping->length);' print ' Trace::EndArg();' print ' Trace::EndEnter();' print ' Trace::BeginLeave(__call);' print ' Trace::EndLeave();' print ' }' Tracer.trace_function_impl_body(self, function)
def header(self, api): Tracer.header(self, api) print '#include "gltrace.hpp"' print # Which glVertexAttrib* variant to use print 'enum vertex_attrib {' print ' VERTEX_ATTRIB,' print ' VERTEX_ATTRIB_ARB,' print ' VERTEX_ATTRIB_NV,' print '};' print print 'static vertex_attrib _get_vertex_attrib(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' if (ctx->user_arrays_arb || ctx->user_arrays_nv) {' print ' GLboolean _vertex_program = GL_FALSE;' print ' _glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &_vertex_program);' print ' if (_vertex_program) {' print ' if (ctx->user_arrays_nv) {' print ' GLint _vertex_program_binding_nv = 0;' print ' _glGetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &_vertex_program_binding_nv);' print ' if (_vertex_program_binding_nv) {' print ' return VERTEX_ATTRIB_NV;' print ' }' print ' }' print ' return VERTEX_ATTRIB_ARB;' print ' }' print ' }' print ' return VERTEX_ATTRIB;' print '}' print self.defineShadowBufferHelper() # Whether we need user arrays print 'static inline bool _need_user_arrays(void)' print '{' print ' gltrace::Context *ctx = gltrace::getContext();' print ' if (!ctx->user_arrays) {' print ' return false;' print ' }' print for camelcase_name, uppercase_name in self.arrays: # in which profile is the array available? profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)'; function_name = 'gl%sPointer' % camelcase_name enable_name = 'GL_%s_ARRAY' % uppercase_name binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name print ' // %s' % function_name print ' if (%s) {' % profile_check self.array_prolog(api, uppercase_name) print ' if (_glIsEnabled(%s)) {' % enable_name print ' GLint _binding = 0;' print ' _glGetIntegerv(%s, &_binding);' % binding_name print ' if (!_binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print ' }' print print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == gltrace::PROFILE_ES1)' print ' return false;' print print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();' print print ' // glVertexAttribPointer' print ' if (_vertex_attrib == VERTEX_ATTRIB) {' print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' print ' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &_enabled);' print ' if (_enabled) {' print ' GLint _binding = 0;' print ' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &_binding);' print ' if (!_binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerARB' print ' if (_vertex_attrib == VERTEX_ATTRIB_ARB) {' print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' print ' _glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &_enabled);' print ' if (_enabled) {' print ' GLint _binding = 0;' print ' _glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &_binding);' print ' if (!_binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerNV' print ' if (_vertex_attrib == VERTEX_ATTRIB_NV) {' print ' for (GLint index = 0; index < 16; ++index) {' print ' GLint _enabled = 0;' print ' _glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &_enabled);' print ' if (_enabled) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void _trace_user_arrays(GLuint count);' print # Buffer mappings print '// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called' print 'static bool _checkBufferMapRange = false;' print print '// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called' print 'static bool _checkBufferFlushingUnmapAPPLE = false;' print # Buffer mapping information, necessary for old Mesa 2.1 drivers which # do not support glGetBufferParameteriv(GL_BUFFER_ACCESS_FLAGS/GL_BUFFER_MAP_LENGTH) print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping _%s_mapping;' % target.lower(); print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & _%s_mapping;' % target.lower() print ' default:' print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '_gl_param_size(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is not None: print ' case %s: return %s;' % (name, count) print ' default:' print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;' print ' }' print '}' print # states such as GL_UNPACK_ROW_LENGTH are not available in GLES print 'static inline bool' print 'can_unpack_subimage(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' return (ctx->profile == gltrace::PROFILE_COMPAT);' print '}' print
def invokeFunction(self, function): if function.name in ('glLinkProgram', 'glLinkProgramARB'): # These functions have been dispatched already return Tracer.invokeFunction(self, function)
from StripedClient import StripedClient import sys, math, traceback, time, os import numpy as np Usage = """ python test.py <data server url> <dataset name> """ columns = [ "ntracks_pmtrack", "track_pmtrack.ntrkhits_pmtrack", "trkhits_pmtrack.dedx", "trkhits_pmtrack.xyz" ] #columns = ["evtwgt.weight", "evtwgt_funcname", "evtwgt_nweight", "trkhits_pmtrack.dedx", "trkhits_pmtrack.xyz", "track_pmtrack.trkpdgtruth_pmtrack", # "mcevts_truth", "mcshwr_AncesotorProcess", "beamtime"] T = Tracer(calibrate=True) url = sys.argv[1] dataset_name = sys.argv[2] client = StripedClient(url) dataset = Dataset(client, dataset_name, columns) for ie, e in enumerate(dataset.events()): print "Event:", ie, " N pmtracks:", e.ntracks_pmtrack, " len(pmtrack):", len( e.track_pmtrack) j = 0 for it, t in enumerate(e.track_pmtrack): print " Track:", it, " nhits:", t.ntrkhits_pmtrack
def footer(self, api): Tracer.footer(self, api) # A simple state tracker to track the pointer values # update the state print 'static void _trace_user_arrays(GLuint count)' print '{' print ' gltrace::Context *ctx = gltrace::getContext();' for camelcase_name, uppercase_name in self.arrays: # in which profile is the array available? profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)' function_name = 'gl%sPointer' % camelcase_name enable_name = 'GL_%s_ARRAY' % uppercase_name binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name function = api.getFunctionByName(function_name) print ' // %s' % function.prototype() print ' if (%s) {' % profile_check self.array_trace_prolog(api, uppercase_name) self.array_prolog(api, uppercase_name) print ' if (_glIsEnabled(%s)) {' % enable_name print ' GLint _binding = 0;' print ' _glGetIntegerv(%s, &_binding);' % binding_name print ' if (!_binding) {' # Get the arguments via glGet* for arg in function.args: arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper()) arg_get_function, arg_type = TypeGetter().visit(arg.type) print ' %s %s = 0;' % (arg_type, arg.name) print ' _%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name) arg_names = ', '.join([arg.name for arg in function.args[:-1]]) print ' size_t _size = _%s_size(%s, count);' % ( function.name, arg_names) # Emit a fake function self.array_trace_intermezzo(api, uppercase_name) print ' unsigned _call = trace::localWriter.beginEnter(&_%s_sig);' % ( function.name, ) for arg in function.args: assert not arg.output print ' trace::localWriter.beginArg(%u);' % ( arg.index, ) if arg.name != 'pointer': self.serializeValue(arg.type, arg.name) else: print ' trace::localWriter.writeBlob((const void *)%s, _size);' % ( arg.name) print ' trace::localWriter.endArg();' print ' trace::localWriter.endEnter();' print ' trace::localWriter.beginLeave(_call);' print ' trace::localWriter.endLeave();' print ' }' print ' }' self.array_epilog(api, uppercase_name) self.array_trace_epilog(api, uppercase_name) print ' }' print # Samething, but for glVertexAttribPointer* # # Some variants of glVertexAttribPointer alias conventional and generic attributes: # - glVertexAttribPointer: no # - glVertexAttribPointerARB: implementation dependent # - glVertexAttribPointerNV: yes # # This means that the implementations of these functions do not always # alias, and they need to be considered independently. # print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == gltrace::PROFILE_ES1)' print ' return;' print print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();' print for suffix in ['', 'ARB', 'NV']: if suffix: SUFFIX = '_' + suffix else: SUFFIX = suffix function_name = 'glVertexAttribPointer' + suffix function = api.getFunctionByName(function_name) print ' // %s' % function.prototype() print ' if (_vertex_attrib == VERTEX_ATTRIB%s) {' % SUFFIX if suffix == 'NV': print ' GLint _max_vertex_attribs = 16;' else: print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' if suffix == 'NV': print ' _glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &_enabled);' else: print ' _glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED%s, &_enabled);' % ( suffix, SUFFIX) print ' if (_enabled) {' print ' GLint _binding = 0;' if suffix != 'NV': # It doesn't seem possible to use VBOs with NV_vertex_program. print ' _glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING%s, &_binding);' % ( suffix, SUFFIX) print ' if (!_binding) {' # Get the arguments via glGet* for arg in function.args[1:]: if suffix == 'NV': arg_get_enum = 'GL_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX) else: arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s%s' % ( arg.name.upper(), SUFFIX) arg_get_function, arg_type = TypeGetter( 'glGetVertexAttrib', False, suffix).visit(arg.type) print ' %s %s = 0;' % (arg_type, arg.name) print ' _%s(index, %s, &%s);' % ( arg_get_function, arg_get_enum, arg.name) arg_names = ', '.join([arg.name for arg in function.args[1:-1]]) print ' size_t _size = _%s_size(%s, count);' % ( function.name, arg_names) # Emit a fake function print ' unsigned _call = trace::localWriter.beginEnter(&_%s_sig);' % ( function.name, ) for arg in function.args: assert not arg.output print ' trace::localWriter.beginArg(%u);' % ( arg.index, ) if arg.name != 'pointer': self.serializeValue(arg.type, arg.name) else: print ' trace::localWriter.writeBlob((const void *)%s, _size);' % ( arg.name) print ' trace::localWriter.endArg();' print ' trace::localWriter.endEnter();' print ' trace::localWriter.beginLeave(_call);' print ' trace::localWriter.endLeave();' print ' }' print ' }' print ' }' print ' }' print print '}' print
def footer(self, api): Tracer.footer(self, api) # A simple state tracker to track the pointer values # update the state print 'static void __trace_user_arrays(GLuint maxindex)' print '{' for camelcase_name, uppercase_name in self.arrays: function_name = 'gl%sPointer' % camelcase_name enable_name = 'GL_%s_ARRAY' % uppercase_name binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name function = api.get_function_by_name(function_name) print ' // %s' % function.name self.array_trace_prolog(api, uppercase_name) self.array_prolog(api, uppercase_name) print ' if (__glIsEnabled(%s)) {' % enable_name print ' GLint __binding = 0;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' # Get the arguments via glGet* for arg in function.args: arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper()) arg_get_function, arg_type = TypeGetter().visit(arg.type) print ' %s %s = 0;' % (arg_type, arg.name) print ' __%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name) arg_names = ', '.join([arg.name for arg in function.args[:-1]]) print ' size_t __size = __%s_size(%s, maxindex);' % ( function.name, arg_names) # Emit a fake function self.array_trace_intermezzo(api, uppercase_name) print ' unsigned __call = Trace::BeginEnter(__%s_sig);' % ( function.name, ) for arg in function.args: assert not arg.output print ' Trace::BeginArg(%u);' % (arg.index, ) if arg.name != 'pointer': dump_instance(arg.type, arg.name) else: print ' Trace::LiteralBlob((const void *)%s, __size);' % ( arg.name) print ' Trace::EndArg();' print ' Trace::EndEnter();' print ' Trace::BeginLeave(__call);' print ' Trace::EndLeave();' print ' }' print ' }' self.array_epilog(api, uppercase_name) self.array_trace_epilog(api, uppercase_name) print # Samething, but for glVertexAttribPointer print ' // glVertexAttribPointer' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' print ' if (!__binding) {' function = api.get_function_by_name('glVertexAttribPointer') # Get the arguments via glGet* for arg in function.args[1:]: arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s' % (arg.name.upper(), ) arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False).visit(arg.type) print ' %s %s = 0;' % (arg_type, arg.name) print ' __%s(index, %s, &%s);' % ( arg_get_function, arg_get_enum, arg.name) arg_names = ', '.join([arg.name for arg in function.args[1:-1]]) print ' size_t __size = __%s_size(%s, maxindex);' % ( function.name, arg_names) # Emit a fake function print ' unsigned __call = Trace::BeginEnter(__%s_sig);' % ( function.name, ) for arg in function.args: assert not arg.output print ' Trace::BeginArg(%u);' % (arg.index, ) if arg.name != 'pointer': dump_instance(arg.type, arg.name) else: print ' Trace::LiteralBlob((const void *)%s, __size);' % ( arg.name) print ' Trace::EndArg();' print ' Trace::EndEnter();' print ' Trace::BeginLeave(__call);' print ' Trace::EndLeave();' print ' }' print ' }' print ' }' print print '}' print
def header(self, api): Tracer.header(self, api) self.state_tracker_decl(api)
def header(self, api): Tracer.header(self, api) print '#include "gltrace.hpp"' print # Which glVertexAttrib* variant to use print 'enum vertex_attrib {' print ' VERTEX_ATTRIB,' print ' VERTEX_ATTRIB_ARB,' print ' VERTEX_ATTRIB_NV,' print '};' print print 'static vertex_attrib _get_vertex_attrib(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' if (ctx->user_arrays_arb || ctx->user_arrays_nv) {' print ' GLboolean _vertex_program = GL_FALSE;' print ' _glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &_vertex_program);' print ' if (_vertex_program) {' print ' if (ctx->user_arrays_nv) {' print ' GLint _vertex_program_binding_nv = 0;' print ' _glGetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &_vertex_program_binding_nv);' print ' if (_vertex_program_binding_nv) {' print ' return VERTEX_ATTRIB_NV;' print ' }' print ' }' print ' return VERTEX_ATTRIB_ARB;' print ' }' print ' }' print ' return VERTEX_ATTRIB;' print '}' print self.defineShadowBufferHelper() # Whether we need user arrays print 'static inline bool _need_user_arrays(void)' print '{' print ' gltrace::Context *ctx = gltrace::getContext();' print ' if (!ctx->user_arrays) {' print ' return false;' print ' }' print for camelcase_name, uppercase_name in self.arrays: # in which profile is the array available? profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)' function_name = 'gl%sPointer' % camelcase_name enable_name = 'GL_%s_ARRAY' % uppercase_name binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name print ' // %s' % function_name print ' if (%s) {' % profile_check self.array_prolog(api, uppercase_name) print ' if (_glIsEnabled(%s)) {' % enable_name print ' GLint _binding = 0;' print ' _glGetIntegerv(%s, &_binding);' % binding_name print ' if (!_binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print ' }' print print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == gltrace::PROFILE_ES1)' print ' return false;' print print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();' print print ' // glVertexAttribPointer' print ' if (_vertex_attrib == VERTEX_ATTRIB) {' print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' print ' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &_enabled);' print ' if (_enabled) {' print ' GLint _binding = 0;' print ' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &_binding);' print ' if (!_binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerARB' print ' if (_vertex_attrib == VERTEX_ATTRIB_ARB) {' print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' print ' _glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &_enabled);' print ' if (_enabled) {' print ' GLint _binding = 0;' print ' _glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &_binding);' print ' if (!_binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerNV' print ' if (_vertex_attrib == VERTEX_ATTRIB_NV) {' print ' for (GLint index = 0; index < 16; ++index) {' print ' GLint _enabled = 0;' print ' _glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &_enabled);' print ' if (_enabled) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void _trace_user_arrays(GLuint count);' print # Buffer mappings print '// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called' print 'static bool _checkBufferMapRange = false;' print print '// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called' print 'static bool _checkBufferFlushingUnmapAPPLE = false;' print # Buffer mapping information, necessary for old Mesa 2.1 drivers which # do not support glGetBufferParameteriv(GL_BUFFER_ACCESS_FLAGS/GL_BUFFER_MAP_LENGTH) print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping _%s_mapping;' % target.lower() print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & _%s_mapping;' % target.lower() print ' default:' print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '_gl_param_size(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is not None: print ' case %s: return %s;' % (name, count) print ' default:' print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;' print ' }' print '}' print # states such as GL_UNPACK_ROW_LENGTH are not available in GLES print 'static inline bool' print 'can_unpack_subimage(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' return (ctx->profile == gltrace::PROFILE_COMPAT);' print '}' print
def traceFunctionImplBody(self, function): # Defer tracing of user array pointers... if function.name in self.array_pointer_function_names: print ' GLint __array_buffer = 0;' print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' print ' if (!__array_buffer) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' ctx->user_arrays = true;' if function.name == "glVertexAttribPointerARB": print ' ctx->user_arrays_arb = true;' if function.name == "glVertexAttribPointerNV": print ' ctx->user_arrays_nv = true;' self.invokeFunction(function) # And also break down glInterleavedArrays into the individual calls if function.name == 'glInterleavedArrays': print # Initialize the enable flags for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() print ' GLboolean %s = GL_FALSE;' % flag_name print # Switch for the interleaved formats print ' switch (format) {' for format in self.interleaved_formats: print ' case %s:' % format for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() if format.find('_' + uppercase_name[0]) >= 0: print ' %s = GL_TRUE;' % flag_name print ' break;' print ' default:' print ' return;' print ' }' print # Emit fake glEnableClientState/glDisableClientState flags for camelcase_name, uppercase_name in self.arrays: flag_name = '__' + uppercase_name.lower() enable_name = 'GL_%s_ARRAY' % uppercase_name # Emit a fake function print ' {' print ' static const trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name print ' unsigned __call = trace::localWriter.beginEnter(&__sig);' print ' trace::localWriter.beginArg(0);' self.serializeValue(glapi.GLenum, enable_name) print ' trace::localWriter.endArg();' print ' trace::localWriter.endEnter();' print ' trace::localWriter.beginLeave(__call);' print ' trace::localWriter.endLeave();' print ' }' print ' return;' print ' }' # ... to the draw calls if function.name in self.draw_function_names: print ' if (__need_user_arrays()) {' arg_names = ', '.join([arg.name for arg in function.args[1:]]) print ' GLuint maxindex = __%s_maxindex(%s);' % (function.name, arg_names) print ' __trace_user_arrays(maxindex);' print ' }' # Emit a fake memcpy on buffer uploads if function.name in ('glUnmapBuffer', 'glUnmapBufferARB', 'glUnmapBufferOES'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping && mapping->write && !mapping->explicit_flush) {' self.emit_memcpy('mapping->map', 'mapping->map', 'mapping->length') print ' }' if function.name == 'glUnmapNamedBufferEXT': print ' GLint access = 0;' print ' glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS, &access);' print ' if ((access & GL_MAP_WRITE_BIT) & !(access & GL_MAP_FLUSH_EXPLICIT_BIT)) {' print ' GLvoid *map = NULL;' print ' glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);' print ' GLint length = 0;' print ' glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);' self.emit_memcpy('map', 'map', 'length') print ' }' if function.name in ('glFlushMappedBufferRange', 'glFlushMappedBufferRangeAPPLE'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' if function.name.endswith('APPLE'): print ' GLsizeiptr length = size;' print ' mapping->explicit_flush = true;' print ' //assert(offset + length <= mapping->length);' self.emit_memcpy('(char *)mapping->map + offset', '(const char *)mapping->map + offset', 'length') print ' }' if function.name == 'glFlushMappedNamedBufferRangeEXT': print ' GLvoid *map = NULL;' print ' glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);' print ' if (map) {' self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'length') print ' }' # Don't leave vertex attrib locations to chance. Instead emit fake # glBindAttribLocation calls to ensure that the same locations will be # used when retracing. Trying to remap locations after the fact would # be an herculian task given that vertex attrib locations appear in # many entry-points, including non-shader related ones. if function.name == 'glLinkProgram': Tracer.invokeFunction(self, function) print ' GLint active_attributes = 0;' print ' __glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);' print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLchar name[256];' # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 print ' __glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);' print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" print ' GLint location = __glGetAttribLocation(program, name);' print ' if (location >= 0) {' bind_function = glapi.glapi.get_function_by_name('glBindAttribLocation') self.fake_call(bind_function, ['program', 'location', 'name']) print ' }' print ' }' print ' }' if function.name == 'glLinkProgramARB': Tracer.invokeFunction(self, function) print ' GLint active_attributes = 0;' print ' __glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);' print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLcharARB name[256];' # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 print ' __glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);' print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" print ' GLint location = __glGetAttribLocationARB(programObj, name);' print ' if (location >= 0) {' bind_function = glapi.glapi.get_function_by_name('glBindAttribLocationARB') self.fake_call(bind_function, ['programObj', 'location', 'name']) print ' }' print ' }' print ' }' Tracer.traceFunctionImplBody(self, function)
def header(self, api): Tracer.header(self, api) print '#include "gltrace.hpp"' print print 'enum tracer_context_profile {' print ' PROFILE_COMPAT,' print ' PROFILE_ES1,' print ' PROFILE_ES2,' print '};' print print 'struct tracer_context {' print ' enum tracer_context_profile profile;' print ' bool user_arrays;' print ' bool user_arrays_arb;' print ' bool user_arrays_nv;' print '};' print # Which glVertexAttrib* variant to use print 'enum vertex_attrib {' print ' VERTEX_ATTRIB,' print ' VERTEX_ATTRIB_ARB,' print ' VERTEX_ATTRIB_NV,' print '};' print print 'static tracer_context *__get_context(void)' print '{' print ' // TODO return the context set by other APIs (GLX, EGL, and etc.)' print ' static tracer_context __ctx = { PROFILE_COMPAT, false, false, false };' print ' return &__ctx;' print '}' print print 'static vertex_attrib __get_vertex_attrib(void) {' print ' tracer_context *ctx = __get_context();' print ' if (ctx->user_arrays_arb || ctx->user_arrays_nv) {' print ' GLboolean __vertex_program = GL_FALSE;' print ' __glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &__vertex_program);' print ' if (__vertex_program) {' print ' if (ctx->user_arrays_nv) {' print ' GLint __vertex_program_binding_nv = 0;' print ' __glGetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &__vertex_program_binding_nv);' print ' if (__vertex_program_binding_nv) {' print ' return VERTEX_ATTRIB_NV;' print ' }' print ' }' print ' return VERTEX_ATTRIB_ARB;' print ' }' print ' }' print ' return VERTEX_ATTRIB;' print '}' print # Whether we need user arrays print 'static inline bool __need_user_arrays(void)' print '{' print ' tracer_context *ctx = __get_context();' print ' if (!ctx->user_arrays) {' print ' return false;' print ' }' print for camelcase_name, uppercase_name in self.arrays: # in which profile is the array available? profile_check = 'ctx->profile == PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == PROFILE_ES1)'; function_name = 'gl%sPointer' % camelcase_name enable_name = 'GL_%s_ARRAY' % uppercase_name binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name print ' // %s' % function_name print ' if (%s) {' % profile_check self.array_prolog(api, uppercase_name) print ' if (__glIsEnabled(%s)) {' % enable_name print ' GLint __binding = 0;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print ' }' print print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == PROFILE_ES1)' print ' return false;' print print ' vertex_attrib __vertex_attrib = __get_vertex_attrib();' print print ' // glVertexAttribPointer' print ' if (__vertex_attrib == VERTEX_ATTRIB) {' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerARB' print ' if (__vertex_attrib == VERTEX_ATTRIB_ARB) {' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerNV' print ' if (__vertex_attrib == VERTEX_ATTRIB_NV) {' print ' for (GLint index = 0; index < 16; ++index) {' print ' GLint __enabled = 0;' print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' print ' if (__enabled) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void __trace_user_arrays(GLuint maxindex);' print print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping __%s_mapping;' % target.lower(); print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & __%s_mapping;' % target.lower() print ' default:' print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '__gl_param_size(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is not None: print ' case %s: return %u;' % (name, count) print ' case GL_COMPRESSED_TEXTURE_FORMATS: {' print ' GLint num_compressed_texture_formats = 0;' print ' __glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num_compressed_texture_formats);' print ' return num_compressed_texture_formats;' print ' }' print ' default:' print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;' print ' }' print '}' print # states such as GL_UNPACK_ROW_LENGTH are not available in GLES print 'static inline bool' print 'can_unpack_subimage(void) {' print ' tracer_context *ctx = __get_context();' print ' return (ctx->profile == PROFILE_COMPAT);' print '}' print
from trace import Tracer from Q import Dataset from Q import cosh, sqrt, cos from StripedClient import StripedClient import sys, math, traceback, time, os import numpy as np columns = ["Muon.pt", "Muon.eta", "Muon.phi", "Muon.q"] T = Tracer(calibrate=True) url = sys.argv[1] dataset_name = sys.argv[2] client = StripedClient(sys.argv[1]) dataset = Dataset(client, dataset_name, columns, trace=T) # # init # m = dataset.event.Muon m.p = m.pt * cosh(m.eta) pair = dataset.event.Muon.pair m1, m2 = pair pair.M = sqrt(2 * m1.pt * m2.pt * (cosh(m1.eta - m2.eta) - cos(m1.phi - m2.phi))) pair.C = m1.q * m2.q with T["run"]:
def traceFunctionImplBody(self, function): # Defer tracing of user array pointers... if function.name in self.array_pointer_function_names: print ' GLint _array_buffer = 0;' print ' _glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &_array_buffer);' print ' if (!_array_buffer) {' print ' gltrace::Context *ctx = gltrace::getContext();' print ' ctx->user_arrays = true;' if function.name == "glVertexAttribPointerARB": print ' ctx->user_arrays_arb = true;' if function.name == "glVertexAttribPointerNV": print ' ctx->user_arrays_nv = true;' self.invokeFunction(function) # And also break down glInterleavedArrays into the individual calls if function.name == 'glInterleavedArrays': print # Initialize the enable flags for camelcase_name, uppercase_name in self.arrays: flag_name = '_' + uppercase_name.lower() print ' GLboolean %s = GL_FALSE;' % flag_name print # Switch for the interleaved formats print ' switch (format) {' for format in self.interleaved_formats: print ' case %s:' % format for camelcase_name, uppercase_name in self.arrays: flag_name = '_' + uppercase_name.lower() if format.find('_' + uppercase_name[0]) >= 0: print ' %s = GL_TRUE;' % flag_name print ' break;' print ' default:' print ' return;' print ' }' print # Emit fake glEnableClientState/glDisableClientState flags for camelcase_name, uppercase_name in self.arrays: flag_name = '_' + uppercase_name.lower() enable_name = 'GL_%s_ARRAY' % uppercase_name # Emit a fake function print ' {' print ' static const trace::FunctionSig &_sig = %s ? _glEnableClientState_sig : _glDisableClientState_sig;' % flag_name print ' unsigned _call = trace::localWriter.beginEnter(&_sig);' print ' trace::localWriter.beginArg(0);' self.serializeValue(glapi.GLenum, enable_name) print ' trace::localWriter.endArg();' print ' trace::localWriter.endEnter();' print ' trace::localWriter.beginLeave(_call);' print ' trace::localWriter.endLeave();' print ' }' print ' return;' print ' }' # ... to the draw calls if function.name in self.draw_function_names: print ' if (_need_user_arrays()) {' arg_names = ', '.join([arg.name for arg in function.args[1:]]) print ' GLuint _count = _%s_count(%s);' % (function.name, arg_names) print ' _trace_user_arrays(_count);' print ' }' # Emit a fake memcpy on buffer uploads if function.name == 'glBufferParameteriAPPLE': print ' if (pname == GL_BUFFER_FLUSHING_UNMAP_APPLE && param == GL_FALSE) {' print ' _checkBufferFlushingUnmapAPPLE = true;' print ' }' if function.name in ('glUnmapBuffer', 'glUnmapBufferARB'): if function.name.endswith('ARB'): suffix = 'ARB' else: suffix = '' print ' GLint access = 0;' print ' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS, &access);' % suffix print ' if (access != GL_READ_ONLY) {' print ' GLvoid *map = NULL;' print ' _glGetBufferPointerv%s(target, GL_BUFFER_MAP_POINTER, &map);' % suffix print ' if (map) {' print ' GLint length = -1;' print ' bool flush = true;' print ' if (_checkBufferMapRange) {' print ' _glGetBufferParameteriv%s(target, GL_BUFFER_MAP_LENGTH, &length);' % suffix print ' GLint access_flags = 0;' print ' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);' print ' flush = flush && !(access_flags & GL_MAP_FLUSH_EXPLICIT_BIT);' print ' if (length == -1) {' print ' // Mesa drivers refuse GL_BUFFER_MAP_LENGTH without GL 3.0' print ' static bool warned = false;' print ' if (!warned) {' print ' os::log("apitrace: warning: glGetBufferParameteriv%s(GL_BUFFER_MAP_LENGTH) failed\\n");' % suffix print ' warned = true;' print ' }' print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' print ' length = mapping->length;' print ' flush = flush && !mapping->explicit_flush;' print ' } else {' print ' length = 0;' print ' flush = false;' print ' }' print ' }' print ' } else {' print ' length = 0;' print ' _glGetBufferParameteriv%s(target, GL_BUFFER_SIZE, &length);' % suffix print ' }' print ' if (_checkBufferFlushingUnmapAPPLE) {' print ' GLint flushing_unmap = GL_TRUE;' print ' _glGetBufferParameteriv%s(target, GL_BUFFER_FLUSHING_UNMAP_APPLE, &flushing_unmap);' % suffix print ' flush = flush && flushing_unmap;' print ' }' print ' if (flush && length > 0) {' self.emit_memcpy('map', 'map', 'length') print ' }' print ' }' print ' }' if function.name == 'glUnmapBufferOES': print ' GLint access = 0;' print ' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_OES, &access);' print ' if (access == GL_WRITE_ONLY_OES) {' print ' GLvoid *map = NULL;' print ' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER_OES, &map);' print ' GLint size = 0;' print ' _glGetBufferParameteriv(target, GL_BUFFER_SIZE, &size);' print ' if (map && size > 0) {' self.emit_memcpy('map', 'map', 'size') self.shadowBufferMethod('bufferSubData(0, size, map)') print ' }' print ' }' if function.name == 'glUnmapNamedBufferEXT': print ' GLint access_flags = 0;' print ' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);' print ' if ((access_flags & GL_MAP_WRITE_BIT) && !(access_flags & GL_MAP_FLUSH_EXPLICIT_BIT)) {' print ' GLvoid *map = NULL;' print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);' print ' GLint length = 0;' print ' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);' print ' if (map && length > 0) {' self.emit_memcpy('map', 'map', 'length') print ' }' print ' }' if function.name == 'glFlushMappedBufferRange': print ' GLvoid *map = NULL;' print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);' print ' if (map && length > 0) {' self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'length') print ' }' if function.name == 'glFlushMappedBufferRangeAPPLE': print ' GLvoid *map = NULL;' print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);' print ' if (map && size > 0) {' self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'size') print ' }' if function.name == 'glFlushMappedNamedBufferRangeEXT': print ' GLvoid *map = NULL;' print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);' print ' if (map && length > 0) {' self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'length') print ' }' # Don't leave vertex attrib locations to chance. Instead emit fake # glBindAttribLocation calls to ensure that the same locations will be # used when retracing. Trying to remap locations after the fact would # be an herculian task given that vertex attrib locations appear in # many entry-points, including non-shader related ones. if function.name == 'glLinkProgram': Tracer.invokeFunction(self, function) print ' GLint active_attributes = 0;' print ' _glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);' print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLchar name[256];' # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 print ' _glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);' print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" print ' GLint location = _glGetAttribLocation(program, name);' print ' if (location >= 0) {' bind_function = glapi.glapi.getFunctionByName( 'glBindAttribLocation') self.fake_call(bind_function, ['program', 'location', 'name']) print ' }' print ' }' print ' }' if function.name == 'glLinkProgramARB': Tracer.invokeFunction(self, function) print ' GLint active_attributes = 0;' print ' _glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);' print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLcharARB name[256];' # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 print ' _glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);' print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" print ' GLint location = _glGetAttribLocationARB(programObj, name);' print ' if (location >= 0) {' bind_function = glapi.glapi.getFunctionByName( 'glBindAttribLocationARB') self.fake_call(bind_function, ['programObj', 'location', 'name']) print ' }' print ' }' print ' }' self.shadowBufferProlog(function) Tracer.traceFunctionImplBody(self, function)
def header(self, api): Tracer.header(self, api) print '// Whether user arrays were used' print 'static bool __user_arrays = false;' print # Whether we need user arrays print 'static inline bool __need_user_arrays(void)' print '{' print ' if (!__user_arrays) {' print ' return false;' print ' }' print for camelcase_name, uppercase_name in self.arrays: function_name = 'gl%sPointer' % camelcase_name enable_name = 'GL_%s_ARRAY' % uppercase_name binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name print ' // %s' % function_name self.array_prolog(api, uppercase_name) print ' if (__glIsEnabled(%s)) {' % enable_name print ' GLint __binding = 0;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print print ' // glVertexAttribPointer' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void __trace_user_arrays(GLuint maxindex);' print print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping __%s_mapping;' % target.lower() print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch(target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & __%s_mapping;' % target.lower() print ' default:' print ' OS::DebugMessage("warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate memcpy's signature self.trace_function_decl(glapi.memcpy) # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch(pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '__gl_param_size(GLenum pname) {' print ' switch(pname) {' for function, type, count, name in glparams.parameters: if type is not None: print ' case %s: return %u;' % (name, count) print ' case GL_COMPRESSED_TEXTURE_FORMATS: {' print ' GLint num_compressed_texture_formats = 0;' print ' __glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num_compressed_texture_formats);' print ' return num_compressed_texture_formats;' print ' }' print ' default:' print r' OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;' print ' }' print '}' print
self.set_cmd_color(FOREGROUND_BLUE | FOREGROUND_INTENSITY) print print_text self.reset_color() def print_color_text(self, print_text, clr): self.set_cmd_color(clr | FOREGROUND_INTENSITY) print print_text self.reset_color() def print_red_text_with_blue_bg(self, print_text): self.set_cmd_color(FOREGROUND_RED | FOREGROUND_INTENSITY| BACKGROUND_BLUE | BACKGROUND_INTENSITY) print print_text self.reset_color() def print_emphasize_text(self, print_text): self.set_cmd_color(5 | FOREGROUND_INTENSITY) print print_text self.reset_color() if __name__ == "__main__": from trace import Tracer log = Tracer() log.registerTrace(ConsoleOutput()) log.output("trace", levelTrace) log.output("hint", levelHintHint) log.output("good", levelHintGood) log.output("warning", levelWarning) log.output("error", levelError)