[AETHER-1265] Integrate Java profiler in TOST env

- Adds a dockerfile to build ONOS image with profiler agent enabled
- Prevents the overriding of the JAVA_OPTS when using the profiler
- Deploy profiler also in the atomix nodes when using stc

Change-Id: I00d5091428083f44360989c701350b7fead66038
diff --git a/tools/test/bin/atomix-install b/tools/test/bin/atomix-install
index b059e12..92ec60f 100755
--- a/tools/test/bin/atomix-install
+++ b/tools/test/bin/atomix-install
@@ -48,6 +48,15 @@
 
     sudo mkdir -p $ATOMIX_INSTALL_DIR && sudo chown ${ONOS_USER}:${ONOS_GROUP} $ATOMIX_INSTALL_DIR
     tar -xvf /tmp/atomix.tar.gz -C $ATOMIX_INSTALL_DIR
+
+    if [ ! -z "$ONOS_YOURKIT" ]; then
+        sudo apt-get install unzip
+        cd /tmp
+        wget -N https://www.yourkit.com/download/YourKit-JavaProfiler-${ONOS_YOURKIT}.zip
+        unzip -o YourKit-JavaProfiler-${ONOS_YOURKIT}.zip
+        rm YourKit-JavaProfiler-${ONOS_YOURKIT}.zip
+        mv /tmp/YourKit-JavaProfiler-$(echo $ONOS_YOURKIT | sed 's/\(.*\)-.*/\1/')/bin/linux-x86-64/libyjpagent.so $ATOMIX_INSTALL_DIR/libyjpagent.so
+    fi
 "
 
 # Configure the ONOS installation
diff --git a/tools/test/bin/atomix-service b/tools/test/bin/atomix-service
index 7b60d93..5910a8c 100755
--- a/tools/test/bin/atomix-service
+++ b/tools/test/bin/atomix-service
@@ -39,11 +39,19 @@
     nodes=$(find_node ${1:-$OCI})
 fi
 
+# Define the java options for atomix
+# FIXME atomix-agent already provides a gc algorithm. Once we fix atomix-agent we can allow this
+# JAVA_OPTS="${JAVA_OPTS:--XX:+UseG1GC -XX:MaxGCPauseMillis=200}"
+if [ ! -z "$ONOS_YOURKIT" ]; then
+    #JAVA_OPTS+=" -agentpath:$ATOMIX_INSTALL_DIR/libyjpagent.so=listen=all"
+    JAVA_OPTS="${JAVA_OPTS:--agentpath:$ATOMIX_INSTALL_DIR/libyjpagent.so=listen=all}"
+fi
+
 case $2 in
     start)
         # Execute the remote commands
         for node in $nodes; do
-            ssh $ONOS_USER@${node} "nohup $ATOMIX_INSTALL_DIR/bin/atomix-agent -c $ATOMIX_INSTALL_DIR/atomix.json >/dev/null 2>&1 &"
+            ssh $ONOS_USER@${node} "JAVA_OPTS=\"${JAVA_OPTS}\" nohup $ATOMIX_INSTALL_DIR/bin/atomix-agent -c $ATOMIX_INSTALL_DIR/atomix.json >/dev/null 2>&1 &"
         done
     ;;
     stop)
diff --git a/tools/test/bin/onos-install b/tools/test/bin/onos-install
index 391640c..df220e3 100755
--- a/tools/test/bin/onos-install
+++ b/tools/test/bin/onos-install
@@ -88,7 +88,7 @@
         unzip -o YourKit-JavaProfiler-${ONOS_YOURKIT}.zip
         rm YourKit-JavaProfiler-${ONOS_YOURKIT}.zip
         mv /tmp/YourKit-JavaProfiler-$(echo $ONOS_YOURKIT | sed 's/\(.*\)-.*/\1/')/bin/linux-x86-64/libyjpagent.so $ONOS_INSTALL_DIR/libyjpagent.so
-        echo -e 'export JAVA_OPTS="${JAVA_OPTS:--agentpath:$ONOS_INSTALL_DIR/libyjpagent.so}=listen=all"' >> $ONOS_INSTALL_DIR/options
+        echo -e 'export ONOS_YOURKIT=$ONOS_YOURKIT' >> $ONOS_INSTALL_DIR/options
     fi
 
     # Set up correct user to run onos-service