These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / scripts / tracetool / backend / log.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-2014, 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 generate_h_begin(events):
23     out('#include "trace/control.h"',
24         '#include "qemu/log.h"',
25         '')
26
27
28 def generate_h(event):
29     argnames = ", ".join(event.args.names())
30     if len(event.args) > 0:
31         argnames = ", " + argnames
32
33     out('    if (trace_event_get_state(%(event_id)s)) {',
34         '        struct timeval _now;',
35         '        gettimeofday(&_now, NULL);',
36         '        qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
37         '                      getpid(),',
38         '                      (size_t)_now.tv_sec, (size_t)_now.tv_usec',
39         '                      %(argnames)s);',
40         '    }',
41         event_id="TRACE_" + event.name.upper(),
42         name=event.name,
43         fmt=event.fmt.rstrip("\n"),
44         argnames=argnames)