From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYxRn-0000Hq-Mc for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:03:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYxRh-0008Ti-UQ for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:03:19 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:37970 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYxRh-0008Te-HX for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:03:13 -0500 From: =?utf-8?b?TGx1w61z?= Vilanova Date: Thu, 25 Feb 2016 16:03:12 +0100 Message-Id: <145641259192.30097.6270551195105705484.stgit@localhost> In-Reply-To: <145641255678.30097.2919142707547689749.stgit@localhost> References: <145641255678.30097.2919142707547689749.stgit@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 5/6] trace: Conditionally trace events based on their per-vCPU state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Stefan Hajnoczi 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=C3=ADs Vilanova --- 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 | 18 ++++++++++++++++-- 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/back= end/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. """ =20 __author__ =3D "Llu=C3=ADs Vilanova " -__copyright__ =3D "Copyright 2012-2014, Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2016, Llu=C3=ADs Vilanova " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" @@ -41,6 +41,6 @@ def generate_h_begin(events): =20 =20 def generate_h(event): - out(' QEMU_%(uppername)s(%(argnames)s);', + out(' QEMU_%(uppername)s(%(argnames)s);', uppername=3Devent.name.upper(), argnames=3D", ".join(event.args.names())) diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/back= end/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 =3D ", " + argnames =20 - out(' {', - ' char ftrace_buf[MAX_TRACE_STRLEN];', - ' int unused __attribute__ ((unused));', - ' int trlen;', - ' if (trace_event_get_state(%(event_id)s)) {', - ' trlen =3D snprintf(ftrace_buf, MAX_TRACE_STRLEN,', - ' "%(name)s " %(fmt)s "\\n" %(argnam= es)s);', - ' trlen =3D MIN(trlen, MAX_TRACE_STRLEN - 1);', - ' unused =3D 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 =3D snprintf(ftrace_buf, MAX_TRACE_STRLEN= ,', + ' "%(name)s " %(fmt)s "\\n" %(ar= gnames)s);', + ' trlen =3D MIN(trlen, MAX_TRACE_STRLEN - 1);', + ' unused =3D write(trace_marker_fd, ftrace_buf, t= rlen);', + ' }', ' }', - ' }', name=3Devent.name, args=3Devent.args, event_id=3D"TRACE_" + event.name.upper(), diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend= /log.py index a62c310..2581f6e 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -6,7 +6,7 @@ Stderr built-in backend. """ =20 __author__ =3D "Llu=C3=ADs Vilanova " -__copyright__ =3D "Copyright 2012-2014, Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2016, Llu=C3=ADs Vilanova " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" @@ -34,15 +34,21 @@ def generate_h(event): if len(event.args) > 0: argnames =3D ", " + argnames =20 - 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=3D"TRACE_" + event.name.upper(), + if "vcpu" in event.properties: + # already checked on the generic format code + cond =3D "true" + else: + cond =3D "trace_event_get_state(%s)" % ("TRACE_" + event.name.up= per()) + + 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=3Dcond, name=3Devent.name, fmt=3Devent.fmt.rstrip("\n"), argnames=3Dargnames) diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/back= end/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): =20 =20 def generate_h(event): - out(' _simple_%(api)s(%(args)s);', + out(' _simple_%(api)s(%(args)s);', api=3Devent.api(), args=3D", ".join(event.args.names())) =20 @@ -68,16 +68,23 @@ def generate_c(event): if len(event.args) =3D=3D 0: sizestr =3D '0' =20 + event_id =3D 'TRACE_' + event.name.upper() + if "vcpu" in event.properties: + # already checked on the generic format code + cond =3D "true" + else: + cond =3D "trace_event_get_state(%s)" % event_id =20 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=3D'TRACE_' + event.name.upper(), + cond=3Dcond, + event_id=3Devent_id, size_str=3Dsizestr) =20 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. """ =20 __author__ =3D "Llu=C3=ADs Vilanova " -__copyright__ =3D "Copyright 2012-2014, Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2016, Llu=C3=ADs Vilanova " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" @@ -30,6 +30,6 @@ def generate_h(event): if len(event.args) > 0: argnames =3D ", " + argnames =20 - out(' tracepoint(qemu, %(name)s%(tp_args)s);', + out(' tracepoint(qemu, %(name)s%(tp_args)s);', name=3Devent.name, tp_args=3Dargnames) diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.p= y index 2bd68a2..52b24e8 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -29,16 +29,30 @@ def generate(events, backend): backend.generate_begin(events) =20 for e in events: + if "vcpu" in e.properties: + trace_cpu =3D next(iter(e.args))[1] + cond =3D "trace_event_get_cpu_state(%(cpu)s,"\ + " TRACE_%(id)s,"\ + " TRACE_VCPU_%(id)s)"\ + % dict( + cpu=3Dtrace_cpu, + id=3De.name.upper()) + else: + cond =3D "true" + out('', 'static inline void %(api)s(%(args)s)', '{', + ' if (%(cond)s) {', api=3De.api(), - args=3De.args) + args=3De.args, + cond=3Dcond) =20 if "disable" not in e.properties: backend.generate(e) =20 - out('}') + out(' }', + '}') =20 backend.generate_end(events) =20