From 52c062965afd02e5788de0c3da3b5c987be0e782 Mon Sep 17 00:00:00 2001
From: Reiner Jung <reiner.jung@email.uni-kiel.de>
Date: Wed, 17 Aug 2022 12:35:38 +0200
Subject: [PATCH] Updated python benchmark

---
 .../Kieker/python/{main.py => benchmark.py}   |   4 +-
 frameworks/Kieker/python/benchmark.sh         | 173 ++++++++++++++++++
 frameworks/Kieker/python/functions.sh         | 110 +++++++++++
 frameworks/Kieker/python/labels.sh            |   5 +
 .../{moo.py => monitored_application.py}      |   0
 5 files changed, 290 insertions(+), 2 deletions(-)
 rename frameworks/Kieker/python/{main.py => benchmark.py} (95%)
 create mode 100755 frameworks/Kieker/python/benchmark.sh
 create mode 100644 frameworks/Kieker/python/functions.sh
 create mode 100644 frameworks/Kieker/python/labels.sh
 rename frameworks/Kieker/python/{moo.py => monitored_application.py} (100%)

diff --git a/frameworks/Kieker/python/main.py b/frameworks/Kieker/python/benchmark.py
similarity index 95%
rename from frameworks/Kieker/python/main.py
rename to frameworks/Kieker/python/benchmark.py
index 31ec864..26cc491 100644
--- a/frameworks/Kieker/python/main.py
+++ b/frameworks/Kieker/python/benchmark.py
@@ -55,7 +55,7 @@ if instrumentation_on:
         sys.meta_path.insert(0, PostImportFinder(pattern_object, exclude_modules, empty = inactive))
 else:
     print('Instrumentation is off')
-import moo
+import monitored_application
 
 
 
@@ -65,7 +65,7 @@ stop_ns = 0
 timings = []
 for i in range(total_calls):
     start_ns = time.time_ns()
-    moo.monitored_method(method_time, recursion_depth)
+    monitored_application.monitored_method(method_time, recursion_depth)
     stop_ns = time.time_ns()
     timings.append(stop_ns-start_ns)
     if i%100000 ==0:
