Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add pipe_test.sh to verify pipe operations

It builds a test program and use it to verify pipe behavior with perf
record, inject and report.

$ perf test pipe -v
80: perf pipe recording and injection test :
--- start ---
test child forked, pid 1109301
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]
1109315 1109315 -1 |test.file.MGNff
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]
99.99% test.file.MGNff test.file.MGNffM [.] noploop
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]
99.99% test.file.MGNff test.file.MGNffM [.] noploop
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.153 MB /tmp/perf.data.dmsnlx (3995 samples) ]
99.99% test.file.MGNff test.file.MGNffM [.] noploop
test child finished with 0
---- end ----
perf pipe recording and injection test: Ok

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210719223153.1618812-6-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
ec02f2b1 c3a057dc

+69
+69
tools/perf/tests/shell/pipe_test.sh
··· 1 + #!/bin/sh 2 + # perf pipe recording and injection test 3 + # SPDX-License-Identifier: GPL-2.0 4 + 5 + # skip if there's no compiler 6 + if ! [ -x "$(command -v cc)" ]; then 7 + echo "failed: no compiler, install gcc" 8 + exit 2 9 + fi 10 + 11 + file=$(mktemp /tmp/test.file.XXXXXX) 12 + data=$(mktemp /tmp/perf.data.XXXXXX) 13 + 14 + cat <<EOF | cc -o ${file} -x c - 15 + #include <signal.h> 16 + #include <stdlib.h> 17 + #include <unistd.h> 18 + 19 + volatile int done; 20 + 21 + void sigalrm(int sig) { 22 + done = 1; 23 + } 24 + 25 + __attribute__((noinline)) void noploop(void) { 26 + while (!done) 27 + continue; 28 + } 29 + 30 + int main(int argc, char *argv[]) { 31 + int sec = 1; 32 + 33 + if (argc > 1) 34 + sec = atoi(argv[1]); 35 + 36 + signal(SIGALRM, sigalrm); 37 + alarm(sec); 38 + 39 + noploop(); 40 + return 0; 41 + } 42 + EOF 43 + 44 + 45 + if ! perf record -e task-clock:u -o - ${file} | perf report -i - --task | grep test.file; then 46 + echo "cannot find the test file in the perf report" 47 + exit 1 48 + fi 49 + 50 + if ! perf record -e task-clock:u -o - ${file} | perf inject -b | perf report -i - | grep noploop; then 51 + echo "cannot find noploop function in pipe #1" 52 + exit 1 53 + fi 54 + 55 + perf record -e task-clock:u -o - ${file} | perf inject -b -o ${data} 56 + if ! perf report -i ${data} | grep noploop; then 57 + echo "cannot find noploop function in pipe #2" 58 + exit 1 59 + fi 60 + 61 + perf record -e task-clock:u -o ${data} ${file} 62 + if ! perf inject -b -i ${data} | perf report -i - | grep noploop; then 63 + echo "cannot find noploop function in pipe #3" 64 + exit 1 65 + fi 66 + 67 + 68 + rm -f ${file} ${data} ${data}.old 69 + exit 0