From patchwork Mon Jul 18 22:00:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9235471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AA5DB602F0 for ; Mon, 18 Jul 2016 22:11:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 978AC205AD for ; Mon, 18 Jul 2016 22:11:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BFDB252D2; Mon, 18 Jul 2016 22:11:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B213D205AD for ; Mon, 18 Jul 2016 22:11:20 +0000 (UTC) Received: from localhost ([::1]:50566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPGkw-0001hq-O2 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jul 2016 18:11:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPGah-00069c-26 for qemu-devel@nongnu.org; Mon, 18 Jul 2016 18:00:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPGab-0005jV-Ru for qemu-devel@nongnu.org; Mon, 18 Jul 2016 18:00:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35511) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPGab-0005jQ-KR for qemu-devel@nongnu.org; Mon, 18 Jul 2016 18:00:37 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2329F7DF33; Mon, 18 Jul 2016 22:00:37 +0000 (UTC) Received: from localhost (ovpn-112-31.ams2.redhat.com [10.36.112.31]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6IM0Zcb001512; Mon, 18 Jul 2016 18:00:36 -0400 From: Stefan Hajnoczi To: Date: Mon, 18 Jul 2016 23:00:17 +0100 Message-Id: <1468879219-24500-8-git-send-email-stefanha@redhat.com> In-Reply-To: <1468879219-24500-1-git-send-email-stefanha@redhat.com> References: <1468879219-24500-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 18 Jul 2016 22:00:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/9] trace: Conditionally trace events based on their per-vCPU state 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: Peter Maydell , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Lluís Vilanova Events with the 'vcpu' property are conditionally emitted according to their per-vCPU state. Other events are emitted normally based on their global tracing state. Note that the per-vCPU condition check applies to all tracing backends. Signed-off-by: Lluís Vilanova Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi --- scripts/tracetool/backend/dtrace.py | 4 ++-- scripts/tracetool/backend/ftrace.py | 20 ++++++++++---------- scripts/tracetool/backend/log.py | 26 ++++++++++++++++---------- scripts/tracetool/backend/simple.py | 13 ++++++++++--- scripts/tracetool/backend/ust.py | 4 ++-- scripts/tracetool/format/h.py | 19 +++++++++++++++++-- 6 files changed, 57 insertions(+), 29 deletions(-) diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py index fabfe99..ab9ecfa 100644 --- a/scripts/tracetool/backend/dtrace.py +++ b/scripts/tracetool/backend/dtrace.py @@ -6,7 +6,7 @@ DTrace/SystemTAP backend. """ __author__ = "Lluís Vilanova " -__copyright__ = "Copyright 2012-2014, Lluís Vilanova " +__copyright__ = "Copyright 2012-2016, Lluís Vilanova " __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" @@ -41,6 +41,6 @@ def generate_h_begin(events): def generate_h(event): - out(' QEMU_%(uppername)s(%(argnames)s);', + out(' QEMU_%(uppername)s(%(argnames)s);', uppername=event.name.upper(), argnames=", ".join(event.args.names())) diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backend/ftrace.py index d798c71..80dcf30 100644 --- a/scripts/tracetool/backend/ftrace.py +++ b/scripts/tracetool/backend/ftrace.py @@ -30,17 +30,17 @@ def generate_h(event): if len(event.args) > 0: argnames = ", " + argnames - out(' {', - ' char ftrace_buf[MAX_TRACE_STRLEN];', - ' int unused __attribute__ ((unused));', - ' int trlen;', - ' if (trace_event_get_state(%(event_id)s)) {', - ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,', - ' "%(name)s " %(fmt)s "\\n" %(argnames)s);', - ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);', - ' unused = write(trace_marker_fd, ftrace_buf, trlen);', + out(' {', + ' char ftrace_buf[MAX_TRACE_STRLEN];', + ' int unused __attribute__ ((unused));', + ' int trlen;', + ' if (trace_event_get_state(%(event_id)s)) {', + ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,', + ' "%(name)s " %(fmt)s "\\n" %(argnames)s);', + ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);', + ' unused = write(trace_marker_fd, ftrace_buf, trlen);', + ' }', ' }', - ' }', name=event.name, args=event.args, event_id="TRACE_" + event.name.upper(), diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py index e409b73..b3ff064 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -6,7 +6,7 @@ Stderr built-in backend. """ __author__ = "Lluís Vilanova " -__copyright__ = "Copyright 2012-2014, Lluís Vilanova " +__copyright__ = "Copyright 2012-2016, Lluís Vilanova " __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" @@ -30,15 +30,21 @@ def generate_h(event): if len(event.args) > 0: argnames = ", " + argnames - out(' if (trace_event_get_state(%(event_id)s)) {', - ' struct timeval _now;', - ' gettimeofday(&_now, NULL);', - ' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",', - ' getpid(),', - ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', - ' %(argnames)s);', - ' }', - event_id="TRACE_" + event.name.upper(), + if "vcpu" in event.properties: + # already checked on the generic format code + cond = "true" + else: + cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) + + out(' if (%(cond)s) {', + ' struct timeval _now;', + ' gettimeofday(&_now, NULL);', + ' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",', + ' getpid(),', + ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', + ' %(argnames)s);', + ' }', + cond=cond, name=event.name, fmt=event.fmt.rstrip("\n"), argnames=argnames) diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py index 3246c20..1bccada 100644 --- a/scripts/tracetool/backend/simple.py +++ b/scripts/tracetool/backend/simple.py @@ -36,7 +36,7 @@ def generate_h_begin(events): def generate_h(event): - out(' _simple_%(api)s(%(args)s);', + out(' _simple_%(api)s(%(args)s);', api=event.api(), args=", ".join(event.args.names())) @@ -68,16 +68,23 @@ def generate_c(event): if len(event.args) == 0: sizestr = '0' + event_id = 'TRACE_' + event.name.upper() + if "vcpu" in event.properties: + # already checked on the generic format code + cond = "true" + else: + cond = "trace_event_get_state(%s)" % event_id out('', - ' if (!trace_event_get_state(%(event_id)s)) {', + ' if (!%(cond)s) {', ' return;', ' }', '', ' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {', ' return; /* Trace Buffer Full, Event Dropped ! */', ' }', - event_id='TRACE_' + event.name.upper(), + cond=cond, + event_id=event_id, size_str=sizestr) if len(event.args) > 0: diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/ust.py index 2f8f44a..ed4c227 100644 --- a/scripts/tracetool/backend/ust.py +++ b/scripts/tracetool/backend/ust.py @@ -6,7 +6,7 @@ LTTng User Space Tracing backend. """ __author__ = "Lluís Vilanova " -__copyright__ = "Copyright 2012-2014, Lluís Vilanova " +__copyright__ = "Copyright 2012-2016, Lluís Vilanova " __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" @@ -30,6 +30,6 @@ def generate_h(event): if len(event.args) > 0: argnames = ", " + argnames - out(' tracepoint(qemu, %(name)s%(tp_args)s);', + out(' tracepoint(qemu, %(name)s%(tp_args)s);', name=event.name, tp_args=argnames) diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py index 0835406..3763e9a 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -23,21 +23,36 @@ def generate(events, backend): '#define TRACE__GENERATED_TRACERS_H', '', '#include "qemu-common.h"', + '#include "trace/control.h"', '') backend.generate_begin(events) for e in events: + if "vcpu" in e.properties: + trace_cpu = next(iter(e.args))[1] + cond = "trace_event_get_vcpu_state(%(cpu)s,"\ + " TRACE_%(id)s,"\ + " TRACE_VCPU_%(id)s)"\ + % dict( + cpu=trace_cpu, + id=e.name.upper()) + else: + cond = "true" + out('', 'static inline void %(api)s(%(args)s)', '{', + ' if (%(cond)s) {', api=e.api(), - args=e.args) + args=e.args, + cond=cond) if "disable" not in e.properties: backend.generate(e) - out('}') + out(' }', + '}') backend.generate_end(events)