perf test: Stat output per thread of just the parent process
authorIan Rogers <irogers@google.com>
Fri, 1 Mar 2024 07:46:37 +0000 (23:46 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 21 Mar 2024 16:54:39 +0000 (13:54 -0300)
Per-thread mode requires either system-wide (-a), a pid (-p) or a tid
(-t).

The stat output tests were using system-wide mode but this is racy when
threads are starting and exiting - something that happens a lot when
running the tests in parallel (perf test -p).

Avoid the race conditions by using pid mode with the pid of the parent
process.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Disha Goel <disgoel@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Link: https://lore.kernel.org/r/20240301074639.2260708-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/shell/lib/stat_output.sh
tools/perf/tests/shell/stat+json_output.sh

index c81d6a9f7983d369f7ee2dff907f2288b0ce3d9e..9a176ceae4a3c3a252d517f0415e9d87bc084507 100644 (file)
@@ -79,7 +79,7 @@ check_per_thread()
                echo "[Skip] paranoid and not root"
                return
        fi
-       perf stat --per-thread -a $2 true
+       perf stat --per-thread -p $$ $2 true
        commachecker --per-thread
        echo "[Success]"
 }
index 2b9c6212dffc6f2a59a0e495b0628c38d34221e7..6b630d33c3287899852c3ffa2ac06df0b96614d8 100755 (executable)
@@ -105,7 +105,7 @@ check_per_thread()
                echo "[Skip] paranoia and not root"
                return
        fi
-       perf stat -j --per-thread -a -o "${stat_output}" true
+       perf stat -j --per-thread -p $$ -o "${stat_output}" true
        $PYTHON $pythonchecker --per-thread --file "${stat_output}"
        echo "[Success]"
 }