From 4bc4bfeff97264036e090b17037738b5d478aca4 Mon Sep 17 00:00:00 2001
From: Reiner Jung <reiner.jung@email.uni-kiel.de>
Date: Fri, 19 Aug 2022 19:17:42 +0200
Subject: [PATCH] Updated python benchmark

---
 Jenkinsfile                           |  1 +
 frameworks/Kieker/java/benchmark.sh   | 50 +++++++-----------------
 frameworks/Kieker/python/benchmark.py | 55 ++++++++++++++++-----------
 frameworks/Kieker/python/benchmark.sh |  7 ++--
 frameworks/Kieker/python/functions.sh | 16 ++++----
 frameworks/Kieker/python/labels.sh    | 12 ++++--
 6 files changed, 67 insertions(+), 74 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 2c831e1..70fa63a 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -44,6 +44,7 @@ pipeline {
 
     stage('Run Benchmark') {
        steps {
+          sh './frameworks/Kieker/python/benchmark.sh'
           sh './frameworks/Kieker/java/benchmark.sh'
           sh './frameworks/OpenTelemetry/benchmark.sh'
           sh './frameworks/inspectIT/benchmark.sh'
diff --git a/frameworks/Kieker/java/benchmark.sh b/frameworks/Kieker/java/benchmark.sh
index d83631c..9d081ee 100755
--- a/frameworks/Kieker/java/benchmark.sh
+++ b/frameworks/Kieker/java/benchmark.sh
@@ -44,21 +44,6 @@ 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
 #
@@ -72,24 +57,23 @@ cd "${BASE_DIR}"
 # load agent
 getAgent
 
+checkDirectory data-dir "${DATA_DIR}" create
+checkDirectory results-directory "${RESULTS_DIR}" recreate
+PARENT=`dirname "${RESULTS_DIR}"`
+checkDirectory result-base "${PARENT}"
+
 # Find receiver and extract it
 checkFile receiver "${RECEIVER_ARCHIVE}"
 tar -xpf "${RECEIVER_ARCHIVE}"
 RECEIVER_BIN="${BASE_DIR}/receiver/bin/receiver"
+checkExecutable receiver "${RECEIVER_BIN}"
 
-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
@@ -153,20 +137,12 @@ 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
+executeBenchmark
+
+# Create R labels
+LABELS=$(createRLabels)
+runStatistics
+cleanupResults
 
 info "Done."
 
diff --git a/frameworks/Kieker/python/benchmark.py b/frameworks/Kieker/python/benchmark.py
index 466f1d5..0ec4039 100644
--- a/frameworks/Kieker/python/benchmark.py
+++ b/frameworks/Kieker/python/benchmark.py
@@ -10,8 +10,6 @@ import re
 if len(sys.argv) < 2:
     print('Path to the benchmark configuration file was not provided.')
 
-
-
 parser = configparser.ConfigParser()
 parser.read(sys.argv[1])
 
@@ -22,10 +20,12 @@ ini_path = parser.get('Benchmark','config_path')
 inactive = parser.getboolean('Benchmark', 'inactive')
 instrumentation_on = parser.getboolean('Benchmark', 'instrumentation_on')
 approach = parser.getint('Benchmark', 'approach')
+output_filename = parser.get('Benchmark', 'output_filename')
 
-print(f"total_calls = {total_calls}")
-print(f"recurison_depth = {recursion_depth}")
-print(f"method_time = {method_time}")
+# debug
+#print(f"total_calls = {total_calls}")
+#print(f"recurison_depth = {recursion_depth}")
+#print(f"method_time = {method_time}")
 
 # instrument
 from monitoring.controller import SingleMonitoringController
@@ -34,39 +34,50 @@ from tools.importhook import PostImportFinder
 ex =[]
 some_var = SingleMonitoringController(ini_path)
 if instrumentation_on:
-    print ('Instrumentation is on.')
+    # print ('Instrumentation is on.')
     if approach == 2:
-        print("2nd instrumentation approach is chosen")
-        if not inactive:
-            print("Instrumentation is activated")
-        else:
-            print("Instrumentation is not activated")
+        # print("2nd instrumentation approach is chosen")
+        #if not inactive:
+            #print("Instrumentation is activated")
+        #else:
+        #    print("Instrumentation is not activated")
         
-        sys.meta_path.insert(0, InstrumentOnImportFinder(ignore_list=ex, empty=inactive, debug_on=True))
+        sys.meta_path.insert(0, InstrumentOnImportFinder(ignore_list=ex, empty=inactive, debug_on=False))
     else:
-        print("1st instrumentation approach is chosen")
-        if not inactive:
-            print("Instrumentation is activated")
-        else:
-            print("Instrumentation is not activated")
-        pattern_object = re.compile('moo')
+        #print("1st instrumentation approach is chosen")
+        #if not inactive:
+        #    print("Instrumentation is activated")
+        #else:
+        #    print("Instrumentation is not activated")
+        
+        pattern_object = re.compile('monitored_application')
         exclude_modules = list()
         sys.meta_path.insert(0, PostImportFinder(pattern_object, exclude_modules, empty = inactive))
-else:
-    print('Instrumentation is off')
-import monitored_application
+#else:
+#    print('Instrumentation is off')
 
+import monitored_application
 
+# setup
+output_file = open(output_filename, "w")
 
+thread_id = 0
 
 start_ns = 0
 stop_ns = 0
 timings = []
+
+# run experiment
 for i in range(total_calls):
     start_ns = time.time_ns()
     monitored_application.monitored_method(method_time, recursion_depth)
     stop_ns = time.time_ns()
     timings.append(stop_ns-start_ns)
-    if i%100000 ==0:
+    if i%100000 == 0:
         print(timings[-1])
+    
+    output_file.write(f"{thread_id};{timings[-1]}\n")
+
+output_file.close()
 
+# end
diff --git a/frameworks/Kieker/python/benchmark.sh b/frameworks/Kieker/python/benchmark.sh
index 8a8a4ff..75c083c 100755
--- a/frameworks/Kieker/python/benchmark.sh
+++ b/frameworks/Kieker/python/benchmark.sh
@@ -76,8 +76,6 @@ 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."
 
-# JAVA_ARGS used to configure and setup a specific writer
-declare -a WRITER_CONFIG
 # Receiver setup if necessary
 declare -a RECEIVER
 # Title
@@ -115,7 +113,10 @@ info "----------------------------------"
 
 executeBenchmark
 
-# cleanup
+# Create R labels
+LABELS=$(createRLabels)
+runStatistics
+cleanupResults
 
 info "Done."
 
diff --git a/frameworks/Kieker/python/functions.sh b/frameworks/Kieker/python/functions.sh
index d027e1c..f9b4ce0 100644
--- a/frameworks/Kieker/python/functions.sh
+++ b/frameworks/Kieker/python/functions.sh
@@ -47,6 +47,7 @@ config_path = ${BASE_DIR}/monitoring.ini
 inactive = $inactive
 instrumentation_on = $instrument
 approach = $approach
+output_filename = ${RAWFN}-${loop}-${RECURSION_DEPTH}-${index}.csv
 EOF
 }
 
@@ -77,7 +78,6 @@ function noInstrumentation() {
   
     "${PYTHON}" benchmark.py "${BASE_DIR}/config.ini" # &> "${RESULTS_DIR}/output_${loop}_${RECURSION_DEPTH}_${index}.txt"
 
-
     echo >> "${DATA_DIR}/kieker.log"
     echo >> "${DATA_DIR}/kieker.log"
     sync
@@ -178,13 +178,13 @@ function executeBenchmark() {
 
     noInstrumentation 0 $loop
     dactivatedProbe 1 $loop 1
-    dactivatedProbe 1 $loop 2
-    noLogging 2 $loop 1
-    noLogging 2 $loop 2
-    textLogging 3 $loop 1
-    textLogging 3 $loop 2
-    tcpLogging 4 $loop 1
-    tcpLogging 4 $loop 2
+    dactivatedProbe 2 $loop 2
+    noLogging 3 $loop 1
+    noLogging 4 $loop 2
+    textLogging 5 $loop 1
+    textLogging 6 $loop 2
+    tcpLogging 7 $loop 1
+    tcpLogging 8 $loop 2
     
     printIntermediaryResults
   done
diff --git a/frameworks/Kieker/python/labels.sh b/frameworks/Kieker/python/labels.sh
index 01ba07a..33dd68f 100644
--- a/frameworks/Kieker/python/labels.sh
+++ b/frameworks/Kieker/python/labels.sh
@@ -1,5 +1,9 @@
 TITLE[0]="No instrumentation"
-TITLE[1]="Deactivated probe"
-TITLE[2]="No logging (null writer)"
-TITLE[3]="Logging (Generic Text)"
-TITLE[4]="Logging (TCP)"
+TITLE[1]="Deactivated probe - A"
+TITLE[2]="Deactivated probe - B"
+TITLE[3]="No logging (null writer) - A"
+TITLE[4]="No logging (null writer) - B"
+TITLE[5]="Logging (Generic Text) - A"
+TITLE[6]="Logging (Generic Text) - B"
+TITLE[7]="Logging (TCP) - A"
+TITLE[8]="Logging (TCP) - B"
-- 
GitLab