diff --git a/frameworks/Kieker/python/benchmark.sh b/frameworks/Kieker/python/benchmark.sh
new file mode 100755
index 0000000..d83631c
--- /dev/null
+++ b/frameworks/Kieker/python/benchmark.sh
@@ -0,0 +1,173 @@
+#!/bin/bash
+
+#
+# Kieker benchmark script
+#
+# Usage: benchmark.sh [execute|test]
+
+# configure base dir
+BASE_DIR=$(cd "$(dirname "$0")"; pwd)
+
+#
+# source functionality
+#
+
+if [ ! -d "${BASE_DIR}" ] ; then
+	echo "Base directory ${BASE_DIR} does not exist."
+	exit 1
+fi
+
+# load configuration and common functions
+if [ -f "${BASE_DIR}/config.rc" ] ; then
+	source "${BASE_DIR}/config.rc"
+else
+	echo "Missing configuration: ${BASE_DIR}/config.rc"
+	exit 1
+fi
+
+if [ -f "${MAIN_DIR}/frameworks/common-functions.sh" ] ; then
+	source "${MAIN_DIR}/frameworks/common-functions.sh"
+else
+	echo "Missing library: ${MAIN_DIR}/frameworks/common-functions.sh"
+	exit 1
+fi
+
+if [ -f "${BASE_DIR}/functions.sh" ] ; then
+	source "${BASE_DIR}/functions.sh"
+else
+	echo "Missing: ${BASE_DIR}/functions.sh"
+	exit 1
+fi
+if [ -f "${BASE_DIR}/labels.sh" ] ; then
+	source "${BASE_DIR}/labels.sh"
+else
+	echo "Missing file: ${BASE_DIR}/labels.sh"
+	exit 1
+fi
+
+#
+# check command line parameters
+#
+if [ "$1" == "" ] ; then
+	MODE="execute"
+else
+	if [ "$1" == "execute" ] ; then
+		MODE="execute"
+	else
+		mode="test"
+	fi
+	OPTION="$2"
+fi
+
+#
+# Setup
+#
+
+info "----------------------------------"
+info "Setup..."
+info "----------------------------------"
+
+cd "${BASE_DIR}"
+
+# load agent
+getAgent
+
+# Find receiver and extract it
+checkFile receiver "${RECEIVER_ARCHIVE}"
+tar -xpf "${RECEIVER_ARCHIVE}"
+RECEIVER_BIN="${BASE_DIR}/receiver/bin/receiver"
+
+PARENT=`dirname "${RESULTS_DIR}"`
+
+checkDirectory DATA_DIR "${DATA_DIR}" create
+checkDirectory result-base "${PARENT}"
+checkFile ApsectJ-Agent "${AGENT}"
+checkExecutable Receiver "${RECEIVER_BIN}"
+checkFile Labels "${BASE_DIR}/labels.sh"
+checkFile R-script "${RSCRIPT_PATH}"
+checkDirectory results-directory "${RESULTS_DIR}" recreate
+checkFile log "${DATA_DIR}/kieker.log" clean
+checkExecutable java "${JAVA_BIN}"
+checkExecutable moobench "${MOOBENCH_BIN}"
+checkExecutable receiver "${RECEIVER_BIN}"
+checkFile aop-file "${AOP}"
+
+showParameter
+
+TIME=`expr ${METHOD_TIME} \* ${TOTAL_NUM_OF_CALLS} / 1000000000 \* 4 \* ${RECURSION_DEPTH} \* ${NUM_OF_LOOPS} + ${SLEEP_TIME} \* 4 \* ${NUM_OF_LOOPS}  \* ${RECURSION_DEPTH} + 50 \* ${TOTAL_NUM_OF_CALLS} / 1000000000 \* 4 \* ${RECURSION_DEPTH} \* ${NUM_OF_LOOPS} `
+info "Experiment will take circa ${TIME} seconds."
+
+# general server arguments
+JAVA_ARGS="-Xms1G -Xmx2G"
+
+LTW_ARGS="-javaagent:${AGENT} --illegal-access=permit -Dorg.aspectj.weaver.showWeaveInfo=true -Daj.weaving.verbose=true -Dkieker.monitoring.skipDefaultAOPConfiguration=true -Dorg.aspectj.weaver.loadtime.configuration=file://${AOP}"
+
+KIEKER_ARGS="-Dlog4j.configuration=log4j.cfg -Dkieker.monitoring.name=KIEKER-BENCHMARK -Dkieker.monitoring.adaptiveMonitoring.enabled=false -Dkieker.monitoring.periodicSensorsExecutorPoolSize=0"
+
+# JAVA_ARGS used to configure and setup a specific writer
+declare -a WRITER_CONFIG
+# Receiver setup if necessary
+declare -a RECEIVER
+# Title
+declare -a TITLE
+
+#
+# Different writer setups
+#
+WRITER_CONFIG[0]=""
+WRITER_CONFIG[1]="-Dkieker.monitoring.enabled=false -Dkieker.monitoring.writer=kieker.monitoring.writer.dump.DumpWriter"
+WRITER_CONFIG[2]="-Dkieker.monitoring.enabled=true -Dkieker.monitoring.writer=kieker.monitoring.writer.dump.DumpWriter"
+WRITER_CONFIG[3]="-Dkieker.monitoring.enabled=true -Dkieker.monitoring.writer=kieker.monitoring.writer.filesystem.FileWriter -Dkieker.monitoring.writer.filesystem.FileWriter.logStreamHandler=kieker.monitoring.writer.filesystem.TextLogStreamHandler -Dkieker.monitoring.writer.filesystem.FileWriter.customStoragePath=${DATA_DIR}/"
+WRITER_CONFIG[4]="-Dkieker.monitoring.enabled=true -Dkieker.monitoring.writer=kieker.monitoring.writer.filesystem.FileWriter -Dkieker.monitoring.writer.filesystem.FileWriter.logStreamHandler=kieker.monitoring.writer.filesystem.BinaryLogStreamHandler -Dkieker.monitoring.writer.filesystem.FileWriter.bufferSize=8192 -Dkieker.monitoring.writer.filesystem.FileWriter.customStoragePath=${DATA_DIR}/"
+WRITER_CONFIG[5]="-Dkieker.monitoring.writer=kieker.monitoring.writer.tcp.SingleSocketTcpWriter -Dkieker.monitoring.writer.tcp.SingleSocketTcpWriter.port=2345"
+RECEIVER[5]="${RECEIVER_BIN} 2345"
+
+#
+# Write configuration
+#
+
+uname -a > "${RESULTS_DIR}/configuration.txt"
+"${JAVA_BIN}" "${JAVA_ARGS}" -version 2>> "${RESULTS_DIR}/configuration.txt"
+cat << EOF >> "${RESULTS_DIR}/configuration.txt"
+JAVA_ARGS: ${JAVA_ARGS}
+
+Runtime: circa ${TIME} seconds
+
+SLEEP_TIME=${SLEEP_TIME}
+NUM_OF_LOOPS=${NUM_OF_LOOPS}
+TOTAL_NUM_OF_CALLS=${TOTAL_NUM_OF_CALLS}
+METHOD_TIME=${METHOD_TIME}
+RECURSION_DEPTH=${RECURSION_DEPTH}
+EOF
+
+info "Ok"
+
+sync
+
+
+#
+# Run benchmark
+#
+
+info "----------------------------------"
+info "Running benchmark..."
+info "----------------------------------"
+
+if [ "$MODE" == "execute" ] ; then
+   if [ "$OPTION" == "" ] ; then
+     executeBenchmark
+   else
+     executeBenchmarkBody $OPTION 1 1
+   fi
+
+   # Create R labels
+   LABELS=$(createRLabels)
+   runStatistics
+   cleanupResults
+else
+   executeBenchmarkBody $OPTION 1 1
+fi
+
+info "Done."
+
+# end
diff --git a/frameworks/Kieker/python/functions.sh b/frameworks/Kieker/python/functions.sh
new file mode 100644
index 0000000..a02f0d6
--- /dev/null
+++ b/frameworks/Kieker/python/functions.sh
@@ -0,0 +1,110 @@
+# Kieker specific functions
+
+# ensure the script is sourced
+if [ "${BASH_SOURCE[0]}" -ef "$0" ]
+then
+    echo "Hey, you should source this script, not execute it!"
+    exit 1
+fi
+
+
+function getAgent() {
+	info "Checking whether Kieker is present in ${AGENT}"
+	if [ ! -f "${AGENT}" ] ; then
+		# get agent
+		export VERSION_PATH=`curl "https://oss.sonatype.org/service/local/repositories/snapshots/content/net/kieker-monitoring/kieker/" | grep '<resourceURI>' | sed 's/ *<resourceURI>//g' | sed 's/<\/resourceURI>//g' | grep '/$' | grep -v ".xml" | head -n 1`
+		export AGENT_PATH=`curl "${VERSION_PATH}" | grep 'aspectj.jar</resourceURI' | sort | sed 's/ *<resourceURI>//g' | sed 's/<\/resourceURI>//g' | tail -1`
+		curl "${AGENT_PATH}" > "${AGENT}"
+
+		if [ ! -f "${AGENT}" ] || [ -s "${AGENT}" ] ; then
+			error "Kieker download from $AGENT_PATH failed; please asure that a correct Kieker AspectJ file is present!"
+		fi
+	fi
+}
+
+# experiment setups
+
+#################################
+# function: execute an experiment
+#
+# $1 = i iterator
+# $2 = j iterator
+# $3 = k iterator
+# $4 = title
+# $5 = writer parameters
+function executeExperiment() {
+    loop="$1"
+    recursion="$2"
+    index="$3"
+    title="$4"
+    kieker_parameters="$5"
+
+    info " # ${loop}.${recursion}.${index} ${title}"
+    echo " # ${loop}.${recursion}.${index} ${title}" >> "${DATA_DIR}/kieker.log"
+
+    if [  "${kieker_parameters}" == "" ] ; then
+       export BENCHMARK_OPTS="${JAVA_ARGS}"
+    else
+       export BENCHMARK_OPTS="${JAVA_ARGS} ${LTW_ARGS} ${KIEKER_ARGS} ${kieker_parameters}"
+    fi
+
+    debug "Run options: ${BENCHMARK_OPTS}"
+
+    "${MOOBENCH_BIN}" \
+	--application moobench.application.MonitoredClassSimple \
+        --output-filename "${RAWFN}-${loop}-${recursion}-${index}.csv" \
+        --total-calls "${TOTAL_NUM_OF_CALLS}" \
+        --method-time "${METHOD_TIME}" \
+        --total-threads 1 \
+        --recursion-depth "${recursion}" &> "${RESULTS_DIR}/output_${loop}_${RECURSION_DEPTH}_${index}.txt"
+
+    rm -rf "${DATA_DIR}"/kieker-*
+
+    [ -f "${DATA_DIR}/hotspot.log" ] && mv "${DATA_DIR}/hotspot.log" "${RESULTS_DIR}/hotspot-${loop}-${recursion}-${index}.log"
+    echo >> "${DATA_DIR}/kieker.log"
+    echo >> "${DATA_DIR}/kieker.log"
+    sync
+    sleep "${SLEEP_TIME}"
+}
+
+function executeBenchmarkBody() {
+  index="$1"
+  loop="$2"
+  recursion="$3"
+  if [[ "${RECEIVER[$index]}" ]] ; then
+     debug "receiver ${RECEIVER[$index]}"
+     ${RECEIVER[$index]} >> "${DATA_DIR}/kieker.receiver-${loop}-${index}.log" &
+     RECEIVER_PID=$!
+     debug "PID ${RECEIVER_PID}"
+  fi
+
+  executeExperiment "$loop" "$recursion" "$index" "${TITLE[$index]}" "${WRITER_CONFIG[$index]}"
+
+  if [[ "${RECEIVER_PID}" ]] ; then
+     kill -TERM "${RECEIVER_PID}"
+     unset RECEIVER_PID
+  fi
+}
+
+## Execute Benchmark
+function executeBenchmark() {
+  for ((loop=1;loop<="${NUM_OF_LOOPS}";loop+=1)); do
+    recursion="${RECURSION_DEPTH}"
+
+    info "## Starting iteration ${loop}/${NUM_OF_LOOPS}"
+    echo "## Starting iteration ${loop}/${NUM_OF_LOOPS}" >> "${DATA_DIR}/kieker.log"
+
+    for ((index=0;index<${#WRITER_CONFIG[@]};index+=1)); do
+      executeBenchmarkBody $index $loop $recursion
+    done
+
+    printIntermediaryResults
+  done
+
+  mv "${DATA_DIR}/kieker.log" "${RESULTS_DIR}/kieker.log"
+  [ -f "${RESULTS_DIR}/hotspot-1-${RECURSION_DEPTH}-1.log" ] && grep "<task " "${RESULTS_DIR}"/hotspot-*.log > "${RESULTS_DIR}/log.log"
+  [ -f "${DATA_DIR}/errorlog.txt" ] && mv "${DATA_DIR}/errorlog.txt" "${RESULTS_DIR}"
+}
+
+
+# end
diff --git a/frameworks/Kieker/python/labels.sh b/frameworks/Kieker/python/labels.sh
new file mode 100644
index 0000000..01ba07a
--- /dev/null
+++ b/frameworks/Kieker/python/labels.sh
@@ -0,0 +1,5 @@
+TITLE[0]="No instrumentation"
+TITLE[1]="Deactivated probe"
+TITLE[2]="No logging (null writer)"
+TITLE[3]="Logging (Generic Text)"
+TITLE[4]="Logging (TCP)"
diff --git a/frameworks/Kieker/python/moo.py b/frameworks/Kieker/python/monitored_application.py
similarity index 100%
rename from frameworks/Kieker/python/moo.py
rename to frameworks/Kieker/python/monitored_application.py
-- 
GitLab