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 generate_h_begin(events):
23    out('#include "trace/ftrace.h"',
24        '#include "trace/control.h"',
25        '')
26
27
28def generate_h(event):
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        '            trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
39        '                             "%(name)s " %(fmt)s "\\n" %(argnames)s);',
40        '            trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
41        '            unused = write(trace_marker_fd, ftrace_buf, trlen);',
42        '        }',
43        '    }',
44        name=event.name,
45        args=event.args,
46        event_id="TRACE_" + event.name.upper(),
47        fmt=event.fmt.rstrip("\n"),
48        argnames=argnames)
49