From nobody Sun May 12 09:09:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1694448531; cv=none; d=zohomail.com; s=zohoarc; b=HkFzRhcvXb3ajQlZwQau356PizXXlzSgXNQQtK/bpT54yc/5yKOK783f/C75T+OiMU/4IkM1vmBQ+q/mZsX+3FANXypLv2eqnGMcp1+mJ/3fF65G0mEGuAjAD6W4Ei1X+7RBFw8XkVwwgkgyeT2SUbERJdgj7h3OdCWkaOZZzR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694448531; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=LsdVyIxXkOCViINSF5QWJqkeUffYmbEMfEE5UQFCeYA=; b=c5K+tJCEiEhDnyk8R6qgznojt2oQasIv7QejZt7cID3kB2Zp33pxY0wP6dteYW8xirOjj5gQcwAByFoAd2pc6v2eqEh4+Ru/qU4HGoPp18CFUCtNaBEXONtgRhqRX7TaFmFLjPEtmBoqE9YwtUxvFH6k6V82HP5tNHgTwUkr8GA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1694448531745259.06714889684224; Mon, 11 Sep 2023 09:08:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.599621.935114 (Exim 4.92) (envelope-from ) id 1qfjSe-0001E6-7I; Mon, 11 Sep 2023 16:08:28 +0000 Received: by outflank-mailman (output) from mailman id 599621.935114; Mon, 11 Sep 2023 16:08:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qfjSe-0001Dz-4e; Mon, 11 Sep 2023 16:08:28 +0000 Received: by outflank-mailman (input) for mailman id 599621; Mon, 11 Sep 2023 16:08:26 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qfjSc-0001Dt-Cq for xen-devel@lists.xenproject.org; Mon, 11 Sep 2023 16:08:26 +0000 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [2a00:1450:4864:20::334]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6f213ba0-50bd-11ee-9b0d-b553b5be7939; Mon, 11 Sep 2023 18:08:24 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4018af103bcso29382735e9.1 for ; Mon, 11 Sep 2023 09:08:24 -0700 (PDT) Received: from EMEAENG6DZjqCfH.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id p11-20020a1c740b000000b003ff013a4fd9sm10499212wmc.7.2023.09.11.09.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 09:08:22 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6f213ba0-50bd-11ee-9b0d-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1694448503; x=1695053303; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LsdVyIxXkOCViINSF5QWJqkeUffYmbEMfEE5UQFCeYA=; b=K4k1TXRxU7W9qsZ8Q0lbsnBUINxRWjBRGe28TC8cIK0XKPkfPhXDz1wsFDVBNChEnc CHRFBJrKfpmRBdT2uXTo20ilWIaot9MqgR36bue3ekiadu8M2yfH/D8lYghtszHFfS8V o5bEJVjHudg7Vc800dKZrkVr9w4HGbnYo/nbE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694448503; x=1695053303; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LsdVyIxXkOCViINSF5QWJqkeUffYmbEMfEE5UQFCeYA=; b=MsrL7Eghx7/mQ764bn1mMeb9XBp2n4v5xGoKAQpQf8heMFqKKa8QsaBu6X1FvXU345 0QHYsW90aZ/nVxUgGPpToT7hU/uYlrzgFwjDGmzlYl+gIa2hxcIRRe1gnLYdkrlG3vXC PWqEUrgmarnAc4Ui09XIyIoWaEWwRrxtpM5U3AuP3lale72nYF8A4t2TFbTcpA6quIqx 1xA796PkNY+HsSI5NXHoL/07BAmtbnZjd3qIVNWwhFNzdW+qs6jZStT9d1x748o4pmWR 1JRdFaXatKM5pABwC6FDELZy5RihaSndABrXxKUD1tI7gGjdCQIOEdbnKQiPxPsjp3Gc Qapw== X-Gm-Message-State: AOJu0Yz6hdtLKISy9SbwjB24jnzT0F9neMPlbOqFatVWfXOX3a25PJDU CB+O1x5fgqf7nRLtl8DBcnhVjofg1Y50ChJaBT0= X-Google-Smtp-Source: AGHT+IGIZXl0Se4q24i9mTW7FWKcWgHkztjomo+neuR4b1WolI1w7D5/CgasEQ1fC/shYE6rh7R0aA== X-Received: by 2002:a05:600c:245:b0:401:c1e2:f74f with SMTP id 5-20020a05600c024500b00401c1e2f74fmr55409wmj.15.1694448503166; Mon, 11 Sep 2023 09:08:23 -0700 (PDT) From: Javi Merino To: xen-devel@lists.xenproject.org Cc: Javi Merino , Andrew Cooper , George Dunlap , Wei Liu , Anthony PERARD Subject: [XEN PATCH v2] tools/xentrace/xentrace_format: Add python 3 compatibility Date: Mon, 11 Sep 2023 17:07:02 +0100 Message-ID: <20230911160701.249853-2-javi.merino@cloud.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1694448612147100001 Content-Type: text/plain; charset="utf-8" Resolves: xen-project/xen#155 Signed-off-by: Javi Merino Acked-by: Andrew Cooper --- Changes since v1: - Remove unneeded import from past.utils to avoid depending on python3's= future module. Tested using the format file in tools/xentrace/formats. With this patch, b= oth python 2.7.18.6 and python 3.10.12 produce the same output. tools/xentrace/xentrace_format | 60 +++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/tools/xentrace/xentrace_format b/tools/xentrace/xentrace_format index 5ff85ae2e8..83a1b04d0c 100644 --- a/tools/xentrace/xentrace_format +++ b/tools/xentrace/xentrace_format @@ -4,11 +4,14 @@ =20 # Program for reformatting trace buffer output according to user-supplied = rules =20 +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals +from builtins import str import re, sys, string, signal, struct, os, getopt =20 def usage(): - print >> sys.stderr, \ - "Usage: " + sys.argv[0] + """ defs-file + print("Usage: " + sys.argv[0] + """ defs-file Parses trace data in binary format, as output by Xentrace and reformats it according to the rules in a file of definitions. T= he rules in this file should have the format ({ and } show grouping @@ -29,7 +32,7 @@ def usage(): this script may not be able to keep up with the output of xentra= ce if it is piped directly. In these circumstances you should have xentrace output to a file for processing off-line. - """ + """, file=3Dsys.stderr) sys.exit(1) =20 def read_defs(defs_file): @@ -49,7 +52,7 @@ def read_defs(defs_file): =20 m =3D reg.match(line) =20 - if not m: print >> sys.stderr, "Bad format file" ; sys.exit(1) + if not m: print("Bad format file", file=3Dsys.stderr) ; sys.exit(1) =20 defs[str(eval(m.group(1)))] =3D m.group(2) =20 @@ -83,8 +86,8 @@ interrupted =3D 0 =20 try: defs =3D read_defs(arg[0]) -except IOError, exn: - print exn +except IOError as exn: + print(exn) sys.exit(1) =20 # structure of trace record (as output by xentrace): @@ -117,12 +120,17 @@ TRC_PV_HYPERCALL_SUBCALL =3D 0x20100e NR_VECTORS =3D 256 irq_measure =3D [{'count':0, 'tot_cycles':0, 'max_cycles':0}] * NR_VECTORS =20 +if sys.version_info >=3D (3, 0): + stdin_bytes =3D sys.stdin.buffer +else: + stdin_bytes =3D sys.stdin + i=3D0 =20 while not interrupted: try: i=3Di+1 - line =3D sys.stdin.read(struct.calcsize(HDRREC)) + line =3D stdin_bytes.read(struct.calcsize(HDRREC)) if not line: break event =3D struct.unpack(HDRREC, line)[0] @@ -140,43 +148,43 @@ while not interrupted: tsc =3D 0 =20 if tsc_in =3D=3D 1: - line =3D sys.stdin.read(struct.calcsize(TSCREC)) + line =3D stdin_bytes.read(struct.calcsize(TSCREC)) if not line: break tsc =3D struct.unpack(TSCREC, line)[0] =20 if n_data =3D=3D 1: - line =3D sys.stdin.read(struct.calcsize(D1REC)) + line =3D stdin_bytes.read(struct.calcsize(D1REC)) if not line: break d1 =3D struct.unpack(D1REC, line)[0] if n_data =3D=3D 2: - line =3D sys.stdin.read(struct.calcsize(D2REC)) + line =3D stdin_bytes.read(struct.calcsize(D2REC)) if not line: break (d1, d2) =3D struct.unpack(D2REC, line) if n_data =3D=3D 3: - line =3D sys.stdin.read(struct.calcsize(D3REC)) + line =3D stdin_bytes.read(struct.calcsize(D3REC)) if not line: break (d1, d2, d3) =3D struct.unpack(D3REC, line) if n_data =3D=3D 4: - line =3D sys.stdin.read(struct.calcsize(D4REC)) + line =3D stdin_bytes.read(struct.calcsize(D4REC)) if not line: break (d1, d2, d3, d4) =3D struct.unpack(D4REC, line) if n_data =3D=3D 5: - line =3D sys.stdin.read(struct.calcsize(D5REC)) + line =3D stdin_bytes.read(struct.calcsize(D5REC)) if not line: break (d1, d2, d3, d4, d5) =3D struct.unpack(D5REC, line) if n_data =3D=3D 6: - line =3D sys.stdin.read(struct.calcsize(D6REC)) + line =3D stdin_bytes.read(struct.calcsize(D6REC)) if not line: break (d1, d2, d3, d4, d5, d6) =3D struct.unpack(D6REC, line) if n_data =3D=3D 7: - line =3D sys.stdin.read(struct.calcsize(D7REC)) + line =3D stdin_bytes.read(struct.calcsize(D7REC)) if not line: break (d1, d2, d3, d4, d5, d6, d7) =3D struct.unpack(D7REC, line) @@ -211,7 +219,7 @@ while not interrupted: if cpu >=3D len(last_tsc): last_tsc +=3D [0] * (cpu - len(last_tsc) + 1) elif tsc < last_tsc[cpu] and tsc_in =3D=3D 1: - print "TSC stepped backward cpu %d ! %d %d" % (cpu,tsc,last_t= sc[cpu]) + print("TSC stepped backward cpu %d ! %d %d" % (cpu,tsc,last_t= sc[cpu])) =20 # provide relative TSC if last_tsc[cpu] > 0 and tsc_in =3D=3D 1: @@ -239,18 +247,18 @@ while not interrupted: =20 try: =20 - if defs.has_key(str(event)):=20 - print defs[str(event)] % args + if str(event) in defs:=20 + print(defs[str(event)] % args) else: - if defs.has_key(str(0)): print defs[str(0)] % args + if str(0) in defs: print(defs[str(0)] % args) except TypeError: - if defs.has_key(str(event)): - print defs[str(event)] - print args + if str(event) in defs: + print(defs[str(event)]) + print(args) else: - if defs.has_key(str(0)): - print defs[str(0)] - print args + if str(0) in defs: + print(defs[str(0)]) + print(args) =20 =20 - except IOError, struct.error: sys.exit() + except (IOError, struct.error): sys.exit() --=20 2.41.0