1# -*- coding: utf-8 -*-
2
3"""
4Ftrace built-in backend.
5"""
6
7__author__     = "Eiichi Tsukata <eiichi.tsukata.xh@hitachi.com>"
8__copyright__  = "Copyright (C) 2013 Hitachi, Ltd."
9__license__    = "GPL version 2 or (at your option) any later version"
10
11__maintainer__ = "Stefan Hajnoczi"
12__email__      = "stefanha@redhat.com"
13
14
15import os.path
16
17from tracetool import out
18
19
20PUBLIC = True
21
22
23def generate_h_begin(events, group):
24    out('#include "trace/ftrace.h"',
25        '')
26
27
28def generate_h(event, group):
29    argnames = ", ".join(event.args.names())
30    if len(event.args) > 0:
31        argnames = ", " + argnames
32
33    out('    {',
34        '        char ftrace_buf[MAX_TRACE_STRLEN];',
35        '        int unused __attribute__ ((unused));',
36        '        int trlen;',
37        '        if (trace_event_get_state(%(event_id)s)) {',
38        '#line %(event_lineno)d "%(event_filename)s"',
39        '            trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
40        '                             "%(name)s " %(fmt)s "\\n" %(argnames)s);',
41        '#line %(out_next_lineno)d "%(out_filename)s"',
42        '            trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
43        '            unused = write(trace_marker_fd, ftrace_buf, trlen);',
44        '        }',
45        '    }',
46        name=event.name,
47        args=event.args,
48        event_id="TRACE_" + event.name.upper(),
49        event_lineno=event.lineno,
50        event_filename=os.path.relpath(event.filename),
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