trace: [stderr] Port to generic event information and new control interface
[sdk/emulator/qemu.git] / scripts / tracetool / backend / stderr.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 Stderr built-in backend.
6 """
7
8 __author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
9 __copyright__  = "Copyright 2012, 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
16 from tracetool import out
17
18
19 PUBLIC = True
20
21
22 def c(events):
23     pass
24
25 def h(events):
26     out('#include <stdio.h>',
27         '#include "trace/control.h"',
28         '',
29         )
30
31     for e in events:
32         argnames = ", ".join(e.args.names())
33         if len(e.args) > 0:
34             argnames = ", " + argnames
35
36         out('static inline void trace_%(name)s(%(args)s)',
37             '{',
38             '    bool _state = trace_event_get_state(%(event_id)s);',
39             '    if (_state) {',
40             '        fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);',
41             '    }',
42             '}',
43             name = e.name,
44             args = e.args,
45             event_id = "TRACE_" + e.name.upper(),
46             fmt = e.fmt.rstrip("\n"),
47             argnames = argnames,
48             )