File: compare_tool_speed.sh

package info (click to toggle)
bpftrace 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,024 kB
  • sloc: cpp: 47,187; ansic: 2,695; python: 816; yacc: 619; sh: 419; lex: 293; makefile: 22
file content (86 lines) | stat: -rwxr-xr-x 2,133 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash

# Compare the processing speed for the shipped
# tools between two bpftrace builds
#
# based on scripts/compare_tool_speed.h
#

set -o pipefail
set -e
set -u

if [[ "$#" -lt 3 ]]; then
  echo "Compare tools' speed between two bpftrace builds"
  echo ""
  echo "USAGE:"
  echo "$(basename $0) <bpftrace_A> <bpftrace_B> <tooldir> [<testmode>] [<threshold>]"
  echo ""
  echo "EXAMPLE:"
  echo "$(basename $0) bpftrace bpftrace_master ./tools"
  echo ""
  echo "NOTE: assume that second bpftrace binary is newer"
  exit 1
fi

TOOLDIR=$3
BPF_A=$(command -v "$1") || ( echo "ERROR: $1 not found"; exit 1 )
BPF_B=$(command -v "$2") || ( echo "ERROR: $2 not found"; exit 1 )
[[ -d "$TOOLDIR" ]] || (echo "tooldir does not appear to be a directory: ${TOOLDIR}"; exit 1)


TMPDIR=$(mktemp -d)
[[ $? -ne 0 || -z $TMPDIR ]] && (echo "Failed to create tmp dir"; exit 10)

cd $TMPDIR
set +e

TESTMODE=${4:-codegen}
if [[ $TESTMODE != "codegen" ]]; then
    echo invalid testmode: $TESTMODE
    exit 20
fi
THRESHOLD=${5:-1}
TIME="/usr/bin/time -f%e --"
FLAGS="--no-warnings --test $TESTMODE"

echo $TESTMODE test
echo "Using version $($BPF_A -V) and $($BPF_B -V)"

MAXLEN=0
for script in ${TOOLDIR}/*.bt; do
    s=$(basename ${script/.bt/})
    len=${#s}
    if [[ "$MAXLEN" -lt "$len" ]]; then
        MAXLEN=$len
    fi
done

echo -n "         script"
for i in `seq 0 1 $((MAXLEN - 6))`; do echo -n ' '; done
echo "A     B     diff"

for script in ${TOOLDIR}/*.bt; do
    s=$(basename ${script/.bt/})
    len=${#s}
    space=$((MAXLEN - len))
    echo -n "Checking $s"
    for i in `seq 0 1 $space`; do echo -n ' '; done
    a=`$TIME $BPF_A $FLAGS "$script" 3>&1 1>&2 2>&3 3>&-`
    b=`$TIME $BPF_B $FLAGS "$script" 3>&1 1>&2 2>&3 3>&-`
    if [ $? -ne 0 ]; then
        echo "###############################"
        echo "bpftrace failed on script: ${s}"
        echo "###############################"
        continue
    fi
    d=$(echo $b - $a | bc)
    t=$(echo "$d > $THRESHOLD" | bc)
    mark=""
    if [[ "$t" -eq 1 ]]; then
        mark="*"
    fi
    echo "$a  $b  $d$mark"
done

[[ -n ${TMPDIR} ]] && rm -rf "${TMPDIR}"