summaryrefslogtreecommitdiff
path: root/tools/perf/tests/shell
diff options
context:
space:
mode:
authorIvan Lazaric <ivan.lazaric1@gmail.com>2026-07-08 15:14:01 +0200
committerNamhyung Kim <namhyung@kernel.org>2026-07-08 16:43:25 -0700
commit261210854462ef5e587eb1b740aa06dbab3b3a40 (patch)
treef9b076f5e53d12f8899f971126c1dd51de575ee6 /tools/perf/tests/shell
parenteda39f98bbc5ce8b7b0be10193d2de38ed59da6c (diff)
downloadlinux-next-261210854462ef5e587eb1b740aa06dbab3b3a40.tar.gz
linux-next-261210854462ef5e587eb1b740aa06dbab3b3a40.zip
perf stat: reject --field-separator and --json-output combination
Specifying --field-separator option is stating you want CSV output. Passing both --field-separator and --json-output is then stating you want output to be in CSV and JSON format at same time. Currently this combination is not rejected, and the outcome is a malformed combination of CSV and JSON output. This is because of inconsistencies in various printing functions, some of them have if-else chains that start with "Should I print JSON?", and some start with "Should I print CSV?". Example of current output: $ tools/perf/perf stat -x , -j -e cpu-migrations true {"counter-value" : "0.000000", "unit" : "", "event" : "cpu-migrations", "event-runtime" : 474817, "pcnt-running" : 100.00,, Instead reject the option combination, with a helpful error message and non-zero exit code. Example of new output: $ tools/perf/perf stat -x , -j true cannot use both --field-separator and --json-output Usage: perf stat [<options>] [<command>] -x, --field-separator <separator> print counts with custom separator -j, --json-output print counts in JSON format Signed-off-by: Ivan Lazaric <ivan.lazaric1@gmail.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/perf/tests/shell')
-rwxr-xr-xtools/perf/tests/shell/stat.sh12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh
index 1e17bee026bd..649de1166fed 100755
--- a/tools/perf/tests/shell/stat.sh
+++ b/tools/perf/tests/shell/stat.sh
@@ -535,6 +535,17 @@ test_stat_delay() {
echo "stat -D test [Success]"
}
+test_csv_json_fail() {
+ echo "stat -x <sep> -j test"
+ if perf stat -x , -j true > /dev/null 2>&1
+ then
+ echo "stat -x <sep> -j test [Failed - command should have errored]"
+ err=1
+ else
+ echo "stat -x <sep> -j test [Success]"
+ fi
+}
+
test_default_stat
test_null_stat
test_offline_cpu_stat
@@ -551,6 +562,7 @@ test_stat_detailed
test_stat_repeat
test_stat_pid
test_stat_delay
+test_csv_json_fail
cleanup
exit $err