Skip to content

Commit

Permalink
revert: Switch to /usr/bin/time for measuring time + memory in physmon (
Browse files Browse the repository at this point in the history
acts-project#3017)

Reverting acts-project#3007 as it seems to break the physmon exit code propagation
  • Loading branch information
andiwand authored and dimitra97 committed Mar 19, 2024
1 parent 3e8a223 commit 10b5565
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:

steps:
- name: Install git lfs
run: apt-get update && apt-get install -y git-lfs time
run: apt-get update && apt-get install -y git-lfs

- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ linux_physmon:
expire_in: 1 week

script:
- apt-get update && apt-get install -y git-lfs time
- apt-get update && apt-get install -y git-lfs

- git clone $CLONE_URL src
- cd src
Expand Down
117 changes: 23 additions & 94 deletions CI/physmon/phys_perf_mon.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
#!/bin/bash

set -e

# helper function to selectively print and run commands without a subshell
function run() {
set -x
"$@"
{ set +x; } 2> /dev/null
}

export run


shopt -s extglob
set -x


mode=${1:-all}
Expand All @@ -33,74 +22,12 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd
histcmp_results=$outdir/histcmp_results.csv
echo -n "" > $histcmp_results

memory_dir=${outdir}/memory
mkdir -p "$memory_dir"

if [ "$(uname)" == "Darwin" ]; then
function measure {
label=$1
slug=$2
shift
shift
echo "Measure Darwin $label ($slug)" >&2
tmp=$(mktemp)
echo "+ $@" >&2
/usr/bin/time -l -o "$tmp" "$@"

of="${memory_dir}/mem_${slug}.csv"
{
echo "# spyral-label: $label"
echo "# spyral-cmd: $*"
echo "time,rss,vms"
# in bytes
grep -E "real" "$tmp" | awk '{printf $1}'
printf ","
grep -E "maximum resident set size" "$tmp" | awk '{printf $1}'
printf ",0\n"
} > "$of"
}
export measure
elif [ "$(uname)" == "Linux" ]; then
function measure {
label=$1
slug=$2
shift
shift
echo "Measure Linux $label ($slug)" >&2
tmp=$(mktemp)
echo "+ $@" >&2
/usr/bin/time -v -o "$tmp" "$@"
# in kbytes
max_rss=$(grep "Maximum resident set size (kbytes):" "$tmp" | awk '{printf $(NF)}')
max_rss=$(( 1000*max_rss ))
wall_time=$(grep "Elapsed (wall clock)" "$tmp" | awk '{printf $(NF)}')
echo $max_rss
wall_time=$(python3 -c "i='${wall_time}';p=i.split(':');p = p if len(p) == 3 else ['0', *p];t=float(p[0])*60*60 + float(p[1])*60 + float(p[2]);print(t)")
echo $wall_time

of="${memory_dir}/mem_${slug}.csv"
{
echo "# spyral-label: $label"
echo "# spyral-cmd: $*"
echo "time,rss,vms"
echo "${wall_time},${max_rss},0"
} > "$of"
}
export measure
else
function measure {
echo "Not measuring because unknown environment"
shift
shift
"$@"
}
export measure
fi
SPYRAL_BIN=${SPYRAL_BIN:=spyral}
SPYRAL="${SPYRAL_BIN} run -i 0.05 --summary"

if [ -n "$CI" ]; then
echo "CI mode, do not abort immediately on failure"
set +e
fi
mkdir -p ${outdir}/memory

set +e
ec=0

source $SCRIPT_DIR/setup.sh
Expand All @@ -111,16 +38,18 @@ function run_physmon_gen() {

script=CI/physmon/workflows/physmon_${slug}.py

measure "$title" "$slug" ${script} $outdir 2>&1 > $outdir/run_${slug}.log
$SPYRAL -l "$title" -o "$outdir/memory/mem_${slug}.csv" -- ${script} $outdir 2>&1 > $outdir/run_${slug}.log

this_ec=$?
ec=$(($ec | $this_ec))

if [ $this_ec -ne 0 ]; then
echo "::error::🟥 Dataset generation failed: ${script} -> ec=$this_ec"
else
echo "::notice::✅ Dataset generation succeeded: ${script}"
echo "::notice::✅ Dataset generation succeeded: ${script}"
fi

$SPYRAL_BIN plot $outdir/memory/mem_${slug}.csv --output $outdir/memory
}

echo "::group::Generate validation dataset"
Expand Down Expand Up @@ -166,7 +95,7 @@ function run_histcmp() {
ec=1
fi

run histcmp $a $b \
histcmp $a $b \
--label-reference=reference \
--label-monitored=monitored \
--title="$title" \
Expand Down Expand Up @@ -195,7 +124,7 @@ function full_chain() {
config="CI/physmon/default.yml"
fi
echo $config

if [ $suffix != truth_smeared ]; then
run_histcmp \
$outdir/performance_seeding_${suffix}.root \
Expand All @@ -204,15 +133,15 @@ function full_chain() {
seeding_${suffix} \
-c $config
fi

run_histcmp \
$outdir/performance_ckf_${suffix}.root \
$refdir/performance_ckf_${suffix}.root \
"CKF ${suffix}" \
ckf_${suffix} \
-c $config

run Examples/Scripts/generic_plotter.py \
Examples/Scripts/generic_plotter.py \
$outdir/performance_ivf_${suffix}.root \
vertexing \
$outdir/performance_ivf_${suffix}_hist.root \
Expand All @@ -229,7 +158,7 @@ function full_chain() {
"IVF ${suffix}" \
ivf_${suffix}

run Examples/Scripts/generic_plotter.py \
Examples/Scripts/generic_plotter.py \
$outdir/performance_amvf_${suffix}.root \
vertexing \
$outdir/performance_amvf_${suffix}_hist.root \
Expand All @@ -247,7 +176,7 @@ function full_chain() {
amvf_${suffix}

if [ $suffix == seeded ]; then
run Examples/Scripts/generic_plotter.py \
Examples/Scripts/generic_plotter.py \
$outdir/performance_amvf_gridseeder_${suffix}.root \
vertexing \
$outdir/performance_amvf_gridseeder_${suffix}_hist.root \
Expand All @@ -265,7 +194,7 @@ function full_chain() {
amvf_gridseeder_${suffix}
fi

run Examples/Scripts/generic_plotter.py \
Examples/Scripts/generic_plotter.py \
$outdir/tracksummary_ckf_${suffix}.root \
tracksummary \
$outdir/tracksummary_ckf_${suffix}_hist.root \
Expand All @@ -289,7 +218,7 @@ function simulation() {

config="CI/physmon/simulation_config.yml"

run Examples/Scripts/generic_plotter.py \
Examples/Scripts/generic_plotter.py \
$outdir/particles_${suffix}.root \
particles \
$outdir/particles_${suffix}_hist.root \
Expand Down Expand Up @@ -345,15 +274,15 @@ if [[ "$mode" == "all" || "$mode" == "fullchains" ]]; then
"Ambisolver " \
ambi_ttbar

run Examples/Scripts/generic_plotter.py \
Examples/Scripts/generic_plotter.py \
$outdir/performance_amvf_ttbar.root \
vertexing \
$outdir/performance_amvf_ttbar_hist.root \
--silent \
--config CI/physmon/vertexing_ttbar_config.yml
ec=$(($ec | $?))

run Examples/Scripts/generic_plotter.py \
Examples/Scripts/generic_plotter.py \
$outdir/tracksummary_ckf_ttbar.root \
tracksummary \
$outdir/tracksummary_ckf_ttbar_hist.root \
Expand All @@ -378,7 +307,7 @@ if [[ "$mode" == "all" || "$mode" == "fullchains" ]]; then
"AMVF ttbar" \
amvf_ttbar

run Examples/Scripts/generic_plotter.py \
Examples/Scripts/generic_plotter.py \
$outdir/performance_amvf_gridseeder_ttbar.root \
vertexing \
$outdir/performance_amvf_gridseeder_ttbar_hist.root \
Expand Down Expand Up @@ -424,7 +353,7 @@ if [[ "$mode" == "all" || "$mode" == "gx2f" ]]; then
fi

if [[ "$mode" == "all" || "$mode" == "vertexing" ]]; then
run Examples/Scripts/vertex_mu_scan.py \
Examples/Scripts/vertex_mu_scan.py \
$outdir/performance_vertexing_*mu*.root \
$outdir/vertexing_mu_scan.pdf

Expand All @@ -436,7 +365,7 @@ if [[ "$mode" == "all" || "$mode" == "simulation" ]]; then
simulation geant4
fi

run CI/physmon/summary.py $histcmp_results \
CI/physmon/summary.py $histcmp_results \
--md $outdir/summary.md \
--html $outdir/summary.html
ec=$(($ec | $?))
Expand Down

0 comments on commit 10b5565

Please sign in to comment.