xref: /openbmc/qemu/scripts/tracetool/backend/log.py (revision 1da79ecc)
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
15from tracetool import out
16
17
18PUBLIC = True
19
20
21def generate_h_begin(events, group):
22    out('#include "qemu/log-for-trace.h"',
23        '#include "qemu/error-report.h"',
24        '')
25
26
27def generate_h(event, group):
28    argnames = ", ".join(event.args.names())
29    if len(event.args) > 0:
30        argnames = ", " + argnames
31
32    if "vcpu" in event.properties:
33        # already checked on the generic format code
34        cond = "true"
35    else:
36        cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
37
38    out('    if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
39        '        if (message_with_timestamp) {',
40        '            struct timeval _now;',
41        '            gettimeofday(&_now, NULL);',
42        '#line %(event_lineno)d "%(event_filename)s"',
43        '            qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",',
44        '                     qemu_get_thread_id(),',
45        '                     (size_t)_now.tv_sec, (size_t)_now.tv_usec',
46        '                     %(argnames)s);',
47        '#line %(out_next_lineno)d "%(out_filename)s"',
48        '        } else {',
49        '#line %(event_lineno)d "%(event_filename)s"',
50        '            qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);',
51        '#line %(out_next_lineno)d "%(out_filename)s"',
52        '        }',
53        '    }',
54        cond=cond,
55        event_lineno=event.lineno,
56        event_filename=event.filename,
57        name=event.name,
58        fmt=event.fmt.rstrip("\n"),
59        argnames=argnames)
60
61
62def generate_h_backend_dstate(event, group):
63    out('    trace_event_get_state_dynamic_by_id(%(event_id)s) || \\',
64        event_id="TRACE_" + event.name.upper())
65