|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +if [ ! -f lib/lib.sh ] |
| 4 | +then |
| 5 | + echo "Error: lib/lib.sh not found!" |
| 6 | + echo "make sure you are in the root of the server repo" |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +source lib/lib.sh |
| 11 | + |
| 12 | +check_deps "$1" |
| 13 | +check_warnings |
| 14 | +check_running |
| 15 | +install_dep heaptrack |
| 16 | +archive_gmon |
| 17 | +restart_side_runner |
| 18 | +die_if_asan_on_because heaptrack |
| 19 | + |
| 20 | +export COMMIT_HASH |
| 21 | +if ! COMMIT_HASH="$(get_commit)" |
| 22 | +then |
| 23 | + err "failed to get commit hash" |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +logfile="$LOGS_PATH_FULL_TW/${CFG_SRV_NAME}_$(date +%F_%H-%M-%S)${CFG_LOG_EXT}" |
| 28 | +cache_logpath "$logfile" |
| 29 | +log_cmd='echo nologging' |
| 30 | +if is_cfg CFG_ENABLE_LOGGING |
| 31 | +then |
| 32 | + log_cmd="logfile $logfile" |
| 33 | +fi |
| 34 | + |
| 35 | +heaptrack_logpath="logs/heaptrack_${COMMIT_HASH:-null}_$(date '+%F_%H-%M')" |
| 36 | + |
| 37 | +# traditionally heaptrack also includes the pid with %p placeholder |
| 38 | +# but then it becomes tricky for us to log the logpath |
| 39 | +# because getting the pid only works at runtime |
| 40 | +# we can not use $$ because its a wrapped launcher |
| 41 | +# there should probably be a proper launch_cmd() helper |
| 42 | +# that can pritty print args and handle pid and exit codes |
| 43 | +# heaptrack_logpath="${heaptrack_logpath}.%p" |
| 44 | + |
| 45 | +read -rd '' run_cmd <<- EOF |
| 46 | +$CFG_ENV_RUNTIME heaptrack \ |
| 47 | + --output "$heaptrack_logpath" \ |
| 48 | + ./$CFG_BIN -f autoexec.cfg "$log_cmd;#sid:$SERVER_UUID:heaptrack.sh" |
| 49 | +EOF |
| 50 | + |
| 51 | +log "$run_cmd" |
| 52 | +git_patches="$(get_applied_git_patches)" |
| 53 | +launch_commit="$(get_commit)" |
| 54 | +bash -c "set -euo pipefail;$run_cmd" |
| 55 | +log "build commit: $launch_commit" |
| 56 | +if [ "$git_patches" != "" ] |
| 57 | +then |
| 58 | + log "applied patches: $git_patches" |
| 59 | +fi |
| 60 | + |
| 61 | +log "created heaptrack report at $heaptrack_logpath" |
| 62 | +log "you can inspect it using this command:" |
| 63 | +echo "" |
| 64 | +echo " $(tput bold)heaptrack_print ${heaptrack_logpath}.zst | less$(tput sgr0)" |
| 65 | +echo "" |
| 66 | +log "or publish it via http and download locally to inspect with heaptrack gui version:" |
| 67 | +echo "" |
| 68 | +echo " cp $(tput bold)heaptrack_print ${heaptrack_logpath}.zst /var/www/html/tmp/$(tput sgr0)" |
| 69 | +echo "" |
| 70 | +log "then click here to download https://zillyhuhn.com/tmp/${heaptrack_logpath}.zst" |
0 commit comments