1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5Ftrace built-in backend.
6"""
7
8__author__     = "Eiichi Tsukata <eiichi.tsukata.xh@hitachi.com>"
9__copyright__  = "Copyright (C) 2013 Hitachi, Ltd."
10__license__    = "GPL version 2 or (at your option) any later version"
11
12__maintainer__ = "Stefan Hajnoczi"
13__email__      = "stefanha@redhat.com"
14
15
16from tracetool import out
17
18
19PUBLIC = True
20
21
22def c(events):
23    pass
24
25def h(events):
26    out('#include "trace/ftrace.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            '    char ftrace_buf[MAX_TRACE_STRLEN];',
39            '    int unused __attribute__ ((unused));',
40            '    int trlen;',
41            '    bool _state = trace_event_get_state(%(event_id)s);',
42            '    if (_state) {',
43            '        trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
44            '                         "%(name)s " %(fmt)s "\\n" %(argnames)s);',
45            '        trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
46            '        unused = write(trace_marker_fd, ftrace_buf, trlen);',
47            '    }',
48            '}',
49            name = e.name,
50            args = e.args,
51            event_id = "TRACE_" + e.name.upper(),
52            fmt = e.fmt.rstrip("\n"),
53            argnames = argnames,
54            )
55