Created
October 24, 2022 23:28
-
-
Save jswrenn/dca411d1b92327fe431aef7d7909475d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# traces a binary for 5s, writing out histograms of the latency of every `Futures::poll` fn | |
export BINARY_PATH="/home/ubuntu/projects/mini-redis/target/debug/mini-redis-server" | |
# generate `poll_latency.bpf` | |
echo "interval:s:5 { | |
print(@latency); | |
exit(); | |
}" >poll_latency.bpf | |
objdump -wtT $BINARY_PATH | tr -s ' ' | cut -d' ' -f1,5- | grep 'Future$GT$4poll' \ | |
| while IFS=" " read -r addr name | |
do | |
echo " | |
uprobe:${BINARY_PATH}:\"${name}\" { | |
@start[\"${addr}\"] = nsecs; | |
} | |
uretprobe:${BINARY_PATH}:\"${name}\" { | |
@latency[\"${addr}\"] = hist(nsecs - @start[\"${addr}\"]) | |
} | |
" | |
done >> poll_latency.bpf | |
# run poll_latency.bpf | |
# notable dependency: rustfilt | |
sudo bpftrace poll_latency.bpf \ | |
| awk 'FNR==NR { array[$1]=$2; next } { for (i in array) gsub(i, array[i]) }1' <(objdump -wtT ${BINARY_PATH} | tr -s ' ' | cut -d' ' -f1,5- | grep 'Future$GT$4poll') - \ | |
| rustfilt \ | |
| grep -v '@start' \ | |
| tee histograms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment