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 15from tracetool import out 16 17 18PUBLIC = True 19 20 21def generate_h_begin(events, group): 22 out('#include "trace/ftrace.h"', 23 '') 24 25 26def generate_h(event, group): 27 argnames = ", ".join(event.args.names()) 28 if len(event.args) > 0: 29 argnames = ", " + argnames 30 31 out(' {', 32 ' char ftrace_buf[MAX_TRACE_STRLEN];', 33 ' int unused __attribute__ ((unused));', 34 ' int trlen;', 35 ' if (trace_event_get_state(%(event_id)s)) {', 36 '#line %(event_lineno)d "%(event_filename)s"', 37 ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,', 38 ' "%(name)s " %(fmt)s "\\n" %(argnames)s);', 39 '#line %(out_next_lineno)d "%(out_filename)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 event_lineno=event.lineno, 48 event_filename=event.filename, 49 fmt=event.fmt.rstrip("\n"), 50 argnames=argnames) 51 52 53def generate_h_backend_dstate(event, group): 54 out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\', 55 event_id="TRACE_" + event.name.upper()) 56