1 # -*- coding: utf-8 -*-
10 A new backend named 'foo-bar' corresponds to Python module
11 'tracetool/backend/foo_bar.py'.
13 A backend module should provide a docstring, whose first non-empty line will be
14 considered its short description.
16 All backends must generate their contents through the 'tracetool.out' routine.
22 ========= ====================================================================
24 ========= ====================================================================
25 PUBLIC If exists and is set to 'True', the backend is considered "public".
26 ========= ====================================================================
32 All the following functions are optional, and no output will be generated if
35 =============================== ==============================================
37 =============================== ==============================================
38 generate_<format>_begin(events) Generate backend- and format-specific file
40 generate_<format>_end(events) Generate backend- and format-specific file
42 generate_<format>(event) Generate backend- and format-specific contents
44 =============================== ==============================================
48 __author__
= "Lluís Vilanova <vilanova@ac.upc.edu>"
49 __copyright__
= "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
50 __license__
= "GPL version 2 or (at your option) any later version"
52 __maintainer__
= "Stefan Hajnoczi"
53 __email__
= "stefanha@redhat.com"
61 def get_list(only_public
= False):
62 """Get a list of (name, description) pairs."""
63 res
= [("nop", "Tracing disabled.")]
65 for filename
in os
.listdir(tracetool
.backend
.__path
__[0]):
66 if filename
.endswith('.py') and filename
!= '__init__.py':
67 modnames
.append(filename
.rsplit('.', 1)[0])
68 for modname
in sorted(modnames
):
69 module
= tracetool
.try_import("tracetool.backend." + modname
)
71 # just in case; should never fail unless non-module files are put there
76 public
= getattr(module
, "PUBLIC", False)
77 if only_public
and not public
:
83 doc
= doc
.strip().split("\n")[0]
85 name
= modname
.replace("_", "-")
86 res
.append((name
, doc
))
91 """Return whether the given backend exists."""
96 name
= name
.replace("-", "_")
97 return tracetool
.try_import("tracetool.backend." + name
)[1]
101 def __init__(self
, backends
, format
):
102 self
._backends
= [backend
.replace("-", "_") for backend
in backends
]
103 self
._format
= format
.replace("-", "_")
104 for backend
in self
._backends
:
105 assert exists(backend
)
106 assert tracetool
.format
.exists(self
._format
)
108 def _run_function(self
, name
, *args
, **kwargs
):
109 for backend
in self
._backends
:
110 func
= tracetool
.try_import("tracetool.backend." + backend
,
111 name
% self
._format
, None)[1]
113 func(*args
, **kwargs
)
115 def generate_begin(self
, events
, group
):
116 self
._run
_function
("generate_%s_begin", events
, group
)
118 def generate(self
, event
, group
):
119 self
._run
_function
("generate_%s", event
, group
)
121 def generate_backend_dstate(self
, event
, group
):
122 self
._run
_function
("generate_%s_backend_dstate", event
, group
)
124 def generate_end(self
, events
, group
):
125 self
._run
_function
("generate_%s_end", events
, group
)