From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724604; cv=none; d=zohomail.com; s=zohoarc; b=nLZJMpNhtIU1gitpooekkpFLvVF8LKMvuWdEYeRRHJ+k4lXEdQlBIcIYjIlVcEJirCsXxw94EYosLcbzbkg5zaISWT3STaY7r726+ggj9Mafois/3EYCNdpnBbafwlKw8P2f7lwVtITmHVDMcMjFH3Bo5Ry5MZK6RTeJlwsipyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724604; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Opjt7pYA8x+4U2fdQc7QHtuH5ZIs1E+6mhQKfPDHwuA=; b=BzBaliH1niSrhOyKQ9x1CviEsu8pdWomrFy10D/UjrNCDGC79OVVqI4sy13P/NgHyryf1MBOnAlIhPXMvfyDbpsmITRiKqYUgOKVesZ6jWr0nyonY74PZUAw8cSYuh3Adn3hmrUv0YHa50ypsS0eUUE1/h4nZBqSl/tPgIN41Rs= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724604337809.2509275818626; Tue, 26 Sep 2023 03:36:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5Ox-0003IN-3B; Tue, 26 Sep 2023 06:34:47 -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 1ql5Ov-0003HS-Mb for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:45 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5Ot-00018Q-R5 for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:45 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 43F482793D78; Tue, 26 Sep 2023 10:34:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724482; bh=Opjt7pYA8x+4U2fdQc7QHtuH5ZIs1E+6mhQKfPDHwuA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=J0h5DpgGMybprBGXzxwIOgWrTjZMxiSHOku4BD9Yiq+NDk/Wflp7WcG/6eZnzh3O9 06Lq0x/ZznhiXNQP5cruQ4hdp7J1+0Y2uzsHiwzdN/nOxPgIOFJyicP9AJiVF2yvrF uTboccOHJrH0F02CkR6En2snUgFweEbv1xk4zC5sZwDqeAM9fftp40hOTaFzOCElUx HXMU0ipfSXbKV8gfYcNWhYC3IT86R0r0rs4Okk4dqrLtwOuqJlKAfMe6MyWscZkD67 BGgj91utSjdqCISpPRqigp0NPmOCpsNrXUGYZwnOEZUkCCftpLXOWZ4CryMVTHKLjv U1sIKs3f7GDdg== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal Subject: [PATCH v5 01/14] simpletrace: add __all__ to define public interface Date: Tue, 26 Sep 2023 12:34:23 +0200 Message-Id: <20230926103436.25700-2-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: pa3OACmjxq2opi5AXScJdp5pO9SQc8TX X-Proofpoint-GUID: pa3OACmjxq2opi5AXScJdp5pO9SQc8TX X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=598 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724605110100003 Content-Type: text/plain; charset="utf-8" From: Mads Ynddal It was unclear what was the supported public interface. I.e. when refactoring the code, what functions/classes are important to retain. Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 1f6d1ae1f3..b221d9a241 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -14,6 +14,8 @@ from tracetool import read_events, Event from tracetool.backend.simple import is_string =20 +__all__ =3D ['Analyzer', 'process', 'run'] + header_event_id =3D 0xffffffffffffffff header_magic =3D 0xf2b177cb0aa429b4 dropped_event_id =3D 0xfffffffffffffffe --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724516; cv=none; d=zohomail.com; s=zohoarc; b=jP5d9SpKldp4x95qwPEBujmz182j90YdvoXEq1upnIqluI5Qaj9g1vSctBJvH4xBUyFhLWytREpLByqnY9JStVAMEsYJRvudtAfkfKDhQkxoz4UDr31//jbbiNHK+fKoTSTn3eW5N0XZvNDOw9iRUSB0g7wCF3SxHP5gI3d4PDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724516; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FocdVLYDNArXFrLxDdBkQHs+kNLDBwoNVCRy8XpQ+dg=; b=irBxWdhYFnCmu0S5yhjzcJyLu1TwS7Kwsgp+4BmOQe+DnjXhezt85a+6bz7kaSmo8ID4nKwAbOKmkRmYtCqgkxsjXIStZD2r3b3VIgBdu5TENllKB9QthARAn6BEWLOsOMXmY+ajTES+L0Qh2jV1uAZJYnmfmxZiRazlJa45wpQ= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724516770799.9443903648934; Tue, 26 Sep 2023 03:35:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5Oz-0003LJ-Lp; Tue, 26 Sep 2023 06:34:49 -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 1ql5Oy-0003KO-BK for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:48 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5Ow-00018d-T6 for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:48 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 36E052793EA9; Tue, 26 Sep 2023 10:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724484; bh=FocdVLYDNArXFrLxDdBkQHs+kNLDBwoNVCRy8XpQ+dg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=BLQHylQQdlsOiOLFQIQT9cFhr63vjTlIzNt6yt/h+uN6fMhW0m4CgiD2lATy2y5lo eUqISRjVuFNVZusXO1TSaDYUufG0c/a+Nbc33Q3D5XEtXKKGS5lZcHjA5te5hMn3Tk jXF4bJdWTAyAqi+o3vJozn9E0lwtb2XWzebyz/nZ4maxMIBuUCHsq3z0g+si9cFpFl wLcmC1s/I8skFYu5AO98d7YAZBPKHGJfxRID/4wo6eFLRv6o/URfMZam269a1LwdWs Z+gBQ3uBN9fo6KSqH3f7JGkeLLTtxMgMJX3gU61BT9LtMPw6rJ+3iMn3qj1ni/IxdQ /SGgq6/XaOGlA== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal Subject: [PATCH v5 02/14] simpletrace: annotate magic constants from QEMU code Date: Tue, 26 Sep 2023 12:34:24 +0200 Message-Id: <20230926103436.25700-3-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: Jy3CRewAFX9vp0Kz8Bql2usenv2YEMyZ X-Proofpoint-GUID: Jy3CRewAFX9vp0Kz8Bql2usenv2YEMyZ X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=450 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724517726100001 Content-Type: text/plain; charset="utf-8" From: Mads Ynddal It wasn't clear where the constants and structs came from, so I added comments to help. Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index b221d9a241..5c230a1b74 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -16,6 +16,11 @@ =20 __all__ =3D ['Analyzer', 'process', 'run'] =20 +# This is the binary format that the QEMU "simple" trace backend +# emits. There is no specification documentation because the format is +# not guaranteed to be stable. Trace files must be parsed with the +# same trace-events-all file and the same simpletrace.py file that +# QEMU was built with. header_event_id =3D 0xffffffffffffffff header_magic =3D 0xf2b177cb0aa429b4 dropped_event_id =3D 0xfffffffffffffffe --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724644; cv=none; d=zohomail.com; s=zohoarc; b=AnnSWxtr530M9omImEp97jNRo/bu2dqpK6kV6gQGWgAwA09tyxs3LOm5+y4QiEpLPDH3H8cZbvOafzo890t8wrVXF9z4BWk7e/BtuJLk+9LoZOzTEBIMbOanJgnOD5UslCwkCQ/S6cjUBS5x1gJbQppnBNkww3EgU/ewR23iXzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724644; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6uATgJUVIjGmWTu33IvdbmCf9GucgSEjOkNSC9vkNHM=; b=bY6ZOOQTVG6vAj92wRW3jyZ3pvOqm/eAIRdc/elLKue/Z6OMytF9pMC4y9ClBC9yEHZixpm+49lf5xyFVX7I4Sv/kSY7xMXTSfRGQDo85bSG7ltZdwD5q7PUDeYyw53FBRpob67GP7TGWbbIIeHhu7jc+HBsXto16yJPPEQOH4U= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724644499923.1626280640388; Tue, 26 Sep 2023 03:37:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5P1-0003Lj-7A; Tue, 26 Sep 2023 06:34:51 -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 1ql5Oz-0003Ku-7K for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:49 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5Ox-00018s-GW for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:48 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 201C02793EB0; Tue, 26 Sep 2023 10:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724486; bh=6uATgJUVIjGmWTu33IvdbmCf9GucgSEjOkNSC9vkNHM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=L3G3zAXpgU7PM22U/Qaji3xBS98MsPHH8j0MWigRR99+yjT5428DclzzWa2Yr7UQu TylutRxl1x3GND/B9fdpY51ilOoKWbOLmOtaWn74z8bKvHq/zf/5QpyXIHC0HafDj4 rFKa9PGNmqhQVrCjOKAv2lk9amxNq8i/FlljXHja89MhiIKeTvxb5+qtZIRdXnPIj0 GpILLCPsBno3QhXwxPobu/CbxpTZF9/EzO11S+aaSsUaSjy1S4/TUEk0V9jNU1Wojl tiio9GOcCYnMeN06A1EIwiUIOt1BI3MgmtPMlHT6qFh+VtAZn0+Iilvpj74WBNCD+n 7u6UszLdhs5nw== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal Subject: [PATCH v5 03/14] simpletrace: improve parsing of sys.argv; fix files never closed. Date: Tue, 26 Sep 2023 12:34:25 +0200 Message-Id: <20230926103436.25700-4-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 8h4ajl2favycgfo6dr5NUTQR6rq-kY7S X-Proofpoint-GUID: 8h4ajl2favycgfo6dr5NUTQR6rq-kY7S X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=855 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724645766100003 Content-Type: text/plain; charset="utf-8" From: Mads Ynddal The arguments extracted from `sys.argv` named and unpacked to make it clear what the arguments are and what they're used for. The two input files were opened, but never explicitly closed. File usage changed to use `with` statement to take care of this. At the same time, ownership of the file-object is moved up to `run` function. Added option to process to support file-like objects. Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 50 ++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 5c230a1b74..283b5918a1 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -9,6 +9,7 @@ # # For help see docs/devel/tracing.rst =20 +import sys import struct import inspect from tracetool import read_events, Event @@ -51,7 +52,6 @@ def get_record(edict, idtoname, rechdr, fobj): try: event =3D edict[name] except KeyError as e: - import sys sys.stderr.write('%s event is logged but is not declared ' \ 'in the trace events file, try using ' \ 'trace-events-all instead.\n' % str(e)) @@ -172,11 +172,28 @@ def end(self): pass =20 def process(events, log, analyzer, read_header=3DTrue): - """Invoke an analyzer on each event in a log.""" + """Invoke an analyzer on each event in a log. + Args: + events (file-object or list or str): events list or file-like obje= ct or file path as str to read event data from + log (file-object or str): file-like object or file path as str to = read log data from + analyzer (Analyzer): Instance of Analyzer to interpret the event d= ata + read_header (bool, optional): Whether to read header data from the= log data. Defaults to True. + """ + if isinstance(events, str): - events =3D read_events(open(events, 'r'), events) + with open(events, 'r') as f: + events_list =3D read_events(f, events) + elif isinstance(events, list): + # Treat as a list of events already produced by tracetool.read_eve= nts + events_list =3D events + else: + # Treat as an already opened file-object + events_list =3D read_events(events, events.name) + + close_log =3D False if isinstance(log, str): log =3D open(log, 'rb') + close_log =3D True =20 if read_header: read_trace_header(log) @@ -187,12 +204,12 @@ def process(events, log, analyzer, read_header=3DTrue= ): edict =3D {"dropped": dropped_event} idtoname =3D {dropped_event_id: "dropped"} =20 - for event in events: + for event in events_list: edict[event.name] =3D event =20 # If there is no header assume event ID mapping matches events list if not read_header: - for event_id, event in enumerate(events): + for event_id, event in enumerate(events_list): idtoname[event_id] =3D event.name =20 def build_fn(analyzer, event): @@ -225,24 +242,25 @@ def build_fn(analyzer, event): fn_cache[event_num](event, rec) analyzer.end() =20 + if close_log: + log.close() + def run(analyzer): """Execute an analyzer on a trace file given on the command-line. =20 This function is useful as a driver for simple analysis scripts. More advanced scripts will want to call process() instead.""" - import sys - - read_header =3D True - if len(sys.argv) =3D=3D 4 and sys.argv[1] =3D=3D '--no-header': - read_header =3D False - del sys.argv[1] - elif len(sys.argv) !=3D 3: - sys.stderr.write('usage: %s [--no-header] ' \ - '\n' % sys.argv[0]) + + try: + # NOTE: See built-in `argparse` module for a more robust cli inter= face + *no_header, trace_event_path, trace_file_path =3D sys.argv[1:] + assert no_header =3D=3D [] or no_header =3D=3D ['--no-header'], 'I= nvalid no-header argument' + except (AssertionError, ValueError): + sys.stderr.write(f'usage: {sys.argv[0]} [--no-header] \n') sys.exit(1) =20 - events =3D read_events(open(sys.argv[1], 'r'), sys.argv[1]) - process(events, sys.argv[2], analyzer, read_header=3Dread_header) + with open(trace_event_path, 'r') as events_fobj, open(trace_file_path,= 'rb') as log_fobj: + process(events_fobj, log_fobj, analyzer, read_header=3Dnot no_head= er) =20 if __name__ =3D=3D '__main__': class Formatter(Analyzer): --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724556; cv=none; d=zohomail.com; s=zohoarc; b=g1MRwYHpTiwGWm1I3foIgOjbIQKBoXlGIAZN19viN6vfzPDMM88XBqyXxf345ucDJeWoMRwoOzeWeEVc9Zunmb7lxZ3qYzOpvYfa9gOo4QbI1RhA+dpZHutnkN0Ih4B2dPRIQojuc3W4phHYiDeXvEzue5iGxV0eoAYtGPA5jeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724556; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=P9WjvnEfg+gRxF9hXm33GvQAhcZGvYrETbTjf9cgSgk=; b=YGfn5zGq+YysdKmIXacctGUxIytmIEnLz5Sou5LC+kQ3dXwX840SsmNKLlyV4o4mKaoso3V8DhcQZn1+EfnFGATdP5i2cK5N6M++CWW14jD6S0yX+mySzCl7FRhfzrDqomI5qj4D2kvfEiIbAnIncrq0CmWmM9SAhJOnvF8XeUY= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724556083782.215913604004; Tue, 26 Sep 2023 03:35:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5P2-0003MA-Q1; Tue, 26 Sep 2023 06:34:53 -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 1ql5P1-0003Lk-6g for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:51 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5Oz-0001AT-Ak for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:50 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id DE2D62793DA2; Tue, 26 Sep 2023 10:34:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724488; bh=P9WjvnEfg+gRxF9hXm33GvQAhcZGvYrETbTjf9cgSgk=; h=From:To:Subject:Date:Message-Id:MIME-Version:Content-Type; b=MInyyBYpFwXvWf9j9WCDUDm4F8GLgtV2HUkc8+BeFGPCSHy7c+6oF8fhg3FPzHqLJ cjKykLp77RNgtbDxLmHzf+AoodRoNECTwZB08nE36hSbVoEPw6Cvgxl7jTOJCo4pi/ 9y2/82Q3FhWzHBSv9SGGwfdjqF3xCBp58jpaD8Uo2Gd9kIudDyx/O4jrg4cTfL7qyc 4iFkA2FRXDrFndjfpIOJ2fC9SmVbuFE7Vyl7K8X6uC1ayk3/MtLvL0n1Vcg1flAjC1 jmgK1vULRyROKUlad0PbWZtQx/N4yF4ue3x7FpVVwTFMGxzMovEl+wJ1v/Tm8PXq0l K/BGNpp0GNp/g== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 04/14] simpletrace: changed naming of edict and idtoname to improve readability Date: Tue, 26 Sep 2023 12:34:26 +0200 Message-Id: <20230926103436.25700-5-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: V32j_a9AObVwnH22KxKhRyi-0BrSA5ZS X-Proofpoint-GUID: V32j_a9AObVwnH22KxKhRyi-0BrSA5ZS X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=819 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724556339100003 From: Mads Ynddal Readability is subjective, but I've expanded the naming of the variables and arguments, to help with understanding for new eyes on the code. Signed-off-by: Mads Ynddal Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- scripts/simpletrace.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 283b5918a1..09511f624d 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -40,17 +40,17 @@ def read_header(fobj, hfmt): return None return struct.unpack(hfmt, hdr) =20 -def get_record(edict, idtoname, rechdr, fobj): +def get_record(event_mapping, event_id_to_name, rechdr, fobj): """Deserialize a trace record from a file into a tuple (name, timestamp, pid, arg1, ..., arg6).""" if rechdr is None: return None if rechdr[0] !=3D dropped_event_id: event_id =3D rechdr[0] - name =3D idtoname[event_id] + name =3D event_id_to_name[event_id] rec =3D (name, rechdr[1], rechdr[3]) try: - event =3D edict[name] + event =3D event_mapping[name] except KeyError as e: sys.stderr.write('%s event is logged but is not declared ' \ 'in the trace events file, try using ' \ @@ -79,10 +79,10 @@ def get_mapping(fobj): =20 return (event_id, name) =20 -def read_record(edict, idtoname, fobj): +def read_record(event_mapping, event_id_to_name, fobj): """Deserialize a trace record from a file into a tuple (event_num, tim= estamp, pid, arg1, ..., arg6).""" rechdr =3D read_header(fobj, rec_header_fmt) - return get_record(edict, idtoname, rechdr, fobj) + return get_record(event_mapping, event_id_to_name, rechdr, fobj) =20 def read_trace_header(fobj): """Read and verify trace file header""" @@ -103,14 +103,14 @@ def read_trace_header(fobj): raise ValueError('Log format %d not supported with this QEMU relea= se!' % log_version) =20 -def read_trace_records(edict, idtoname, fobj): +def read_trace_records(event_mapping, event_id_to_name, fobj): """Deserialize trace records from a file, yielding record tuples (even= t_num, timestamp, pid, arg1, ..., arg6). =20 - Note that `idtoname` is modified if the file contains mapping records. + Note that `event_id_to_name` is modified if the file contains mapping = records. =20 Args: - edict (str -> Event): events dict, indexed by name - idtoname (int -> str): event names dict, indexed by event ID + event_mapping (str -> Event): events dict, indexed by name + event_id_to_name (int -> str): event names dict, indexed by event = ID fobj (file): input file =20 """ @@ -122,9 +122,9 @@ def read_trace_records(edict, idtoname, fobj): (rectype, ) =3D struct.unpack('=3DQ', t) if rectype =3D=3D record_type_mapping: event_id, name =3D get_mapping(fobj) - idtoname[event_id] =3D name + event_id_to_name[event_id] =3D name else: - rec =3D read_record(edict, idtoname, fobj) + rec =3D read_record(event_mapping, event_id_to_name, fobj) =20 yield rec =20 @@ -201,16 +201,16 @@ def process(events, log, analyzer, read_header=3DTrue= ): frameinfo =3D inspect.getframeinfo(inspect.currentframe()) dropped_event =3D Event.build("Dropped_Event(uint64_t num_events_dropp= ed)", frameinfo.lineno + 1, frameinfo.filename) - edict =3D {"dropped": dropped_event} - idtoname =3D {dropped_event_id: "dropped"} + event_mapping =3D {"dropped": dropped_event} + event_id_to_name =3D {dropped_event_id: "dropped"} =20 for event in events_list: - edict[event.name] =3D event + event_mapping[event.name] =3D event =20 # If there is no header assume event ID mapping matches events list if not read_header: for event_id, event in enumerate(events_list): - idtoname[event_id] =3D event.name + event_id_to_name[event_id] =3D event.name =20 def build_fn(analyzer, event): if isinstance(event, str): @@ -234,9 +234,9 @@ def build_fn(analyzer, event): =20 analyzer.begin() fn_cache =3D {} - for rec in read_trace_records(edict, idtoname, log): + for rec in read_trace_records(event_mapping, event_id_to_name, log): event_num =3D rec[0] - event =3D edict[event_num] + event =3D event_mapping[event_num] if event_num not in fn_cache: fn_cache[event_num] =3D build_fn(analyzer, event) fn_cache[event_num](event, rec) --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724555; cv=none; d=zohomail.com; s=zohoarc; b=JjZ/FjyPnbzDGsvvH5h0zxPeGKNWndg3t/PIKLMcUtUHRzeeVRAcCo/69oeDgmJgNI7GKko24N3FzEmYQrBCwLE1J/g/WBoQh8TKznSwBxVA3kX0xAtAFCYEl7suMw4QIs5AEPzF261AYhtn1ZVyY2Tndk2p5PYqzBGW7j0xNiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724555; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aErmfBbboF4Q39RVl+T079JOR2lHn59rWKN1DOJwoKw=; b=GDZ4AVYMji7uVEuiqQMkUDhkX5C/ngYRdtdYTS8RA8+HUHPdbyPTXSgyUoZcZQ+2SjMW4o3HtxqkrXduM8QOe0E6kfp6X1TCBk7dy2/zGbRDQ0Ev8vDI46iuKIgD0O0f4FHJSiwVD7wl5sjlHufhCLRPtwsppvNUny9foMoYxLw= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724555075213.11988617560905; Tue, 26 Sep 2023 03:35:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5P5-0003Pc-QQ; Tue, 26 Sep 2023 06:34:55 -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 1ql5P3-0003Md-V4 for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:53 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5P1-0001Ai-E1 for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:52 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id E477C2793EA2; Tue, 26 Sep 2023 10:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724490; bh=aErmfBbboF4Q39RVl+T079JOR2lHn59rWKN1DOJwoKw=; h=From:To:Subject:Date:Message-Id:MIME-Version:Content-Type; b=Jvi173q5nCUI3rFJ1AQjd8uASWXnbg00AuLdPXZQc3yE9FqVlf4HMCK7gNKKxDcMt sJcICPowqHu3VBaFgKJH202ZpYQ5WzPHWJWE6RIUbx03vke+eALKw6529D0BU5fl4v GYENqMThZt0DDWW1Q+ClAfUNjW5IEFEvl8VsLXi5GbB1jspB7X7wupyXj/f+pMMnMP 09v/tZt7QoDi6WInort4zovRpw8trb+t7oc1shrlSxP6JPuFCBQ18aDWfvhQkipVpK aleliN7NrfjCkymsoItnJguq7Nv6yD8SB9IU2I7O3L+c3Oc+3mcNh8mP+OellGn0Av u6JrFcP1uxfVg== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 05/14] simpletrace: update code for Python 3.11 Date: Tue, 26 Sep 2023 12:34:27 +0200 Message-Id: <20230926103436.25700-6-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 4daowjkcU6-u1D6fgWIhIHfPCOXjK83F X-Proofpoint-GUID: 4daowjkcU6-u1D6fgWIhIHfPCOXjK83F X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=844 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724556841100005 From: Mads Ynddal The call to `getargspec` was deprecated and in Python 3.11 it has been removed in favor of `getfullargspec`. `getfullargspec` is compatible with QEMU's requirement of at least Python version 3.6. Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 09511f624d..971b2a0f6a 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -221,7 +221,7 @@ def build_fn(analyzer, event): return analyzer.catchall =20 event_argcount =3D len(event.args) - fn_argcount =3D len(inspect.getargspec(fn)[0]) - 1 + fn_argcount =3D len(inspect.getfullargspec(fn)[0]) - 1 if fn_argcount =3D=3D event_argcount + 1: # Include timestamp as first argument return lambda _, rec: fn(*(rec[1:2] + rec[3:3 + event_argcount= ])) --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724579; cv=none; d=zohomail.com; s=zohoarc; b=KurEuNdZGHWGCFAPBbpGOjrd3LkKNTasaDxp1mXqQonN2/uSirngH5vdVCPrNjMntGeTllTQttiNeHzfSlDxiN7yj3uToedGuU2ZleOlA1DaKCCgQ4rNaGzjsH05TaubQtWkxhPiuco6HZyuL3t3GIV0u2U8qHXuBvVyCms7iAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724579; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oFD+azi+aAn1RpYJdhK5/J4MYt+AbmHo5ScQ7I1pFog=; b=CkXWXWa1LN7sUa04CJ/DU4xacqKgGk6APZzu87bYxT2PTS3uHrH9EMV5akMka0exv8U2Q7EnTTvXW32oBIIZ1KaTIbubgguI/1jtxn+cFSCp/lcrwy8Niiyjew6Al+92ZJFenPp5/DkCqgTP0GFN8vgSYLOF9ZHwa+1NKjyGxvA= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724579727905.5265026670867; Tue, 26 Sep 2023 03:36:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5P6-0003QT-GE; Tue, 26 Sep 2023 06:34:56 -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 1ql5P5-0003Ov-2F for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:55 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5P3-0001BB-CC for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:54 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id C8A052793DA9; Tue, 26 Sep 2023 10:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724492; bh=oFD+azi+aAn1RpYJdhK5/J4MYt+AbmHo5ScQ7I1pFog=; h=From:To:Subject:Date:Message-Id:MIME-Version:Content-Type; b=e/L4h/+v0Kd/sRqEsyA76LvbMR6ie7E5HmmuyPvK3W/4FzUbifpr6rCRJiML8/F4s wdj+REOHc/64AKz+yR0TITCO8VshEZEnmtYkC1ngSpSLU4tN4+Bm3nWC5zYnMsF7// QIht9EMyGbAP8hb1KI7l/oT/nj9FQGUFuze1XkabigsFPTjlMEc1HL7wxQPYCCdFxv USTS5XQi4gnwq5rSzgoECfJi4odSFZ/p/qE9eXaciRc7xs4R3hDG0MiurmaWEL1Tyz pwI/T7bQe6FviYKLuZqHFFlwjSyYQnm1yBJSVAtRZKTtNE37zzyxqfaweLk5sEqu54 hk/bngGdFqcWA== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 06/14] simpletrace: improved error handling on struct unpack Date: Tue, 26 Sep 2023 12:34:28 +0200 Message-Id: <20230926103436.25700-7-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: eawjZnqWQCuyxXiPnzFSasjITxPrslac X-Proofpoint-GUID: eawjZnqWQCuyxXiPnzFSasjITxPrslac X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=430 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724581401100003 From: Mads Ynddal A failed call to `read_header` wouldn't be handled the same for the two different code paths (one path would try to use `None` as a list). Changed to raise exception to be handled centrally. This also allows for easier unpacking, as errors has been filtered out. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 971b2a0f6a..8aea0d169b 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -37,26 +37,24 @@ def read_header(fobj, hfmt): hlen =3D struct.calcsize(hfmt) hdr =3D fobj.read(hlen) if len(hdr) !=3D hlen: - return None + raise ValueError('Error reading header. Wrong filetype provided?') return struct.unpack(hfmt, hdr) =20 def get_record(event_mapping, event_id_to_name, rechdr, fobj): """Deserialize a trace record from a file into a tuple (name, timestamp, pid, arg1, ..., arg6).""" - if rechdr is None: - return None - if rechdr[0] !=3D dropped_event_id: - event_id =3D rechdr[0] + event_id, timestamp_ns, length, pid =3D rechdr + if event_id !=3D dropped_event_id: name =3D event_id_to_name[event_id] - rec =3D (name, rechdr[1], rechdr[3]) try: event =3D event_mapping[name] except KeyError as e: - sys.stderr.write('%s event is logged but is not declared ' \ + sys.stderr.write(f'{e} event is logged but is not declared ' \ 'in the trace events file, try using ' \ - 'trace-events-all instead.\n' % str(e)) + 'trace-events-all instead.\n') sys.exit(1) =20 + rec =3D (name, timestamp_ns, pid) for type, name in event.args: if is_string(type): l =3D fobj.read(4) @@ -67,9 +65,8 @@ def get_record(event_mapping, event_id_to_name, rechdr, f= obj): (value,) =3D struct.unpack('=3DQ', fobj.read(8)) rec =3D rec + (value,) else: - rec =3D ("dropped", rechdr[1], rechdr[3]) - (value,) =3D struct.unpack('=3DQ', fobj.read(8)) - rec =3D rec + (value,) + (dropped_count,) =3D struct.unpack('=3DQ', fobj.read(8)) + rec =3D ("dropped", timestamp_ns, pid, dropped_count) return rec =20 def get_mapping(fobj): @@ -86,22 +83,16 @@ def read_record(event_mapping, event_id_to_name, fobj): =20 def read_trace_header(fobj): """Read and verify trace file header""" - header =3D read_header(fobj, log_header_fmt) - if header is None: - raise ValueError('Not a valid trace file!') - if header[0] !=3D header_event_id: - raise ValueError('Not a valid trace file, header id %d !=3D %d' % - (header[0], header_event_id)) - if header[1] !=3D header_magic: - raise ValueError('Not a valid trace file, header magic %d !=3D %d'= % - (header[1], header_magic)) - - log_version =3D header[2] + _header_event_id, _header_magic, log_version =3D read_header(fobj, log= _header_fmt) + if _header_event_id !=3D header_event_id: + raise ValueError(f'Not a valid trace file, header id {_header_even= t_id} !=3D {header_event_id}') + if _header_magic !=3D header_magic: + raise ValueError(f'Not a valid trace file, header magic {_header_m= agic} !=3D {header_magic}') + if log_version not in [0, 2, 3, 4]: - raise ValueError('Unknown version of tracelog format!') + raise ValueError(f'Unknown version {log_version} of tracelog forma= t!') if log_version !=3D 4: - raise ValueError('Log format %d not supported with this QEMU relea= se!' - % log_version) + raise ValueError(f'Log format {log_version} not supported with thi= s QEMU release!') =20 def read_trace_records(event_mapping, event_id_to_name, fobj): """Deserialize trace records from a file, yielding record tuples (even= t_num, timestamp, pid, arg1, ..., arg6). --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724516; cv=none; d=zohomail.com; s=zohoarc; b=bWERX+DjIxEbYQOkmYfGfwuELJ88/qJHnmFkXrjvZmZ38eSYcH6z+zPbBP+lS+6sfZeyEHGk/V7AQCkZHcKqVE6tyBsuqq5esysUThTzYzwWs/YeARHFaK5XLtZWloHtNezrRatqFjaa1iyEUDC27P29Cp22DubV4Eayog7kC4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724516; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ezwzZ8lsPDmHeJKdePGG761txtOjsM/wC3C259+dRK0=; b=TaaogxrYL00HJJD7F2Zy9djxUVdwdTlv2oUXot1MQZIqpgowRfIxlZsLR3CCl3vwH+RTBpKFV2C+pPM1dvjGWsLGUgbH0xelCYvIeLBX09A2jwO15YfIqVkYAKunF1HXlqm6fWCgFeF682Lb02D39N/H5iEUt6/qaipwyQI0pXE= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169572451665820.493015221232667; Tue, 26 Sep 2023 03:35:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5P9-0003Su-47; Tue, 26 Sep 2023 06:34:59 -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 1ql5P7-0003Rk-RY for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:57 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5P5-0001Bb-QY for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:57 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id C94DA2793ED0; Tue, 26 Sep 2023 10:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724494; bh=ezwzZ8lsPDmHeJKdePGG761txtOjsM/wC3C259+dRK0=; h=From:To:Subject:Date:Message-Id:MIME-Version:Content-Type; b=Xwuek8NEmK6I2LHEOwTWKjVLdupPAkZuqQNmOs2CjCGsnBcS3Q/WDjleoEAuKjar0 TgGy3R1k0zwf9qir1TMJ6+qJw2Qtazhx9iDW083dE2tEU243la4xfjbQv/jnMNBoyZ +V6asQ6CJ0NVC0ryoQjzIaiAIz3quuYGBT4B9CY0EpuOYJ62HmS53mmL9e/hS/sJbe EJfP85ooeSgahnFdiB9KW/w9E5ySNUQokPh+kuzWsqy49xwAr3bUxOFIIUOGMQQabG 6iab3OklrFM1PPPNiNc7AcTsmXa2GjG+pKq/KGq+ysmTI3daWWUqMzLffRXLlNBhRU e3X8b22xMI8Ag== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 07/14] simpletrace: define exception and add handling Date: Tue, 26 Sep 2023 12:34:29 +0200 Message-Id: <20230926103436.25700-8-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: g0F3YBgxJGbaed64WT7pkOwmoZjcpvUs X-Proofpoint-GUID: g0F3YBgxJGbaed64WT7pkOwmoZjcpvUs X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=781 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724517735100003 From: Mads Ynddal Define `SimpleException` to differentiate our exceptions from generic exceptions (IOError, etc.). Adapted simpletrace to support this and output to stderr. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 8aea0d169b..229b10aa99 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -32,12 +32,15 @@ log_header_fmt =3D '=3DQQQ' rec_header_fmt =3D '=3DQQII' =20 +class SimpleException(Exception): + pass + def read_header(fobj, hfmt): '''Read a trace record header''' hlen =3D struct.calcsize(hfmt) hdr =3D fobj.read(hlen) if len(hdr) !=3D hlen: - raise ValueError('Error reading header. Wrong filetype provided?') + raise SimpleException('Error reading header. Wrong filetype provid= ed?') return struct.unpack(hfmt, hdr) =20 def get_record(event_mapping, event_id_to_name, rechdr, fobj): @@ -49,10 +52,10 @@ def get_record(event_mapping, event_id_to_name, rechdr,= fobj): try: event =3D event_mapping[name] except KeyError as e: - sys.stderr.write(f'{e} event is logged but is not declared ' \ - 'in the trace events file, try using ' \ - 'trace-events-all instead.\n') - sys.exit(1) + raise SimpleException( + f'{e} event is logged but is not declared in the trace eve= nts' + 'file, try using trace-events-all instead.' + ) =20 rec =3D (name, timestamp_ns, pid) for type, name in event.args: @@ -247,8 +250,7 @@ def run(analyzer): *no_header, trace_event_path, trace_file_path =3D sys.argv[1:] assert no_header =3D=3D [] or no_header =3D=3D ['--no-header'], 'I= nvalid no-header argument' except (AssertionError, ValueError): - sys.stderr.write(f'usage: {sys.argv[0]} [--no-header] \n') - sys.exit(1) + raise SimpleException(f'usage: {sys.argv[0]} [--no-header] \n') =20 with open(trace_event_path, 'r') as events_fobj, open(trace_file_path,= 'rb') as log_fobj: process(events_fobj, log_fobj, analyzer, read_header=3Dnot no_head= er) @@ -276,4 +278,8 @@ def catchall(self, event, rec): i +=3D 1 print(' '.join(fields)) =20 - run(Formatter()) + try: + run(Formatter()) + except SimpleException as e: + sys.stderr.write(str(e) + "\n") + sys.exit(1) --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724536; cv=none; d=zohomail.com; s=zohoarc; b=Hkld8lfGML2I+nxuaekFKMzAKohJFa6TS5QRP8ppqtAmDJbqivSllcm1FLNTgURp2qwDAqFsH+8Z+26RPcml3/2Lv/smEM7gM12R1nMkkR1Gut+NVJCH0edWCCMogAsnE52kCCvUfi8pdbdTTxZ9q3uWQpS8BaH1T+dZKM6KDww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724536; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y2nmdttjidRoS1xj35Eh2CiUadmbk0qliUJWvkQLMUc=; b=NxOkj9nnCJJuDygbH4muSRWOdgnY7ow5VxMwIv0zRvNwxRfBl5DAEBK5jDgnjbSgWmsFifWu2nc6AnDTU38C8FNHpnk+mBFp9xsI703zZ7GWDC8Wfs68GxGcrHchQjlSlkcZgY1bifc5H3o2ZXwVdDtECDK8NoOq96AXShShsX4= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724536027944.9217522358636; Tue, 26 Sep 2023 03:35:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5PA-0003Tb-Kb; Tue, 26 Sep 2023 06:35:00 -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 1ql5P9-0003T9-Hz for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:59 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5P7-0001Bm-Ut for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:34:59 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 5EFC02793EBB; Tue, 26 Sep 2023 10:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724496; bh=y2nmdttjidRoS1xj35Eh2CiUadmbk0qliUJWvkQLMUc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=VGD68KPTfrdhBvMOropY4oVxq6+SCGXLYt4robGcefVde17B+XxiJTd/APe6GR1ZN 1o8yVE9kT+jUzGbFuAjpd1ptOGLnudPhuJqA7N6BpIn8ljkOy0qfn6LmjllCqjBcBm U1sMd+lAH3h0ZYeqV9wvYGxNG4AhmDCwWevQTGkAHWs4qquIDuJ8wrFnPnXl9XodA3 Fyo7pJahlfIric8/3HGjAwVcFL6Zr2zcWlYjjRjfnpJNsPaey6s1t9KEFTDK/ogE04 /RkizsDpt5JR/ZFRIXkbtxylTq56XKEuiTfpn3GvpdxokHICoqR1Mv003DCW8N//v8 FdakavHz0ut0w== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal Subject: [PATCH v5 08/14] simpletrace: made Analyzer into context-manager Date: Tue, 26 Sep 2023 12:34:30 +0200 Message-Id: <20230926103436.25700-9-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: H3SxdCE8n3o_nzcLRDG3_XoYaaWjSI-1 X-Proofpoint-GUID: H3SxdCE8n3o_nzcLRDG3_XoYaaWjSI-1 X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=910 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724538274100003 Content-Type: text/plain; charset="utf-8" From: Mads Ynddal Instead of explicitly calling `begin` and `end`, we can change the class to use the context-manager paradigm. This is mostly a styling choice, used in modern Python code. But it also allows for more advanced analyzers to handle exceptions gracefully in the `__exit__` method (not demonstrated here). Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 229b10aa99..7f514d1577 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -122,12 +122,13 @@ def read_trace_records(event_mapping, event_id_to_nam= e, fobj): =20 yield rec =20 -class Analyzer(object): +class Analyzer: """A trace file analyzer which processes trace records. =20 An analyzer can be passed to run() or process(). The begin() method is invoked, then each trace record is processed, and finally the end() me= thod - is invoked. + is invoked. When Analyzer is used as a context-manager (using the `wit= h` + statement), begin() and end() are called automatically. =20 If a method matching a trace event name exists, it is invoked to proce= ss that trace record. Otherwise the catchall() method is invoked. @@ -165,6 +166,15 @@ def end(self): """Called at the end of the trace.""" pass =20 + def __enter__(self): + self.begin() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + if exc_type is None: + self.end() + return False + def process(events, log, analyzer, read_header=3DTrue): """Invoke an analyzer on each event in a log. Args: @@ -226,15 +236,14 @@ def build_fn(analyzer, event): # Just arguments, no timestamp or pid return lambda _, rec: fn(*rec[3:3 + event_argcount]) =20 - analyzer.begin() - fn_cache =3D {} - for rec in read_trace_records(event_mapping, event_id_to_name, log): - event_num =3D rec[0] - event =3D event_mapping[event_num] - if event_num not in fn_cache: - fn_cache[event_num] =3D build_fn(analyzer, event) - fn_cache[event_num](event, rec) - analyzer.end() + with analyzer: + fn_cache =3D {} + for rec in read_trace_records(event_mapping, event_id_to_name, log= ): + event_num =3D rec[0] + event =3D event_mapping[event_num] + if event_num not in fn_cache: + fn_cache[event_num] =3D build_fn(analyzer, event) + fn_cache[event_num](event, rec) =20 if close_log: log.close() --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724645; cv=none; d=zohomail.com; s=zohoarc; b=dgB52wdm5SqVLOkeJtcaBlj3dYWtEd2xO6KWUlbMBTf0twGUppBwdgx2xEJbpYyI0bFyhdAimY44tX/006nkQZ2FDPdOoAoziUOuf0xPxDvO6aTu1ZKQNvwyRYOKwRmzVQwaMEDGtwyYur7pdN4dE14o3/1NG6pBe1+anXd+1r0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724645; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NumwqMO+a0M0mKzhySCUIzUlP3gWYKiiAU8JllX54Ew=; b=HLWzf3LObczgqD9lc8OeD5gkDwchQPtagl6hCnw/V6vXehhBQYNZsN4qp98HF291OB9N+RVbPNe/+vt+KE1lpOf/0IJ7oTvjE0DSUis1d4YfzMzPujijrhdF8fZV2nzyWuUEqTFNSUQEULeja+VGcMnqqLblN7Z3pwSBbzSUIO4= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724645560489.3372486128719; Tue, 26 Sep 2023 03:37:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5PD-0003WY-7r; Tue, 26 Sep 2023 06:35:03 -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 1ql5PB-0003UF-Jw for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:01 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5P9-0001C6-Kq for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:01 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 47D162793EC6; Tue, 26 Sep 2023 10:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724498; bh=NumwqMO+a0M0mKzhySCUIzUlP3gWYKiiAU8JllX54Ew=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=cWFSbdYKbdUl+pkGxQ33vF1eE5VzvtvYr3Kh4UvWIT8JhMBT6DCbqODvBKpjN7weT cEX7AHVJa4ysZExjVc5C3cDS64th3i0jmm/CoppYuwdqNs70mSJpJpZuRGeLpTDZuI HJWrWDzRjnkGrsJXwB5Msj7RM7BaUcnnIyBNz9gFA6XTHteHWkHziNyZzrbcwL5jnG rJfGvZ8YJ5XVyC9oRXZ7PaJ2WjzVVSjngsG2ZNOffsDHdoA71Rsmi+vVtYUceAjm3u 9Erve5r+j7RatHIAvBY7He6YUgAEqIf6qIlvHFYAjI5D3lszya4OOph4BdMtkCuBLC lWWtrHBpVwjRA== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal Subject: [PATCH v5 09/14] simpletrace: refactor to separate responsibilities Date: Tue, 26 Sep 2023 12:34:31 +0200 Message-Id: <20230926103436.25700-10-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 2Q0SNG19QNjnJG5oTaEY7PHassPI85fG X-Proofpoint-GUID: 2Q0SNG19QNjnJG5oTaEY7PHassPI85fG X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724645778100004 Content-Type: text/plain; charset="utf-8" From: Mads Ynddal Moved event_mapping and event_id_to_name down one level in the function call-stack to keep variable instantiation and usage closer (`process` and `run` has no use of the variables; `read_trace_records` does). Instead of passing event_mapping and event_id_to_name to the bottom of the call-stack, we move their use to `read_trace_records`. This separates responsibility and ownership of the information. `read_record` now just reads the arguments from the file-object by knowning the total number of bytes. Parsing it to specific arguments is moved up to `read_trace_records`. Special handling of dropped events removed, as they can be handled by the general code. Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 115 +++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 62 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 7f514d1577..0826aef283 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -31,6 +31,7 @@ =20 log_header_fmt =3D '=3DQQQ' rec_header_fmt =3D '=3DQQII' +rec_header_fmt_len =3D struct.calcsize(rec_header_fmt) =20 class SimpleException(Exception): pass @@ -43,35 +44,6 @@ def read_header(fobj, hfmt): raise SimpleException('Error reading header. Wrong filetype provid= ed?') return struct.unpack(hfmt, hdr) =20 -def get_record(event_mapping, event_id_to_name, rechdr, fobj): - """Deserialize a trace record from a file into a tuple - (name, timestamp, pid, arg1, ..., arg6).""" - event_id, timestamp_ns, length, pid =3D rechdr - if event_id !=3D dropped_event_id: - name =3D event_id_to_name[event_id] - try: - event =3D event_mapping[name] - except KeyError as e: - raise SimpleException( - f'{e} event is logged but is not declared in the trace eve= nts' - 'file, try using trace-events-all instead.' - ) - - rec =3D (name, timestamp_ns, pid) - for type, name in event.args: - if is_string(type): - l =3D fobj.read(4) - (len,) =3D struct.unpack('=3DL', l) - s =3D fobj.read(len) - rec =3D rec + (s,) - else: - (value,) =3D struct.unpack('=3DQ', fobj.read(8)) - rec =3D rec + (value,) - else: - (dropped_count,) =3D struct.unpack('=3DQ', fobj.read(8)) - rec =3D ("dropped", timestamp_ns, pid, dropped_count) - return rec - def get_mapping(fobj): (event_id, ) =3D struct.unpack('=3DQ', fobj.read(8)) (len, ) =3D struct.unpack('=3DL', fobj.read(4)) @@ -79,10 +51,11 @@ def get_mapping(fobj): =20 return (event_id, name) =20 -def read_record(event_mapping, event_id_to_name, fobj): - """Deserialize a trace record from a file into a tuple (event_num, tim= estamp, pid, arg1, ..., arg6).""" - rechdr =3D read_header(fobj, rec_header_fmt) - return get_record(event_mapping, event_id_to_name, rechdr, fobj) +def read_record(fobj): + """Deserialize a trace record from a file into a tuple (event_num, tim= estamp, pid, args).""" + event_id, timestamp_ns, record_length, record_pid =3D read_header(fobj= , rec_header_fmt) + args_payload =3D fobj.read(record_length - rec_header_fmt_len) + return (event_id, timestamp_ns, record_pid, args_payload) =20 def read_trace_header(fobj): """Read and verify trace file header""" @@ -97,17 +70,28 @@ def read_trace_header(fobj): if log_version !=3D 4: raise ValueError(f'Log format {log_version} not supported with thi= s QEMU release!') =20 -def read_trace_records(event_mapping, event_id_to_name, fobj): - """Deserialize trace records from a file, yielding record tuples (even= t_num, timestamp, pid, arg1, ..., arg6). - - Note that `event_id_to_name` is modified if the file contains mapping = records. +def read_trace_records(events, fobj, read_header): + """Deserialize trace records from a file, yielding record tuples (even= t, event_num, timestamp, pid, arg1, ..., arg6). =20 Args: event_mapping (str -> Event): events dict, indexed by name - event_id_to_name (int -> str): event names dict, indexed by event = ID fobj (file): input file + read_header (bool): whether headers were read from fobj =20 """ + frameinfo =3D inspect.getframeinfo(inspect.currentframe()) + dropped_event =3D Event.build("Dropped_Event(uint64_t num_events_dropp= ed)", + frameinfo.lineno + 1, frameinfo.filename) + + event_mapping =3D {e.name: e for e in events} + event_mapping["dropped"] =3D dropped_event + event_id_to_name =3D {dropped_event_id: "dropped"} + + # If there is no header assume event ID mapping matches events list + if not read_header: + for event_id, event in enumerate(events): + event_id_to_name[event_id] =3D event.name + while True: t =3D fobj.read(8) if len(t) =3D=3D 0: @@ -115,12 +99,35 @@ def read_trace_records(event_mapping, event_id_to_name= , fobj): =20 (rectype, ) =3D struct.unpack('=3DQ', t) if rectype =3D=3D record_type_mapping: - event_id, name =3D get_mapping(fobj) - event_id_to_name[event_id] =3D name + event_id, event_name =3D get_mapping(fobj) + event_id_to_name[event_id] =3D event_name else: - rec =3D read_record(event_mapping, event_id_to_name, fobj) + event_id, timestamp_ns, pid, args_payload =3D read_record(fobj) + event_name =3D event_id_to_name[event_id] + + try: + event =3D event_mapping[event_name] + except KeyError as e: + raise SimpleException( + f'{e} event is logged but is not declared in the trace= events' + 'file, try using trace-events-all instead.' + ) + + offset =3D 0 + args =3D [] + for type, _ in event.args: + if is_string(type): + (length,) =3D struct.unpack_from('=3DL', args_payload,= offset=3Doffset) + offset +=3D 4 + s =3D args_payload[offset:offset+length] + offset +=3D length + args.append(s) + else: + (value,) =3D struct.unpack_from('=3DQ', args_payload, = offset=3Doffset) + offset +=3D 8 + args.append(value) =20 - yield rec + yield (event_mapping[event_name], event_name, timestamp_ns, pi= d) + tuple(args) =20 class Analyzer: """A trace file analyzer which processes trace records. @@ -202,20 +209,6 @@ def process(events, log, analyzer, read_header=3DTrue): if read_header: read_trace_header(log) =20 - frameinfo =3D inspect.getframeinfo(inspect.currentframe()) - dropped_event =3D Event.build("Dropped_Event(uint64_t num_events_dropp= ed)", - frameinfo.lineno + 1, frameinfo.filename) - event_mapping =3D {"dropped": dropped_event} - event_id_to_name =3D {dropped_event_id: "dropped"} - - for event in events_list: - event_mapping[event.name] =3D event - - # If there is no header assume event ID mapping matches events list - if not read_header: - for event_id, event in enumerate(events_list): - event_id_to_name[event_id] =3D event.name - def build_fn(analyzer, event): if isinstance(event, str): return analyzer.catchall @@ -238,12 +231,10 @@ def build_fn(analyzer, event): =20 with analyzer: fn_cache =3D {} - for rec in read_trace_records(event_mapping, event_id_to_name, log= ): - event_num =3D rec[0] - event =3D event_mapping[event_num] - if event_num not in fn_cache: - fn_cache[event_num] =3D build_fn(analyzer, event) - fn_cache[event_num](event, rec) + for event, event_id, timestamp_ns, record_pid, *rec_args in read_t= race_records(events, log, read_header): + if event_id not in fn_cache: + fn_cache[event_id] =3D build_fn(analyzer, event) + fn_cache[event_id](event, (event_id, timestamp_ns, record_pid,= *rec_args)) =20 if close_log: log.close() --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724614; cv=none; d=zohomail.com; s=zohoarc; b=MhPE+ZLEuCqMuPfRFvjNwVTgcReXRwxuiULfoJYZkWGbD2W8+fPlZke06irbYadDBxvDdcfY4KGNlS2CQIVfbGmwmxhifxy2eGSvGDoPta+y6kZf0S/bGeFGn7c8ssFudD32gSv1Tu9YJx1+kW/2jRNQgBMoFTNVHwHHdkS54PY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724614; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TFYyrNI9zvNor2iiOUfUBQ22WiXmSUh6nt/AbP8tW6s=; b=UPFBy1yJSTrnAYMKDGm44ZJI/tzLa2JRRgiDzddfM05x0d6WOEqIfnMQ6L7ef354raB34x+fB847Vy40oWC6PdyTZqMSWcm4ewCxIi/TbRM8Yb3E3CfT+Sua6dDrsKnFFqz6ANL9J0eibCVdjoFAxEf9PjVTqAraJFCzBUhB5tY= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724614707394.47503858264474; Tue, 26 Sep 2023 03:36:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5PI-0003Yc-Ot; Tue, 26 Sep 2023 06:35:08 -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 1ql5PD-0003WQ-35 for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:03 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5PB-0001CN-Ds for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:02 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 127D02793E60; Tue, 26 Sep 2023 10:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724500; bh=TFYyrNI9zvNor2iiOUfUBQ22WiXmSUh6nt/AbP8tW6s=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=QNwMXOpTjpwRKRtFImjvpjX5gNtR0J4IBaEOwbzHdEz2+4GwoWISbBh0mx2CW/ojf BwfHEf5O692W5lUjjSfCKC8c+XuhXSnnPRwPa1vCD9+T0qnLA/Ovi0SzKsjVi6PNHX U3Mnm8WkNcNq+2Z8uWX6axAT9MXvIeif/uVLClBZmEUR57fE/ogHPVhjqdWNpMca9Y ymW3j/y7Nt4LlSDMuGZWx3LaRZBK4eGyUxkwOjHwLM6yDfjlbYoVt6I7VywG6WAoxM YKtkzJRyIA62fRM93su4kmmGAj0NAvr1XmCJYH9wTY79LJmpIx35gW0dtWwbBr2A0d yF0IASFsBuxdw== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal Subject: [PATCH v5 10/14] simpletrace: move logic of process into internal function Date: Tue, 26 Sep 2023 12:34:32 +0200 Message-Id: <20230926103436.25700-11-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: VQy1LU8Gh95K0enLcQThClNW94rIS_Qf X-Proofpoint-GUID: VQy1LU8Gh95K0enLcQThClNW94rIS_Qf X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=935 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724615466100001 Content-Type: text/plain; charset="utf-8" From: Mads Ynddal To avoid duplicate code depending on input types and to better handle open/close of log with a context-manager, we move the logic of process into _process. Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 0826aef283..6969fdd59a 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -201,13 +201,26 @@ def process(events, log, analyzer, read_header=3DTrue= ): # Treat as an already opened file-object events_list =3D read_events(events, events.name) =20 - close_log =3D False if isinstance(log, str): - log =3D open(log, 'rb') - close_log =3D True + with open(log, 'rb') as log_fobj: + _process(events_list, log_fobj, analyzer, read_header) + else: + # Treat `log` as an already opened file-object. We will not close = it, + # as we do not own it. + _process(events_list, log, analyzer, read_header) + +def _process(events, log_fobj, analyzer, read_header=3DTrue): + """Internal function for processing + + Args: + events (list): list of events already produced by tracetool.read_e= vents + log_fobj (file): file-object to read log data from + analyzer (Analyzer): the Analyzer to interpret the event data + read_header (bool, optional): Whether to read header data from the= log data. Defaults to True. + """ =20 if read_header: - read_trace_header(log) + read_trace_header(log_fobj) =20 def build_fn(analyzer, event): if isinstance(event, str): @@ -231,14 +244,11 @@ def build_fn(analyzer, event): =20 with analyzer: fn_cache =3D {} - for event, event_id, timestamp_ns, record_pid, *rec_args in read_t= race_records(events, log, read_header): + for event, event_id, timestamp_ns, record_pid, *rec_args in read_t= race_records(events, log_fobj, read_header): if event_id not in fn_cache: fn_cache[event_id] =3D build_fn(analyzer, event) fn_cache[event_id](event, (event_id, timestamp_ns, record_pid,= *rec_args)) =20 - if close_log: - log.close() - def run(analyzer): """Execute an analyzer on a trace file given on the command-line. =20 --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724604; cv=none; d=zohomail.com; s=zohoarc; b=czMC7fF/KBLeZbuVkasWYB0cgdGtZMHqMZKlCagifS+yEbeRCHSvr7by+Luxf03Lhqe9cTDP7IYV57sS3Y4f6gluWQDYebmQEhYcbRJgA5NyBpb/c6oviFic9Eh8sJ23nXuY9gX9fK03vzxv9dgRbFd3plK48QYzh3QMCaaFZy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724604; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xzZ4RfX7hC7a5tnHsYZ2SHf/poag7qDVOsXZVLrc+UQ=; b=inxhyxwIJebZMcI0EUKMmCpE4LuVP0EUGILVMWDFLb4FjzNwT3j16T/Sk4ygwsgvValD76gkvtgFR9aQoFdP6TXN9UhvvnBHzsi/aTGzSJyJ0z2lCX0yUijuPJFYp7m/7KuLIQsQCCGkxmQ12fESzftBEGXScgiZU+QYWsuaMvk= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724604822424.7327084325882; Tue, 26 Sep 2023 03:36:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5PL-0003cQ-2N; Tue, 26 Sep 2023 06:35:11 -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 1ql5PF-0003Xr-11 for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:05 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5PD-0001Cy-7O for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:04 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id BFCE32793EE2; Tue, 26 Sep 2023 10:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724502; bh=xzZ4RfX7hC7a5tnHsYZ2SHf/poag7qDVOsXZVLrc+UQ=; h=From:To:Subject:Date:Message-Id:MIME-Version:Content-Type; b=XXnSO9HITJvekI/LURFqhuO6ukWb+THQuExR+npwrCenhFD7SPekzzyspIhAPLkV7 RnUo4cNsB/D4B3YyuPGHGvqGJ2EaiSCCthWpWcwMdvJSil0ciEfX3rAZ2qkrL3Yubx NIBQU2GobQtG5dr1oALzdQ6koyXlYEaG8ulCuJyl5B1O+QAbpLbw84ifQpmLvIf5FG bxC0CPDcTNstaJuNIsRrg+pDYoG22TlNKCKc66j0gWEROH+D1Ft0KFN0Mdf8M1OSGq +YIRPGprQwwpVasTaKhEKnkjBGoBNtKrqdXikP6IoSoJFS1H6rq/tK5SGPbnYTJQKL VQ2CWa4HOCtwA== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 11/14] simpletrace: move event processing to Analyzer class Date: Tue, 26 Sep 2023 12:34:33 +0200 Message-Id: <20230926103436.25700-12-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: RQfuxrRxXzrkOMtTSwg1fZp5THkRWlkB X-Proofpoint-GUID: RQfuxrRxXzrkOMtTSwg1fZp5THkRWlkB X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724605023100001 From: Mads Ynddal Moved event processing to the Analyzer class to separate specific analyzer logic (like caching and function signatures) from the _process function. This allows for new types of Analyzer-based subclasses without changing the core code. Note, that the fn_cache is important for performance in cases where the analyzer is branching away from the catch-all a lot. The cache has no measurable performance penalty. Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 60 +++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 6969fdd59a..4136d00600 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -169,6 +169,35 @@ def catchall(self, event, rec): """Called if no specific method for processing a trace event has b= een found.""" pass =20 + def _build_fn(self, event): + fn =3D getattr(self, event.name, None) + if fn is None: + # Return early to avoid costly call to inspect.getfullargspec + return self.catchall + + event_argcount =3D len(event.args) + fn_argcount =3D len(inspect.getfullargspec(fn)[0]) - 1 + if fn_argcount =3D=3D event_argcount + 1: + # Include timestamp as first argument + return lambda _, rec: fn(*(rec[1:2] + rec[3:3 + event_argcount= ])) + elif fn_argcount =3D=3D event_argcount + 2: + # Include timestamp and pid + return lambda _, rec: fn(*rec[1:3 + event_argcount]) + else: + # Just arguments, no timestamp or pid + return lambda _, rec: fn(*rec[3:3 + event_argcount]) + + def _process_event(self, rec_args, *, event, event_id, timestamp_ns, p= id, **kwargs): + if not hasattr(self, '_fn_cache'): + # NOTE: Cannot depend on downstream subclasses to have + # super().__init__() because of legacy. + self._fn_cache =3D {} + + rec =3D (event_id, timestamp_ns, pid, *rec_args) + if event_id not in self._fn_cache: + self._fn_cache[event_id] =3D self._build_fn(event) + self._fn_cache[event_id](event, rec) + def end(self): """Called at the end of the trace.""" pass @@ -222,32 +251,15 @@ def _process(events, log_fobj, analyzer, read_header= =3DTrue): if read_header: read_trace_header(log_fobj) =20 - def build_fn(analyzer, event): - if isinstance(event, str): - return analyzer.catchall - - fn =3D getattr(analyzer, event.name, None) - if fn is None: - return analyzer.catchall - - event_argcount =3D len(event.args) - fn_argcount =3D len(inspect.getfullargspec(fn)[0]) - 1 - if fn_argcount =3D=3D event_argcount + 1: - # Include timestamp as first argument - return lambda _, rec: fn(*(rec[1:2] + rec[3:3 + event_argcount= ])) - elif fn_argcount =3D=3D event_argcount + 2: - # Include timestamp and pid - return lambda _, rec: fn(*rec[1:3 + event_argcount]) - else: - # Just arguments, no timestamp or pid - return lambda _, rec: fn(*rec[3:3 + event_argcount]) - with analyzer: - fn_cache =3D {} for event, event_id, timestamp_ns, record_pid, *rec_args in read_t= race_records(events, log_fobj, read_header): - if event_id not in fn_cache: - fn_cache[event_id] =3D build_fn(analyzer, event) - fn_cache[event_id](event, (event_id, timestamp_ns, record_pid,= *rec_args)) + analyzer._process_event( + rec_args, + event=3Devent, + event_id=3Devent_id, + timestamp_ns=3Dtimestamp_ns, + pid=3Drecord_pid, + ) =20 def run(analyzer): """Execute an analyzer on a trace file given on the command-line. --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724648; cv=none; d=zohomail.com; s=zohoarc; b=abF1TXOJ7l42J21b8uOfdhkEaSC6W2sUCSZ9LovnYlHhjNDI0bzPEjtvIGRmS5AmJmhC0fGt68J4j48Oibz/BSj0V7UgEVgkYbcXqlEayMaRn8SJxa2W5mWA64d7sEakei1855PuMH1TT9cSPlw1yq2+KT5IATz8O40McWuI9A4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724648; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DnKjALWbipcz/A/jhfp4bzOPKLhDEKwFH9WXhiPht4w=; b=hWK2ZritH/XvHgMB2sGIqsDBxersV6Le51BcB26Xy2ASOjdsfAlNhT27tvrYhumYL/PThB+EJT09CoQn0+7behyxuh6m440x+UKTh9Yi8ceD2cyt8PlUfLYBRpr2Kb3Cb+JwrMhzo5BI+5i6ueCuouBpaX0SkZbY25DkEw7tiTw= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724647916692.2212953244663; Tue, 26 Sep 2023 03:37:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5PV-00049p-EQ; Tue, 26 Sep 2023 06:35:21 -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 1ql5PR-0003up-M1 for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:18 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5PP-0001Nu-MD for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:17 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 977A62793EE4; Tue, 26 Sep 2023 10:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724504; bh=DnKjALWbipcz/A/jhfp4bzOPKLhDEKwFH9WXhiPht4w=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=RQl0NuOxkM4cVHPaheILZrMge3td50qnwYB3zJPJajBp+GmL3LWLX9MLuj+2AdlDy X+qPAzeM56RLbsfY9brXTozi9CquIYD0n9BNwO2+/exbh26v4jsjojALAisL+1FdBj F9LiUOtVyefnRYgqJljf96xIsJSLGgyA43nGijzgi4gvn8Gh4PvcRo8XewTIn3U1wT bQ4iRe8x94ahH+icQebLescDg9qAC2SlsAAxORZpyVU4qJ51bn30EHWao/VrpvMtFZ IU1VbVxWG/n7eQbPAC2n9mzeakiw4GtbaevnROVqPnwWBVoczIg9vrUsmyRIq07Ewx nve0IiqK5jY6A== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal Subject: [PATCH v5 12/14] simpletrace: added simplified Analyzer2 class Date: Tue, 26 Sep 2023 12:34:34 +0200 Message-Id: <20230926103436.25700-13-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 164nT5YhwYAQYEbQSOj9IVxw1emHv8Ei X-Proofpoint-GUID: 164nT5YhwYAQYEbQSOj9IVxw1emHv8Ei X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724650350100003 Content-Type: text/plain; charset="utf-8" From: Mads Ynddal By moving the dynamic argument construction to keyword-arguments, we can remove all of the specialized handling, and streamline it. If a tracing method wants to access these, they can define the kwargs, or ignore it be placing `**kwargs` at the end of the function's arguments list. Added deprecation warning to Analyzer class to make users aware of the Analyzer2 class. No removal date is planned. Signed-off-by: Mads Ynddal --- scripts/simpletrace.py | 98 ++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 23 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 4136d00600..cef81b0707 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -12,10 +12,11 @@ import sys import struct import inspect +import warnings from tracetool import read_events, Event from tracetool.backend.simple import is_string =20 -__all__ =3D ['Analyzer', 'process', 'run'] +__all__ =3D ['Analyzer', 'Analyzer2', 'process', 'run'] =20 # This is the binary format that the QEMU "simple" trace backend # emits. There is no specification documentation because the format is @@ -130,7 +131,9 @@ def read_trace_records(events, fobj, read_header): yield (event_mapping[event_name], event_name, timestamp_ns, pi= d) + tuple(args) =20 class Analyzer: - """A trace file analyzer which processes trace records. + """[Deprecated. Refer to Analyzer2 instead.] + + A trace file analyzer which processes trace records. =20 An analyzer can be passed to run() or process(). The begin() method is invoked, then each trace record is processed, and finally the end() me= thod @@ -188,6 +191,11 @@ def _build_fn(self, event): return lambda _, rec: fn(*rec[3:3 + event_argcount]) =20 def _process_event(self, rec_args, *, event, event_id, timestamp_ns, p= id, **kwargs): + warnings.warn( + "Use of deprecated Analyzer class. Refer to Analyzer2 instead.= ", + DeprecationWarning, + ) + if not hasattr(self, '_fn_cache'): # NOTE: Cannot depend on downstream subclasses to have # super().__init__() because of legacy. @@ -211,6 +219,56 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.end() return False =20 +class Analyzer2(Analyzer): + """A trace file analyzer which processes trace records. + + An analyzer can be passed to run() or process(). The begin() method is + invoked, then each trace record is processed, and finally the end() me= thod + is invoked. When Analyzer is used as a context-manager (using the `wit= h` + statement), begin() and end() are called automatically. + + If a method matching a trace event name exists, it is invoked to proce= ss + that trace record. Otherwise the catchall() method is invoked. + + The methods are called with a set of keyword-arguments. These can be i= gnored + using `**kwargs` or defined like any keyword-argument. + + The following keyword-arguments are available, but make sure to have an + **kwargs to allow for unmatched arguments in the future: + event: Event object of current trace + event_id: The id of the event in the current trace file + timestamp_ns: The timestamp in nanoseconds of the trace + pid: The process id recorded for the given trace + + Example: + The following method handles the runstate_set(int new_state) trace eve= nt:: + + def runstate_set(self, new_state, **kwargs): + ... + + The method can also explicitly take a timestamp keyword-argument with = the + trace event arguments:: + + def runstate_set(self, new_state, *, timestamp_ns, **kwargs): + ... + + Timestamps have the uint64_t type and are in nanoseconds. + + The pid can be included in addition to the timestamp and is useful when + dealing with traces from multiple processes: + + def runstate_set(self, new_state, *, timestamp_ns, pid, **kwargs): + ... + """ + + def catchall(self, *rec_args, event, timestamp_ns, pid, event_id, **kw= args): + """Called if no specific method for processing a trace event has b= een found.""" + pass + + def _process_event(self, rec_args, *, event, **kwargs): + fn =3D getattr(self, event.name, self.catchall) + fn(*rec_args, event=3Devent, **kwargs) + def process(events, log, analyzer, read_header=3DTrue): """Invoke an analyzer on each event in a log. Args: @@ -278,30 +336,24 @@ def run(analyzer): process(events_fobj, log_fobj, analyzer, read_header=3Dnot no_head= er) =20 if __name__ =3D=3D '__main__': - class Formatter(Analyzer): + class Formatter2(Analyzer2): def __init__(self): - self.last_timestamp =3D None - - def catchall(self, event, rec): - timestamp =3D rec[1] - if self.last_timestamp is None: - self.last_timestamp =3D timestamp - delta_ns =3D timestamp - self.last_timestamp - self.last_timestamp =3D timestamp - - fields =3D [event.name, '%0.3f' % (delta_ns / 1000.0), - 'pid=3D%d' % rec[2]] - i =3D 3 - for type, name in event.args: - if is_string(type): - fields.append('%s=3D%s' % (name, rec[i])) - else: - fields.append('%s=3D0x%x' % (name, rec[i])) - i +=3D 1 - print(' '.join(fields)) + self.last_timestamp_ns =3D None + + def catchall(self, *rec_args, event, timestamp_ns, pid, event_id): + if self.last_timestamp_ns is None: + self.last_timestamp_ns =3D timestamp_ns + delta_ns =3D timestamp_ns - self.last_timestamp_ns + self.last_timestamp_ns =3D timestamp_ns + + fields =3D [ + f'{name}=3D{r}' if is_string(type) else f'{name}=3D0x{r:x}' + for r, (type, name) in zip(rec_args, event.args) + ] + print(f'{event.name} {delta_ns / 1000:0.3f} {pid=3D} ' + ' '.j= oin(fields)) =20 try: - run(Formatter()) + run(Formatter2()) except SimpleException as e: sys.stderr.write(str(e) + "\n") sys.exit(1) --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724548; cv=none; d=zohomail.com; s=zohoarc; b=D1P2RW0XXD4K22gmFRAikGQHt85Db+wi/NjDpDTFQsfkqkB0PAQk/sKwqwNAjTvakdoqxwncvRZ+9ftB/AT16pedRtUYzNFVy3gWbSFsg1wpDTRI1l1i8i8dpTFo9C0wwtMP3aNRJVJgTLv8DT5Hm6PB87gMub7CILCuLH6ox2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724548; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EXTVgrsCo7pbRmkSb7Wom7gNlLXkp7KqE9K6uvSiPFE=; b=dYP9t7DTg9Imzl3Xfk+nZcQIKRuuOE/FcKDY8YfAfk5AkKIwNXwIfcZHVLmX1xZmZtnteAZFghNBniwWG+n0qNF0Fto1qExzfaKIDAbFNagAbZBlH15kadGujvEWnQr1x/kASOD4IRVR+rOHY8v8qVwdaAJVBA9xjaDKXwSub/0= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724548630467.234490645924; Tue, 26 Sep 2023 03:35:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5PX-0004Ld-0f; Tue, 26 Sep 2023 06:35:23 -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 1ql5PS-0003wZ-Fp for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:18 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5PQ-0001OC-Uh for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:18 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 5CCF32793E9D; Tue, 26 Sep 2023 10:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724505; bh=EXTVgrsCo7pbRmkSb7Wom7gNlLXkp7KqE9K6uvSiPFE=; h=From:To:Subject:Date:Message-Id:MIME-Version:Content-Type; b=RLE03LCw8v+wIJKFcUEXtHsSlWY4D64kw1eFAhkSCRnFaUw8DNsBQFF8sYeVi3viD M3EpUcj7jZictfNKxxR8Tvb174qJYcL/pxX72gpGkNUfSW5sX6GfS3Lm3L4wUbBQMq kjyZXa5D928C8AIs8pwHO8GKakn8aZkHOuVDsmiT90Gb4DFOOBh/bb+V+MRx3ijhus taGYU4lYu0aZs7rXFJZyEf+ga5QtSPeG/Quu2aRYCOwYdpcGZtkSG9S0OOIBiuZhzB Chey8Km0AlEvQag46xQ/C2ZqWLDWcRlflUsyWN77tEuU4QgfD9m0WLBw/dYV56DORo mrBzxKtzrJVFA== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 13/14] MAINTAINERS: add maintainer of simpletrace.py Date: Tue, 26 Sep 2023 12:34:35 +0200 Message-Id: <20230926103436.25700-14-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: NZvlN8ggkSbcnZQ4aiJlQV95-ZoZl2oW X-Proofpoint-GUID: NZvlN8ggkSbcnZQ4aiJlQV95-ZoZl2oW X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=887 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724550664100003 From: Mads Ynddal In my work to refactor simpletrace.py, I noticed that there's no maintainer of it, and has the status of "odd fixes". I'm using it from time to time, so I'd like to maintain the script. I've added myself as reviewer under "Tracing" to be informed of changes that might affect simpletrace.py. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Mads Ynddal --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 355b1960ce..81625f036b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3170,6 +3170,7 @@ F: stubs/ =20 Tracing M: Stefan Hajnoczi +R: Mads Ynddal S: Maintained F: trace/ F: trace-events @@ -3182,6 +3183,11 @@ F: docs/tools/qemu-trace-stap.rst F: docs/devel/tracing.rst T: git https://github.com/stefanha/qemu.git tracing =20 +Simpletrace +M: Mads Ynddal +S: Maintained +F: scripts/simpletrace.py + TPM M: Stefan Berger S: Maintained --=20 2.38.1 From nobody Wed May 15 14:23:00 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1695724565; cv=none; d=zohomail.com; s=zohoarc; b=AehvsaAeKX3Kj09z3nBUZJyc574SgzuKn045kiSPd+QSkavUkS6wFlEMzf+1QzDH3VN4r4cBFhrBTBI1sHUiTpQjI4wy19CubCkM7ZMxVE3ODEBtLbeefPDHJEwysyVoul0oN3khn8eKNbQIZcpn5EyJ7PJxjryI+QQz9rD2vlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695724565; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=it2JPuObXZmGZgZVYdTI0jT1RUlfQEJ/017blYBJFQ8=; b=TRI15mb/761Og9PaI8PgqlCqR7R38VRsk0IvPoHcfac/OrQcaEBIEEvItSpY2AlkK0UK0wfok3RgeB8K9uh//+LvaObdk244qXS1FBWEgtEmWdpkvlwy4KbnQemeZNR9qsyvek2sB2Kr7mtkTU7fui0eDYqfqixv6R0DUIIOncU= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695724565044593.550064800745; Tue, 26 Sep 2023 03:36:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ql5PW-0004GY-9s; Tue, 26 Sep 2023 06:35:22 -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 1ql5PU-00040S-6U for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:20 -0400 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ql5PS-0001OY-Oc for qemu-devel@nongnu.org; Tue, 26 Sep 2023 06:35:19 -0400 Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 328182793EA1; Tue, 26 Sep 2023 10:35:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ynddal.dk; s=sig1; t=1695724507; bh=it2JPuObXZmGZgZVYdTI0jT1RUlfQEJ/017blYBJFQ8=; h=From:To:Subject:Date:Message-Id:MIME-Version:Content-Type; b=DXn5w9dYUfSrWwtm8QPt21bPX3UpcFmtwD9a0xtRjSZ8njtF9WtKg2pKonNxDzjPC 9PU1pykneVhq5zceKYVJdRRJr/GTPKX+V0xOjr0CferV2h+Js4iRZQ7i/cTBCMPgwm M41G+Sd6YvN/2gxWZeXS7d9N1lMUBVJ3oagimO4wPpi7JDrpV9tmzTFTScVSytqjwt 7UvmLy+gVQQCTSIF4rwH84Dc8l22Vd/l8ghKLUz7j12yeWmXjGsuj/3xkcYdMud97G JDGFgQuKtFdKXw1LeRf/Q332onVPDLqCCQUfthkqoxA890Hmh9jgZuhpW4gvDg9Pmc ilvtz349hx6DA== From: Mads Ynddal To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , John Snow , Mads Ynddal , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 14/14] scripts/analyse-locks-simpletrace.py: changed iteritems() to items() Date: Tue, 26 Sep 2023 12:34:36 +0200 Message-Id: <20230926103436.25700-15-mads@ynddal.dk> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230926103436.25700-1-mads@ynddal.dk> References: <20230926103436.25700-1-mads@ynddal.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: hRyUWhsoMu12t2hDP0Phz_zlkSstcxCi X-Proofpoint-GUID: hRyUWhsoMu12t2hDP0Phz_zlkSstcxCi X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1030 adultscore=0 mlxlogscore=637 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309260091 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=17.58.23.183; envelope-from=mads@ynddal.dk; helo=mr85p00im-zteg06021501.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ynddal.dk) X-ZM-MESSAGEID: 1695724566461100002 From: Mads Ynddal Python 3 removed `dict.iteritems()` in favor of `dict.items()`. This means the script currently doesn't work on Python 3. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi Signed-off-by: Mads Ynddal --- scripts/analyse-locks-simpletrace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analyse-locks-simpletrace.py b/scripts/analyse-locks-s= impletrace.py index 63c11f4fce..d650dd7140 100755 --- a/scripts/analyse-locks-simpletrace.py +++ b/scripts/analyse-locks-simpletrace.py @@ -75,7 +75,7 @@ def get_args(): (analyser.locks, analyser.locked, analyser.unlocks)) =20 # Now dump the individual lock stats - for key, val in sorted(analyser.mutex_records.iteritems(), + for key, val in sorted(analyser.mutex_records.items(), key=3Dlambda k_v: k_v[1]["locks"]): print ("Lock: %#x locks: %d, locked: %d, unlocked: %d" % (key, val["locks"], val["locked"], val["unlocked"])) --=20 2.38.1