1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4""" 5trace/generated-tracers.h 6""" 7 8__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" 9__copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>" 10__license__ = "GPL version 2 or (at your option) any later version" 11 12__maintainer__ = "Stefan Hajnoczi" 13__email__ = "stefanha@linux.vnet.ibm.com" 14 15 16from tracetool import out 17 18 19def generate(events, backend, group): 20 out('/* This file is autogenerated by tracetool, do not edit. */', 21 '', 22 '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(), 23 '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(), 24 '', 25 '#include "qemu-common.h"', 26 '#include "trace/control.h"', 27 '') 28 29 for e in events: 30 out('extern TraceEvent %(event)s;', 31 event = e.api(e.QEMU_EVENT)) 32 33 for e in events: 34 out('extern uint16_t %s;' % e.api(e.QEMU_DSTATE)) 35 36 # static state 37 for e in events: 38 if 'disable' in e.properties: 39 enabled = 0 40 else: 41 enabled = 1 42 if "tcg-exec" in e.properties: 43 # a single define for the two "sub-events" 44 out('#define TRACE_%(name)s_ENABLED %(enabled)d', 45 name=e.original.name.upper(), 46 enabled=enabled) 47 out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled)) 48 49 backend.generate_begin(events, group) 50 51 for e in events: 52 # tracer without checks 53 out('', 54 'static inline void %(api)s(%(args)s)', 55 '{', 56 api=e.api(e.QEMU_TRACE_NOCHECK), 57 args=e.args) 58 59 if "disable" not in e.properties: 60 backend.generate(e, group) 61 62 out('}') 63 64 # tracer wrapper with checks (per-vCPU tracing) 65 if "vcpu" in e.properties: 66 trace_cpu = next(iter(e.args))[1] 67 cond = "trace_event_get_vcpu_state(%(cpu)s,"\ 68 " TRACE_%(id)s)"\ 69 % dict( 70 cpu=trace_cpu, 71 id=e.name.upper()) 72 else: 73 cond = "true" 74 75 out('', 76 'static inline void %(api)s(%(args)s)', 77 '{', 78 ' if (%(cond)s) {', 79 ' %(api_nocheck)s(%(names)s);', 80 ' }', 81 '}', 82 api=e.api(), 83 api_nocheck=e.api(e.QEMU_TRACE_NOCHECK), 84 args=e.args, 85 names=", ".join(e.args.names()), 86 cond=cond) 87 88 backend.generate_end(events, group) 89 90 out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper()) 91