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, group):
23    out('#include "trace/ftrace.h"',
24        '')
25
26
27def generate_h(event, group):
28    argnames = ", ".join(event.args.names())
29    if len(event.args) > 0:
30        argnames = ", " + argnames
31
32    out('    {',
33        '        char ftrace_buf[MAX_TRACE_STRLEN];',
34        '        int unused __attribute__ ((unused));',
35        '        int trlen;',
36        '        if (trace_event_get_state(%(event_id)s)) {',
37        '            trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
38        '                             "%(name)s " %(fmt)s "\\n" %(argnames)s);',
39        '            trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
40        '            unused = write(trace_marker_fd, ftrace_buf, trlen);',
41        '        }',
42        '    }',
43        name=event.name,
44        args=event.args,
45        event_id="TRACE_" + event.name.upper(),
46        fmt=event.fmt.rstrip("\n"),
47        argnames=argnames)
48