15de7f9c8SLluís Vilanova#!/usr/bin/env python 25de7f9c8SLluís Vilanova# -*- coding: utf-8 -*- 35de7f9c8SLluís Vilanova 45de7f9c8SLluís Vilanova""" 530b572efSLluís Vilanovatrace/generated-tracers.c 65de7f9c8SLluís Vilanova""" 75de7f9c8SLluís Vilanova 85de7f9c8SLluís Vilanova__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" 930b572efSLluís Vilanova__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>" 105de7f9c8SLluís Vilanova__license__ = "GPL version 2 or (at your option) any later version" 115de7f9c8SLluís Vilanova 125de7f9c8SLluís Vilanova__maintainer__ = "Stefan Hajnoczi" 135de7f9c8SLluís Vilanova__email__ = "stefanha@linux.vnet.ibm.com" 145de7f9c8SLluís Vilanova 155de7f9c8SLluís Vilanova 165de7f9c8SLluís Vilanovafrom tracetool import out 175de7f9c8SLluís Vilanova 185de7f9c8SLluís Vilanova 1980dd5c49SDaniel P. Berrangedef generate(events, backend, group): 2034770187SDaniel P. Berrange active_events = [e for e in events 211dad2ce9SLluís Vilanova if "disable" not in e.properties] 221dad2ce9SLluís Vilanova 230ab8ed18SDaniel P. Berrange if group == "root": 240ab8ed18SDaniel P. Berrange header = "trace-root.h" 250ab8ed18SDaniel P. Berrange else: 260ab8ed18SDaniel P. Berrange header = "trace.h" 270ab8ed18SDaniel P. Berrange 281dad2ce9SLluís Vilanova out('/* This file is autogenerated by tracetool, do not edit. */', 2934770187SDaniel P. Berrange '', 3034770187SDaniel P. Berrange '#include "qemu/osdep.h"', 31*13d4ff07SMarkus Armbruster '#include "qemu/module.h"', 320ab8ed18SDaniel P. Berrange '#include "%s"' % header, 331dad2ce9SLluís Vilanova '') 3434770187SDaniel P. Berrange 3534770187SDaniel P. Berrange for e in events: 3634770187SDaniel P. Berrange out('uint16_t %s;' % e.api(e.QEMU_DSTATE)) 3734770187SDaniel P. Berrange 3834770187SDaniel P. Berrange for e in events: 3934770187SDaniel P. Berrange if "vcpu" in e.properties: 4034770187SDaniel P. Berrange vcpu_id = 0 4134770187SDaniel P. Berrange else: 4234770187SDaniel P. Berrange vcpu_id = "TRACE_VCPU_EVENT_NONE" 4334770187SDaniel P. Berrange out('TraceEvent %(event)s = {', 4434770187SDaniel P. Berrange ' .id = 0,', 4534770187SDaniel P. Berrange ' .vcpu_id = %(vcpu_id)s,', 4634770187SDaniel P. Berrange ' .name = \"%(name)s\",', 4734770187SDaniel P. Berrange ' .sstate = %(sstate)s,', 4834770187SDaniel P. Berrange ' .dstate = &%(dstate)s ', 4934770187SDaniel P. Berrange '};', 5034770187SDaniel P. Berrange event = e.api(e.QEMU_EVENT), 5134770187SDaniel P. Berrange vcpu_id = vcpu_id, 5234770187SDaniel P. Berrange name = e.name, 5334770187SDaniel P. Berrange sstate = "TRACE_%s_ENABLED" % e.name.upper(), 5434770187SDaniel P. Berrange dstate = e.api(e.QEMU_DSTATE)) 5534770187SDaniel P. Berrange 5680dd5c49SDaniel P. Berrange out('TraceEvent *%(group)s_trace_events[] = {', 5780dd5c49SDaniel P. Berrange group = group.lower()) 5834770187SDaniel P. Berrange 5934770187SDaniel P. Berrange for e in events: 6034770187SDaniel P. Berrange out(' &%(event)s,', event = e.api(e.QEMU_EVENT)) 6134770187SDaniel P. Berrange 6234770187SDaniel P. Berrange out(' NULL,', 6334770187SDaniel P. Berrange '};', 6434770187SDaniel P. Berrange '') 6534770187SDaniel P. Berrange 6680dd5c49SDaniel P. Berrange out('static void trace_%(group)s_register_events(void)', 6734770187SDaniel P. Berrange '{', 6880dd5c49SDaniel P. Berrange ' trace_event_register_group(%(group)s_trace_events);', 6934770187SDaniel P. Berrange '}', 7080dd5c49SDaniel P. Berrange 'trace_init(trace_%(group)s_register_events)', 7180dd5c49SDaniel P. Berrange group = group.lower()) 7234770187SDaniel P. Berrange 7380dd5c49SDaniel P. Berrange backend.generate_begin(active_events, group) 7434770187SDaniel P. Berrange for event in active_events: 7580dd5c49SDaniel P. Berrange backend.generate(event, group) 7680dd5c49SDaniel P. Berrange backend.generate_end(active_events, group) 77