diff --git a/DiSLProject2022/run-instr.sh b/DiSLProject2022/run-instr.sh new file mode 100755 index 0000000..0dd6f4a --- /dev/null +++ b/DiSLProject2022/run-instr.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -e + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit; +fi + +exnum="$1" + +dir="$(dirname -- "${BASH_SOURCE[0]}")" +cd "$dir" + +ant clean +ant "-Ddislclass=ex$exnum.Instrumentation" + +printf "\e[32mRunning without instrumentation...\e[0m\n" +time ./run.sh "ex$exnum.Main" +./startDiSLServer.sh +sleep 1 +printf "\e[32mRunning WITH instrumentation...\e[0m\n" +time ./runInstrumented.sh "ex$exnum.Main" + + diff --git a/DiSLProject2022/src-profiler/ex1/Instrumentation.java b/DiSLProject2022/src-profiler/ex1/Instrumentation.java index 8562abe..9fbfad1 100644 --- a/DiSLProject2022/src-profiler/ex1/Instrumentation.java +++ b/DiSLProject2022/src-profiler/ex1/Instrumentation.java @@ -1,4 +1,27 @@ package ex1; +import ch.usi.dag.disl.annotation.After; +import ch.usi.dag.disl.annotation.Before; +import ch.usi.dag.disl.annotation.SyntheticLocal; +import ch.usi.dag.disl.marker.BodyMarker; +import ch.usi.dag.disl.staticcontext.MethodStaticContext; + public class Instrumentation { + + @SyntheticLocal + static long entryTimestamp; + + @Before(marker = BodyMarker.class, scope = "ex1.MainThread.factorial") + static void beforeMethod() { + entryTimestamp = System.nanoTime(); + } + + @After(marker = BodyMarker.class, scope = "ex1.MainThread.factorial") + static void afterMethod(final MethodStaticContext ctx) { + final long endTimestamp = System.nanoTime(); + System.out.printf("%s - Execution time for %s: %d ns%n", + Thread.currentThread().getName(), + ctx.getUniqueInternalName(), + endTimestamp - entryTimestamp); + } }