2 # -*- coding: utf-8 -*-
11 A new format named 'foo-bar' corresponds to Python module
12 'tracetool/format/foo_bar.py'.
14 A format module should provide a docstring, whose first non-empty line will be
15 considered its short description.
17 All formats must generate their contents through the 'tracetool.out' routine.
23 All the following functions are optional, and no output will be generated if
26 ======== =======================================================================
28 ======== =======================================================================
29 begin Called to generate the format-specific file header.
30 end Called to generate the format-specific file footer.
31 nop Called to generate the per-event contents when the event is disabled or
32 the selected backend is 'nop'.
33 ======== =======================================================================
36 __author__
= "Lluís Vilanova <vilanova@ac.upc.edu>"
37 __copyright__
= "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
38 __license__
= "GPL version 2 or (at your option) any later version"
40 __maintainer__
= "Stefan Hajnoczi"
41 __email__
= "stefanha@linux.vnet.ibm.com"
50 """Get a list of (name, description) pairs."""
53 for filename
in os
.listdir(tracetool
.format
.__path
__[0]):
54 if filename
.endswith('.py') and filename
!= '__init__.py':
55 modnames
.append(filename
.rsplit('.', 1)[0])
56 for modname
in sorted(modnames
):
57 module
= tracetool
.try_import("tracetool.format." + modname
)
59 # just in case; should never fail unless non-module files are put there
67 doc
= doc
.strip().split("\n")[0]
69 name
= modname
.replace("_", "-")
70 res
.append((name
, doc
))
75 """Return whether the given format exists."""
78 name
= name
.replace("-", "_")
79 return tracetool
.try_import("tracetool.format." + name
)[1]
85 def generate_begin(name
, events
):
86 """Generate the header of the format-specific file."""
88 raise ValueError("unknown format: %s" % name
)
90 name
= name
.replace("-", "_")
91 func
= tracetool
.try_import("tracetool.format." + name
,
95 def generate_end(name
, events
):
96 """Generate the footer of the format-specific file."""
98 raise ValueError("unknown format: %s" % name
)
100 name
= name
.replace("-", "_")
101 func
= tracetool
.try_import("tracetool.format." + name
,