From patchwork Mon Jul 24 17:18:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 792914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xGSwz1K6Xz9s65 for ; Tue, 25 Jul 2017 03:27:15 +1000 (AEST) Received: from localhost ([::1]:56046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZh0k-00079p-2k for incoming@patchwork.ozlabs.org; Mon, 24 Jul 2017 13:19:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZh0M-00079k-QF for qemu-devel@nongnu.org; Mon, 24 Jul 2017 13:18:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZh0H-0005z9-RI for qemu-devel@nongnu.org; Mon, 24 Jul 2017 13:18:50 -0400 Received: from roura.ac.upc.edu ([147.83.33.10]:41356 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZh0H-0005yO-AX for qemu-devel@nongnu.org; Mon, 24 Jul 2017 13:18:45 -0400 Received: from correu-1.ac.upc.es (correu-1.ac.upc.es [147.83.30.91]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id v6OHIfes032384; Mon, 24 Jul 2017 19:18:41 +0200 Received: from localhost (unknown [31.210.188.120]) by correu-1.ac.upc.es (Postfix) with ESMTPSA id D512E1770; Mon, 24 Jul 2017 19:18:35 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Mon, 24 Jul 2017 20:18:34 +0300 Message-Id: <150091671441.30739.10101532119130561053.stgit@frigg.lan> X-Mailer: git-send-email 2.13.2 In-Reply-To: <150091574424.30739.4131793221953168474.stgit@frigg.lan> References: <150091574424.30739.4131793221953168474.stgit@frigg.lan> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id v6OHIfes032384 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 147.83.33.10 Subject: [Qemu-devel] [PATCH 04/13] instrument: Allow adding the "instrument" property without modifying event files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Emilio G. Cota" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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- --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-" 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 " -__copyright__ = "Copyright 2012-2014, Lluís Vilanova " +__copyright__ = "Copyright 2012-2017, Lluís Vilanova " __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)