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 PUBLIC If exists and is set to 'True', the backend is considered "public".
27 ========= ====================================================================
33 ======== =======================================================================
35 ======== =======================================================================
36 <format> Called to generate the format- and backend-specific code for each of
37 the specified events. If the function does not exist, the backend is
38 considered not compatible with the given format.
39 ======== =======================================================================
42 __author__
= "Lluís Vilanova <vilanova@ac.upc.edu>"
43 __copyright__
= "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
44 __license__
= "GPL version 2 or (at your option) any later version"
46 __maintainer__
= "Stefan Hajnoczi"
47 __email__
= "stefanha@linux.vnet.ibm.com"
55 def get_list(only_public
= False):
56 """Get a list of (name, description) pairs."""
57 res
= [("nop", "Tracing disabled.")]
59 for filename
in os
.listdir(tracetool
.backend
.__path
__[0]):
60 if filename
.endswith('.py') and filename
!= '__init__.py':
61 modnames
.append(filename
.rsplit('.', 1)[0])
62 for modname
in modnames
:
63 module
= tracetool
.try_import("tracetool.backend." + modname
)
65 # just in case; should never fail unless non-module files are put there
70 public
= getattr(module
, "PUBLIC", False)
71 if only_public
and not public
:
77 doc
= doc
.strip().split("\n")[0]
79 name
= modname
.replace("_", "-")
80 res
.append((name
, doc
))
85 """Return whether the given backend exists."""
90 name
= name
.replace("-", "_")
91 return tracetool
.try_import("tracetool.backend." + name
)[1]
94 def compatible(backend
, format
):
95 """Whether a backend is compatible with the given format."""
96 if not exists(backend
):
97 raise ValueError("unknown backend: %s" % backend
)
99 backend
= backend
.replace("-", "_")
100 format
= format
.replace("-", "_")
105 func
= tracetool
.try_import("tracetool.backend." + backend
,
107 return func
is not None
113 def generate(backend
, format
, events
):
114 """Generate the per-event output for the given (backend, format) pair."""
115 if not compatible(backend
, format
):
116 raise ValueError("backend '%s' not compatible with format '%s'" %
119 backend
= backend
.replace("-", "_")
120 format
= format
.replace("-", "_")
123 func
= tracetool
.try_import("tracetool.format." + format
,
126 func
= tracetool
.try_import("tracetool.backend." + backend
,