From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908796; cv=none; d=zohomail.com; s=zohoarc; b=TFTSVeHeQGBgL9432hYXPbccO0TR7Hzs/p9CUKwW4Oe34oTETrDSOgepJeH//xoHeTPojLqXCZxocrt0ybrxyiJGF7Mghma+EVA7sI+4/7Fy8RliYMCB1+R1WUZR7ntw4lLhF9KuLn5Uzg6Apa1YdJXJSoUGmh6wRQDoIFBahLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908796; 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=5a+Sfl4+XDRgp7FT+3zfvklhFMtJBxRGcdWHy6W9jaI=; b=DpyNCyNJocbxKGHUCMqHlk4JkqODuEtds5yTo8FCcu2LHxhKEVRP3vTMOzx3FiUR/J2vB4WX6J/9d8TYcnWPxCwsrRaSWMUXXB0KRdgqfCiW/awJqqz6kgmGHN0FB77lLhZhxdG/K1LzZRf9TdoU/j0IDEdRfvC4oiERTER0C+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908796265979.4405451197892; Thu, 28 Sep 2023 06:46:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJk-0000zF-Nn; Thu, 28 Sep 2023 09:44:36 -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 1qlrJe-0000vM-NK for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJP-0005FU-Eo for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:30 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-0KtYT3rOMqq7fvU9PsHbmQ-1; Thu, 28 Sep 2023 09:44:11 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4066C3C40C0D; Thu, 28 Sep 2023 13:44:11 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CA592156A27; Thu, 28 Sep 2023 13:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5a+Sfl4+XDRgp7FT+3zfvklhFMtJBxRGcdWHy6W9jaI=; b=JNCXmJgH+cu+gAtw1UvaHHOGhb2AdKh8GXYDm09nQxYqNlNLr7XxrpLPlyQzc3+LrbPL1G HFSFdiVbuTvezKK2OkNMWcQZb1hvyTyqQGpkI4IZ64GWxoB4KOaMIH9QG+EqCKosKw0IUY 97lyH5yq8/dkHKwOn2TUfrsyn0Ci38k= X-MC-Unique: 0KtYT3rOMqq7fvU9PsHbmQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi Subject: [PULL 01/14] simpletrace: add __all__ to define public interface Date: Thu, 28 Sep 2023 09:43:54 -0400 Message-ID: <20230928134407.568453-2-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695908797265100001 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 Message-id: 20230926103436.25700-2-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908676; cv=none; d=zohomail.com; s=zohoarc; b=czg1AgOLBi6EDQCoHH2KBREZr+6luF06bvn3siqdzog9S2KQfb80Fn7wM5IaOFDXDofidRRz9UErYn6H5vJkxzxIBAFe3Ok4/tCj8wuYk/XOy7sAlBn7Mx0sVEBtCNoZ9Jn1kLNpHL5rdzJ2XpvSYm3W6zIkIjzNVqWzXApyA1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908676; 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=XP7c9vdCGfJZ1fbHAm02M6koOwVOL2mRAsj0b8DjvUE=; b=aVjo4aXXLp8DTX+sXTjdnXXX6QhKBU0mzjYvR3Gh6WRZ9qoC1pDn2XCksRKae0pXpaE0S8Yvbtsc4n72Mg6raHsH6IXyHr6mSzbVp3B1YDriiNbTeStl/8WMIK3f8MpoMgZA/XpJ9bJt4DfyQlrolm3lLFzGx/LtG67corP4ifE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169590867624830.512725217207958; Thu, 28 Sep 2023 06:44:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJV-0000sQ-CK; Thu, 28 Sep 2023 09:44: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 1qlrJT-0000ro-Tt for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJR-0005G2-6w for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:19 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-38-9Qj2beCbMCugh1ZmCOyvkg-1; Thu, 28 Sep 2023 09:44:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B233280BCA4; Thu, 28 Sep 2023 13:44:13 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F7DA2026D4B; Thu, 28 Sep 2023 13:44:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XP7c9vdCGfJZ1fbHAm02M6koOwVOL2mRAsj0b8DjvUE=; b=LMxI8APu3rtKIippnJTDhtVJlplWRaW5Dupj+8V9S2JpnbTMfbhUdvenYlfsG2n5dnsTC3 XtSIO/V9NCtuBiXGmd9dRSMYWKMKHGUrFU2JTZtufQnyIKo1v+zqJDnOmPesHBhCT3yqfD NXaN6YCPO6G7a3uuApjvj5p2kccGd4Q= X-MC-Unique: 9Qj2beCbMCugh1ZmCOyvkg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi Subject: [PULL 02/14] simpletrace: annotate magic constants from QEMU code Date: Thu, 28 Sep 2023 09:43:55 -0400 Message-ID: <20230928134407.568453-3-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695908676817100001 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 Message-id: 20230926103436.25700-3-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908735; cv=none; d=zohomail.com; s=zohoarc; b=mZUWRq9hlp5oUIwA30i9+QNz03LdrJjoxlfslkQRgg7jvrxHHteu75rQZ4yHkV5XjYoWTwXhxjY/YqUeo+PBFD/VgTmoAwVP4ops0E66jGFnHfJ9ktHe2j2tSV5HZdMPyLBSX182A5PqKcKU/h+YDjKIAGKOfjrNL4o+LsI5ZQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908735; 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=Vm5kLZlRphXSSqt2nLmBq/ePitBZl+I2AcJc1D6gMJc=; b=VOMF+/d61XuIafJ2Uny4CnOAVZcb5xusyHQUhW3h2xkblllTF5w4YmIEiiP21jsQj8cvEt1nwiS1Y7R84PUsfR1C8akWHm8/2RX3pt+1HejiY+n3efWioYYL8BAZRFH6/HBw28A0lOHNlWV9Fh5fJFinG//jHjiiukZMVi+MuKs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908735112458.765413983297; Thu, 28 Sep 2023 06:45:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJX-0000uD-3y; Thu, 28 Sep 2023 09:44: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 1qlrJV-0000sI-4r for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJT-0005GL-Ec for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:20 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-562-YsH-DfREN5e3G-yEWCsnGg-1; Thu, 28 Sep 2023 09:44:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11B54280BC9E; Thu, 28 Sep 2023 13:44:15 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FF90167F8; Thu, 28 Sep 2023 13:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vm5kLZlRphXSSqt2nLmBq/ePitBZl+I2AcJc1D6gMJc=; b=Z8selqDyXBFvziEapkpw/mIWK+hjDoFUW0QUSyWdCWtig9RQ0IDEcjM+wQZ4HyQCbLs5kT +zBNggrBk6ovEZEX3d9Sv8s7X69ifROJhbQqrhsZL2dVKt6XZqGfTfRhvasKSk3FqieMkO 5AbNSSMz9SkFLiYIO0buXi9VvMH6zOI= X-MC-Unique: YsH-DfREN5e3G-yEWCsnGg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi Subject: [PULL 03/14] simpletrace: improve parsing of sys.argv; fix files never closed. Date: Thu, 28 Sep 2023 09:43:56 -0400 Message-ID: <20230928134407.568453-4-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695908736205100002 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 Message-id: 20230926103436.25700-4-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- scripts/simpletrace.py | 48 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 15 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 =20 - 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908722; cv=none; d=zohomail.com; s=zohoarc; b=mEIeyvSC6DiYqOJARwgUrzR4H3rGgMowsYEkGjc/lGgpYU2Vt9S7fR2QRECeeXfg+4Sm7IMyYMLjBkMzyl0DJVTaTPXgCEZyFAmIeQTEtbiqQSuRJvf7nFzOP+0j4LdgpkqR9P58bLvSV8gz0taOGC2yesrklW8iIqrsC4XxwQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908722; 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=Kj2D4WbyQ2y/gYlvTvzVG7JkqeV8gImVzIWrYt4H6y0=; b=jBNY0V2XqINSIxLvv5d6vdpuMoAApM/OU/s38nYguujV3gs+ul27jVGQPPBUO2zupJ94VeiGugg6eljuRBEcTjWodeNT3gGO1EJFh7BUI8ElnU3ngxcUw9ePD4WENjPsI8vn/Y/yXNtYEiWNVF7IsLV5lTjVfkYA/C9uEDpOvfg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908721998675.8993683716577; Thu, 28 Sep 2023 06:45:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJo-00015N-2V; Thu, 28 Sep 2023 09:44:40 -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 1qlrJj-0000wB-8U for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJT-0005GO-Ri for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:35 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-607-PvgyykUNPsWP2fGMFOHnzA-1; Thu, 28 Sep 2023 09:44:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE2D31C0512E; Thu, 28 Sep 2023 13:44:16 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B5EF2156702; Thu, 28 Sep 2023 13:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kj2D4WbyQ2y/gYlvTvzVG7JkqeV8gImVzIWrYt4H6y0=; b=WSPA3sOz0YP5CDUex9PmxWlsKEoO6CGBiyRz8u/v/qyx3M2CA15iXLV+LYfQIrDce6IY1A QLTBKDkGOXPG9x5aUnM1p6yFlqKFKdOMtcz5IzA5GBLBjCpgBaw4PqOcq8ik6mFu1B9Isc iuJSqVUquVGLvuRX4PBFyBOWqp7lBuw= X-MC-Unique: PvgyykUNPsWP2fGMFOHnzA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi Subject: [PULL 04/14] simpletrace: changed naming of edict and idtoname to improve readability Date: Thu, 28 Sep 2023 09:43:57 -0400 Message-ID: <20230928134407.568453-5-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @redhat.com) X-ZM-MESSAGEID: 1695908724116100003 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 Message-id: 20230926103436.25700-5-mads@ynddal.dk Signed-off-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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908690; cv=none; d=zohomail.com; s=zohoarc; b=NHjiAoiaH4qVb+VuqVhQNgLAmmkGB8+EIkB7Ryo7da9Q47kM9bTAOvwf45cX0dUYnR1Z51+cZEceMz64F3OfxsQ8P5XEVXXET61QXipIdyfea/BzOfkXOl5c6wxI4VNXcXQfCP5pOCj/IRhi2p/mZuSx5DwX3VLVVguCorO/f7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908690; 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=/0TPVEJqMRP81u7RIyJNACT0FrgRwZTFrX4qes/1y9I=; b=YG+rkbNeDarSLI6rs4Y/b9XyODXSh2X30ch5gOfNG/x4752idA39O2ufpVEBtgcIBwNIc76Iz0hpPXEg0GAH0JNXwq1kCxkEMLSrryMWPP4doS0o3JHIE8CYxpDvkaxDHT3zgfqKBDwUpmSa4UgvmvHZPmkxKtda1EbragZoi8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908690474613.7732956292093; Thu, 28 Sep 2023 06:44:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJc-0000uc-0A; Thu, 28 Sep 2023 09:44:28 -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 1qlrJY-0000uR-Gf for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJX-0005Gj-0K for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:24 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-192-AZ_RANfyOQCQbL2zUEpmjQ-1; Thu, 28 Sep 2023 09:44:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A42681C0512B; Thu, 28 Sep 2023 13:44:18 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36E90176F0; Thu, 28 Sep 2023 13:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/0TPVEJqMRP81u7RIyJNACT0FrgRwZTFrX4qes/1y9I=; b=PIv4akyzCNUykE5hyM1tC2aZyN8HEsWcj9S68VowCHhr3Qfr7NWEFLX8/ATyjZJJNF6lQP cRlOE48NCO0iz/ky1WYKUM2adl2t7sW18cy3r/8+RPeh6tJx69LybW6RJOR2wv6Fryvkth 2VwKLs8e3YUOq/51xbGQ5fOmVrEn/rU= X-MC-Unique: AZ_RANfyOQCQbL2zUEpmjQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 05/14] simpletrace: update code for Python 3.11 Date: Thu, 28 Sep 2023 09:43:58 -0400 Message-ID: <20230928134407.568453-6-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695908690726100001 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 Message-id: 20230926103436.25700-6-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908677; cv=none; d=zohomail.com; s=zohoarc; b=B4x3q2toufsgMjYPL7esZCGkKsYx7llO38g/iKoMlT0CmkWHNxkNz+ARm/Biio1bVXqQGifRnbph2LWa/+teHTkEq11jIGboEtY3vUsO0cT798vkierB+jTTGOHEDT+Cj98hqrxDyMhzgNOIRPwcuJ8K+bhwCO8cveQ2ZCiS9kI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908677; 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=J48OycNztKVj3b0x6e/yZdSeR6A0hYpyBUdSd50kql4=; b=e4DcT9KhVcTt0pwEqBl/IoRvjp3sap7ej5TixhJ/60bbR+RG1AB+UP96aIXvzRcmTxs1D9IaaBBXa0DI83P5qvB2DOUobkASrWAFxubNZetDOtaErqujInWpBGXN9Fq1Tu17sfJ3XbPrl+pdH5O8NlI/o9N3pWfg68UWGHFrQ08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908677565367.25029045050405; Thu, 28 Sep 2023 06:44:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJe-0000vL-NU; Thu, 28 Sep 2023 09:44:32 -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 1qlrJc-0000uq-5X for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJZ-0005Gy-Rv for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-xIsF8zuGMluIjQyUP_kR8g-1; Thu, 28 Sep 2023 09:44:21 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4856811E7D; Thu, 28 Sep 2023 13:44:20 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30D6740C2064; Thu, 28 Sep 2023 13:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J48OycNztKVj3b0x6e/yZdSeR6A0hYpyBUdSd50kql4=; b=BcCVLBPNKdvIAJSoqQ2epzM59/82GD0NN28SmweBLakjYz7gJ2/vvXFNG+IcjnHu80DWVL Avpace4yaVO0if3jaoSfPfAVnAyo+9tLMuPIeBcsZKfCr4y1jBt6PnBHeDKwnETlY1xdAm o6RO6kyHA0OvpQUmCwg0enf5Dxk6qV4= X-MC-Unique: xIsF8zuGMluIjQyUP_kR8g-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi Subject: [PULL 06/14] simpletrace: improved error handling on struct unpack Date: Thu, 28 Sep 2023 09:43:59 -0400 Message-ID: <20230928134407.568453-7-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=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 @redhat.com) X-ZM-MESSAGEID: 1695908678680100005 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 Message-id: 20230926103436.25700-7-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- scripts/simpletrace.py | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 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)) + _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}') =20 - log_version =3D header[2] 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908847; cv=none; d=zohomail.com; s=zohoarc; b=m925EsVHvxWg7PukWnkUVmUS6Jgev8Rp4AXxv34JwQ7z5CQWrvkqdWVud0CtyOgO9JJdoJJLW6MFwxFBTmtC1LR93dNSQIDuCSOKYiT/UCA9nZd2i6l6+hvRLa6hGXToFlAt5YXEAAw+usb2uUlJ3JzvCzYnlXuw5t3pWmQdjT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908847; 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=WMEIXnCPufnjyiqocUwGtPFCA0We/cAhLUoZHd95EmA=; b=ge43edygD4DbJZt2AH5GUwiEIxSActHNBT+rvp6X8OFzl7IiwsW6qF5aG+he6St4RYw+E56Qx2yTDfNtOr9fsa8VpTKw6w5TS0iSYnznoQlKX0l0mhJiN2QcmKpbdsAEyDVRcNyLtsyg5/gPbtJlgF9TWZGDSVCIxnjHEkq2OZY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908847860732.1893655302935; Thu, 28 Sep 2023 06:47:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJl-00012p-H7; Thu, 28 Sep 2023 09:44:37 -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 1qlrJg-0000va-Fi for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJb-0005H3-DQ for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:32 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-385-0xspyTotNj2HI5BIv37uSA-1; Thu, 28 Sep 2023 09:44:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7210A101A529; Thu, 28 Sep 2023 13:44:22 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2BE7140273D; Thu, 28 Sep 2023 13:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WMEIXnCPufnjyiqocUwGtPFCA0We/cAhLUoZHd95EmA=; b=UFwm0xcHWd9zOAxglh2PY1jEiKoBN49z8Lcni5VRm4BAN7wihUFmRgc5pdOvavYkg/TW/b GnbZCwXyzZWsOEUXSZ/pUWEFkeQd56EXJcDdtBjA1CCjnj5LK1Wb7SXQqoKWQmKnJ21/W/ EBSWT9vKsHg7qV3ais3I7zHqAJh/N24= X-MC-Unique: 0xspyTotNj2HI5BIv37uSA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi Subject: [PULL 07/14] simpletrace: define exception and add handling Date: Thu, 28 Sep 2023 09:44:00 -0400 Message-ID: <20230928134407.568453-8-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695908848963100002 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 Message-id: 20230926103436.25700-8-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908848; cv=none; d=zohomail.com; s=zohoarc; b=EsByR1N95N9DASFpZWae9QfkptJvmsOsqOFhtfk53uoql7Kq0X5/bNlGLXhM/QYqXp127CKH3IYSK9COeuLwXNwAoTT9OdrSXXtvSYA1sfz80Uz0nOYQcjYMJIpzKCnlwATJXixXM5uDUuljxnOkJdgzXH5fJ4RDTq6MTBMszbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908848; 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=Ra4SiqIZX5+1ZMDMrjsmfd3AXlb8bNimdMX7saAN+BQ=; b=m32GEpn6D54xLi1gcwWn3Mqbz8+GhpsCaqBBxDbWY7RvA/gvuBdjnZL1gu2gScW/MI4XuclUlplyFx5kO0H+Fwww2mj6cZmD6Wrq7dW7a0OqS3rdAk6V1fDj3DXLED0F1ay5BceFhMOuQXlKY2m8GfROPrANF0fo82LJt7fZXFI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16959088478271009.8439090994026; Thu, 28 Sep 2023 06:47:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJl-00011t-2j; Thu, 28 Sep 2023 09:44:37 -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 1qlrJe-0000vE-EX for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJb-0005H6-R2 for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-209-ICON1eygOvea_VgqUOOskA-1; Thu, 28 Sep 2023 09:44:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 376398002B2; Thu, 28 Sep 2023 13:44:24 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB379100650B; Thu, 28 Sep 2023 13:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ra4SiqIZX5+1ZMDMrjsmfd3AXlb8bNimdMX7saAN+BQ=; b=gFSji/cftaL5TR1VgIqM1p/Db6ZGVtACMu3sTNCxnwVWq5EQc7FVlxwIwOJ9OlAZ9zvfyW LvhVgHrwuTdQ7Bk9pvFuhhbzkEpGSN0J/bX74wy2e+p+jWRixBz1nm1HB9n4lG1lzv5lbY 1SpQGPzmcldnGQc8O8mHchvtxKHxjKc= X-MC-Unique: ICON1eygOvea_VgqUOOskA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi Subject: [PULL 08/14] simpletrace: made Analyzer into context-manager Date: Thu, 28 Sep 2023 09:44:01 -0400 Message-ID: <20230928134407.568453-9-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 @redhat.com) X-ZM-MESSAGEID: 1695908850227100007 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 Message-id: 20230926103436.25700-9-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908815; cv=none; d=zohomail.com; s=zohoarc; b=N/Ds6z3KS7COn5Jaf5+AvjWHcWm0NfEgHeOAHJLTaUaHAUpcJV2qtb8ZQ/bzrYZ9QlzD1nhTPQss6fW7z9wen2ScCpU8Q5px5hJnYplgsKbwWwrnxllzZztG1nxCnM1Z10Vv5SWWrvycKpe/XTUngZkmTyLoT2MFk4hCkznsQIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908815; 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=W+JrhEih6eDrXserQqVVSH4pRxfR3uI97rG6lDCoaTA=; b=M8FwS3FZ6cytJrn9Txvwl2s0vHf3wmhxQ2d/e8AMmtskckh707idccKVsHo76qJRimVPImjIUlzJ9Rns2Gj4Dx2VNI1Ad+LyW7A9ehhOnxU1UB5VW9Gg5XtWRJ2bgTmFfnki7+X72cEpH1UW/PB7yjXN8+gLsBqbI7rjS74cgIc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908815107497.7851204983832; Thu, 28 Sep 2023 06:46:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJn-00014q-8x; Thu, 28 Sep 2023 09:44:39 -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 1qlrJg-0000vT-Bx for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJe-0005J5-D3 for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:32 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-252-rAWorF1xNZOyAwJK33ragA-1; Thu, 28 Sep 2023 09:44:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3879B8007A4; Thu, 28 Sep 2023 13:44:26 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9BFC2156702; Thu, 28 Sep 2023 13:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W+JrhEih6eDrXserQqVVSH4pRxfR3uI97rG6lDCoaTA=; b=YzQB7H6ofIFYuFATVgKSGvJ1bWHzus92Dy+0VT+VCCzUDWpxQe9tIcmN49VWw8deWgUkQx qY1WnXeyq8O0ftM9YKrC2rLNDRFI7uSg+0UXh2MRUoTpv4SpLc+7dJ/zbSfphkLCM1C9WE PH7eyINYexaXg+zDor+a6cLyrxyiIh8= X-MC-Unique: rAWorF1xNZOyAwJK33ragA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi Subject: [PULL 09/14] simpletrace: refactor to separate responsibilities Date: Thu, 28 Sep 2023 09:44:02 -0400 Message-ID: <20230928134407.568453-10-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=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 @redhat.com) X-ZM-MESSAGEID: 1695908815640100001 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 Message-id: 20230926103436.25700-10-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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] =20 - yield rec + 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) + + 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908759; cv=none; d=zohomail.com; s=zohoarc; b=K3gh92e1DEYby7p0msxnuFyNgikvpSStEb8pI8qFV1D1ZnrGLsZpGT+JVcVPuF8S4/SqjstSbfz4ZlVklNN/gTxUxn3FyzyAfoSjmkHe6OmM3pTaoaf2rC+oYFKCZ/AY/jPveedDIBYMLnC1r8EDqGZP6l99MyRhk1DEDtZQPxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908759; 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=fIubrVTLv2aIB0yoYmMLr14Qh9OpvvC4aDxWE1y6kxU=; b=Jy+Ze44aZJy4EC7ER/gWo+3ZXzapF3+rygFq4fAy4mB7fcaHlE8FERvJJT77IWHZ8ARL5SczG10OzTzcsH14PyKfsQPRiwy+6KGSJ3qYNvQGZTiQRkRmkOwHGqcS6EEu1uhC/qYzIKHVGWDc4BQo6goZ/J1P6O9hcgOfQRnWkdY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908759147152.46759316960595; Thu, 28 Sep 2023 06:45:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJn-000152-Pc; Thu, 28 Sep 2023 09:44:39 -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 1qlrJi-0000vu-04 for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJg-0005JR-F7 for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:33 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-288-JLM-mBlmOzOD-m8WlJzGoA-1; Thu, 28 Sep 2023 09:44:28 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 053373C40C03; Thu, 28 Sep 2023 13:44:28 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 897CE140273D; Thu, 28 Sep 2023 13:44:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fIubrVTLv2aIB0yoYmMLr14Qh9OpvvC4aDxWE1y6kxU=; b=CLH+vcMA13Wzg8ctIjH8kVvCWV9pKyC0miutGTYCbM0qjhH9nAJ7xdSFCdotk9Z1udjj3+ BrZbQTHvV1Eryz15BC0un9jJsfpsuEjvc3wP9hMxairZ2F9J2+wfqKjRGqsMSuuhuFc01F XqzLxxaYFdAfSk2oy8w7+/EujOJlKW4= X-MC-Unique: JLM-mBlmOzOD-m8WlJzGoA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi Subject: [PULL 10/14] simpletrace: move logic of process into internal function Date: Thu, 28 Sep 2023 09:44:03 -0400 Message-ID: <20230928134407.568453-11-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695908760730100003 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 Message-id: 20230926103436.25700-11-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908800; cv=none; d=zohomail.com; s=zohoarc; b=B13aj7NXqb+lXnEm9EUbWfASQmXnOiObLnYKr05J1C7ALBAu2KOGwj5nym7xPvSN/wnHAfGY5A+fcJr0dNXu8P15HkN0iNIdH9Ya5qDH0lhTEPqiMjPhIbYTsnBmARXzSQ5lfW7FCTVqCw1KYfmOpshgNryXFZ3NLjQ8djhMkzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908800; 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=7cUQJhMGVzKyq+FWndXTE7qzur1fzrM77GUDAxWgGCU=; b=Y0EIBOnMzuxH9Uy/Nv1gwa0sm3ok6ZqM01/x4TK312v+0FDVlQ64QizX7YkrLAl9xA31PqlgVfE9vOvofVRdykpCfy36yyJ+G/QgmaQYKaNH4FNpHcRXHhVj9wEOO6LFuPmfNJXBMsz/D2j3QfnvmiL+zPGWAT2Bdvh3JyPIDck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169590880055845.581395129686825; Thu, 28 Sep 2023 06:46:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJn-00014r-Ax; Thu, 28 Sep 2023 09:44:39 -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 1qlrJk-0000yw-J0 for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJi-0005Jr-Pr for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:36 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-395-Ffqk8ggWMJe6KWoBvGeasw-1; Thu, 28 Sep 2023 09:44:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD9A3811E7B; Thu, 28 Sep 2023 13:44:29 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EAB5167F8; Thu, 28 Sep 2023 13:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cUQJhMGVzKyq+FWndXTE7qzur1fzrM77GUDAxWgGCU=; b=hU3CAzrsMD0pi+5QVe2Y/dryrqSWLN2/bvXi/ZrlJ0wr/uBG/7+ylWCzIbuz/7vQ7PJQAJ bEu0M5tBPV5QqvUPIykI8lqaFxffYKI6OVJntHckwB7/yunoqDlf+Dp+g55TSd5v/sOg0V 6NjdDZAKywm12E2mZwW4DPiboHFVfH4= X-MC-Unique: Ffqk8ggWMJe6KWoBvGeasw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 11/14] simpletrace: move event processing to Analyzer class Date: Thu, 28 Sep 2023 09:44:04 -0400 Message-ID: <20230928134407.568453-12-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 @redhat.com) X-ZM-MESSAGEID: 1695908801374100001 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 Message-id: 20230926103436.25700-12-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908724; cv=none; d=zohomail.com; s=zohoarc; b=lLcUS4EJ5/LggU2ae9d5e49mGRj3swN85HTlofg6/fLh8dsvKXjfqODnkKc091VaGapMwyg141kCCNxL9xwuQV8RtakyOZYinfnngkMOe8pHIsbWPwkDOgfRdlqdEKQanId/90muukrp+J6G9bWejdKi4Q0/9HeiCuyY91GdKAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908724; 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=OpTmq6yG7OMEAB3IGMTVF1Y8c3kIz/JqAYZLwbYMckI=; b=eBu+F2jFabHzmVBVoYNO/Qk8/INJaYdNIKEoThWsZu4mCH2zo6N5dca2y7g8JpkkQopkFRw3tEMiwLPH2ouejrTXAIfKesyy8bzeP7oc5RZbuOEyfmrMSlBMXdJ03DmUwFMjvbKOY3fYsfFmzh4XFmpOM4MK6gAsPAXNQ/nrR0o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169590872478573.49792172816024; Thu, 28 Sep 2023 06:45:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJq-00016S-1F; Thu, 28 Sep 2023 09:44:42 -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 1qlrJn-000154-PX for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJi-0005Jj-1b for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:39 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-532-qYP5yZaDP_Gad6THlYcrow-1; Thu, 28 Sep 2023 09:44:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8E073C40C06; Thu, 28 Sep 2023 13:44:31 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43C4240C6E76; Thu, 28 Sep 2023 13:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OpTmq6yG7OMEAB3IGMTVF1Y8c3kIz/JqAYZLwbYMckI=; b=TzcDu8shqA1goCC5RY13VFbcj8X+l9UGI4ZSzdEwMkZ6A55xhy+5RvkPi96cUp2hxlSP88 gJbrs/y2DrS8/PohrVR8Ne0BhkPdaoadCBCHOQ2u8nqPQOYmPZz1KgJ4GHiUlNIvKmPD1o SM0vH6gNyOdCUy8+iwtC4MjPUr6OTQ4= X-MC-Unique: qYP5yZaDP_Gad6THlYcrow-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , Stefan Hajnoczi Subject: [PULL 12/14] simpletrace: added simplified Analyzer2 class Date: Thu, 28 Sep 2023 09:44:05 -0400 Message-ID: <20230928134407.568453-13-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695908725922100005 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 Message-id: 20230926103436.25700-13-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- scripts/simpletrace.py | 94 ++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 21 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 + self.last_timestamp_ns =3D None =20 - 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 + 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 =20 - 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)) + 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908742; cv=none; d=zohomail.com; s=zohoarc; b=AQMZdvpbKFOlQVA03ReiX3bD3om5C0JMppbmdiKlf+ONABcWS9xn92BCbyDPaOAl1v7gdtXfcEA33EhglS8Sk812UziQaqWIGLsWB14kGnqr1OqiRfy1K3o4CuTa/LbzsBXUA9XLgF+i1WmW6LErjETX2sVt4d4nuRJhYmD4H38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908742; 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=XALRFOYZDZkSqJ14j522Ifzsbcw92TU6s3y4Ag7ZeOA=; b=Kg21GIV8iPChsFSC1KM0V1/qkH1Tl0rLH6fmycYI+xajfE1PhJ2ZXWEQSrIusmo5egfGRbYI0Q9myVJ+HQABHY1F1fGd3uMl5h9lo/5WLTKzOJgtWcreGsmLb3v1hvRDGBR24wBFrQJndWjyIeMP5T9G8AvN7QfvoklKoMUyHw0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695908742544563.059084298867; Thu, 28 Sep 2023 06:45:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJp-000164-Dm; Thu, 28 Sep 2023 09:44:41 -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 1qlrJn-00014s-Ci for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJl-0005KQ-OQ for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:39 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-246-z4yS8sS0N3G-IEnwuEuynw-1; Thu, 28 Sep 2023 09:44:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 810AC101AA42; Thu, 28 Sep 2023 13:44:33 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1222110005D4; Thu, 28 Sep 2023 13:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XALRFOYZDZkSqJ14j522Ifzsbcw92TU6s3y4Ag7ZeOA=; b=L4kSJaxKY0zyZkTuSlhS9KieKNpQ3mWWixVLOx2mkg6JIGBbNVQvYt8CfaUapCaONUwtd6 3SQrxPGa+HZslUv67ooZC8sqyr0UZL6MujQ2Uu/JeJiz/XdM7WhYGfs6/NOEQQbsS4j+Cq 2uG5fxi0wh0JjgyQX/XZuRlBmvXCWdc= X-MC-Unique: z4yS8sS0N3G-IEnwuEuynw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi Subject: [PULL 13/14] MAINTAINERS: add maintainer of simpletrace.py Date: Thu, 28 Sep 2023 09:44:06 -0400 Message-ID: <20230928134407.568453-14-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=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 @redhat.com) X-ZM-MESSAGEID: 1695908743570100003 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 Message-id: 20230926103436.25700-14-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0 From nobody Fri May 17 21:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695908791; cv=none; d=zohomail.com; s=zohoarc; b=ZjfDNSda+tHcRAUmbTOKR8W/b0xYkJ1ryy7oKMn2kaokYCuR0V1WoiO6FrTiJbuoLha0FlhgQ6kNFlhuIntk2DUY7sH7+QwxLOsOMDn4rUm67rKTt/DlooArIyI6wmjoblZyKOfSCd7oNudTiRg1zI97CEf/HW8PLTh4r5DCi30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695908791; 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=2Kb0p5MGizk0MiZ/a8eyHhqVqqtw4i9ZXuFEyWNCYoA=; b=F7CKVpAZ8bhFxsDCi5XWFvtFriAaeWl+RLHNwn7UAEn7vkyVhNuoXjTHoBe2wB5l2W+K5O3brpP+6+wNDOOD23xDc5M4gF+h5mepZBEMqrIzJm3U+5MV6OqJ/qakhDnVtUL8pYXDtgj/NHf1RD4i1i0IOMxlE1geDNGcgw5E9ig= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16959087910455.6469129874203645; Thu, 28 Sep 2023 06:46:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlrJv-0001Jb-0K; Thu, 28 Sep 2023 09:44: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 1qlrJt-0001DL-5k for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlrJr-0005L3-Lk for qemu-devel@nongnu.org; Thu, 28 Sep 2023 09:44:44 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-220-19JeK2vsNpaoShcidNIrFA-1; Thu, 28 Sep 2023 09:44:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 551BB3C40C05; Thu, 28 Sep 2023 13:44:35 +0000 (UTC) Received: from localhost (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5AD7167F8; Thu, 28 Sep 2023 13:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695908683; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Kb0p5MGizk0MiZ/a8eyHhqVqqtw4i9ZXuFEyWNCYoA=; b=C3UVDW3GKTy1WdcsAKradqH7zzkohjsYNIO4rfsdKbKA7DEVER9Q4ks2XFMLjTx7IrMHfR 8LkiM6OkAxHhoIq2+3BQ52cidqkP/vF/59gnwxFMJMHVUtF8gN8818PhNaeYS6A8YUCpod ot6nxS8uI4h9UWk28yESyAqkwzS2aCE= X-MC-Unique: 19JeK2vsNpaoShcidNIrFA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Mads Ynddal , John Snow , Cleber Rosa , Mads Ynddal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi Subject: [PULL 14/14] scripts/analyse-locks-simpletrace.py: changed iteritems() to items() Date: Thu, 28 Sep 2023 09:44:07 -0400 Message-ID: <20230928134407.568453-15-stefanha@redhat.com> In-Reply-To: <20230928134407.568453-1-stefanha@redhat.com> References: <20230928134407.568453-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695908793219100001 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 Message-id: 20230926103436.25700-15-mads@ynddal.dk Signed-off-by: Stefan Hajnoczi --- 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.41.0