xref: /qemu/scripts/tracetool/backend/log.py (revision 7a4e543d)
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5Stderr 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
16from tracetool import out
17
18
19PUBLIC = True
20
21
22def generate_h_begin(events):
23    out('#include <stdio.h>',
24        '#include <sys/time.h>',
25        '#include <sys/types.h>',
26        '#include <unistd.h>',
27        '#include "trace/control.h"',
28        '#include "qemu/log.h"',
29        '')
30
31
32def generate_h(event):
33    argnames = ", ".join(event.args.names())
34    if len(event.args) > 0:
35        argnames = ", " + argnames
36
37    out('    if (trace_event_get_state(%(event_id)s)) {',
38        '        struct timeval _now;',
39        '        gettimeofday(&_now, NULL);',
40        '        qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
41        '                      getpid(),',
42        '                      (size_t)_now.tv_sec, (size_t)_now.tv_usec',
43        '                      %(argnames)s);',
44        '    }',
45        event_id="TRACE_" + event.name.upper(),
46        name=event.name,
47        fmt=event.fmt.rstrip("\n"),
48        argnames=argnames)
49