From nobody Sat Feb 7 08:43:57 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEF6B14F9E2; Sat, 1 Mar 2025 04:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740801774; cv=none; b=DY7rhH823oCCsxYUfL316uiKXbidu3po/SHLgOET42Omm4fgSnOV07n7GhgMIqyh5rB0GK3csOld/4NFVXWm0Q4HHpkx0hv2soCOXtFh6lCWMeMwucrj/QjqPvklVjd76CesV/YpYG6rdyaj2jp4UeRO+0/vUHFF7n3XyPcbyE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740801774; c=relaxed/simple; bh=nZ8ZCLcaVnVr2jRx2sOVDA3QIxlrVukP83MzQFyKq/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VRdMyyWw7NXqhe/oFuy/9RCR9IOUI49Zwed3d6sHzkd8ED6Xmj7GrfYJUhOk8kiL0g2woCQvBvEzlDI70EyyFhjiaWNf1+TJIgzPrpYjL9i/emXzSKNR6v4BL0UeIDRBw1r4zXirraBTwGVhKx+SXlw62J/gJa/2ftOmJE8tHYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d1wfEIKm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d1wfEIKm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAA8FC4CEE5; Sat, 1 Mar 2025 04:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740801774; bh=nZ8ZCLcaVnVr2jRx2sOVDA3QIxlrVukP83MzQFyKq/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d1wfEIKmxDm8sbwOD021UTwIt/gk8iHtkDQDPDBdV8fPNEIow9pBQTKJ3nwmEG4Jt 2TS73MBBXKND2LPBVFyrDZCEkqCrM/3txwS1rNqDk0hc/4Z8MhsTwKnh2hdS4RH51j zuvhS7zGlRrkGiEpciqaHXbxdKB/0C+Zh4xdk0xf47oS4TSXAN2yXLCOhAyuGJ9fAS zBqL1rE5Xx1G/dkaVAfP1dJRn5Bkna12eqncy1C4UQLDzqiFt31o0oWAYlVCKp4/Bk TVoQdSpoblTlKpsZC7oXYvVUtAuqhK5gc8JqVHViRfrA0IiLTgPl8f44Wgzzh3gF1J HD8uyWAllCKCg== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 1/4] perf test: Add --metric-only to perf stat output tests Date: Fri, 28 Feb 2025 20:02:49 -0800 Message-ID: <20250301040252.1586750-2-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250301040252.1586750-1-namhyung@kernel.org> References: <20250301040252.1586750-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a test case for --metric-only for std, csv, json output mode using shadow IPC metric from instructions and cycles events. It should produce 'insn per cycle' metric. But currently JSON output has (none) 'GHz' as well. It looks like a bug but I don't have enough time to debug it for now so I made it pass. :( $ perf stat --metric-only -e instructions,cycles true Performance counter stats for 'true': 0.56 0.002127319 seconds time elapsed 0.002077000 seconds user 0.000000000 seconds sys $ perf stat -x, --metric-only -e instructions,cycles true 0.55,, $ perf stat -j --metric-only -e instructions,cycles true {"insn per cycle" : "0.53", "GHz" : "none"} $ perf test output -v 5: Test data source output : Ok 31: Sort output of hist entries : Ok 88: perf stat CSV output linter : Ok 90: perf stat JSON output linter : Ok 92: perf stat STD output linter : Ok Suggested-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/tests/shell/lib/perf_json_output_lint.py | 7 +++++++ tools/perf/tests/shell/lib/stat_output.sh | 8 ++++++++ tools/perf/tests/shell/stat+csv_output.sh | 2 ++ tools/perf/tests/shell/stat+json_output.sh | 9 +++++++++ tools/perf/tests/shell/stat+std_output.sh | 8 ++++++++ 5 files changed, 34 insertions(+) diff --git a/tools/perf/tests/shell/lib/perf_json_output_lint.py b/tools/pe= rf/tests/shell/lib/perf_json_output_lint.py index b066d721f89735df..9e772a89ce381636 100644 --- a/tools/perf/tests/shell/lib/perf_json_output_lint.py +++ b/tools/perf/tests/shell/lib/perf_json_output_lint.py @@ -19,6 +19,7 @@ ap.add_argument('--per-cluster', action=3D'store_true') ap.add_argument('--per-die', action=3D'store_true') ap.add_argument('--per-node', action=3D'store_true') ap.add_argument('--per-socket', action=3D'store_true') +ap.add_argument('--metric-only', action=3D'store_true') ap.add_argument('--file', type=3Dargparse.FileType('r'), default=3Dsys.std= in) args =3D ap.parse_args() =20 @@ -64,6 +65,8 @@ Lines =3D args.file.readlines() 'socket': lambda x: True, 'thread': lambda x: True, 'unit': lambda x: True, + 'insn per cycle': lambda x: isfloat(x), + 'GHz': lambda x: True, # FIXME: it seems unintended for --metric-on= ly } input =3D '[\n' + ','.join(Lines) + '\n]' for item in json.loads(input): @@ -78,6 +81,8 @@ Lines =3D args.file.readlines() pass elif count - 1 in expected_items and 'metric-threshold' in item: pass + elif count in expected_items and 'insn per cycle' in item: + pass elif count not in expected_items: raise RuntimeError(f'wrong number of fields. counted {count} expec= ted {expected_items}' f' in \'{item}\'') @@ -95,6 +100,8 @@ Lines =3D args.file.readlines() expected_items =3D [6, 8] elif args.per_core or args.per_socket or args.per_node or args.per_die o= r args.per_cluster or args.per_cache: expected_items =3D [7, 9] + elif args.metric_only: + expected_items =3D [1, 2] else: # If no option is specified, don't check the number of items. expected_items =3D -1 diff --git a/tools/perf/tests/shell/lib/stat_output.sh b/tools/perf/tests/s= hell/lib/stat_output.sh index 9a176ceae4a3c3a2..4d4aac547f0109d1 100644 --- a/tools/perf/tests/shell/lib/stat_output.sh +++ b/tools/perf/tests/shell/lib/stat_output.sh @@ -148,6 +148,14 @@ check_per_socket() echo "[Success]" } =20 +check_metric_only() +{ + echo -n "Checking $1 output: metric only " + perf stat --metric-only $2 -e instructions,cycles true + commachecker --metric-only + echo "[Success]" +} + # The perf stat options for per-socket, per-core, per-die # and -A ( no_aggr mode ) uses the info fetched from this # directory: "/sys/devices/system/cpu/cpu*/topology". For diff --git a/tools/perf/tests/shell/stat+csv_output.sh b/tools/perf/tests/s= hell/stat+csv_output.sh index fc2d8cc6e5e0b1e5..7a6f6e1774028322 100755 --- a/tools/perf/tests/shell/stat+csv_output.sh +++ b/tools/perf/tests/shell/stat+csv_output.sh @@ -44,6 +44,7 @@ function commachecker() ;; "--per-die") exp=3D8 ;; "--per-cluster") exp=3D8 ;; "--per-cache") exp=3D8 + ;; "--metric-only") exp=3D2 esac =20 while read line @@ -75,6 +76,7 @@ check_interval "CSV" "$perf_cmd" check_event "CSV" "$perf_cmd" check_per_thread "CSV" "$perf_cmd" check_per_node "CSV" "$perf_cmd" +check_metric_only "CSV" "$perf_cmd" if [ $skip_test -ne 1 ] then check_system_wide_no_aggr "CSV" "$perf_cmd" diff --git a/tools/perf/tests/shell/stat+json_output.sh b/tools/perf/tests/= shell/stat+json_output.sh index 6b630d33c3287899..a4f257ea839e1368 100755 --- a/tools/perf/tests/shell/stat+json_output.sh +++ b/tools/perf/tests/shell/stat+json_output.sh @@ -173,6 +173,14 @@ check_per_socket() echo "[Success]" } =20 +check_metric_only() +{ + echo -n "Checking json output: metric only " + perf stat -j --metric-only -e instructions,cycles -o "${stat_output}" true + $PYTHON $pythonchecker --metric-only --file "${stat_output}" + echo "[Success]" +} + # The perf stat options for per-socket, per-core, per-die # and -A ( no_aggr mode ) uses the info fetched from this # directory: "/sys/devices/system/cpu/cpu*/topology". For @@ -207,6 +215,7 @@ check_interval check_event check_per_thread check_per_node +check_metric_only if [ $skip_test -ne 1 ] then check_system_wide_no_aggr diff --git a/tools/perf/tests/shell/stat+std_output.sh b/tools/perf/tests/s= hell/stat+std_output.sh index 0f7967be60afdc7d..6fee67693ba7a9be 100755 --- a/tools/perf/tests/shell/stat+std_output.sh +++ b/tools/perf/tests/shell/stat+std_output.sh @@ -30,6 +30,7 @@ trap trap_cleanup EXIT TERM INT function commachecker() { local prefix=3D1 + local -i metric_only=3D0 =20 case "$1" in "--interval") prefix=3D2 @@ -41,6 +42,7 @@ function commachecker() ;; "--per-die") prefix=3D3 ;; "--per-cache") prefix=3D3 ;; "--per-cluster") prefix=3D3 + ;; "--metric-only") metric_only=3D1 esac =20 while read line @@ -60,6 +62,9 @@ function commachecker() x=3D${main_body%#*} [ "$x" =3D "" ] && continue =20 + # Check metric only - if it has a non-empty result + [ $metric_only -eq 1 ] && return 0 + # Skip metrics without event name y=3D${main_body#*#} for i in "${!skip_metric[@]}"; do @@ -84,6 +89,8 @@ function commachecker() exit 1; } done < "${stat_output}" + + [ $metric_only -eq 1 ] && exit 1 return 0 } =20 @@ -95,6 +102,7 @@ check_system_wide "STD" "$perf_cmd" check_interval "STD" "$perf_cmd" check_per_thread "STD" "$perf_cmd" check_per_node "STD" "$perf_cmd" +check_metric_only "STD" "$perf_cmd" if [ $skip_test -ne 1 ] then check_system_wide_no_aggr "STD" "$perf_cmd" --=20 2.48.1.711.g2feabab25a-goog From nobody Sat Feb 7 08:43:57 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 125541B87F0; Sat, 1 Mar 2025 04:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740801776; cv=none; b=HJSivuYWCNWjqsZEUASNCX3F3SYpSYs/lJLR2z3jdtfJLnc8HQPSvyOKbkrBR/r/rg59HkJNqpeSrtGT4OL3LUs5PWuph0yhF5TMERhEBFiltl9xLFTOfAVLqlK277grcHruHYuJj9cCjWZQPGzwxZvoKPTcqxGDddBUUQzMX2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740801776; c=relaxed/simple; bh=d901Y/hjDUT/pU0UBAW8Em2x+X51gXf/2YaVHj81Xq0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q/Se/0nGd4jlt+qHfGu69/mW7JF2QjS8tV8br2LaidOA5HxUWWOGby0WeDqToBSFrcNBJ64vmXZ3QbEN2JCWOrv6v0Upg/RSgOZbURz+MEE0PwHNPq7EdWroCWENzutPkYUr+jrXiH4fhyQKEhhln+gY7+3q8BTuk3hlqTnCbmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F4xZVTKR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F4xZVTKR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DDE2C4CEEA; Sat, 1 Mar 2025 04:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740801774; bh=d901Y/hjDUT/pU0UBAW8Em2x+X51gXf/2YaVHj81Xq0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F4xZVTKRgOkBhiYeEjseUPb3NxTpr+XHFa+i6lHdE55KvQU3g/AVgypO2lJFRm6uC /lUu4+vMEHy6012YTeMe0iTS6RDa+k9jGgJF9Wc6SxxYJ2Kzy/5BabPGDvpA7BF9Wd PbvMqvBzKLqcMltNCttieuzDAyQLoMqO9zv4z9TkESf/x36QA8VVWeb+Tejb3GFhnr /HXDZIP91fC7jiwP5UpKqODwbaHPvIvKtIklWceqWW73AbnNVEb931xL5+0o0+jbRk K2+AnuklBSR8SsJ/1maTpLW5uFgfw++HD+rlezGOAP5h3H7WZeZzl8nN+BNxyc3bTJ Go2WfOu8BgtFw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 2/4] perf test: Skip perf probe tests when running as non-root Date: Fri, 28 Feb 2025 20:02:50 -0800 Message-ID: <20250301040252.1586750-3-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250301040252.1586750-1-namhyung@kernel.org> References: <20250301040252.1586750-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf trace requires root because it needs to use [ku]probes. Skip those test when it's not run as root. Before: $ perf test probe 47: Probe SDT events : Ok 104: test perf probe of function from different CU : FA= ILED! 115: perftool-testsuite_probe : FA= ILED! 117: Add vfs_getname probe to get syscall args filenames : FA= ILED! 118: probe libc's inet_pton & backtrace it with ping : FA= ILED! 119: Use vfs_getname probe to get syscall args filenames : FA= ILED! After: $ perf test probe 47: Probe SDT events : Ok 104: test perf probe of function from different CU : Sk= ip 115: perftool-testsuite_probe : Sk= ip 117: Add vfs_getname probe to get syscall args filenames : Sk= ip 118: probe libc's inet_pton & backtrace it with ping : Sk= ip 119: Use vfs_getname probe to get syscall args filenames : Sk= ip Signed-off-by: Namhyung Kim --- tools/perf/tests/shell/perftool-testsuite_probe.sh | 1 + tools/perf/tests/shell/probe_vfs_getname.sh | 1 + tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 1 + .../tests/shell/record+script_probe_vfs_getname.sh | 1 + .../perf/tests/shell/test_uprobe_from_different_cu.sh | 11 +++++------ 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/perf/tests/shell/perftool-testsuite_probe.sh b/tools/per= f/tests/shell/perftool-testsuite_probe.sh index 7b1bfd0f888fc30c..add77aaeb26421a5 100755 --- a/tools/perf/tests/shell/perftool-testsuite_probe.sh +++ b/tools/perf/tests/shell/perftool-testsuite_probe.sh @@ -2,6 +2,7 @@ # perftool-testsuite_probe (exclusive) # SPDX-License-Identifier: GPL-2.0 =20 +[ "$(id -u)" =3D=3D 0 ] || exit 2 test -d "$(dirname "$0")/base_probe" || exit 2 cd "$(dirname "$0")/base_probe" || exit 2 status=3D0 diff --git a/tools/perf/tests/shell/probe_vfs_getname.sh b/tools/perf/tests= /shell/probe_vfs_getname.sh index 0c5aacc446b3ef76..b8e53a9d8473bf6b 100755 --- a/tools/perf/tests/shell/probe_vfs_getname.sh +++ b/tools/perf/tests/shell/probe_vfs_getname.sh @@ -8,6 +8,7 @@ . "$(dirname $0)"/lib/probe.sh =20 skip_if_no_perf_probe || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 # shellcheck source=3Dlib/probe_vfs_getname.sh . "$(dirname $0)"/lib/probe_vfs_getname.sh diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh b/tools/= perf/tests/shell/record+probe_libc_inet_pton.sh index d5e5193cceb625fd..07a1527c5c03b93d 100755 --- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh +++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh @@ -105,6 +105,7 @@ delete_libc_inet_pton_event() { =20 # Check for IPv6 interface existence ip a sh lo | grep -F -q inet6 || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 skip_if_no_perf_probe && \ add_libc_inet_pton_event && \ diff --git a/tools/perf/tests/shell/record+script_probe_vfs_getname.sh b/to= ols/perf/tests/shell/record+script_probe_vfs_getname.sh index 5940fdc1df37c502..0af3af90a8dcc742 100755 --- a/tools/perf/tests/shell/record+script_probe_vfs_getname.sh +++ b/tools/perf/tests/shell/record+script_probe_vfs_getname.sh @@ -13,6 +13,7 @@ . "$(dirname "$0")/lib/probe.sh" =20 skip_if_no_perf_probe || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 # shellcheck source=3Dlib/probe_vfs_getname.sh . "$(dirname "$0")/lib/probe_vfs_getname.sh" diff --git a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh b/tool= s/perf/tests/shell/test_uprobe_from_different_cu.sh index 33387c329f92b6ed..7adf9755d6de240e 100755 --- a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh +++ b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh @@ -4,12 +4,11 @@ =20 set -e =20 -# Skip if there's no probe command. -if ! perf | grep probe -then - echo "Skip: probe command isn't present" - exit 2 -fi +# shellcheck source=3Dlib/probe.sh +. "$(dirname $0)"/lib/probe.sh + +skip_if_no_perf_probe || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 # skip if there's no gcc if ! [ -x "$(command -v gcc)" ]; then --=20 2.48.1.711.g2feabab25a-goog From nobody Sat Feb 7 08:43:57 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 124F91B87E9; Sat, 1 Mar 2025 04:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740801776; cv=none; b=X/binHy4MgBGSQ1RT9JdIeLaPQyei/2R0Z8En82D3xURTM14MwlSeVLqajkd6zh75QdJP5B7fMCAnJP7lfekLn/8Mn1djjv62C00a5RJf1YXNa1ha02WYvsMt8TKx67Sg/ozZM2ILIIWLNlT24dOuCrFKvY+wCh5928ZLIhMZnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740801776; c=relaxed/simple; bh=/tAtFCekLIQIOE0oqyYQAhRFugV1278wNpYABUitf9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C3DlhHQufexyf4xsKOYjPizR2kt+j5S7z+yd5NE8hScHtnadyDJlabWGnFBHmOUa0GPWFMTXO+zQQCs74WsYpj3txUSK/2Ykok/pGzpSJL+UVXhbp10OT1PIyOVaHPn1DhFP8RCStJU/VLCZtVeusheobgz8e+dXkSw/WQ+NoZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b+pGHfc2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b+pGHfc2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3176C4CEE8; Sat, 1 Mar 2025 04:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740801775; bh=/tAtFCekLIQIOE0oqyYQAhRFugV1278wNpYABUitf9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b+pGHfc28PCHUQ9VXq+WMysfU83hlI35Ph2xFfugTpJrNqm8GjS11luxp/3ZwnJsg dL+QbPqctyZUKFkE0SyVg+x6h4jB6SGFRwh391bjlfK4C21jNLcQ913ydQZkiOvHSH 5++JUjGj2dyAheI/7IktT/+qOh82USVxoL9ADUcifyPO7EC+fBGuZBeQ4ezoF2wvXN QYfVYN6SLYpAnHh7Hy3Gow/V/kDmYJbP/8Yv0brmDCgbBKLR//xw2DBW/kJ7LWCRA0 M/zTHJPLf2qD8TCBE+FrOfZb6HtvcHm5LSRRCnN4MAHYEA8RZ5gyJWZ4Sdw3m6vPIw ZJVn6m5Qp0fqQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 3/4] perf test: Skip perf trace tests when running as non-root Date: Fri, 28 Feb 2025 20:02:51 -0800 Message-ID: <20250301040252.1586750-4-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250301040252.1586750-1-namhyung@kernel.org> References: <20250301040252.1586750-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf trace requires root because it needs to use tracepoints and BPF. Skip those test when it's not run as root. Before: $ perf test trace 15: Parse sched tracepoints fields : Sk= ip (permissions) 80: perf ftrace tests : Sk= ip 105: perf trace enum augmentation tests : FA= ILED! 106: perf trace BTF general tests : FA= ILED! 107: perf trace exit race : FA= ILED! 118: probe libc's inet_pton & backtrace it with ping : Sk= ip 125: Check Arm CoreSight trace data recording and synthesized samples: Sk= ip 127: Check Arm SPE trace data recording and synthesized samples : Sk= ip 132: Check open filename arg using perf trace + vfs_getname : FA= ILED! After: $ perf test trace 15: Parse sched tracepoints fields : Sk= ip (permissions) 80: perf ftrace tests : Sk= ip 105: perf trace enum augmentation tests : Sk= ip 106: perf trace BTF general tests : Sk= ip 107: perf trace exit race : Sk= ip 118: probe libc's inet_pton & backtrace it with ping : Sk= ip 125: Check Arm CoreSight trace data recording and synthesized samples: Sk= ip 127: Check Arm SPE trace data recording and synthesized samples : Sk= ip 132: Check open filename arg using perf trace + vfs_getname : Sk= ip Signed-off-by: Namhyung Kim --- tools/perf/tests/shell/trace+probe_vfs_getname.sh | 1 + tools/perf/tests/shell/trace_btf_enum.sh | 1 + tools/perf/tests/shell/trace_btf_general.sh | 1 + tools/perf/tests/shell/trace_exit_race.sh | 1 + 4 files changed, 4 insertions(+) diff --git a/tools/perf/tests/shell/trace+probe_vfs_getname.sh b/tools/perf= /tests/shell/trace+probe_vfs_getname.sh index 708a13f006353611..cd64408043ccc89f 100755 --- a/tools/perf/tests/shell/trace+probe_vfs_getname.sh +++ b/tools/perf/tests/shell/trace+probe_vfs_getname.sh @@ -15,6 +15,7 @@ =20 skip_if_no_perf_probe || exit 2 skip_if_no_perf_trace || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 . "$(dirname $0)"/lib/probe_vfs_getname.sh =20 diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/sh= ell/trace_btf_enum.sh index 8d1e6bbeac906843..02da49af1f4ec71f 100755 --- a/tools/perf/tests/shell/trace_btf_enum.sh +++ b/tools/perf/tests/shell/trace_btf_enum.sh @@ -13,6 +13,7 @@ TESTPROG=3D"perf test -w landlock" # shellcheck source=3Dlib/probe.sh . "$(dirname $0)"/lib/probe.sh skip_if_no_perf_trace || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 check_vmlinux() { echo "Checking if vmlinux exists" diff --git a/tools/perf/tests/shell/trace_btf_general.sh b/tools/perf/tests= /shell/trace_btf_general.sh index e9ee727f3433eaba..a89dc4a6cfd1b1a5 100755 --- a/tools/perf/tests/shell/trace_btf_general.sh +++ b/tools/perf/tests/shell/trace_btf_general.sh @@ -76,6 +76,7 @@ trace_config() { =20 skip_if_no_perf_trace || exit 2 check_vmlinux || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 trace_config =20 diff --git a/tools/perf/tests/shell/trace_exit_race.sh b/tools/perf/tests/s= hell/trace_exit_race.sh index fbb0adc33a889516..7187ebc16c96b5ee 100755 --- a/tools/perf/tests/shell/trace_exit_race.sh +++ b/tools/perf/tests/shell/trace_exit_race.sh @@ -10,6 +10,7 @@ . "$(dirname $0)"/lib/probe.sh =20 skip_if_no_perf_trace || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 if [ "$1" =3D "-v" ]; then verbose=3D"1" --=20 2.48.1.711.g2feabab25a-goog From nobody Sat Feb 7 08:43:57 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1259F1B87F3; Sat, 1 Mar 2025 04:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740801776; cv=none; b=C53VMjP/LNmyL0ER0R7evhoDIazv9RtO1BG7VPxb7AAkZQ9Eqcs313379NWuCLCEcwXdaQeCW+jSdG7eks/XX84c4kduExql4gYwZ0bpjhgJtv2H2aJKgHuydZycadoHUAQokkjX/WQYj8K53of4OFRt+gmWxFgHxE6XXajxYeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740801776; c=relaxed/simple; bh=4e5iV1jyt44+vFhgI8mzweFLermL3m37/dLdNcU2d2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UAIwpRUFAp1+QWD0YUabbOKeu4uImJTbQPpQOhX8RNhql8xydbt73jDOXiSYjB+LeKElGYACdutqZG3ISKKErIYDx8RzzBxVbKT7o3HhsHTaufjOf5CZWrwcYetqkEPx42YMB574zNheUJsBFexjYvY4AKwH4SKPapRtqL7jeLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OvOz6dOT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OvOz6dOT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58B26C4CEE6; Sat, 1 Mar 2025 04:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740801775; bh=4e5iV1jyt44+vFhgI8mzweFLermL3m37/dLdNcU2d2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OvOz6dOTQ7658+ndf+zgKMBRg26gYWGlCgFa3qPI7oWrsAvt96aGx2ljvuqP7vr95 sBkdEfzb1Vr6VqLD6CNEm5mT0kO9bsWPtCNfsGWjUr7vr5iemk+ssjPZ/iD+q1eI1u Ji4nTlf1yUeGDXrzpktp/snr1mv60r1t/Wxxbe8BSx+NtlMivkRInY7DA7w1cVseCI BkCg+rk10b/cMm0MQ2K8fUSrhqozij5HxSamDzatWpvojEEEem3pN9CT2xUAX6iacL ntkhj0svisdIfDUaZJpIE1ZeZfFvdHAJ2VTgrGx9MP8AdZfAGLRApNSSIf+p5wuhib TamHgA0vIVpgw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 4/4] perf test: Add trace record and replay test Date: Fri, 28 Feb 2025 20:02:52 -0800 Message-ID: <20250301040252.1586750-5-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250301040252.1586750-1-namhyung@kernel.org> References: <20250301040252.1586750-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It just check trace record and replay could display correct output. It uses 'sleep' process and sees there's a clock_nanosleep syscall. $ sudo perf test -vv replay 108: perf trace record and replay: --- start --- test child forked, pid 1563219 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.077 MB /tmp/temporary_file.w1ApA (242= samples) ] 0.686 (1000.068 ms): sleep/1563226 clock_nanosleep(rqtp: 0x7ffc20ffe= e10, rmtp: 0x7ffc20ffee50) =3D 0 ---- end(0) ---- 108: perf trace record and replay : Ok Signed-off-by: Namhyung Kim --- tools/perf/tests/shell/trace_record_replay.sh | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tools/perf/tests/shell/trace_record_replay.sh diff --git a/tools/perf/tests/shell/trace_record_replay.sh b/tools/perf/tes= ts/shell/trace_record_replay.sh new file mode 100755 index 0000000000000000..f948a84072b7a9b1 --- /dev/null +++ b/tools/perf/tests/shell/trace_record_replay.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# perf trace record and replay +# SPDX-License-Identifier: GPL-2.0 + +# Check that perf trace works with record and replay + +# shellcheck source=3Dlib/probe.sh +. "$(dirname $0)"/lib/probe.sh + +skip_if_no_perf_trace || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 + +file=3D$(mktemp /tmp/temporary_file.XXXXX) + +perf trace record -o ${file} sleep 1 || exit 1 +if ! perf trace -i ${file} 2>&1 | grep nanosleep; then + echo "Failed: cannot find *nanosleep syscall" + exit 1 +fi + +rm -f ${file} --=20 2.48.1.711.g2feabab25a-goog