2 # -*- coding: utf-8 -*-
11 A new backend named 'foo-bar' corresponds to Python module
12 'tracetool/backend/foo_bar.py'.
14 A backend module should provide a docstring, whose first non-empty line will be
15 considered its short description.
17 All backends must generate their contents through the 'tracetool.out' routine.
23 ======== =======================================================================
25 ======== =======================================================================
26 <format> Called to generate the format- and backend-specific code for each of
27 the specified events. If the function does not exist, the backend is
28 considered not compatible with the given format.
29 ======== =======================================================================
32 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
33 __copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
34 __license__ = "GPL version 2 or (at your option) any later version"
36 __maintainer__ = "Stefan Hajnoczi"
37 __email__ = "stefanha@linux.vnet.ibm.com"
46 """Get a list of (name, description) pairs."""
47 res = [("nop", "Tracing disabled.")]
49 for filename in os.listdir(tracetool.backend.__path__[0]):
50 if filename.endswith('.py') and filename != '__init__.py':
51 modnames.append(filename.rsplit('.', 1)[0])
52 for modname in modnames:
53 module = tracetool.try_import("tracetool.backend." + modname)
55 # just in case; should never fail unless non-module files are put there
63 doc = doc.strip().split("\n")[0]
65 name = modname.replace("_", "-")
66 res.append((name, doc))
71 """Return whether the given backend exists."""
76 name = name.replace("-", "_")
77 return tracetool.try_import("tracetool.backend." + name)[1]
80 def compatible(backend, format):
81 """Whether a backend is compatible with the given format."""
82 if not exists(backend):
83 raise ValueError("unknown backend: %s" % backend)
85 backend = backend.replace("-", "_")
86 format = format.replace("-", "_")
91 func = tracetool.try_import("tracetool.backend." + backend,
93 return func is not None
99 def generate(backend, format, events):
100 """Generate the per-event output for the given (backend, format) pair."""
101 if not compatible(backend, format):
102 raise ValueError("backend '%s' not compatible with format '%s'" %
105 backend = backend.replace("-", "_")
106 format = format.replace("-", "_")
109 func = tracetool.try_import("tracetool.format." + format,
112 func = tracetool.try_import("tracetool.backend." + backend,