2012-04-03 22:47:39 +04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Machinery for generating tracing-related intermediate files.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
2017-07-04 11:46:39 +03:00
|
|
|
__copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
|
2012-04-03 22:47:39 +04:00
|
|
|
__license__ = "GPL version 2 or (at your option) any later version"
|
|
|
|
|
|
|
|
__maintainer__ = "Stefan Hajnoczi"
|
2020-05-11 11:28:16 +03:00
|
|
|
__email__ = "stefanha@redhat.com"
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
import sys
|
2014-05-30 16:11:38 +04:00
|
|
|
import weakref
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
import tracetool.format
|
|
|
|
import tracetool.backend
|
|
|
|
|
|
|
|
|
|
|
|
def error_write(*lines):
|
|
|
|
"""Write a set of error lines."""
|
|
|
|
sys.stderr.writelines("\n".join(lines) + "\n")
|
|
|
|
|
|
|
|
def error(*lines):
|
|
|
|
"""Write a set of error lines and exit."""
|
|
|
|
error_write(*lines)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2020-08-27 17:29:13 +03:00
|
|
|
out_lineno = 1
|
2020-08-27 17:29:12 +03:00
|
|
|
out_filename = '<none>'
|
|
|
|
out_fobj = sys.stdout
|
|
|
|
|
|
|
|
def out_open(filename):
|
|
|
|
global out_filename, out_fobj
|
|
|
|
out_filename = filename
|
|
|
|
out_fobj = open(filename, 'wt')
|
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
def out(*lines, **kwargs):
|
|
|
|
"""Write a set of output lines.
|
|
|
|
|
2020-09-17 10:50:23 +03:00
|
|
|
You can use kwargs as a shorthand for mapping variables when formatting all
|
2012-04-03 22:47:39 +04:00
|
|
|
the strings in lines.
|
2020-08-27 17:29:12 +03:00
|
|
|
|
2020-08-27 17:29:13 +03:00
|
|
|
The 'out_lineno' kwarg is automatically added to reflect the current output
|
|
|
|
file line number. The 'out_next_lineno' kwarg is also automatically added
|
|
|
|
with the next output line number. The 'out_filename' kwarg is automatically
|
|
|
|
added with the output filename.
|
2012-04-03 22:47:39 +04:00
|
|
|
"""
|
2020-08-27 17:29:13 +03:00
|
|
|
global out_lineno
|
2020-08-27 17:29:12 +03:00
|
|
|
output = []
|
|
|
|
for l in lines:
|
2020-08-27 17:29:13 +03:00
|
|
|
kwargs['out_lineno'] = out_lineno
|
|
|
|
kwargs['out_next_lineno'] = out_lineno + 1
|
2020-08-27 17:29:12 +03:00
|
|
|
kwargs['out_filename'] = out_filename
|
|
|
|
output.append(l % kwargs)
|
2020-08-27 17:29:13 +03:00
|
|
|
out_lineno += 1
|
2020-08-27 17:29:12 +03:00
|
|
|
|
|
|
|
out_fobj.writelines("\n".join(output) + "\n")
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2018-03-08 18:55:24 +03:00
|
|
|
# We only want to allow standard C types or fixed sized
|
|
|
|
# integer types. We don't want QEMU specific types
|
|
|
|
# as we can't assume trace backends can resolve all the
|
|
|
|
# typedefs
|
|
|
|
ALLOWED_TYPES = [
|
|
|
|
"int",
|
|
|
|
"long",
|
|
|
|
"short",
|
|
|
|
"char",
|
|
|
|
"bool",
|
|
|
|
"unsigned",
|
|
|
|
"signed",
|
|
|
|
"int8_t",
|
|
|
|
"uint8_t",
|
|
|
|
"int16_t",
|
|
|
|
"uint16_t",
|
|
|
|
"int32_t",
|
|
|
|
"uint32_t",
|
|
|
|
"int64_t",
|
|
|
|
"uint64_t",
|
|
|
|
"void",
|
|
|
|
"size_t",
|
|
|
|
"ssize_t",
|
|
|
|
"uintptr_t",
|
|
|
|
"ptrdiff_t",
|
|
|
|
]
|
|
|
|
|
|
|
|
def validate_type(name):
|
|
|
|
bits = name.split(" ")
|
|
|
|
for bit in bits:
|
2023-11-08 13:56:49 +03:00
|
|
|
bit = re.sub(r"\*", "", bit)
|
2018-03-08 18:55:24 +03:00
|
|
|
if bit == "":
|
|
|
|
continue
|
|
|
|
if bit == "const":
|
|
|
|
continue
|
|
|
|
if bit not in ALLOWED_TYPES:
|
2021-03-03 21:46:41 +03:00
|
|
|
raise ValueError("Argument type '%s' is not allowed. "
|
2018-03-08 18:55:24 +03:00
|
|
|
"Only standard C types and fixed size integer "
|
|
|
|
"types should be used. struct, union, and "
|
|
|
|
"other complex pointer types should be "
|
|
|
|
"declared as 'void *'" % name)
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
class Arguments:
|
|
|
|
"""Event arguments description."""
|
|
|
|
|
|
|
|
def __init__(self, args):
|
|
|
|
"""
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
args :
|
2016-02-25 19:43:04 +03:00
|
|
|
List of (type, name) tuples or Arguments objects.
|
2012-04-03 22:47:39 +04:00
|
|
|
"""
|
2016-02-25 19:43:04 +03:00
|
|
|
self._args = []
|
|
|
|
for arg in args:
|
|
|
|
if isinstance(arg, Arguments):
|
|
|
|
self._args.extend(arg._args)
|
|
|
|
else:
|
|
|
|
self._args.append(arg)
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2014-02-23 23:37:08 +04:00
|
|
|
def copy(self):
|
|
|
|
"""Create a new copy."""
|
|
|
|
return Arguments(list(self._args))
|
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
@staticmethod
|
|
|
|
def build(arg_str):
|
|
|
|
"""Build and Arguments instance from an argument string.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
arg_str : str
|
|
|
|
String describing the event arguments.
|
|
|
|
"""
|
|
|
|
res = []
|
|
|
|
for arg in arg_str.split(","):
|
|
|
|
arg = arg.strip()
|
2018-01-10 23:25:53 +03:00
|
|
|
if not arg:
|
|
|
|
raise ValueError("Empty argument (did you forget to use 'void'?)")
|
2012-04-27 18:12:04 +04:00
|
|
|
if arg == 'void':
|
2012-04-03 22:47:39 +04:00
|
|
|
continue
|
2012-04-27 18:12:04 +04:00
|
|
|
|
|
|
|
if '*' in arg:
|
|
|
|
arg_type, identifier = arg.rsplit('*', 1)
|
|
|
|
arg_type += '*'
|
|
|
|
identifier = identifier.strip()
|
|
|
|
else:
|
|
|
|
arg_type, identifier = arg.rsplit(None, 1)
|
|
|
|
|
2018-03-08 18:55:24 +03:00
|
|
|
validate_type(arg_type)
|
2012-04-27 18:12:04 +04:00
|
|
|
res.append((arg_type, identifier))
|
2012-04-03 22:47:39 +04:00
|
|
|
return Arguments(res)
|
|
|
|
|
2016-02-25 19:43:04 +03:00
|
|
|
def __getitem__(self, index):
|
|
|
|
if isinstance(index, slice):
|
|
|
|
return Arguments(self._args[index])
|
|
|
|
else:
|
|
|
|
return self._args[index]
|
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
def __iter__(self):
|
|
|
|
"""Iterate over the (type, name) pairs."""
|
|
|
|
return iter(self._args)
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
"""Number of arguments."""
|
|
|
|
return len(self._args)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
"""String suitable for declaring function arguments."""
|
|
|
|
if len(self._args) == 0:
|
|
|
|
return "void"
|
|
|
|
else:
|
|
|
|
return ", ".join([ " ".join([t, n]) for t,n in self._args ])
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
"""Evaluable string representation for this object."""
|
|
|
|
return "Arguments(\"%s\")" % str(self)
|
|
|
|
|
|
|
|
def names(self):
|
|
|
|
"""List of argument names."""
|
|
|
|
return [ name for _, name in self._args ]
|
|
|
|
|
|
|
|
def types(self):
|
|
|
|
"""List of argument types."""
|
|
|
|
return [ type_ for type_, _ in self._args ]
|
|
|
|
|
2016-02-25 19:43:27 +03:00
|
|
|
def casted(self):
|
|
|
|
"""List of argument names casted to their type."""
|
|
|
|
return ["(%s)%s" % (type_, name) for type_, name in self._args]
|
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
class Event(object):
|
|
|
|
"""Event description.
|
|
|
|
|
|
|
|
Attributes
|
|
|
|
----------
|
|
|
|
name : str
|
|
|
|
The event name.
|
|
|
|
fmt : str
|
|
|
|
The event format string.
|
|
|
|
properties : set(str)
|
|
|
|
Properties of the event.
|
|
|
|
args : Arguments
|
|
|
|
The event arguments.
|
2020-08-27 17:29:14 +03:00
|
|
|
lineno : int
|
|
|
|
The line number in the input file.
|
|
|
|
filename : str
|
|
|
|
The path to the input file.
|
2014-08-18 17:02:07 +04:00
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
"""
|
|
|
|
|
2023-10-16 09:22:56 +03:00
|
|
|
_CRE = re.compile(r"((?P<props>[\w\s]+)\s+)?"
|
|
|
|
r"(?P<name>\w+)"
|
|
|
|
r"\((?P<args>[^)]*)\)"
|
|
|
|
r"\s*"
|
|
|
|
r"(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
|
|
|
|
r"\s*")
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2022-02-04 23:43:29 +03:00
|
|
|
_VALID_PROPS = set(["disable", "vcpu"])
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2020-08-27 17:29:14 +03:00
|
|
|
def __init__(self, name, props, fmt, args, lineno, filename, orig=None,
|
2016-02-25 16:06:30 +03:00
|
|
|
event_trans=None, event_exec=None):
|
2012-04-03 22:47:39 +04:00
|
|
|
"""
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
name : string
|
|
|
|
Event name.
|
|
|
|
props : list of str
|
|
|
|
Property names.
|
2014-05-30 16:11:44 +04:00
|
|
|
fmt : str, list of str
|
2018-01-10 23:25:52 +03:00
|
|
|
Event printing format string(s).
|
2012-04-03 22:47:39 +04:00
|
|
|
args : Arguments
|
|
|
|
Event arguments.
|
2020-08-27 17:29:14 +03:00
|
|
|
lineno : int
|
|
|
|
The line number in the input file.
|
|
|
|
filename : str
|
|
|
|
The path to the input file.
|
2014-05-30 16:11:38 +04:00
|
|
|
orig : Event or None
|
2016-02-25 16:06:30 +03:00
|
|
|
Original Event before transformation/generation.
|
|
|
|
event_trans : Event or None
|
|
|
|
Generated translation-time event ("tcg" property).
|
|
|
|
event_exec : Event or None
|
|
|
|
Generated execution-time event ("tcg" property).
|
2014-08-01 20:08:56 +04:00
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
"""
|
|
|
|
self.name = name
|
|
|
|
self.properties = props
|
|
|
|
self.fmt = fmt
|
|
|
|
self.args = args
|
2020-08-27 17:29:14 +03:00
|
|
|
self.lineno = int(lineno)
|
|
|
|
self.filename = str(filename)
|
2016-02-25 16:06:30 +03:00
|
|
|
self.event_trans = event_trans
|
|
|
|
self.event_exec = event_exec
|
2012-04-03 22:47:39 +04:00
|
|
|
|
trace: disallow more than 10 arguments per trace event
The UST trace backend can only cope with upto 10 arguments. To ensure we
don't exceed the limit when UST is not compiled in, disallow more than
10 arguments upfront.
This prevents the case where:
commit 0fc8aec7de64f2bf83a274a2a38b938ce03425d2
Author: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
Date: Tue Apr 18 10:20:20 2017 +0800
COLO-compare: Optimize tcp compare trace event
Optimize two trace events as one, adjust print format make
it easy to read. rename trace_colo_compare_pkt_info_src/dst
to trace_colo_compare_tcp_info.
regressed the fix done in
commit 2dfe5113b11ce0ddb08176ebb54ab7ac4104b413
Author: Alex Bennée <alex.bennee@linaro.org>
Date: Fri Oct 28 14:25:59 2016 +0100
net: split colo_compare_pkt_info into two trace events
It seems there is a limit to the number of arguments a UST trace event
can take and at 11 the previous trace command broke the build. Split the
trace into a src pkt and dst pkt trace to fix this.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-id: 20161028132559.8324-1-alex.bennee@linaro.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Now we get an immediate fail even when UST is disabled:
GEN net/trace.h
Traceback (most recent call last):
File "/home/berrange/src/virt/qemu/scripts/tracetool.py", line 154, in <module>
main(sys.argv)
File "/home/berrange/src/virt/qemu/scripts/tracetool.py", line 145, in main
events.extend(tracetool.read_events(fh))
File "/home/berrange/src/virt/qemu/scripts/tracetool/__init__.py", line 307, in read_events
event = Event.build(line)
File "/home/berrange/src/virt/qemu/scripts/tracetool/__init__.py", line 244, in build
event = Event(name, props, fmt, args)
File "/home/berrange/src/virt/qemu/scripts/tracetool/__init__.py", line 196, in __init__
"argument count" % name)
ValueError: Event 'colo_compare_tcp_info' has more than maximum permitted argument count
Makefile:96: recipe for target 'net/trace.h-timestamp' failed
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20170426153900.21066-1-berrange@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2017-04-26 18:39:00 +03:00
|
|
|
if len(args) > 10:
|
|
|
|
raise ValueError("Event '%s' has more than maximum permitted "
|
|
|
|
"argument count" % name)
|
|
|
|
|
2014-05-30 16:11:38 +04:00
|
|
|
if orig is None:
|
|
|
|
self.original = weakref.ref(self)
|
|
|
|
else:
|
|
|
|
self.original = orig
|
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
unknown_props = set(self.properties) - self._VALID_PROPS
|
|
|
|
if len(unknown_props) > 0:
|
2014-02-23 23:37:13 +04:00
|
|
|
raise ValueError("Unknown properties: %s"
|
|
|
|
% ", ".join(unknown_props))
|
2014-05-30 16:11:44 +04:00
|
|
|
assert isinstance(self.fmt, str) or len(self.fmt) == 2
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2014-02-23 23:37:08 +04:00
|
|
|
def copy(self):
|
|
|
|
"""Create a new copy."""
|
|
|
|
return Event(self.name, list(self.properties), self.fmt,
|
2020-08-27 17:29:14 +03:00
|
|
|
self.args.copy(), self.lineno, self.filename,
|
|
|
|
self, self.event_trans, self.event_exec)
|
2014-02-23 23:37:08 +04:00
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
@staticmethod
|
2020-08-27 17:29:14 +03:00
|
|
|
def build(line_str, lineno, filename):
|
2012-04-03 22:47:39 +04:00
|
|
|
"""Build an Event instance from a string.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
line_str : str
|
|
|
|
Line describing the event.
|
2020-08-27 17:29:14 +03:00
|
|
|
lineno : int
|
|
|
|
Line number in input file.
|
|
|
|
filename : str
|
|
|
|
Path to input file.
|
2012-04-03 22:47:39 +04:00
|
|
|
"""
|
|
|
|
m = Event._CRE.match(line_str)
|
|
|
|
assert m is not None
|
|
|
|
groups = m.groupdict('')
|
|
|
|
|
|
|
|
name = groups["name"]
|
|
|
|
props = groups["props"].split()
|
|
|
|
fmt = groups["fmt"]
|
2014-05-30 16:11:44 +04:00
|
|
|
fmt_trans = groups["fmt_trans"]
|
2019-01-23 15:00:15 +03:00
|
|
|
if fmt.find("%m") != -1 or fmt_trans.find("%m") != -1:
|
|
|
|
raise ValueError("Event format '%m' is forbidden, pass the error "
|
|
|
|
"as an explicit trace argument")
|
2019-09-16 12:51:21 +03:00
|
|
|
if fmt.endswith(r'\n"'):
|
|
|
|
raise ValueError("Event format must not end with a newline "
|
|
|
|
"character")
|
2019-01-23 15:00:15 +03:00
|
|
|
|
2014-05-30 16:11:44 +04:00
|
|
|
if len(fmt_trans) > 0:
|
|
|
|
fmt = [fmt_trans, fmt]
|
2012-04-03 22:47:39 +04:00
|
|
|
args = Arguments.build(groups["args"])
|
|
|
|
|
2020-08-27 17:29:14 +03:00
|
|
|
event = Event(name, props, fmt, args, lineno, filename)
|
2016-02-25 19:43:38 +03:00
|
|
|
|
|
|
|
# add implicit arguments when using the 'vcpu' property
|
|
|
|
import tracetool.vcpu
|
|
|
|
event = tracetool.vcpu.transform_event(event)
|
|
|
|
|
|
|
|
return event
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
"""Evaluable string representation for this object."""
|
2014-05-30 16:11:44 +04:00
|
|
|
if isinstance(self.fmt, str):
|
|
|
|
fmt = self.fmt
|
|
|
|
else:
|
|
|
|
fmt = "%s, %s" % (self.fmt[0], self.fmt[1])
|
2012-04-03 22:47:39 +04:00
|
|
|
return "Event('%s %s(%s) %s')" % (" ".join(self.properties),
|
|
|
|
self.name,
|
|
|
|
self.args,
|
2014-05-30 16:11:44 +04:00
|
|
|
fmt)
|
2018-01-29 07:16:47 +03:00
|
|
|
# Star matching on PRI is dangerous as one might have multiple
|
|
|
|
# arguments with that format, hence the non-greedy version of it.
|
2023-10-16 09:22:56 +03:00
|
|
|
_FMT = re.compile(r"(%[\d\.]*\w+|%.*?PRI\S+)")
|
2014-08-18 17:02:07 +04:00
|
|
|
|
|
|
|
def formats(self):
|
2018-01-10 23:25:52 +03:00
|
|
|
"""List conversion specifiers in the argument print format string."""
|
2014-08-18 17:02:07 +04:00
|
|
|
assert not isinstance(self.fmt, list)
|
|
|
|
return self._FMT.findall(self.fmt)
|
|
|
|
|
2014-02-23 23:37:02 +04:00
|
|
|
QEMU_TRACE = "trace_%(name)s"
|
2017-07-04 11:46:39 +03:00
|
|
|
QEMU_TRACE_NOCHECK = "_nocheck__" + QEMU_TRACE
|
2014-05-30 16:11:50 +04:00
|
|
|
QEMU_TRACE_TCG = QEMU_TRACE + "_tcg"
|
2016-10-04 16:35:45 +03:00
|
|
|
QEMU_DSTATE = "_TRACE_%(NAME)s_DSTATE"
|
2017-07-31 17:07:17 +03:00
|
|
|
QEMU_BACKEND_DSTATE = "TRACE_%(NAME)s_BACKEND_DSTATE"
|
2016-10-04 16:35:48 +03:00
|
|
|
QEMU_EVENT = "_TRACE_%(NAME)s_EVENT"
|
2014-02-23 23:37:02 +04:00
|
|
|
|
|
|
|
def api(self, fmt=None):
|
|
|
|
if fmt is None:
|
|
|
|
fmt = Event.QEMU_TRACE
|
2016-10-04 16:35:45 +03:00
|
|
|
return fmt % {"name": self.name, "NAME": self.name.upper()}
|
2014-02-23 23:37:02 +04:00
|
|
|
|
|
|
|
|
2018-03-06 18:46:50 +03:00
|
|
|
def read_events(fobj, fname):
|
2016-10-04 16:35:56 +03:00
|
|
|
"""Generate the output for the given (format, backends) pair.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
fobj : file
|
|
|
|
Event description file.
|
2018-03-06 18:46:50 +03:00
|
|
|
fname : str
|
|
|
|
Name of event file
|
2016-10-04 16:35:56 +03:00
|
|
|
|
|
|
|
Returns a list of Event objects
|
|
|
|
"""
|
|
|
|
|
2014-11-03 00:37:59 +03:00
|
|
|
events = []
|
2018-01-10 23:25:51 +03:00
|
|
|
for lineno, line in enumerate(fobj, 1):
|
2019-01-23 15:00:14 +03:00
|
|
|
if line[-1] != '\n':
|
|
|
|
raise ValueError("%s does not end with a new line" % fname)
|
2012-04-03 22:47:39 +04:00
|
|
|
if not line.strip():
|
|
|
|
continue
|
|
|
|
if line.lstrip().startswith('#'):
|
|
|
|
continue
|
2014-11-03 00:37:59 +03:00
|
|
|
|
2018-01-10 23:25:51 +03:00
|
|
|
try:
|
2020-08-27 17:29:14 +03:00
|
|
|
event = Event.build(line, lineno, fname)
|
2018-01-10 23:25:51 +03:00
|
|
|
except ValueError as e:
|
2018-03-06 18:46:50 +03:00
|
|
|
arg0 = 'Error at %s:%d: %s' % (fname, lineno, e.args[0])
|
2018-01-10 23:25:51 +03:00
|
|
|
e.args = (arg0,) + e.args[1:]
|
|
|
|
raise
|
2014-11-03 00:37:59 +03:00
|
|
|
|
2022-02-04 23:43:29 +03:00
|
|
|
events.append(event)
|
2014-11-03 00:37:59 +03:00
|
|
|
|
|
|
|
return events
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
|
|
|
|
class TracetoolError (Exception):
|
|
|
|
"""Exception for calls to generate."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2014-02-23 23:37:13 +04:00
|
|
|
def try_import(mod_name, attr_name=None, attr_default=None):
|
2012-04-03 22:47:39 +04:00
|
|
|
"""Try to import a module and get an attribute from it.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
mod_name : str
|
|
|
|
Module name.
|
|
|
|
attr_name : str, optional
|
|
|
|
Name of an attribute in the module.
|
|
|
|
attr_default : optional
|
|
|
|
Default value if the attribute does not exist in the module.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
A pair indicating whether the module could be imported and the module or
|
|
|
|
object or attribute value.
|
|
|
|
"""
|
|
|
|
try:
|
2012-04-27 17:24:41 +04:00
|
|
|
module = __import__(mod_name, globals(), locals(), ["__package__"])
|
2012-04-03 22:47:39 +04:00
|
|
|
if attr_name is None:
|
|
|
|
return True, module
|
|
|
|
return True, getattr(module, str(attr_name), attr_default)
|
|
|
|
except ImportError:
|
|
|
|
return False, None
|
|
|
|
|
|
|
|
|
2016-10-04 16:35:59 +03:00
|
|
|
def generate(events, group, format, backends,
|
2014-02-23 23:37:13 +04:00
|
|
|
binary=None, probe_prefix=None):
|
2014-05-27 17:02:14 +04:00
|
|
|
"""Generate the output for the given (format, backends) pair.
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
2016-10-04 16:35:57 +03:00
|
|
|
events : list
|
|
|
|
list of Event objects to generate for
|
2016-10-04 16:35:59 +03:00
|
|
|
group: str
|
|
|
|
Name of the tracing group
|
2012-04-03 22:47:39 +04:00
|
|
|
format : str
|
|
|
|
Output format name.
|
2014-05-27 17:02:14 +04:00
|
|
|
backends : list
|
|
|
|
Output backend names.
|
2012-04-03 22:48:12 +04:00
|
|
|
binary : str or None
|
|
|
|
See tracetool.backend.dtrace.BINARY.
|
|
|
|
probe_prefix : str or None
|
|
|
|
See tracetool.backend.dtrace.PROBEPREFIX.
|
2012-04-03 22:47:39 +04:00
|
|
|
"""
|
|
|
|
# fix strange python error (UnboundLocalError tracetool)
|
|
|
|
import tracetool
|
|
|
|
|
|
|
|
format = str(format)
|
2019-10-10 15:21:54 +03:00
|
|
|
if len(format) == 0:
|
2012-04-03 22:47:39 +04:00
|
|
|
raise TracetoolError("format not set")
|
2014-02-23 23:37:19 +04:00
|
|
|
if not tracetool.format.exists(format):
|
2012-04-03 22:47:39 +04:00
|
|
|
raise TracetoolError("unknown format: %s" % format)
|
2014-05-27 17:02:14 +04:00
|
|
|
|
2019-10-10 15:21:54 +03:00
|
|
|
if len(backends) == 0:
|
2014-05-27 17:02:14 +04:00
|
|
|
raise TracetoolError("no backends specified")
|
|
|
|
for backend in backends:
|
|
|
|
if not tracetool.backend.exists(backend):
|
|
|
|
raise TracetoolError("unknown backend: %s" % backend)
|
|
|
|
backend = tracetool.backend.Wrapper(backends, format)
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2012-04-03 22:48:12 +04:00
|
|
|
import tracetool.backend.dtrace
|
|
|
|
tracetool.backend.dtrace.BINARY = binary
|
|
|
|
tracetool.backend.dtrace.PROBEPREFIX = probe_prefix
|
|
|
|
|
2016-10-04 16:35:59 +03:00
|
|
|
tracetool.format.generate(events, format, backend, group)
|