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