Eiichi Tsukata | 781e954 | 2013-04-11 20:25:15 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | """ |
| 5 | Ftrace 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 | |
| 16 | from tracetool import out |
| 17 | |
| 18 | |
| 19 | PUBLIC = True |
| 20 | |
| 21 | |
| 22 | def c(events): |
| 23 | pass |
| 24 | |
| 25 | def 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 | ) |