# Lab 6 - Software Performance 2023

This is Lab 6 of the **Software Performance** course at USI.

## Submission Info

| Property   | Value    |
|------------|----------|
| First Name | Claudio  |
| Last Name  | Maggioni |

## Setup

To run this application, Java 1.8 is required. The following commands assume that the file `java-home-path.txt` contains
an absolute path pointing to a valid `JAVA_HOME` for Java 1.8. To automatically do this on macOS run:

```shell
/usr/libexec/java_home -V
```

to list all installed JVMs. Then run this command to populate `java-home-path.txt`:

```shell
/usr/libexec/java_home -v $VERSION > java-home-path.txt
```

Here `$VERSION` is the JVM version number for the Java 1.8 JVM chosen from the previous list.

The following sections explain how to compile each module of this project. The shell blocks may be executed with 
IntelliJ IDEA's _RunMarkdown_ feature by opening this file and clicking on the green run button to the side of each 
shell block.

## How to compile the agent as JAR

```shell
export JAVA_HOME=`cat java-home-path.txt`
export PATH="${JAVA_HOME}/bin:$PATH"
cd agent/src
find . -name '*.java' -print -exec javac -cp ../lib/\*:. -d ../../out/production/agent \{\} \;
cd ..
jar cfm agent.jar manifest.txt -C ../out/production/agent .
jar tf agent.jar
```

## How to compile the profiler classes

```shell
export JAVA_HOME=`cat java-home-path.txt`
export PATH="${JAVA_HOME}/bin:$PATH"
cd profiler/src
find . -name '*.java' -print -exec javac -d ../../out/production/profiler \{\} \;
cd ../..
```

## How to compile the application classes

```shell
export JAVA_HOME=`cat java-home-path.txt`
export PATH="${JAVA_HOME}/bin:$PATH"
cd application/src
find . -name '*.java' -print -exec javac -d ../../out/production/application \{\} \;
cd ../..
```

### Running

To run the application compile the agent, the profiler and the application and then execute:

```shell
export JAVA_HOME=`cat java-home-path.txt`
export PATH="${JAVA_HOME}/bin:$PATH"
java -javaagent:agent/agent.jar=hello \
  -cp out/production/application \
  -Xbootclasspath/p:out/production/profiler \
  ch.usi.inf.sp.dbi.Application
```

The output of this command will include the program output and the calling context tree for the application execution.