Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Switch to /usr/bin/time for measuring time + memory in physmon #3007

Merged
merged 10 commits into from
Mar 7, 2024
85 changes: 78 additions & 7 deletions CI/physmon/phys_perf_mon.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#!/bin/bash

set -e
set -x

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

paulgessinger marked this conversation as resolved.
Show resolved Hide resolved
}

export run


shopt -s extglob


mode=${1:-all}
Expand All @@ -23,9 +35,68 @@ histcmp_results=$outdir/histcmp_results.csv
echo -n "" > $histcmp_results

SPYRAL_BIN=${SPYRAL_BIN:=spyral}
SPYRAL="${SPYRAL_BIN} run -i 0.05 --summary"

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

if [ "$(uname)" == "Darwin" ]; then
function measure {
label=$1
shift
slug=$2
shift
echo "Measure Darwin $label"
tmp=$(mktemp)
/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
shift
slug=$2
shift
echo "Measure Linux $label"
tmp=$(mktemp)
/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

set +e
ec=0
Expand All @@ -38,15 +109,15 @@ function run_physmon_gen() {

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

$SPYRAL -l "$title" -o "$outdir/memory/mem_${slug}.csv" -- ${script} $outdir 2>&1 > $outdir/run_${slug}.log
measure "$title" ${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
Expand Down Expand Up @@ -124,7 +195,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 @@ -133,7 +204,7 @@ function full_chain() {
seeding_${suffix} \
-c $config
fi

run_histcmp \
$outdir/performance_ckf_${suffix}.root \
$refdir/performance_ckf_${suffix}.root \
Expand Down
11 changes: 6 additions & 5 deletions Tests/UnitTests/Plugins/DD4hep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ set_target_properties(ActsTestsDD4hepFactories PROPERTIES LIBRARY_OUTPUT_DIRECTO
dd4hep_set_version(ActsTestsDD4hepFactories MAJOR 1 MINOR 0 PATCH 0)
dd4hep_generate_rootmap(ActsTestsDD4hepFactories)

find_library(dd4hep_core_plugins_library DDCorePlugins REQUIRED)
cmake_path(GET dd4hep_core_plugins_library PARENT_PATH DD4HEP_LIBRARY_PATH)
find_library(dd4hep_core_library DDCore)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
set(factory_path "$<PATH:GET_PARENT_PATH,$<TARGET_FILE:ActsTestsDD4hepFactories>>")
else()
set(factory_path "${CMAKE_CURRENT_BINARY_DIR}")
endif()

if (EXISTS ${DD4hep_DIR}/${CMAKE_INSTALL_LIBDIR})

if (NOT "${dd4hep_core_library}" STREQUAL "dd4hep_core_library-NOTFOUND")
cmake_path(GET dd4hep_core_library PARENT_PATH DD4HEP_LIBRARY_PATH)
# set test library dependencies
set(unittest_extra_libraries ActsTestsDD4hepFactories ActsPluginDD4hep)
set(dd4hep_tests DD4hepDetectorElement DD4hepCylinderLayerStructure DD4hepDiscLayerStructure DD4hepCylindricalDetector)
Expand All @@ -41,5 +42,5 @@ if (EXISTS ${DD4hep_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
endforeach()
else()
message(WARNING "DD4hep libraries not found under ${DD4hep_DIR}/${CMAKE_INSTALL_LIBDIR}, DD4hep tests will not be built.")
endif()
message(WARNING "DD4hep libraries not found under, DD4hep tests will not be built.")
endif()