1# -*- coding: utf-8 -*- 2 3""" 4Stderr built-in backend. 5""" 6 7__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" 8__copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>" 9__license__ = "GPL version 2 or (at your option) any later version" 10 11__maintainer__ = "Stefan Hajnoczi" 12__email__ = "stefanha@redhat.com" 13 14 15import os.path 16 17from tracetool import out 18 19 20PUBLIC = True 21 22 23def generate_h_begin(events, group): 24 out('#include "qemu/log-for-trace.h"', 25 '#include "qemu/error-report.h"', 26 '') 27 28 29def generate_h(event, group): 30 argnames = ", ".join(event.args.names()) 31 if len(event.args) > 0: 32 argnames = ", " + argnames 33 34 if "vcpu" in event.properties: 35 # already checked on the generic format code 36 cond = "true" 37 else: 38 cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) 39 40 out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {', 41 ' if (message_with_timestamp) {', 42 ' struct timeval _now;', 43 ' gettimeofday(&_now, NULL);', 44 '#line %(event_lineno)d "%(event_filename)s"', 45 ' qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",', 46 ' qemu_get_thread_id(),', 47 ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', 48 ' %(argnames)s);', 49 '#line %(out_next_lineno)d "%(out_filename)s"', 50 ' } else {', 51 '#line %(event_lineno)d "%(event_filename)s"', 52 ' qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);', 53 '#line %(out_next_lineno)d "%(out_filename)s"', 54 ' }', 55 ' }', 56 cond=cond, 57 event_lineno=event.lineno, 58 event_filename=os.path.relpath(event.filename), 59 name=event.name, 60 fmt=event.fmt.rstrip("\n"), 61 argnames=argnames) 62 63 64def generate_h_backend_dstate(event, group): 65 out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\', 66 event_id="TRACE_" + event.name.upper()) 67