From nobody Tue Feb 10 06:04:50 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 56C8B3382E0 for ; Mon, 9 Feb 2026 20:22:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770668535; cv=none; b=f7uWAxDhJPytlujHI6h2Xt0iW1HP8Aa+f+Oh8iBsTXqrKlERsNWYSAtPWFBtUW9AWa61xbZyS5MBJ/kLythdu2tfJUdUfs4QRe9gaN9NOJRHPy6HZSS9rcjO7cZifisX+fXVwDBpNlvM3qKRBuqgUeNXPVrz+zb6ISHzq3GjXlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770668535; c=relaxed/simple; bh=Ui/SugiVmcRAov8tt7/adCmjGYW1ScNgh0Y3uPIDkF4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ZRbgfGtixIY3Hia9+oouDplrV3Mf6W7IqMlN2u8DkYwMSpI1sKNAgudfyYhkLKIDSZRruyziNxvyzh8kaa4flXzzcNqquiJWwOTg85pYCE8NIaD4W6VUnhe3agDBKS6Mkw02E/uqBEsGX9DNugfyhM+9h2k5Fj6ps61cqvlnS2o= 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=RIHqp01x; arc=none smtp.client-ip=74.125.82.74 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="RIHqp01x" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-126e8ee6227so83395c88.0 for ; Mon, 09 Feb 2026 12:22:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770668533; x=1771273333; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=K0daziDUtL2ibgI5WtkZQDKzcSzE6a5XxpXzSEtLh90=; b=RIHqp01xMw0CKXnUwhwekkv+fvTer6yLvlaE91cU+3sMApi2wa8oKtZAN4RI7DhAZy sv+Myh8ZEA5s1DuoSHXK1SPG8drknmHizTCIA96pjXm+Ht4/Jbo+fclvGKJBwPp1Phr4 X6bkgHmW+NKZyapK6ohbY06YmpeF1l/8rGAhfa4GDnBwBUSfx0hO8S8hdkfYGLuNt+xt 5h0iLwDLnx1IRNIf/nT3kjIcwXYBQexZ95WbXcXIL2aa9zUIKiHn3diaYUKm+fOzaO4H K4YXRB66rIjzO61bSmf2xwiW624+xlkB70iuCpTLp1lFN/k1/ggp/FBiEDQPy9cs05tm BU5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770668533; x=1771273333; h=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; bh=K0daziDUtL2ibgI5WtkZQDKzcSzE6a5XxpXzSEtLh90=; b=c2EZNYe3tDekrOH1+L22xZ4IwloXBwc33eAg/I7Op/e2Hr77L4u/8/OjZXYvIQGiCu B2nJr1KR+vswQJRAUc9CDaypeFEG1QLy1JI8OIKfQuB04MLWGQFYhOGvl9GcXxbMn7KJ TKv0LMFNCfmg6Yt0HjHMMD0MnwSqHB09f2xtkRbbP8rOde18VhexJOh+LbA/rga1oKDa gATokwknldsqeSinoO0AMauJwU1hk3KVhDz8XJ7uvfkZSzp0h2E0oMtlOH45zQGnWIGH KImRomJGpS1QuFjqVPu9wSvva/RFzlIORohqXbnylN6D3j6tffgM59scjA49EXL5Y1FJ WPfg== X-Forwarded-Encrypted: i=1; AJvYcCUWASRFstsnqaovXEddp/qo0F5JQjBGqUFJ/IEcyxXgYTBHdzqdfz8m7iM0rZFuhJqea01ZdM7T7zKyGgs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxh4Yp6z6YZJVhWPxQm/fZVFwo++fPTu6IJaF/6wxLgOKdR4+Jh AYLJsEXPYyjC2R0rIETNFsf4J9U942hNeQYMWbslKgK5Uo2EuWS6cuJe1RLtzG36k9jKZDXqN6K s6+/VAYBjaQ== X-Received: from dll39.prod.google.com ([2002:a05:7022:227:b0:123:2708:9404]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e22:b0:11b:8b4b:bff7 with SMTP id a92af1059eb24-1270409535emr5362949c88.39.1770668533318; Mon, 09 Feb 2026 12:22:13 -0800 (PST) Date: Mon, 9 Feb 2026 12:22:06 -0800 In-Reply-To: <20260209202208.2027001-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260209202208.2027001-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260209202208.2027001-2-irogers@google.com> Subject: [PATCH v1 1/3] perf script: Allow the generated script to be a path From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Sandipan Das , Leo Yan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow the script generated by "perf script -g " to be a file path and the language determined by the file extension. This is useful in testing so that the generated script file can be written to a test directory. Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-script.txt | 6 ++++-- tools/perf/builtin-script.c | 24 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Document= ation/perf-script.txt index 03d112960632..ddf92f9c7821 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -98,8 +98,10 @@ OPTIONS =20 -g:: --gen-script=3D:: - Generate perf-script.[ext] starter script for given language, - using current perf.data. + Generate a starter script. If a language is given then the + script is named perf-script.[ext] according to the + language. If a file path is given then python is used for + files ending '.py' and perl used for files ending '.pl'. =20 --dlfilter=3D:: Filter sample events using the given shared object file. diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 14c6f6c3c4f2..7c743a303507 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -4489,6 +4489,7 @@ int cmd_script(int argc, const char **argv) if (generate_script_lang) { struct stat perf_stat; int input; + char *filename =3D strdup("perf-script"); =20 if (output_set_by_user()) { fprintf(stderr, @@ -4516,17 +4517,32 @@ int cmd_script(int argc, const char **argv) } =20 scripting_ops =3D script_spec__lookup(generate_script_lang); + if (!scripting_ops && ends_with(generate_script_lang, ".py")) { + scripting_ops =3D script_spec__lookup("python"); + free(filename); + filename =3D strdup(generate_script_lang); + filename[strlen(filename) - 3] =3D '\0'; + } else if (!scripting_ops && ends_with(generate_script_lang, ".pl")) { + scripting_ops =3D script_spec__lookup("perl"); + free(filename); + filename =3D strdup(generate_script_lang); + filename[strlen(filename) - 3] =3D '\0'; + } if (!scripting_ops) { - fprintf(stderr, "invalid language specifier"); + fprintf(stderr, "invalid language specifier '%s'\n", generate_script_la= ng); err =3D -ENOENT; goto out_delete; } + if (!filename) { + err =3D -ENOMEM; + goto out_delete; + } #ifdef HAVE_LIBTRACEEVENT - err =3D scripting_ops->generate_script(session->tevent.pevent, - "perf-script"); + err =3D scripting_ops->generate_script(session->tevent.pevent, filename); #else - err =3D scripting_ops->generate_script(NULL, "perf-script"); + err =3D scripting_ops->generate_script(NULL, filename); #endif + free(filename); goto out_delete; } =20 --=20 2.53.0.rc2.204.g2597b5adb4-goog From nobody Tue Feb 10 06:04:50 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (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 4DAC23382EC for ; Mon, 9 Feb 2026 20:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770668538; cv=none; b=hST80DVXRXlMSBY6iIJdDMGHEYdocux2aSZWpZXciJ+up9GxqogRn5fBUgcJS/LCffhcWbJHGlm0tK28g85pPpS2QKWQyE2l4wNs9gatbYKz/PHM4NKhA3DC+BRcc9YgIwaXUxgZ3QINotU4J3o4lfET3Y3zm8eXasIZkFmbIik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770668538; c=relaxed/simple; bh=99vpJ8GhF7eNAqDOXeu+Fr9toiJJdQEGZfjkLvia1ng=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=oICfYkqEHyxJyzRnGKiMxSezb5h+xFOm6yNPQur5fnNYA9hcjvAU7TFDx+72UmfiqfK0ryGSjxFea1aWZc482UsTlm6lYIDpHtlEvLVBhIDP9pxPhIculC2RvAZxf8TbRiBx9XEz+UEL3NmjzU/8zMI+qqlG7NtoyuhixADg0BY= 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=kDDua+kR; arc=none smtp.client-ip=74.125.82.202 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="kDDua+kR" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2ba6e8ac125so442688eec.0 for ; Mon, 09 Feb 2026 12:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770668535; x=1771273335; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7betNIsJE10/NnsmMe+hD7nf/zhUEKUN9SyRdUo6KrU=; b=kDDua+kRerBxBeAb7/yZP6iAcjtRzVVuEbD3DqYYHwu7SJLLbDxryvaySnLxXNM14D ed2bXiPexGD198UGOm7UgEMaJOrPVosC1eQwS7i1Pz6pW6+znnzsD5luvLbUXr81fp1g e4pybYwMhAEjvLnJ3+nZDrKrPZ4pHH9EzhfhRGGmrF7UarBidBoSodsPcYewo03MFdUi +VdrFi5pInyIuFXncANWFGW+ehS/QmPsJbolFGKKfzdoguTuHWG5tGxRwXDYjHQveovt RIg/XoDyaY6+J6+i/uT2jffz5xzu2l4AYmhFycaxcN3OCaXsSK27pjyjppVh31odRG/l nBSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770668535; x=1771273335; h=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; bh=7betNIsJE10/NnsmMe+hD7nf/zhUEKUN9SyRdUo6KrU=; b=R9HQglhuTyYL00dxp6r70W052bJyM7f0IdmMUBVUGzpL9/tikrMnknN1XddgwfwlrT xXqIwv28APm7yLxz3oO43STf//0hdGOLQD8Izuecif2V3Kst/H3WzkvBmcPtWTRQ4oUD Xw8SCK8wzgyMMRojXR6bhQogiZe6PHrV/lCTlJErxafNEuAq459kDaiCelgAQzqd+fH2 qDDrSDE4/XSfnTLIwSHw1mG735qe4ClSZBeodnioONjLpqsVC20D66cHpj4P1TAE4l5p 2HH8NA6+Nq2BXZowQRL8rqG3eDVaNShXTpTjoSmc22uz9Fp6XITZ8Va+yxIk09Oy1e0J k9lg== X-Forwarded-Encrypted: i=1; AJvYcCUifDAGzm9S5PoKosHzq/r3N0SbJ3bhqQ55J3Rz2NeFDoe6ITrHUiAk5OQzFX5X4RYVJ+HPzkSL2Bvu7Wc=@vger.kernel.org X-Gm-Message-State: AOJu0Ywp6K9orpnkVwah93BBL/CpOLGddGhX+m8lhBIhzQ1OVuYA09uq fdYFU6e9it/5phP20SX0nE9P6Xeqt0TKeRikxU41RGAKSugHs0yjJ/epq0kqCowVHIHbmbEuHHP lz0YSdDOIAQ== X-Received: from dybhk9.prod.google.com ([2002:a05:7301:2889:b0:2b6:bc40:5234]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:2288:b0:2a4:3594:72ed with SMTP id 5a478bee46e88-2b8564ecb2cmr4777348eec.28.1770668535306; Mon, 09 Feb 2026 12:22:15 -0800 (PST) Date: Mon, 9 Feb 2026 12:22:07 -0800 In-Reply-To: <20260209202208.2027001-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260209202208.2027001-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260209202208.2027001-3-irogers@google.com> Subject: [PATCH v1 2/3] perf test script: Add perl script testing support From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Sandipan Das , Leo Yan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Basic coverage of perl script support from `perf script`. This is disabled by default and so the test will most normally skip. Signed-off-by: Ian Rogers --- tools/perf/tests/shell/script_perl.sh | 102 ++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 tools/perf/tests/shell/script_perl.sh diff --git a/tools/perf/tests/shell/script_perl.sh b/tools/perf/tests/shell= /script_perl.sh new file mode 100755 index 000000000000..b6d65b6fbda1 --- /dev/null +++ b/tools/perf/tests/shell/script_perl.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# perf script perl tests +# SPDX-License-Identifier: GPL-2.0 + +set -e + +# set PERF_EXEC_PATH to find scripts in the source directory +perfdir=3D$(dirname "$0")/../.. +if [ -e "$perfdir/scripts/perl/Perf-Trace-Util" ]; then + export PERF_EXEC_PATH=3D$perfdir +fi + + +perfdata=3D$(mktemp /tmp/__perf_test_script_perl.perf.data.XXXXX) +generated_script=3D$(mktemp /tmp/__perf_test_script.XXXXX.pl) + +cleanup() { + rm -f "${perfdata}" + rm -f "${generated_script}" + trap - EXIT TERM INT +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup TERM INT +trap cleanup EXIT + +check_perl_support() { + if perf check feature -q libperl; then + return 0 + fi + echo "perf script perl test [Skipped: no libperl support]" + return 2 +} + +test_script() { + local event_name=3D$1 + local expected_output=3D$2 + local record_opts=3D$3 + + echo "Testing event: $event_name" + + # Try to record. If this fails, it might be permissions or lack of suppor= t. + # We return 2 to indicate "skip this event" rather than "fail test". + if ! perf record -o "${perfdata}" -e "$event_name" $record_opts -- perf t= est -w thloop > /dev/null 2>&1; then + echo "perf script perl test [Skipped: failed to record $event_name]" + return 2 + fi + + echo "Generating perl script..." + if ! perf script -i "${perfdata}" -g "${generated_script}"; then + echo "perf script perl test [Failed: script generation for $event_name]" + return 1 + fi + + if [ ! -f "${generated_script}" ]; then + echo "perf script perl test [Failed: script not generated for $event_nam= e]" + return 1 + fi + + echo "Executing perl script..." + output=3D$(perf script -i "${perfdata}" -s "${generated_script}" 2>&1) + + if echo "$output" | grep -q "$expected_output"; then + echo "perf script perl test [Success: $event_name triggered $expected_ou= tput]" + return 0 + else + echo "perf script perl test [Failed: $event_name did not trigger $expect= ed_output]" + echo "Output was:" + echo "$output" | head -n 20 + return 1 + fi +} + +check_perl_support || exit 2 + +# Try tracepoint first +test_script "sched:sched_switch" "sched::sched_switch" "-c 1" && res=3D0 |= | res=3D$? + +if [ $res -eq 0 ]; then + exit 0 +elif [ $res -eq 1 ]; then + exit 1 +fi + +# If tracepoint skipped (res=3D2), try task-clock +# For generic events like task-clock, the generated script uses process_ev= ent() +# which dumps data using Data::Dumper. We check for "$VAR1" which is stand= ard Dumper output. +test_script "task-clock" "\$VAR1" "-c 100" && res=3D0 || res=3D$? + +if [ $res -eq 0 ]; then + exit 0 +elif [ $res -eq 1 ]; then + exit 1 +fi + +# If both skipped +echo "perf script perl test [Skipped: Could not record tracepoint or task-= clock]" +exit 2 --=20 2.53.0.rc2.204.g2597b5adb4-goog From nobody Tue Feb 10 06:04:50 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (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 4BF703382E2 for ; Mon, 9 Feb 2026 20:22:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770668539; cv=none; b=EzDtobBaXI7ndLXKi2SImwymfnfjUeW3M6f5AgseKJBtz5pjwBrp+XK+G1pMwUzj1G3wWOhNetaFkB/nuJ15KPU0JlXqW8PGU6VaZSrn4Ez2jDtHm1LkxJxO348uwngf1E7wVcPxOog/yTGKMfpDuSSfxuJSZucMORt9XZxv1FA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770668539; c=relaxed/simple; bh=WD07r+zXb1oQG7d6AS1Ukm/XofMWenplrDPBHy3EgUc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=eES/VWfehvzBz973FVXsl27owt5TGzQ2h2GFVrbdTDZc4qXX2t6fW+a2YowQ75VS1g4Ao0r/QSEwXZVyVwcLfBm8FGrddKzICNUnkE4CXPBJ1bGEvO14WFtwtFCGA9ax5BC5lsjXRzTnB81SM+RN+q9mK6T0KCguQiOUkYySwZM= 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=WB3GV2UY; arc=none smtp.client-ip=74.125.82.201 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="WB3GV2UY" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2ba8013a9e3so81583eec.0 for ; Mon, 09 Feb 2026 12:22:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770668537; x=1771273337; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=eg434dzqJzkiMn4Wl04ZGI19f2RXB1FpMi/xYmoSVd0=; b=WB3GV2UYeZDYjp4QJ5Gm1EYZz8rI0X9dLNiDJwyi7+sVvTn6TNfGkwHLuloL6t1dPS sk0ysBMnx/wFaYiPYsTMnBTE+28fiQxomr8lbuIOMAx4UtPY3bbLtdEzfeHo2FEwOL93 05NEWb59nDyKvEjNzhFVl5tZ7Ey+Q11jehr7WvCG8yotLuxalwF+VETiJFTz7b8IxJVI YyYECkBqxCpM6X5ip7haMbEv6Xmk8Y9ntmHN9M0clye48erdLDI+Kdt3D98YkZxoKkHa 2PlBOdKVrbNCQvwwoxAmHsQaZW2UQFzK84F6xAT3LZvNP8eK1hnqFfCyeqMPQ6HQBGPb vsCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770668537; x=1771273337; h=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; bh=eg434dzqJzkiMn4Wl04ZGI19f2RXB1FpMi/xYmoSVd0=; b=C/0W9ER9r9jeZSKJh2alvGY+pizUFZ4Yshch7juoRnUeMiGNjc3hqQtU/ROrWACGg2 dZeDPjVWZ0HqbgKZwYMS6V8Hk/uv8g6CJfiXtmlKC6bpU6yOxnkUVdBZDXDzgkm8pqDv aET1G/TRcQzfVr1vOQrrJXtN7Cn3h6/S5xCD1xY/W7nG7ASwjn7vdksOlQgSgMhftj/Y laQYgjARLUSIrI/yb1j0/YUIVldg23bjma+9aUJQUeStI9VMQmNLqY3q0cJVVeNvQTcN 5e+IRXyfZPHbINLWsyegZJnBv/4DcHXoXOuA2wtmN6onNS4v6rXEI7o0aB7dHqrUJ0nu EiMQ== X-Forwarded-Encrypted: i=1; AJvYcCVeOrM2kv68EgGZ7R6q+cG+bxjwhIOlq5ZRCPW41HrOwdySwkHXl3wAY3nE+rVG7sIJVhNNT/uecUulR0w=@vger.kernel.org X-Gm-Message-State: AOJu0Yzh2X3+qRVqnR66olpWqR/9r0y0M+DhttXwCM7rseRbm7VtNASD tQVfZUlj//ZKVJKyJ+Z8MNdcB4ynvWfzQjyNHuW0LNSYvD889IBTV6X5oQ0fDO86zng5KAR9c6A KHtwM3mXUSA== X-Received: from dyz14.prod.google.com ([2002:a05:693c:408e:b0:2ba:6448:ee87]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:6d07:b0:2ba:7b63:3f6e with SMTP id 5a478bee46e88-2ba7b635108mr972397eec.11.1770668537368; Mon, 09 Feb 2026 12:22:17 -0800 (PST) Date: Mon, 9 Feb 2026 12:22:08 -0800 In-Reply-To: <20260209202208.2027001-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260209202208.2027001-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260209202208.2027001-4-irogers@google.com> Subject: [PATCH v1 3/3] perf test script: Add python script testing support From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Sandipan Das , Leo Yan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Basic coverage of python script support from `perf script`. Signed-off-by: Ian Rogers --- tools/perf/tests/shell/script_python.sh | 113 ++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 tools/perf/tests/shell/script_python.sh diff --git a/tools/perf/tests/shell/script_python.sh b/tools/perf/tests/she= ll/script_python.sh new file mode 100755 index 000000000000..6bc66074a31f --- /dev/null +++ b/tools/perf/tests/shell/script_python.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# perf script python tests +# SPDX-License-Identifier: GPL-2.0 + +set -e + +# set PERF_EXEC_PATH to find scripts in the source directory +perfdir=3D$(dirname "$0")/../.. +if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then + export PERF_EXEC_PATH=3D$perfdir +fi + + +perfdata=3D$(mktemp /tmp/__perf_test_script_python.perf.data.XXXXX) +generated_script=3D$(mktemp /tmp/__perf_test_script.XXXXX.py) + +cleanup() { + rm -f "${perfdata}" + rm -f "${generated_script}" + trap - EXIT TERM INT +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup TERM INT +trap cleanup EXIT + +check_python_support() { + if perf check feature -q libpython; then + return 0 + fi + echo "perf script python test [Skipped: no libpython support]" + return 2 +} + +test_script() { + local event_name=3D$1 + local expected_output=3D$2 + local record_opts=3D$3 + + echo "Testing event: $event_name" + + # Try to record. If this fails, it might be permissions or lack of + # support. Return 2 to indicate "skip this event" rather than "fail + # test". + if ! perf record -o "${perfdata}" -e "$event_name" $record_opts -- perf t= est -w thloop > /dev/null 2>&1; then + echo "perf script python test [Skipped: failed to record $event_name]" + return 2 + fi + + echo "Generating python script..." + if ! perf script -i "${perfdata}" -g "${generated_script}"; then + echo "perf script python test [Failed: script generation for $event_name= ]" + return 1 + fi + + if [ ! -f "${generated_script}" ]; then + echo "perf script python test [Failed: script not generated for $event_n= ame]" + return 1 + fi + + # Perf script -g python doesn't generate process_event for generic + # events so append it manually to test that the callback works. + if ! grep -q "def process_event" "${generated_script}"; then + cat <> "${generated_script}" + +def process_event(param_dict): + print("param_dict: %s" % param_dict) +EOF + fi + + echo "Executing python script..." + output=3D$(perf script -i "${perfdata}" -s "${generated_script}" 2>&1) + + if echo "$output" | grep -q "$expected_output"; then + echo "perf script python test [Success: $event_name triggered $expected_= output]" + return 0 + else + echo "perf script python test [Failed: $event_name did not trigger $expe= cted_output]" + echo "Output was:" + echo "$output" | head -n 20 + return 1 + fi +} + +check_python_support || exit 2 + +# Try tracepoint first +test_script "sched:sched_switch" "sched__sched_switch" "-c 1" && res=3D0 |= | res=3D$? + +if [ $res -eq 0 ]; then + exit 0 +elif [ $res -eq 1 ]; then + exit 1 +fi + +# If tracepoint skipped (res=3D2), try task-clock +# For generic events like task-clock, the generated script uses process_ev= ent() +# which prints the param_dict. +test_script "task-clock" "param_dict" "-c 100" && res=3D0 || res=3D$? + +if [ $res -eq 0 ]; then + exit 0 +elif [ $res -eq 1 ]; then + exit 1 +fi + +# If both skipped +echo "perf script python test [Skipped: Could not record tracepoint or tas= k-clock]" +exit 2 --=20 2.53.0.rc2.204.g2597b5adb4-goog