def generate(events, backend): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', '', ) for e in events: if "tcg-exec" not in e.properties: continue # tracetool.generate always transforms types to host e_args = e.original.args # TCG helper proxy declaration fmt = "DEF_HELPER_FLAGS_%(argc)d(%(name)s, %(flags)svoid%(types)s)" args = e_args.transform(HOST_2_TCG_COMPAT, HOST_2_TCG, TCG_2_TCG_HELPER_DECL) types = ", ".join(args.types()) if types != "": types = ", " + types flags = "TCG_CALL_NO_RWG, " out(fmt, flags=flags, argc=len(args), name=e.api() + "_proxy", types=types, )
def generate_h_begin(events): out('#include <stdio.h>', '#include <sys/time.h>', '#include <sys/types.h>', '#include <unistd.h>', '#include "trace/control.h"', '')
def generate(events, backend): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', '', '#include "qemu/osdep.h"', '#include "qemu-common.h"', '#include "cpu.h"', '#include "trace.h"', '#include "exec/helper-proto.h"', '', ) for e in events: if "tcg-exec" not in e.properties: continue e_args_api = tracetool.vcpu.transform_args( "tcg_helper_c", e.original, "header").transform( HOST_2_TCG_COMPAT, TCG_2_TCG_HELPER_DEF) e_args_call = tracetool.vcpu.transform_args( "tcg_helper_c", e, "code") out('void %(name_tcg)s(%(args_api)s)', '{', ' %(name)s(%(args_call)s);', '}', name_tcg="helper_%s_proxy" % e.api(), name=e.api(), args_api=e_args_api, args_call=", ".join(e_args_call.casted()), )
def generate(events, backend, group): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', '') for e in events: # Define prototype for probe arguments out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")', '{', probeprefix=probeprefix(), name=e.name, binary=binary()) i = 1 if len(e.args) > 0: for name in e.args.names(): name = stap_escape(name) out(' %s = $arg%d;' % (name, i)) i += 1 out('}') out()
def begin(events): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#undef TRACEPOINT_PROVIDER', '#define TRACEPOINT_PROVIDER qemu', '', '#undef TRACEPOINT_INCLUDE_FILE', '#define TRACEPOINT_INCLUDE_FILE ./generated-ust-provider.h', '', '#if !defined (TRACE__GENERATED_UST_H) || defined(TRACEPOINT_HEADER_MULTI_READ)', '#define TRACE__GENERATED_UST_H', '', '#include "qemu-common.h"', '#include <lttng/tracepoint.h>', '', '/*', ' * LTTng ust 2.0 does not allow you to use TP_ARGS(void) for tracepoints', ' * requiring no arguments. We define these macros introduced in more recent' ' * versions of LTTng ust as a workaround', ' */', '#ifndef _TP_EXPROTO1', '#define _TP_EXPROTO1(a) void', '#endif', '#ifndef _TP_EXDATA_PROTO1', '#define _TP_EXDATA_PROTO1(a) void *__tp_data', '#endif', '#ifndef _TP_EXDATA_VAR1', '#define _TP_EXDATA_VAR1(a) __tp_data', '#endif', '#ifndef _TP_EXVAR1', '#define _TP_EXVAR1(a)', '#endif', '')
def h(events): out('#include "trace/ftrace.h"', '#include "trace/control.h"', '', ) for e in events: argnames = ", ".join(e.args.names()) if len(e.args) > 0: argnames = ", " + argnames out('static inline void trace_%(name)s(%(args)s)', '{', ' char ftrace_buf[MAX_TRACE_STRLEN];', ' int unused __attribute__ ((unused));', ' int trlen;', ' bool _state = trace_event_get_state(%(event_id)s);', ' if (_state) {', ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,', ' "%(name)s " %(fmt)s "\\n" %(argnames)s);', ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);', ' unused = write(trace_marker_fd, ftrace_buf, trlen);', ' }', '}', name = e.name, args = e.args, event_id = "TRACE_" + e.name.upper(), fmt = e.fmt.rstrip("\n"), argnames = argnames, )
def generate(events, backend): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', '') for e in events: # Define prototype for probe arguments out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")', '{', probeprefix=probeprefix(), name=e.name, binary=binary()) i = 1 if len(e.args) > 0: for name in e.args.names(): # Append underscore to reserved keywords if name in RESERVED_WORDS: name += '_' out(' %s = $arg%d;' % (name, i)) i += 1 out('}') out()
def begin(events): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#ifndef TRACE__GENERATED_TRACERS_H', '#define TRACE__GENERATED_TRACERS_H', '', '#include "qemu-common.h"')
def generate(events, backend): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', '', '#include "qemu/osdep.h"', '#include "qemu-common.h"', '#include "trace.h"', '#include "exec/helper-proto.h"', '', ) for e in events: if "tcg-exec" not in e.properties: continue # tracetool.generate always transforms types to host e_args = e.original.args values = ["(%s)%s" % (t, n) for t, n in e.args.transform(TCG_2_TCG_HELPER_DEF)] out('void %(name_tcg)s(%(args)s)', '{', ' %(name)s(%(values)s);', '}', name_tcg="helper_%s_proxy" % e.api(), name=e.api(), args=e_args.transform(HOST_2_TCG_COMPAT, TCG_2_TCG_HELPER_DEF), values=", ".join(values), )
def generate_h(event, group): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnames out(' tracepoint(qemu, %(name)s%(tp_args)s);', name=event.name, tp_args=argnames)
def generate_h_begin(events, group): if group == "root": header = "trace-dtrace-root.h" else: header = "trace-dtrace.h" out('#include "%s"' % header, '')
def generate_h_begin(events, group): if group == "root": header = "trace-ust-root.h" else: header = "trace-ust.h" out('#include <lttng/tracepoint.h>', '#include "%s"' % header, '')
def end(events): for e in events: if "disable" in e.properties: enabled = 0 else: enabled = 1 out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled)) out('', '#endif /* TRACE_H */')
def nop(events): for e in events: out('', 'static inline void trace_%(name)s(%(args)s)', '{', '}', name = e.name, args = e.args, )
def generate(events, backend): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', '') backend.generate_begin(events) for event in events: backend.generate(event) backend.generate_end(events)
def generate(events, backend, group): if group == "root": header = "trace-root.h" else: header = "trace.h" out('/* This file is autogenerated by tracetool, do not edit. */', '/* You must include this file after the inclusion of helper.h */', '', '#ifndef TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(), '#define TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(), '', '#include "exec/helper-proto.h"', '#include "%s"' % header, '', ) for e in events: # just keep one of them if "tcg-exec" not in e.properties: continue out('static inline void %(name_tcg)s(%(args)s)', '{', name_tcg=e.original.api(e.QEMU_TRACE_TCG), args=tracetool.vcpu.transform_args("tcg_h", e.original)) if "disable" not in e.properties: args_trans = e.original.event_trans.args args_exec = tracetool.vcpu.transform_args( "tcg_helper_c", e.original.event_exec, "wrapper") if "vcpu" in e.properties: trace_cpu = e.args.names()[0] cond = "trace_event_get_vcpu_state(%(cpu)s,"\ " TRACE_%(id)s)"\ % dict( cpu=trace_cpu, id=e.original.event_exec.name.upper()) else: cond = "true" out(' %(name_trans)s(%(argnames_trans)s);', ' if (%(cond)s) {', ' gen_helper_%(name_exec)s(%(argnames_exec)s);', ' }', name_trans=e.original.event_trans.api(e.QEMU_TRACE), name_exec=e.original.event_exec.api(e.QEMU_TRACE), argnames_trans=", ".join(args_trans.names()), argnames_exec=", ".join(args_exec.names()), cond=cond) out('}') out('', '#endif /* TRACE_%s_GENERATED_TCG_TRACERS_H */' % group.upper())
def begin(events): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#define TRACEPOINT_DEFINE', '#define TRACEPOINT_CREATE_PROBES', '', '/* If gcc version 4.7 or older is used, LTTng ust gives a warning when compiling with', ' -Wredundant-decls.', ' */', '#pragma GCC diagnostic ignored "-Wredundant-decls"', '', '#include "generated-ust-provider.h"')
def h(events): out('#include "trace/simple.h"', '') for event in events: out('void trace_%(name)s(%(args)s);', name = event.name, args = event.args, ) out('') out('#define NR_TRACE_EVENTS %d' % len(events)) out('extern TraceEvent trace_list[NR_TRACE_EVENTS];')
def h(events): out('#include "trace/generated-tracers-dtrace.h"', '') for e in events: out('static inline void trace_%(name)s(%(args)s) {', ' QEMU_%(uppername)s(%(argnames)s);', '}', name = e.name, args = e.args, uppername = e.name.upper(), argnames = ", ".join(e.args.names()), )
def generate(events, backend): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', '', '#define tcg_temp_new_nop(v) (v)', '#define tcg_temp_free_nop(v)', '', ) for e in events: if "tcg-exec" not in e.properties: continue # tracetool.generate always transforms types to host e_args = tracetool.vcpu.transform_args("tcg_helper_c", e.original, "wrapper") # mixed-type to TCG helper bridge args_tcg_compat = e_args.transform(HOST_2_TCG_COMPAT) code_new = [ "%(tcg_type)s __%(name)s = %(tcg_func)s(%(name)s);" % {"tcg_type": transform_type(type_, HOST_2_TCG), "tcg_func": transform_type(type_, HOST_2_TCG_TMP_NEW), "name": name} for (type_, name) in args_tcg_compat ] code_free = [ "%(tcg_func)s(__%(name)s);" % {"tcg_func": transform_type(type_, HOST_2_TCG_TMP_FREE), "name": name} for (type_, name) in args_tcg_compat ] gen_name = "gen_helper_" + e.api() out('static inline void %(name)s(%(args)s)', '{', ' %(code_new)s', ' %(proxy_name)s(%(tmp_names)s);', ' %(code_free)s', '}', name=gen_name, args=e_args, proxy_name=gen_name + "_proxy", code_new="\n ".join(code_new), code_free="\n ".join(code_free), tmp_names=", ".join(["__%s" % name for _, name in e_args]), )
def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#ifndef TRACE__GENERATED_TRACERS_H', '#define TRACE__GENERATED_TRACERS_H', '', '#include "qemu-common.h"', '') backend.generate_begin(events) for e in events: out('', 'static inline void %(api)s(%(args)s)', '{', api=e.api(), args=e.args) if "disable" not in e.properties: backend.generate(e) out('}') backend.generate_end(events) out('#endif /* TRACE__GENERATED_TRACERS_H */')
def h(events): out('#include "trace/simple.h"', '') for num, e in enumerate(events): if len(e.args): argstr = e.args.names() arg_prefix = ', (uint64_t)(uintptr_t)' cast_args = arg_prefix + arg_prefix.join(argstr) simple_args = (str(num) + cast_args) else: simple_args = str(num) out('static inline void trace_%(name)s(%(args)s)', '{', ' trace%(argc)d(%(trace_args)s);', '}', name = e.name, args = e.args, argc = len(e.args), trace_args = simple_args, ) out('#define NR_TRACE_EVENTS %d' % len(events)) out('extern TraceEvent trace_list[NR_TRACE_EVENTS];')
def generate_h(event): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnames out( " if (trace_event_get_state(%(event_id)s)) {", ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);', " }", event_id="TRACE_" + event.name.upper(), name=event.name, fmt=event.fmt.rstrip("\n"), argnames=argnames, )
def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#include "qemu/osdep.h"', '#include "trace.h"', '#include "trace/generated-events.h"', '#include "trace/control.h"', '') out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {') for e in events: if "vcpu" in e.properties: vcpu_id = "TRACE_VCPU_" + e.name.upper() else: vcpu_id = "TRACE_VCPU_EVENT_COUNT" out(' { .id = %(id)s, .vcpu_id = %(vcpu_id)s,' ' .name = \"%(name)s\",' ' .sstate = %(sstate)s },', id = "TRACE_" + e.name.upper(), vcpu_id = vcpu_id, name = e.name, sstate = "TRACE_%s_ENABLED" % e.name.upper()) out('};', '')
def generate(events, backend): out( "/* This file is autogenerated by tracetool, do not edit. */", "", "#ifndef TRACE__GENERATED_TRACERS_H", "#define TRACE__GENERATED_TRACERS_H", "", '#include "qemu-common.h"', '#include "qemu/typedefs.h"', "", ) backend.generate_begin(events) for e in events: out("", "static inline void %(api)s(%(args)s)", "{", api=e.api(), args=e.args) if "disable" not in e.properties: backend.generate(e) out("}") backend.generate_end(events) out("#endif /* TRACE__GENERATED_TRACERS_H */")
def generate_h_begin(events, group): if group == "root": header = "trace-ust-root.h" else: header = "trace-ust.h" out('#include <lttng/tracepoint.h>', '#include "%s"' % header, '', '/* tracepoint_enabled() was introduced in LTTng UST 2.7 */', '#ifndef tracepoint_enabled', '#define tracepoint_enabled(a, b) true', '#endif', '')
def generate(events, backend): events = [e for e in events if "disabled" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', '', '#define TRACEPOINT_DEFINE', '#define TRACEPOINT_CREATE_PROBES', '', '/* If gcc version 4.7 or older is used, LTTng ust gives a warning when compiling with', ' -Wredundant-decls.', ' */', '#pragma GCC diagnostic ignored "-Wredundant-decls"', '', '#include "generated-ust-provider.h"')
def generate_h_begin(events, group): if group == "root": header = "trace-dtrace-root.h" else: header = "trace-dtrace.h" out('#include "%s"' % header, '') # SystemTap defines <provider>_<name>_ENABLED() but other DTrace # implementations might not. for e in events: out('#ifndef QEMU_%(uppername)s_ENABLED', '#define QEMU_%(uppername)s_ENABLED() true', '#endif', uppername=e.name.upper())
def generate_h(event): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnames out(' if (trace_event_get_state(%(event_id)s)) {', ' struct timeval _now;', ' gettimeofday(&_now, NULL);', ' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",', ' getpid(),', ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', ' %(argnames)s);', ' }', event_id="TRACE_" + event.name.upper(), name=event.name, fmt=event.fmt.rstrip("\n"), argnames=argnames)
def generate_h(event, group): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnames if "vcpu" in event.properties: # already checked on the generic format code cond = "true" else: cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) out(' if (%(cond)s) {', ' syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);', ' }', cond=cond, name=event.name, fmt=event.fmt.rstrip("\n"), argnames=argnames)
def h(events): out('#include <lttng/tracepoint.h>', '#include "trace/generated-ust-provider.h"', '') for e in events: argnames = ", ".join(e.args.names()) if len(e.args) > 0: argnames = ", " + argnames out( 'static inline void trace_%(name)s(%(args)s)', '{', ' tracepoint(qemu, %(name)s%(tp_args)s);', '}', '', name=e.name, args=e.args, tp_args=argnames, )
def begin(events): out( '/* This file is autogenerated by tracetool, do not edit. */', '', '#undef TRACEPOINT_PROVIDER', '#define TRACEPOINT_PROVIDER qemu', '', '#undef TRACEPOINT_INCLUDE_FILE', '#define TRACEPOINT_INCLUDE_FILE ./generated-ust-provider.h', '', '#if !defined (TRACE__GENERATED_UST_H) || defined(TRACEPOINT_HEADER_MULTI_READ)', '#define TRACE__GENERATED_UST_H', '', '#include "qemu-common.h"', '#include <lttng/tracepoint.h>', '', '/*', ' * LTTng ust 2.0 does not allow you to use TP_ARGS(void) for tracepoints', ' * requiring no arguments. We define these macros introduced in more recent' ' * versions of LTTng ust as a workaround', ' */', '#ifndef _TP_EXPROTO1', '#define _TP_EXPROTO1(a) void', '#endif', '#ifndef _TP_EXDATA_PROTO1', '#define _TP_EXDATA_PROTO1(a) void *__tp_data', '#endif', '#ifndef _TP_EXDATA_VAR1', '#define _TP_EXDATA_VAR1(a) __tp_data', '#endif', '#ifndef _TP_EXVAR1', '#define _TP_EXVAR1(a)', '#endif', '')
def h(events): out('#include <lttng/tracepoint.h>', '#include "trace/generated-ust-provider.h"', '') for e in events: argnames = ", ".join(e.args.names()) if len(e.args) > 0: argnames = ", " + argnames out('static inline void trace_%(name)s(%(args)s)', '{', ' tracepoint(qemu, %(name)s%(tp_args)s);', '}', '', name = e.name, args = e.args, tp_args = argnames, )
def simpletrace_stap(events): for event_id, e in enumerate(events): out('probe %(probeprefix)s.simpletrace.%(name)s = %(probeprefix)s.%(name)s ?', '{', probeprefix=_probeprefix(), name=e.name) # Calculate record size sizes = ['24'] # sizeof(TraceRecord) for type_, name in e.args: name = stap_escape(name) if is_string(type_): out(' try {', ' arg%(name)s_str = %(name)s ? user_string_n(%(name)s, 512) : "<null>"', ' } catch {}', ' arg%(name)s_len = strlen(arg%(name)s_str)', name=name) sizes.append('4 + arg%s_len' % name) else: sizes.append('8') sizestr = ' + '.join(sizes) # Generate format string and value pairs for record header and arguments fields = [('8b', str(event_id)), ('8b', 'gettimeofday_ns()'), ('4b', sizestr), ('4b', 'pid()')] for type_, name in e.args: name = stap_escape(name) if is_string(type_): fields.extend([('4b', 'arg%s_len' % name), ('.*s', 'arg%s_len, arg%s_str' % (name, name))]) else: fields.append(('8b', name)) # Emit the entire record in a single SystemTap printf() fmt_str = '%'.join(fmt for fmt, _ in fields) arg_str = ', '.join(arg for _, arg in fields) out(' printf("%%%(fmt_str)s", %(arg_str)s)', fmt_str=fmt_str, arg_str=arg_str) out('}') out()
def generate(events, backend, group): if group == "root": header = "trace-root.h" else: header = "trace.h" out( '/* This file is autogenerated by tracetool, do not edit. */', '/* You must include this file after the inclusion of helper.h */', '', '#ifndef TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(), '#define TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(), '', '#include "exec/helper-proto.h"', '#include "%s"' % header, '', ) for e in events: # just keep one of them if "tcg-trans" not in e.properties: continue out('static inline void %(name_tcg)s(%(args)s)', '{', name_tcg=e.original.api(e.QEMU_TRACE_TCG), args=tracetool.vcpu.transform_args("tcg_h", e.original)) if "disable" not in e.properties: args_trans = e.original.event_trans.args args_exec = tracetool.vcpu.transform_args("tcg_helper_c", e.original.event_exec, "wrapper") out(' %(name_trans)s(%(argnames_trans)s);', ' gen_helper_%(name_exec)s(%(argnames_exec)s);', name_trans=e.original.event_trans.api(e.QEMU_TRACE), name_exec=e.original.event_exec.api(e.QEMU_TRACE), argnames_trans=", ".join(args_trans.names()), argnames_exec=", ".join(args_exec.names())) out('}') out('', '#endif /* TRACE_%s_GENERATED_TCG_TRACERS_H */' % group.upper())
def generate_h(event, group): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnames out(' {', ' char ftrace_buf[MAX_TRACE_STRLEN];', ' int unused __attribute__ ((unused));', ' int trlen;', ' if (trace_event_get_state(%(event_id)s)) {', ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,', ' "%(name)s " %(fmt)s "\\n" %(argnames)s);', ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);', ' unused = write(trace_marker_fd, ftrace_buf, trlen);', ' }', ' }', name=event.name, args=event.args, event_id="TRACE_" + event.name.upper(), fmt=event.fmt.rstrip("\n"), argnames=argnames)
def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#include "trace.h"', '#include "trace/generated-events.h"', '#include "trace/control.h"', '') out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {') for e in events: out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },', id="TRACE_" + e.name.upper(), name=e.name, sstate="TRACE_%s_ENABLED" % e.name.upper()) out('};', '')
def generate(events, backend, group): if group == "root": header = "trace-root.h" else: header = "trace.h" events = [e for e in events if "disable" not in e.properties] out( '/* This file is autogenerated by tracetool, do not edit. */', '', '#include "qemu/osdep.h"', '#include "qemu-common.h"', '#include "cpu.h"', '#include "exec/helper-proto.h"', '#include "%s"' % header, '', ) for e in events: if "tcg-exec" not in e.properties: continue e_args_api = tracetool.vcpu.transform_args("tcg_helper_c", e.original, "header").transform( HOST_2_TCG_COMPAT, TCG_2_TCG_HELPER_DEF) e_args_call = tracetool.vcpu.transform_args("tcg_helper_c", e, "code") out( 'void %(name_tcg)s(%(args_api)s)', '{', # NOTE: the check was already performed at TCG-generation time ' %(name)s(%(args_call)s);', '}', name_tcg="helper_%s_proxy" % e.api(), name=e.api(e.QEMU_TRACE_NOCHECK), args_api=e_args_api, args_call=", ".join(e_args_call.casted()), )
def generate(events, backend): out( '/* This file is autogenerated by tracetool, do not edit. */', '/* You must include this file after the inclusion of helper.h */', '', '#ifndef TRACE__GENERATED_TCG_TRACERS_H', '#define TRACE__GENERATED_TCG_TRACERS_H', '', '#include <stdint.h>', '', '#include "trace.h"', '#include "exec/helper-proto.h"', '', ) for e in events: # just keep one of them if "tcg-trans" not in e.properties: continue # get the original event definition e = e.original.original out('static inline void %(name_tcg)s(%(args)s)', '{', name_tcg=e.api(e.QEMU_TRACE_TCG), args=e.args) if "disable" not in e.properties: out(' %(name_trans)s(%(argnames_trans)s);', ' gen_helper_%(name_exec)s(%(argnames_exec)s);', name_trans=e.event_trans.api(e.QEMU_TRACE), name_exec=e.event_exec.api(e.QEMU_TRACE), argnames_trans=", ".join(e.event_trans.args.names()), argnames_exec=", ".join(e.event_exec.args.names())) out('}') out('', '#endif /* TRACE__GENERATED_TCG_TRACERS_H */')
def generate_h(event, group): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnames if "vcpu" in event.properties: # already checked on the generic format code cond = "true" else: cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {', ' struct timeval _now;', ' gettimeofday(&_now, NULL);', ' qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",', ' qemu_get_thread_id(),', ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', ' %(argnames)s);', ' }', cond=cond, name=event.name, fmt=event.fmt.rstrip("\n"), argnames=argnames)
def h(events): out('#include <stdio.h>', '#include "trace/control.h"', '', ) for e in events: argnames = ", ".join(e.args.names()) if len(e.args) > 0: argnames = ", " + argnames out('static inline void trace_%(name)s(%(args)s)', '{', ' bool _state = trace_event_get_state(%(event_id)s);', ' if (_state) {', ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);', ' }', '}', name = e.name, args = e.args, event_id = "TRACE_" + e.name.upper(), fmt = e.fmt.rstrip("\n"), argnames = argnames, )
def c(events): out('#include "trace.h"', '', 'TraceEvent trace_list[] = {') for e in events: out( '{.tp_name = "%(name)s", .state=0},', name=e.name, ) out('};')
def stap(events): for e in events: # Define prototype for probe arguments out( 'probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")', '{', probeprefix=_probeprefix(), name=e.name, binary=_binary(), ) i = 1 if len(e.args) > 0: for name in e.args.names(): name = stap_escape(name) out(' %s = $arg%d;' % (name, i)) i += 1 out('}') out()
def stap(events): for e in events: # Define prototype for probe arguments out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")', '{', probeprefix = _probeprefix(), name = e.name, binary = _binary(), ) i = 1 if len(e.args) > 0: for name in e.args.names(): # Append underscore to reserved keywords if name in RESERVED_WORDS: name += '_' out(' %s = $arg%d;' % (name, i)) i += 1 out('}') out()
def h(events): out('#include <ust/tracepoint.h>', '#undef mutex_lock', '#undef mutex_unlock', '#undef inline', '#undef wmb') for e in events: if len(e.args) > 0: out( 'DECLARE_TRACE(ust_%(name)s, TP_PROTO(%(args)s), TP_ARGS(%(argnames)s));', '#define trace_%(name)s trace_ust_%(name)s', name=e.name, args=e.args, argnames=", ".join(e.args.names()), ) else: out( '_DECLARE_TRACEPOINT_NOARGS(ust_%(name)s);', '#define trace_%(name)s trace_ust_%(name)s', name=e.name, ) out()
def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#ifndef TRACE__GENERATED_TRACERS_H', '#define TRACE__GENERATED_TRACERS_H', '', '#include "qemu-common.h"', '#include "qemu/typedefs.h"', '') backend.generate_begin(events) for e in events: out('', 'static inline void %(api)s(%(args)s)', '{', api=e.api(), args=e.args) if "disable" not in e.properties: backend.generate(e) out('}') backend.generate_end(events) out('#endif /* TRACE__GENERATED_TRACERS_H */')
def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#ifndef TRACE__GENERATED_TRACERS_H', '#define TRACE__GENERATED_TRACERS_H', '', '#include "qemu-common.h"', '#include "trace/control.h"', '') backend.generate_begin(events) for e in events: if "vcpu" in e.properties: trace_cpu = next(iter(e.args))[1] cond = "trace_event_get_vcpu_state(%(cpu)s,"\ " TRACE_%(id)s,"\ " TRACE_VCPU_%(id)s)"\ % dict( cpu=trace_cpu, id=e.name.upper()) else: cond = "true" out('', 'static inline void %(api)s(%(args)s)', '{', ' if (%(cond)s) {', api=e.api(), args=e.args, cond=cond) if "disable" not in e.properties: backend.generate(e) out(' }', '}') backend.generate_end(events) out('#endif /* TRACE__GENERATED_TRACERS_H */')
def generate(events, backend, group): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */' '', 'provider qemu {') for e in events: args = [] for type_, name in e.args: if name in RESERVED_WORDS: name += '_' args.append(type_ + ' ' + name) # Define prototype for probe arguments out('', 'probe %(name)s(%(args)s);', name=e.name, args=','.join(args)) out('', '};')
def generate(events, backend): events = [e for e in events if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */' '', 'provider qemu {') for e in events: args = str(e.args) # DTrace provider syntax expects foo() for empty # params, not foo(void) if args == 'void': args = '' # Define prototype for probe arguments out('', 'probe %(name)s(%(args)s);', name=e.name, args=args) out('', '};')
def d(events): out('provider qemu {') for e in events: args = str(e.args) # DTrace provider syntax expects foo() for empty # params, not foo(void) if args == 'void': args = '' # Define prototype for probe arguments out('', 'probe %(name)s(%(args)s);', name = e.name, args = args, ) out('', '};')
def generate(events, backend, group): events = [e for e in events if "disable" not in e.properties] # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy # with an empty file. Avoid the warning. # But dtrace on macOS can't deal with empty files. if not events and platform != "darwin": return out('/* This file is autogenerated by tracetool, do not edit. */' '', 'provider qemu {') for e in events: args = [] for type_, name in e.args: if platform == "darwin": # macOS dtrace accepts only C99 _Bool if type_ == 'bool': type_ = '_Bool' if type_ == 'bool *': type_ = '_Bool *' # It converts int8_t * in probe points to char * in header # files and introduces [-Wpointer-sign] warning. # Avoid it by changing probe type to signed char * beforehand. if type_ == 'int8_t *': type_ = 'signed char *' # SystemTap dtrace(1) emits a warning when long long is used type_ = type_.replace('unsigned long long', 'uint64_t') type_ = type_.replace('signed long long', 'int64_t') type_ = type_.replace('long long', 'int64_t') if name in RESERVED_WORDS: name += '_' args.append(type_ + ' ' + name) # Define prototype for probe arguments out('', 'probe %(name)s(%(args)s);', name=e.name, args=','.join(args)) out('', '};')
def generate(events, backend, group): events = [e for e in events if "disable" not in e.properties] # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy # with an empty file. Avoid the warning. if not events: return out('/* This file is autogenerated by tracetool, do not edit. */' '', 'provider qemu {') for e in events: args = [] for type_, name in e.args: if name in RESERVED_WORDS: name += '_' args.append(type_ + ' ' + name) # Define prototype for probe arguments out('', 'probe %(name)s(%(args)s);', name=e.name, args=','.join(args)) out('', '};')
def h(events): out('#include <stdio.h>', '#include "trace/stderr.h"', '', 'extern TraceEvent trace_list[];') for num, e in enumerate(events): argnames = ", ".join(e.args.names()) if len(e.args) > 0: argnames = ", " + argnames out( 'static inline void trace_%(name)s(%(args)s)', '{', ' if (trace_list[%(event_num)s].state != 0) {', ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);', ' }', '}', name=e.name, args=e.args, event_num=num, fmt=e.fmt, argnames=argnames, ) out('', '#define NR_TRACE_EVENTS %d' % len(events))
def generate_h_backend_dstate(event, group): out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\', event_id="TRACE_" + event.name.upper())
def generate(events, backend, group): active_events = [e for e in events if "disable" not in e.properties] if group == "root": header = "trace-root.h" else: header = "trace.h" out('/* This file is autogenerated by tracetool, do not edit. */', '', '#include "qemu/osdep.h"', '#include "qemu/module.h"', '#include "%s"' % header, '') for e in events: out('uint16_t %s;' % e.api(e.QEMU_DSTATE)) for e in events: if "vcpu" in e.properties: vcpu_id = 0 else: vcpu_id = "TRACE_VCPU_EVENT_NONE" out('TraceEvent %(event)s = {', ' .id = 0,', ' .vcpu_id = %(vcpu_id)s,', ' .name = \"%(name)s\",', ' .sstate = %(sstate)s,', ' .dstate = &%(dstate)s ', '};', event=e.api(e.QEMU_EVENT), vcpu_id=vcpu_id, name=e.name, sstate="TRACE_%s_ENABLED" % e.name.upper(), dstate=e.api(e.QEMU_DSTATE)) out('TraceEvent *%(group)s_trace_events[] = {', group=group.lower()) for e in events: out(' &%(event)s,', event=e.api(e.QEMU_EVENT)) out(' NULL,', '};', '') out('static void trace_%(group)s_register_events(void)', '{', ' trace_event_register_group(%(group)s_trace_events);', '}', 'trace_init(trace_%(group)s_register_events)', group=group.lower()) backend.generate_begin(active_events, group) for event in active_events: backend.generate(event, group) backend.generate_end(active_events, group)
def generate_h_begin(events, group): out('#include "qemu/log-for-trace.h"', '')
def generate(events, backend, group): out('/* This file is autogenerated by tracetool, do not edit. */', '') for event_id, e in enumerate(events): if 'disable' in e.properties: continue out('probe %(probeprefix)s.log.%(name)s = %(probeprefix)s.%(name)s ?', '{', probeprefix=probeprefix(), name=e.name) # Get references to userspace strings for type_, name in e.args: name = stap_escape(name) if is_string(type_): out(' try {', ' arg%(name)s_str = %(name)s ? ' + 'user_string_n(%(name)s, 512) : "<null>"', ' } catch {}', name=name) # Determine systemtap's view of variable names fields = ["pid()", "gettimeofday_ns()"] for type_, name in e.args: name = stap_escape(name) if is_string(type_): fields.append("arg" + name + "_str") else: fields.append(name) # Emit the entire record in a single SystemTap printf() arg_str = ', '.join(arg for arg in fields) fmt_str = "%d@%d " + e.name + " " + c_fmt_to_stap(e.fmt) + "\\n" out(' printf("%(fmt_str)s", %(arg_str)s)', fmt_str=fmt_str, arg_str=arg_str) out('}') out()
def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#ifndef TRACE__GENERATED_EVENTS_H', '#define TRACE__GENERATED_EVENTS_H', '') # event identifiers out('typedef enum {') for e in events: out(' TRACE_%s,' % e.name.upper()) out(' TRACE_EVENT_COUNT', '} TraceEventID;') # static state for e in events: if 'disable' in e.properties: enabled = 0 else: enabled = 1 if "tcg-trans" in e.properties: # a single define for the two "sub-events" out('#define TRACE_%(name)s_ENABLED %(enabled)d', name=e.original.name.upper(), enabled=enabled) out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled)) out('#include "trace/event-internal.h"', '', '#endif /* TRACE__GENERATED_EVENTS_H */')
def generate_h_begin(events, group): out('#include "trace/ftrace.h"', '')