ftrace.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Ftrace built-in backend.
  5. """
  6. __author__ = "Eiichi Tsukata <eiichi.tsukata.xh@hitachi.com>"
  7. __copyright__ = "Copyright (C) 2013 Hitachi, Ltd."
  8. __license__ = "GPL version 2 or (at your option) any later version"
  9. __maintainer__ = "Stefan Hajnoczi"
  10. __email__ = "stefanha@redhat.com"
  11. from tracetool import out
  12. PUBLIC = True
  13. def c(events):
  14. pass
  15. def h(events):
  16. out('#include "trace/ftrace.h"',
  17. '#include "trace/control.h"',
  18. '',
  19. )
  20. for e in events:
  21. argnames = ", ".join(e.args.names())
  22. if len(e.args) > 0:
  23. argnames = ", " + argnames
  24. out('static inline void trace_%(name)s(%(args)s)',
  25. '{',
  26. ' char ftrace_buf[MAX_TRACE_STRLEN];',
  27. ' int unused __attribute__ ((unused));',
  28. ' int trlen;',
  29. ' bool _state = trace_event_get_state(%(event_id)s);',
  30. ' if (_state) {',
  31. ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
  32. ' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
  33. ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
  34. ' unused = write(trace_marker_fd, ftrace_buf, trlen);',
  35. ' }',
  36. '}',
  37. name = e.name,
  38. args = e.args,
  39. event_id = "TRACE_" + e.name.upper(),
  40. fmt = e.fmt.rstrip("\n"),
  41. argnames = argnames,
  42. )