Fuzion Logo
flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

base_fum/run.sh


#!/bin/bash
set -euo pipefail

if ! [ -x "$(command -v fz)" ]; then
  echo 'Error: fz must be in PATH.' >&2
  exit 1
fi

FUZION_HOME=$(realpath "$(dirname "$(readlink -f "$(type -aP fz)")")/..")

echo "$FUZION_HOME"

APP="fz -sourceDirs=$FUZION_HOME/lib -XloadBaseLib=off -saveLib=$FUZION_HOME/modules/base.fum"
LOG_FILE=base_fum.log.txt

echo "started benchmarking: build base.fum"

/usr/bin/time -o buildtime.txt -f "%e,%M" $APP

# sudo sysctl kernel.perf_event_paranoid=-1
# perf also supports running average power limit (RAPL) for power consumption measurements
# Paper: Ranking Programming Languages by Energy Efficiency https://haslab.github.io/SAFER/scp21.pdf

sudo -n sysctl kernel.perf_event_paranoid=-1 || echo "failure setting perf_event_paranoid"

perf stat -o perf_stat_general.txt -x ',' -e task-clock,context-switches,cpu-migrations,page-faults,cpu-cycles,instructions,branches,branch-misses,branch-instructions,bus-cycles,cache-misses,cache-references,ref-cycles timeout --preserve-status --signal=15 --kill-after=70s 60s $APP
perf stat -o perf_stat_energy.txt -x ',' -e power/energy-pkg/ timeout --preserve-status --signal=15 --kill-after=70s 60s $APP

{
  echo -n "$(date --iso-8601='minutes'),"
  echo -n "$(cat buildtime.txt),"
  echo -n ",,"
  echo -n "0,"
  echo -n "0,"
  echo -n " # $(fz -version),"
  echo -n ","
  # sed: remove everything after first comma, grep: select only lines starting with a digit, tr: remove all line breaks
  sed 's/,.*/,/g' perf_stat_general.txt | grep -E '^[0-9]' | tr -d '\n'
  sed 's/,.*/,/g' perf_stat_energy.txt  | grep -E '^[0-9]' | tr -d '\n'
} >> "$LOG_FILE"

# new line
echo "" >> "$LOG_FILE"

# log file format:
#
# date, build time (seconds), build memory usage (kilobyte), run time (seconds), run memory usage (kilobyte),
# c code source size (bytes), binary size (bytes), fz version, additional args,
# task-clock,context-switches,cpu-migrations,page-faults,cpu-cycles,instructions,
# branches,branch-misses,branch-instructions,bus-cycles,cache-misses,cache-references,ref-cycles,
# energy usage (joule)
#

rm buildtime.txt perf_stat_general.txt perf_stat_energy.txt

echo "finished benchmarking: $APP"