Adds a configure argument to allow users to add the instrument property to events without having to modify any trace event files.
Signed-off-by: Lluís Vilanova <vilan...@ac.upc.edu> --- configure | 17 +++++++++++++++++ rules.mak | 3 +++ scripts/tracetool.py | 11 +++++++++-- scripts/tracetool/__init__.py | 20 +++++++++++++++++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 13191052cb..8ab2a36130 100755 --- a/configure +++ b/configure @@ -353,6 +353,7 @@ trace_backends="log" trace_file="trace" trace_instrument="no" trace_instrument_backend="none" +instrument_events="" spice="" rbd="" smartcard="" @@ -901,6 +902,13 @@ for opt do trace_instrument="yes" trace_instrument_backend="dynamic" ;; + --with-instrument-events=*) + if test ! -f "$optarg"; then + echo "ERROR: no such file: $optarg" + exit 1 + fi + instrument_events="`realpath $optarg`" + ;; --enable-gprof) gprof="yes" ;; --enable-gcov) gcov="yes" @@ -1433,6 +1441,9 @@ Advanced options (experts only): Default:trace-<pid> --enable-trace-instrument Enable trace instrumentation + --with-instrument-events=FILE + File with a list of events to enable instrumentation + on (one per line) --disable-slirp disable SLIRP userspace network connectivity --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI) --oss-lib path to OSS library @@ -5291,6 +5302,9 @@ if have_backend "simple"; then echo "Trace output file $trace_file-<pid>" fi echo "Trace instrumentation $trace_instrument" +if test -n "$instrument_events"; then +echo "Instrument events $instrument_events" +fi echo "spice support $spice $(echo_version $spice $spice_protocol_version/$spice_server_version)" echo "rbd support $rbd" echo "xfsctl support $xfs" @@ -6004,6 +6018,9 @@ echo "TRACE_INSTRUMENT_BACKEND=instr-$trace_instrument_backend" >> $config_host_ if test "$trace_instrument" = "yes"; then echo "CONFIG_INSTRUMENT=y" >> $config_host_mak fi +if test -n "$instrument_events"; then + echo "CONFIG_INSTRUMENT_EVENTS=$instrument_events" >> $config_host_mak +fi ########################################## echo "TOOLS=$tools" >> $config_host_mak diff --git a/rules.mak b/rules.mak index 6e943335f3..fbeda68022 100644 --- a/rules.mak +++ b/rules.mak @@ -188,6 +188,9 @@ notempty = $(if $1,y,n) # Generate files with tracetool TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py +ifdef CONFIG_INSTRUMENT_EVENTS +TRACETOOL += --instrument=$(CONFIG_INSTRUMENT_EVENTS) +endif # Generate timestamp files for .h include files diff --git a/scripts/tracetool.py b/scripts/tracetool.py index c55a21518b..d5d212e98f 100755 --- a/scripts/tracetool.py +++ b/scripts/tracetool.py @@ -6,7 +6,7 @@ Command-line wrapper for the tracetool machinery. """ __author__ = "Lluís Vilanova <vilan...@ac.upc.edu>" -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilan...@ac.upc.edu>" +__copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilan...@ac.upc.edu>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" @@ -70,6 +70,7 @@ def main(args): long_opts = ["backends=", "format=", "help", "list-backends", "check-backends", "group="] long_opts += ["binary=", "target-type=", "target-name=", "probe-prefix="] + long_opts += ["instrument="] try: opts, args = getopt.getopt(args[1:], "", long_opts) @@ -84,6 +85,7 @@ def main(args): target_type = None target_name = None probe_prefix = None + instrument = None for opt, arg in opts: if opt == "--help": error_opt() @@ -111,6 +113,9 @@ def main(args): elif opt == '--probe-prefix': probe_prefix = arg + elif opt == "--instrument": + instrument = arg + else: error_opt("unhandled option: %s" % opt) @@ -137,12 +142,14 @@ def main(args): if probe_prefix is None: probe_prefix = ".".join(["qemu", target_type, target_name]) + instrument_cre = tracetool.read_instrument(instrument) + if len(args) < 1: error_opt("missing trace-events filepath") events = [] for arg in args: with open(arg, "r") as fh: - events.extend(tracetool.read_events(fh)) + events.extend(tracetool.read_events(fh, instrument_cre)) try: tracetool.generate(events, arg_group, arg_format, arg_backends, diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index e65349bc33..b9ddf8fbf9 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -292,13 +292,26 @@ class Event(object): self) -def read_events(fobj): +def read_instrument(path): + if path is None: + return None + + with open(path) as f: + patterns = f.readlines() + patterns = [p.replace("\n", "") for p in patterns] + patterns = [p.replace("*", ".*") for p in patterns] + pattern = "|".join(patterns) + return re.compile(pattern) + +def read_events(fobj, instrument): """Generate the output for the given (format, backends) pair. Parameters ---------- fobj : file Event description file. + instrument : cre or None + Event patterns to instrument. Returns a list of Event objects """ @@ -312,6 +325,11 @@ def read_events(fobj): event = Event.build(line) + if instrument is not None and instrument.match(event.name): + event.properties = [p for p in event.properties + if p != "disable"] + event.properties.append("instrument") + # transform TCG-enabled events if "tcg" not in event.properties: events.append(event)