From nobody Wed Apr 15 05:47:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66DAAC43334 for ; Mon, 25 Jul 2022 10:42:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234755AbiGYKmh (ORCPT ); Mon, 25 Jul 2022 06:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234682AbiGYKmc (ORCPT ); Mon, 25 Jul 2022 06:42:32 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D72317AA6 for ; Mon, 25 Jul 2022 03:42:31 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id b7-20020a17090a12c700b001f20eb82a08so13987738pjg.3 for ; Mon, 25 Jul 2022 03:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vggSN88yvyTH37AE3BHE2CmA8tVQM9HZuT6NW9rbdyA=; b=MXw5MsxLZOCOl+Fs14jwG6AdAy08tQZpjBJ6mVGH2hblw13A1JOidIRr86c+z2iryl UIeNggNqFYr4dTNvHeYzZfi/7+PlKEC2g6KaghR7N4g/e0xwXQW7+gvZMd6qxLimwo2K Wzm0b+dkfQwidEBPPAqWxwG2+4YDUnTk+1p6mWJ1Fe8qwvF+DHYeKPeJE1LT1YZMIWKf /ZqwuTFv9ExA1TzMy97TLlFtcxYT3OdJSP/TgRGHJKH8rSd0aAhRcLERhZeesA7l1BuW 3HcyFXF2PXdHKC793+URvXVThrrgpERaSmRlIe8aQyPt0pXN4jNMslv11gBR9IGiiHJq 377g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vggSN88yvyTH37AE3BHE2CmA8tVQM9HZuT6NW9rbdyA=; b=KFKk2ULmYRDldZdV4Zju00OyVHPUbQwSqVOKA9mOZxbe9+6yEEiIo58iA7EKqfCoEl Zw0ErrBWdfUCwtQAO2UUb0/G0/hsk+1u8lzbHEyqSIYQdnkjFMnx1QSz1QAkjgE60yat QqTiTaWOSSOodi9Oup8+HdakHeprgeOfNMB0b2Mck8abQPIvvWYIkv1fexCxYxampXqv Km4oIqisIycMnuPB3ddu8VgRcLJzI53HjJgawBtN7Vvw9raaJETvtUU0SpWYMYokiI/L 2d1C4TGPZLWkCpGCGzmyQQeDH9PS0uR7Y6c/+qWzBNsRlJ8AFRmRx+TZCB7nlroTFRhP tIsA== X-Gm-Message-State: AJIora/667R+19a1bZYlsa7XKuTNsaKlydqH+yEc1Bu0hiJljuVUyY1w l6M08XQ/kri+We5yFjEO/hVwNg== X-Google-Smtp-Source: AGRyM1tj/NDFe2VQLn5EKKBO4qBHEv32kZ7qXMbydRktu29i7TikE6lk58qk9S7Jc63xvWRPWMQAsw== X-Received: by 2002:a17:902:9043:b0:16c:d862:fdf5 with SMTP id w3-20020a170902904300b0016cd862fdf5mr11690038plz.97.1658745750484; Mon, 25 Jul 2022 03:42:30 -0700 (PDT) Received: from leo-build-box.lan (n058152077182.netvigator.com. [58.152.77.182]) by smtp.gmail.com with ESMTPSA id n3-20020a170902f60300b0016bdea07b9esm8808510plg.190.2022.07.25.03.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 03:42:30 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Akemi Yagi , ElRepo , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH] perf scripts python: Let script to be python2 compliant Date: Mon, 25 Jul 2022 18:42:20 +0800 Message-Id: <20220725104220.1106663-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The mainline kernel can be used for relative old distros, e.g. RHEL 7. The distro doesn't upgrade from python2 to python3, this causes the building error that the python script is not python2 compliant. To fix the building failure, this patch changes from the python f-string format to traditional string format. Reported-by: Akemi Yagi Fixes: 12fdd6c009da ("perf scripts python: Support Arm CoreSight trace data= disassembly") Signed-off-by: Leo Yan Tested-by: Alan Bartlett --- .../scripts/python/arm-cs-trace-disasm.py | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/= scripts/python/arm-cs-trace-disasm.py index 5f57d9829956..4339692a8d0b 100755 --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py @@ -61,7 +61,7 @@ def get_optional(perf_dict, field): =20 def get_offset(perf_dict, field): if field in perf_dict: - return f"+0x{perf_dict[field]:x}" + return "+%#x" % perf_dict[field] return "" =20 def get_dso_file_path(dso_name, dso_build_id): @@ -76,7 +76,7 @@ def get_dso_file_path(dso_name, dso_build_id): else: append =3D "/elf" =20 - dso_path =3D f"{os.environ['PERF_BUILDID_DIR']}/{dso_name}/{dso_build_id}= {append}" + dso_path =3D os.environ['PERF_BUILDID_DIR'] + "/" + dso_name + "/" + dso_= build_id + append; # Replace duplicate slash chars to single slash char dso_path =3D dso_path.replace('//', '/', 1) return dso_path @@ -94,8 +94,8 @@ def read_disam(dso_fname, dso_start, start_addr, stop_add= r): start_addr =3D start_addr - dso_start; stop_addr =3D stop_addr - dso_start; disasm =3D [ options.objdump_name, "-d", "-z", - f"--start-address=3D0x{start_addr:x}", - f"--stop-address=3D0x{stop_addr:x}" ] + "--start-address=3D"+format(start_addr,"#x"), + "--stop-address=3D"+format(stop_addr,"#x") ] disasm +=3D [ dso_fname ] disasm_output =3D check_output(disasm).decode('utf-8').split('\n') disasm_cache[addr_range] =3D disasm_output @@ -109,12 +109,14 @@ def print_disam(dso_fname, dso_start, start_addr, sto= p_addr): m =3D disasm_re.search(line) if m is None: continue - print(f"\t{line}") + print("\t" + line) =20 def print_sample(sample): - print(f"Sample =3D {{ cpu: {sample['cpu']:04} addr: 0x{sample['addr']:016= x} " \ - f"phys_addr: 0x{sample['phys_addr']:016x} ip: 0x{sample['ip']:016x}= " \ - f"pid: {sample['pid']} tid: {sample['tid']} period: {sample['period= ']} time: {sample['time']} }}") + print("Sample =3D { cpu: %04d addr: 0x%016x phys_addr: 0x%016x ip: 0x%016= x " \ + "pid: %d tid: %d period: %d time: %d }" % \ + (sample['cpu'], sample['addr'], sample['phys_addr'], \ + sample['ip'], sample['pid'], sample['tid'], \ + sample['period'], sample['time'])) =20 def trace_begin(): print('ARM CoreSight Trace Data Assembler Dump') @@ -131,7 +133,7 @@ def common_start_str(comm, sample): cpu =3D sample["cpu"] pid =3D sample["pid"] tid =3D sample["tid"] - return f"{comm:>16} {pid:>5}/{tid:<5} [{cpu:04}] {sec:9}.{ns:09} " + return "%16s %5u/%-5u [%04u] %9u.%09u " % (comm, pid, tid, cpu, sec, ns) =20 # This code is copied from intel-pt-events.py for printing source code # line and symbols. @@ -171,7 +173,7 @@ def print_srccode(comm, param_dict, sample, symbol, dso= ): glb_line_number =3D line_number glb_source_file_name =3D source_file_name =20 - print(f"{start_str}{src_str}") + print(start_str, src_str) =20 def process_event(param_dict): global cache_size @@ -188,7 +190,7 @@ def process_event(param_dict): symbol =3D get_optional(param_dict, "symbol") =20 if (options.verbose =3D=3D True): - print(f"Event type: {name}") + print("Event type: %s" % name) print_sample(sample) =20 # If cannot find dso so cannot dump assembler, bail out @@ -197,7 +199,7 @@ def process_event(param_dict): =20 # Validate dso start and end addresses if ((dso_start =3D=3D '[unknown]') or (dso_end =3D=3D '[unknown]')): - print(f"Failed to find valid dso map for dso {dso}") + print("Failed to find valid dso map for dso %s" % dso) return =20 if (name[0:12] =3D=3D "instructions"): @@ -244,15 +246,15 @@ def process_event(param_dict): =20 # Handle CS_ETM_TRACE_ON packet if start_addr=3D0 and stop_addr=3D4 if (start_addr =3D=3D 0 and stop_addr =3D=3D 4): - print(f"CPU{cpu}: CS_ETM_TRACE_ON packet is inserted") + print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu) return =20 if (start_addr < int(dso_start) or start_addr > int(dso_end)): - print(f"Start address 0x{start_addr:x} is out of range [ 0x{dso_start:x}= .. 0x{dso_end:x} ] for dso {dso}") + print("Start address 0x%x is out of range [ 0x%x .. 0x%x ] for dso %s" %= (start_addr, int(dso_start), int(dso_end), dso)) return =20 if (stop_addr < int(dso_start) or stop_addr > int(dso_end)): - print(f"Stop address 0x{stop_addr:x} is out of range [ 0x{dso_start:x} .= . 0x{dso_end:x} ] for dso {dso}") + print("Stop address 0x%x is out of range [ 0x%x .. 0x%x ] for dso %s" % = (stop_addr, int(dso_start), int(dso_end), dso)) return =20 if (options.objdump_name !=3D None): @@ -267,6 +269,6 @@ def process_event(param_dict): if path.exists(dso_fname): print_disam(dso_fname, dso_vm_start, start_addr, stop_addr) else: - print(f"Failed to find dso {dso} for address range [ 0x{start_addr:x} .= . 0x{stop_addr:x} ]") + print("Failed to find dso %s for address range [ 0x%x .. 0x%x ]" % (dso= , start_addr, stop_addr)) =20 print_srccode(comm, param_dict, sample, symbol, dso) --=20 2.25.1