From nobody Mon May 13 17:15:46 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=1694006747; cv=none; d=zohomail.com; s=zohoarc; b=g+tVSABTZP3V2/CUu/zSX+INzVISDkYLmA2cvDGQW+nCDNQWDWIJUpwIOo3/SVh076vNoq59luotpDdgYdrmo74QSPIYnlkVPpaYFRGuQyiJVXVbJ8Ppw5RKGx1VsfZun/MPG+qAdXDY7dFqSlfdtaY+HXVcLde+r1LSQCWFBHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694006747; 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=gHZT37ph+apRRKVcB+jqgGnudNtO5NAW3UTxBPcaBmY=; b=caBWt3m/GhZUB3mmqPXNEbmmH12z1TEe0PMdCxumtZjbTB9nelEewgYdEfWIqzj0pQ/zdi/gOcf/H3QseFh4IdAQnteuVlZy4zVEj50KIzw5CqtTEtURiODB81j1SaADjDm6lObt3I43TRyzmfy84uBJF6nvSM1sKGqaLhV2/34= 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 1694006747317629.4637348452756; Wed, 6 Sep 2023 06:25:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.596619.930556 (Exim 4.92) (envelope-from ) id 1qdsWt-0000AE-7d; Wed, 06 Sep 2023 13:25:11 +0000 Received: by outflank-mailman (output) from mailman id 596619.930556; Wed, 06 Sep 2023 13:25:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdsWt-0000A2-4p; Wed, 06 Sep 2023 13:25:11 +0000 Received: by outflank-mailman (input) for mailman id 596619; Wed, 06 Sep 2023 13:25:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdsWr-00009b-QX for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 13:25:09 +0000 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [2a00:1450:4864:20::32c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cc97563a-4cb8-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 15:25:08 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-401d67434daso36132585e9.2 for ; Wed, 06 Sep 2023 06:25:08 -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 p22-20020a1c7416000000b003fe23b10fdfsm23024250wmc.36.2023.09.06.06.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 06:25:07 -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: cc97563a-4cb8-11ee-8783-cb3800f73035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1694006708; x=1694611508; 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=gHZT37ph+apRRKVcB+jqgGnudNtO5NAW3UTxBPcaBmY=; b=G9hWF1dhaRCu4RjudwR98T2pZAf+zXJ3DPW5VMtV/z6GxvSH2Yvc7HRLit2Z/uWhv2 VZZsSLQ1CgoY3PkCotiOFX283r+LlTyV+JSjipTUzNzFQQTGEc11icZmE8ULUjsUF17O L7w5U8ibPFVE9k3ktNOblhaOOWPu7mkpqy1hQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694006708; x=1694611508; 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=gHZT37ph+apRRKVcB+jqgGnudNtO5NAW3UTxBPcaBmY=; b=dwwWxtqBngPtyu0LZAVFZ58w9eb3Ue11BWDLcf2er7w2sfZBAQMOGEHOJ7JlpP3ouG i6wIUwZ4d0D369wQMBvqxxN6MBaQKyxwuKoaq2gfPSWvV0hI30ge9bhlPl/aub0tLdSa HKAUTybEZOw6pM0OUfeQHMlZ2Q364nfoy/LjCOByHXuuQ6DtAPyv+kACfd2MAbDKl0es q140Wn7xM/yYeAUR0zT43f9ia9jd4gpXjeWIfVv36S+EoJe+0ghiPrHE57ycLVpyAUBt 8JdVBUbj5trTnzGPk8P3O0+kEA4UNzPc3nPWVmECEJgEJnSuXRVsMYO172zx2wSZZBO+ opNw== X-Gm-Message-State: AOJu0YxoQgnTgsPQHax7popU6regGh+vRruwjvO0FmrkH1SrFeSczLzk JcP5J5P3ZZtT/LbM7MEZw9kn9H7vmlHnNqSPeikoeA== X-Google-Smtp-Source: AGHT+IFRyI7vnw2itWYrvrd1dlj8ak/GmBDyIg87mloQAJiyVTgqPJNfmLhCD2ztSTk+8gXRSIT/yQ== X-Received: by 2002:a7b:c389:0:b0:3ff:28b8:c53d with SMTP id s9-20020a7bc389000000b003ff28b8c53dmr2174762wmj.33.1694006707892; Wed, 06 Sep 2023 06:25:07 -0700 (PDT) From: Javi Merino To: xen-devel@lists.xenproject.org Cc: Javi Merino , George Dunlap , Wei Liu , Anthony PERARD Subject: [PATCH v1] tools/xentrace/xentrace_format: Add python 3 compatibility Date: Wed, 6 Sep 2023 14:14:46 +0100 Message-ID: <20230906131616.7681-1-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: 1694006748755100001 Content-Type: text/plain; charset="utf-8" Closes issue #155 Signed-off-by: Javi Merino --- Tested using the format file in tools/xentrace/formats. With this patch, b= oth python2 and python3 produce the same output. tools/xentrace/xentrace_format | 63 +++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/tools/xentrace/xentrace_format b/tools/xentrace/xentrace_format index 5ff85ae2e8..166ebae325 100644 --- a/tools/xentrace/xentrace_format +++ b/tools/xentrace/xentrace_format @@ -4,11 +4,15 @@ =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 +from past.utils import old_div 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 +33,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 +53,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 +87,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 +121,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 +149,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 +220,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: @@ -223,7 +232,7 @@ while not interrupted: last_tsc[cpu] =3D tsc =20 if mhz: - tsc =3D tsc / (mhz*1000000.0) + tsc =3D old_div(tsc, (mhz*1000000.0)) =20 args =3D {'cpu' : cpu, 'tsc' : tsc, @@ -239,18 +248,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