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