Merge tag 'trace-v5.4-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux-2.6-microblaze.git] / tools / perf / tests / shell / record+zstd_comp_decomp.sh
1 #!/bin/sh
2 # Zstd perf.data compression/decompression
3
4 # SPDX-License-Identifier: GPL-2.0
5
6 trace_file=$(mktemp /tmp/perf.data.XXX)
7 perf_tool=perf
8
9 skip_if_no_z_record() {
10         $perf_tool record -h 2>&1 | grep -q '\-z, \-\-compression\-level'
11 }
12
13 collect_z_record() {
14         echo "Collecting compressed record file:"
15         $perf_tool record -o $trace_file -g -z -F 5000 -- \
16                 dd count=500 if=/dev/urandom of=/dev/null
17 }
18
19 check_compressed_stats() {
20         echo "Checking compressed events stats:"
21         $perf_tool report -i $trace_file --header --stats | \
22                 grep -E "(# compressed : Zstd,)|(COMPRESSED events:)"
23 }
24
25 check_compressed_output() {
26         $perf_tool inject -i $trace_file -o $trace_file.decomp &&
27         $perf_tool report -i $trace_file --stdio | head -n -3 > $trace_file.comp.output &&
28         $perf_tool report -i $trace_file.decomp --stdio | head -n -3 > $trace_file.decomp.output &&
29         diff $trace_file.comp.output $trace_file.decomp.output
30 }
31
32 skip_if_no_z_record || exit 2
33 collect_z_record && check_compressed_stats && check_compressed_output
34 err=$?
35 rm -f $trace_file*
36 exit $err