From nobody Sun Sep 28 16:59:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1758281377; cv=none; d=zohomail.com; s=zohoarc; b=Ll8eZLyC93N6P3KvihifX/rP7XgYyTk8Ho0nkNF38JzdH+BsM980RND/fjo3CHToveujwyWfRF1S0u9zRHyIxGWbz8GgzXVKNGsYTicfV7A6vFFYnex2RD+saZUL9+7U/tJg1o7zffSk2gigVTVZuSvrGmP7wubUCOxM7epqBNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758281377; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XE480yyfhzYbFzSjQEPQSJUuYLlL1XqwbZWj8rCIyyA=; b=hUaIh+TepIXNnLQna1OtyYiUFsdcawN3nWpy4lJ0RnvDe/RJwhj87PjjNtCiIQ2fk0uN6XEOrP20jdJQB0jeS8IUohHtnPyzKcNRAjB9sssBOp8GAvo8SXIFYIm7YbUODyFqsSXaWaHmtgeZeN9FyuVKMPPiHn6pKTLNWZNi1AU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758281377510736.1903572900814; Fri, 19 Sep 2025 04:29:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZG4-0001iU-Qc; Fri, 19 Sep 2025 07:26:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzZFz-0001eI-69 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:26:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzZFp-00018b-Hp for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:26:26 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-If0gFn-7PjSB-LS-Dxjn-Q-1; Fri, 19 Sep 2025 07:26:11 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 147141955F28; Fri, 19 Sep 2025 11:26:10 +0000 (UTC) Received: from avogadro.redhat.com (unknown [10.44.33.250]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 557D630002C5; Fri, 19 Sep 2025 11:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758281176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XE480yyfhzYbFzSjQEPQSJUuYLlL1XqwbZWj8rCIyyA=; b=MUML0hYPfziFMmTvvIRHXvai+2PlW6OiXSGWRJmi2ZytfMKXanJ3xbNfKt4lPPAeKkWpdg doUi0dchhLSCvgVF8ZF2LLkUM1qJgJrCPp4+qwG/6gSX+G9IHsFPmDjKLs+lF29jHuuz8b nX9TsyJJnfT5DJsbK1F3HKY/LPxWOcE= X-MC-Unique: If0gFn-7PjSB-LS-Dxjn-Q-1 X-Mimecast-MFC-AGG-ID: If0gFn-7PjSB-LS-Dxjn-Q_1758281170 From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Tanish Desai , Zhao Liu , Stefan Hajnoczi , Manos Pitsidianakis , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Mads Ynddal Subject: [PATCH 06/16] tracetool: add CHECK_TRACE_EVENT_GET_STATE Date: Fri, 19 Sep 2025 13:25:26 +0200 Message-ID: <20250919112536.141782-7-pbonzini@redhat.com> In-Reply-To: <20250919112536.141782-1-pbonzini@redhat.com> References: <20250919112536.141782-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.105, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1758281377988116600 Content-Type: text/plain; charset="utf-8" From: Tanish Desai Add a new attribute CHECK_TRACE_EVENT_GET_STATE to the backends. When present and True, the code generated by the generate function is wrapped in a conditional that checks whether the event is enabled; this removes the need for repeating the same conditional in multiple backends. Signed-off-by: Tanish Desai Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- scripts/tracetool/backend/__init__.py | 39 ++++++++++++++++++--------- scripts/tracetool/format/h.py | 11 +++++--- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/back= end/__init__.py index bf91e443e99..9109a783c72 100644 --- a/scripts/tracetool/backend/__init__.py +++ b/scripts/tracetool/backend/__init__.py @@ -19,11 +19,15 @@ Backend attributes ------------------ =20 -=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D -Attribute Description -=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D -PUBLIC If exists and is set to 'True', the backend is considered "publi= c". -=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D +Attribute Description +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D +PUBLIC If exists and is set to 'True', the backend is + considered "public". +CHECK_TRACE_EVENT_GET_STATE If exists and is set to 'True', the backend-sp= ecific + code inside the tracepoint is emitted within an + ``if trace_event_get_state()`` conditional. +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D =20 =20 Backend functions @@ -101,22 +105,33 @@ class Wrapper: def __init__(self, backends, format): self._backends =3D [backend.replace("-", "_") for backend in backe= nds] self._format =3D format.replace("-", "_") + self.check_trace_event_get_state =3D False for backend in self._backends: assert exists(backend) assert tracetool.format.exists(self._format) + for backend in self.backend_modules(): + check_trace_event_get_state =3D getattr(backend, "CHECK_TRACE_= EVENT_GET_STATE", False) + self.check_trace_event_get_state =3D self.check_trace_event_ge= t_state or check_trace_event_get_state =20 - def _run_function(self, name, *args, **kwargs): + def backend_modules(self): for backend in self._backends: - func =3D tracetool.try_import("tracetool.backend." + backend, - name % self._format, None)[1] - if func is not None: - func(*args, **kwargs) + module =3D tracetool.try_import("tracetool.backend." + backen= d)[1] + if module is not None: + yield module + + def _run_function(self, name, *args, check_trace_event_get_state=3DNon= e, **kwargs): + for backend in self.backend_modules(): + func =3D getattr(backend, name % self._format, None) + if func is not None and \ + (check_trace_event_get_state is None or + check_trace_event_get_state =3D=3D getattr(backend, 'CHEC= K_TRACE_EVENT_GET_STATE', False)): + func(*args, **kwargs) =20 def generate_begin(self, events, group): self._run_function("generate_%s_begin", events, group) =20 - def generate(self, event, group): - self._run_function("generate_%s", event, group) + def generate(self, event, group, check_trace_event_get_state=3DNone): + self._run_function("generate_%s", event, group, check_trace_event_= get_state=3Dcheck_trace_event_get_state) =20 def generate_backend_dstate(self, event, group): self._run_function("generate_%s_backend_dstate", event, group) diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py index be7f32e67b9..dd58713a158 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -55,7 +55,6 @@ def generate(events, backend, group): =20 out(' false)') =20 - # tracer without checks out('', 'static inline void %(api)s(%(args)s)', '{', @@ -63,11 +62,17 @@ def generate(events, backend, group): args=3De.args) =20 if "disable" not in e.properties: - backend.generate(e, group) + backend.generate(e, group, check_trace_event_get_state=3DFalse) =20 + if backend.check_trace_event_get_state: + event_id =3D 'TRACE_' + e.name.upper() + cond =3D "trace_event_get_state(%s)" % event_id + out(' if (%(cond)s) {', + cond=3Dcond) + backend.generate(e, group, check_trace_event_get_state=3DT= rue) + out(' }') out('}') =20 - backend.generate_end(events, group) =20 out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper()) --=20 2.51.0