From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BB5B3E8C64 for ; Sun, 20 Sep 2026 05:23:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789881835; cv=none; b=CxDm/qZdfsIWVLb0T6IUfkA4dVWYguMmIDE08ssHP0SL/J7MmkKwGkO4p8WuEgTkQj+xrMYXOSZr45ljzrFFxpAq5xKNswYFspPbCU+t+h1inyDnyqWKrY9KgqtuAy7TNyamo5balkEGiEh8xrElSlUq2/G6gTBVPtGIwk/4+Qs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789881835; c=relaxed/simple; bh=zwM1q1YUzZunL1x1lMbSfSDg6zmfdHldNS3fF7NQPj0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B+PJe+HRXwUmOHqHCaKzsLCPMfAbdnWfyLpTaDsRgFoKzTlzjXq5NFF0nqEopRXldLPjQVbw7uVTa7WIc/7mGeQfsnqAEnWr7HEMKwLkfmd/kJP7e6dUgiqddPI/+W8yon76/328yd2Hcrng38uV5jNk1CUcFlLX2Rd7CSQggZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IO02cimN; arc=none smtp.client-ip=209.85.216.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IO02cimN" Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-39aee9b4cf2so3750976a91.0 for ; Sat, 19 Sep 2026 22:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789881833; x=1790486633; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0HHfRcO9ZuBTSYkylxeBWu1seR4mW7jH0oHiQdS/3lo=; b=IO02cimNTXn252ffMFdCr1wP7Nyzd+PXf//RzYdIHe/7BBSmAtJ17pFvoV/5Updu1m Q9V9WXam26vlK6gIMZw9QZwjQl6eqBDG8NgNJ8fTEov2Q2s816gce46SZHPeD/mW07nD mKaygNyFo+312ZNP3UXyShwZLqxF0XMQwck8sH8zf7O98gfdTWUFp3ekQvIAX0TuCzJY t+xnHPowd9fnT5o7JIg4USEoSGvKZfkmZBD6XnX/O8tj7/QyMndbJUS/WUuXbpza7zBL 9+6ECjLgdMqy7sVcJIcu2QGQODdS7roeqWZJJD8FDOfDHM+H7RT0uMB+9O2vp6NIYN8n hcxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789881833; x=1790486633; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0HHfRcO9ZuBTSYkylxeBWu1seR4mW7jH0oHiQdS/3lo=; b=Ub5T1SvapQJ284raXkKxgM4DOXtLHyHn0qqcvaGq+6hlf8Y/VMXMEvEBgcDkp2MVqJ UTT2Hdx8hwzoPDe68k76/Xk6jF6U4X8HrqcSj+QSUoJI6mh+UxN06InIinG59Zw7h9wE TP5hNpBpud4FHWSMXz8p/6ekR7YZZhW49cyzuX7ascgRol96Tp2AbDYm948IqugkJv2D hon250UaNhKO1V86O7EW2HZ+FivWs/dWnmer5p8Z53T5T9DlU8l4B2h8+RFUXhGC+t56 7ToaUQFGmdG3slTciNPz8lpeyrTmvs3re04Y9HwwuHCUqdxcyvFha9SDN7ycrhIgzGSI 3/cw== X-Forwarded-Encrypted: i=1; AKwUvBwaVpO2NWC8+Dlti+EVeYRorwNLDYLcftePxwYkM7UTV2DqKhow0k0USqpBvyHEW4lTk+8htLVmy2XaqZI=@vger.kernel.org X-Gm-Message-State: AFuF++m9tI9rmiK9XN+Kquo/E/7huugy4ryYyuH/jL3luT/sZWhip7+5 O/L+NPaLaNvXRrlHmd/CuXdlKUrlokRM4Qrh3Uf2N4af5H2A+wIKM05cTrwqQGK1W2VQA6l+FYA iAAhcAwuy6g== X-Received: from dlbts22-n2.prod.google.com ([2002:a05:7022:b056:20b0:144:ce9a:b252]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1347:b0:39e:6c68:c77e with SMTP id 98e67ed59e1d1-39e6c68cae6mr5817878a91.52.1789881832482; Sat, 19 Sep 2026 22:23:52 -0700 (PDT) Date: Sat, 19 Sep 2026 22:21:33 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.55.0.1082.g2b9226bbc0-goog Message-ID: Subject: [PATCH v1 41/49] perf test: Migrate Intel PT virtual LBR test to Python API From: Ian Rogers To: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com, alice.mei.rogers@gmail.com, james.clark@linaro.org, linux-perf-users@vger.kernel.org, namhyung@kernel.org Cc: dapeng1.mi@linux.intel.com, leo.yan@linux.dev, linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, tmricht@linux.ibm.com Content-Type: text/plain; charset="UTF-8" Migrate the Intel PT virtual LBR test from generating an inline legacy perf script callback to using a standalone Python script (perf_brstack_max.py) with the brstack iterator API in the perf Python module. Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers --- .../perf/tests/shell/lib/perf_brstack_max.py | 37 +++++++++++++++++ tools/perf/tests/shell/test_intel_pt.sh | 41 ++++++++----------- 2 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 tools/perf/tests/shell/lib/perf_brstack_max.py diff --git a/tools/perf/tests/shell/lib/perf_brstack_max.py b/tools/perf/tests/shell/lib/perf_brstack_max.py new file mode 100644 index 000000000000..e2f5362de5e6 --- /dev/null +++ b/tools/perf/tests/shell/lib/perf_brstack_max.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +# SPDX-License-Identifier: GPL-2.0 +# Determine the maximum size of branch stacks in a perf.data file. + +import argparse +import sys + +import perf + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("-i", "--input", default="perf.data", help="Input file name") + args = ap.parse_args() + + bmax = 0 + + def process_event(sample): + nonlocal bmax + try: + brstack = sample.brstack + if brstack: + n = len(list(brstack)) + if n > bmax: + bmax = n + except AttributeError: + pass + + try: + session = perf.session(perf.data(args.input), sample=process_event) + session.process_events() + print("max brstack", bmax) + except Exception as e: + print(f"Error processing events: {e}", file=sys.stderr) + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/tools/perf/tests/shell/test_intel_pt.sh b/tools/perf/tests/shell/test_intel_pt.sh index 26243ff760ec..e512d0c88dd0 100755 --- a/tools/perf/tests/shell/test_intel_pt.sh +++ b/tools/perf/tests/shell/test_intel_pt.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Miscellaneous Intel PT testing (exclusive) # SPDX-License-Identifier: GPL-2.0 +# Miscellaneous Intel PT testing (exclusive) set -e @@ -22,7 +22,7 @@ perfdatafile="${temp_dir}/test-perf.data" outfile="${temp_dir}/test-out.txt" errfile="${temp_dir}/test-err.txt" awkscript="${temp_dir}/awkscript" -maxbrstack="${temp_dir}/maxbrstack.py" + cleanup() { @@ -376,34 +376,27 @@ test_kernel_trace() test_virtual_lbr() { echo "--- Test virtual LBR ---" - # Check if python script is supported - libpython=$(perf version --build-options | grep python | grep -cv OFF) - if [ "${libpython}" != "1" ] ; then - echo "SKIP: python scripting is not supported" + # Check if python is available + if ! command -v python3 >/dev/null 2>&1 && ! command -v python >/dev/null 2>&1; then + echo "SKIP: python not found" return 2 fi - # Python script to determine the maximum size of branch stacks - cat << "_end_of_file_" > "${maxbrstack}" -from __future__ import print_function - -bmax = 0 + # shellcheck source=lib/setup_python.sh + . "$(dirname "$0")"/lib/setup_python.sh -def process_event(param_dict): - if "brstack" in param_dict: - brstack = param_dict["brstack"] - n = len(brstack) - global bmax - if n > bmax: - bmax = n - -def trace_end(): - print("max brstack", bmax) -_end_of_file_ + if ! $PYTHON -c 'import perf' > /dev/null 2>&1; then + echo "SKIP: Python perf module not found" + return 2 + fi # Check if virtual lbr is working - perf_record_no_bpf -o "${perfdatafile}" --aux-sample -e '{intel_pt//,cycles}:u' uname - times_val=$(perf script -i "${perfdatafile}" --itrace=L -s "${maxbrstack}" 2>/dev/null | grep "max brstack " | cut -d " " -f 3) + perf_record_no_bpf -o "${tmpfile}" --aux-sample \ + -e '{intel_pt//,cycles}:u' perf test -w brstack + perf inject --itrace=L -i "${tmpfile}" -o "${perfdatafile}" + output=$($PYTHON "$(dirname "$0")"/lib/perf_brstack_max.py -i "${perfdatafile}") + echo "Debug: perf_brstack_max.py output: $output" + times_val=$(echo "$output" | grep "max brstack " | cut -d " " -f 3) case "${times_val}" in [0-9]*) ;; *) times_val=0;; -- 2.55.0.1082.g2b9226bbc0-goog