Skip to content

Commit

Permalink
Integrate IProfiler with Blinky
Browse files Browse the repository at this point in the history
- A compile-time config to register an IProfiler impl. w/ Blinky.
- Blinky now invokes the IProfiler to log instrumentation TraceEvents.
- Blinky prefers calling IProfiler instead of generic print statements.
  • Loading branch information
VijayKrishna committed May 23, 2020
1 parent 4e110e1 commit f7132da
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 276 deletions.
140 changes: 59 additions & 81 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,42 +79,65 @@
</executions>
</plugin>

<!--<plugin>-->
<!--<groupId>org.codehaus.mojo</groupId>-->
<!--<artifactId>exec-maven-plugin</artifactId>-->
<!--<version>1.5.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>blinky-config-runner</id>-->
<!--<phase>compile</phase>-->
<!--<goals>-->
<!--<goal>java</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--<configuration>-->
<!--<mainClass>org.spideruci.analysis.config.Main</mainClass>-->
<!--<additionalClasspathElements>-->
<!--<additionalClasspathElement>-->
<!--${basedir}/../blinky-config/target/blinky-config-0.0.1-SNAPSHOT-jar-with-dependencies.jar-->
<!--</additionalClasspathElement>-->
<!--</additionalClasspathElements>-->
<!--<systemProperties>-->
<!--<systemProperty>-->
<!--<key>config.filepath</key>-->
<!--<value>${basedir}/resources/config.yaml</value>-->
<!--</systemProperty>-->
<!--<systemProperty>-->
<!--<key>config.classname</key>-->
<!--<value>org.spideruci.analysis.statik.instrumentation.Config</value>-->
<!--</systemProperty>-->
<!--<systemProperty>-->
<!--<key>config.compiledoutput</key>-->
<!--<value>${basedir}/target/classes</value>-->
<!--</systemProperty>-->
<!--</systemProperties>-->
<!--</configuration>-->
<!--</plugin>-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>blinky-config-runner</id>
<goals>
<goal>java</goal>
</goals>

<!-- so that we run it after compiling blinky-core -->
<phase>compile</phase>
</execution>
</executions>

<configuration>
<!-- entry class for blinky-config -->
<mainClass>org.spideruci.analysis.config.Main</mainClass>

<!-- setting up a lean dependency graph to run blinky-config -->
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>org.spideruci.analysis.config</groupId>
<artifactId>blinky-config</artifactId>
</executableDependency>

<!-- passing arguments to blinky-config via system arguments-->
<systemProperties>
<systemProperty>
<key>config.filepath</key>
<value>${basedir}/resources/config.yaml</value>
</systemProperty>
<systemProperty>
<key>config.classname</key>
<value>org.spideruci.analysis.statik.instrumentation.Config</value>
</systemProperty>
<systemProperty>
<key>config.compiledoutput</key>
<value>${basedir}/target/classes</value>
</systemProperty>
<systemProperty>
<key>config.profilerclassname</key>
<value>org.spideruci.analysis.dynamic.api.EmptyProfiler</value>
</systemProperty>

</systemProperties>
</configuration>

<!-- List of direct dependencies needed to run blinky-config -->
<dependencies>
<dependency>
<groupId>org.spideruci.analysis.config</groupId>
<artifactId>blinky-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>

</plugins>
</build>
Expand Down Expand Up @@ -146,51 +169,6 @@

<profiles>

<profile>
<id>config</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>blinky-config-runner</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.spideruci.analysis.config.Main</mainClass>
<additionalClasspathElements>
<additionalClasspathElement>
${basedir}/../blinky-config/target/blinky-config-0.0.1-SNAPSHOT-jar-with-dependencies.jar
</additionalClasspathElement>
</additionalClasspathElements>
<systemProperties>
<systemProperty>
<key>config.filepath</key>
<value>${basedir}/resources/config.yaml</value>
</systemProperty>
<systemProperty>
<key>config.classname</key>
<value>org.spideruci.analysis.statik.instrumentation.Config</value>
</systemProperty>
<systemProperty>
<key>config.compiledoutput</key>
<value>${basedir}/target/classes</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>

</build>
</profile>

<profile>
<id>offline</id>
<build>
Expand Down
2 changes: 0 additions & 2 deletions resources/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ retransformInclusionList:
# - org/w3c
# - org/xml

profiler: 'org/spideruci/analysis/dynamic/profilers/CoverageTracker'

## FUTURE EXAMPLES (NOT YET TESTED; DO NOT UNCOMMENT):
# name: blinky
# number: !!int 1
Expand Down
36 changes: 36 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

pwd

## <ENV VARIABLES>
$MAIN_ARGS=
$TRACES_LOC=
$INPUT_ID=
$SUBJECT=
$BLINKY=
$ENTRY=

echo "[ENV VARIABLES]"
echo "MAIN_ARGS: "$MAIN_ARGS
echo "TRACES_LOC: "$TRACES_LOC
echo "INPUT_ID: "$INPUT_ID
echo "SUBJECT: "$SUBJECT
echo "BLINKY: "$BLINKY

JAVA="/Users/vpalepu/open-source/java/jre1.7.0_60.jre/Contents/Home/bin/java -d64 -Xmx6g"

BLINKYHOME="/Users/vpalepu/phd-open-source/blinky-core"
BLINKYJAR="$BLINKYHOME/blinky-core/target/blinky-core-0.0.1-SNAPSHOT-jar-with-dependencies.jar"

CONFIG_YAML="$BLINKYHOME/$INPUT_ID-methods.yaml"



BLINKY="-Xbootclasspath/p:$BLINKYJAR -javaagent:$BLINKYJAR=0,retransform,whitelist,purewhitelist,$ENTRY"

# prepare blinky jar file
cd $BLINKYHOME
mvn package -DskipTests -Dconfig.override=$CONFIG_YAML -q
cd -

$JAVA $BLINKY $SUBJECT $MAIN_ARGS > $TRACES_LOC/$INPUT_ID-full.trc 2> $TRACES_LOC/$INPUT_ID-full.err
2 changes: 1 addition & 1 deletion src/org/spideruci/analysis/dynamic/Blinksformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static byte[] instrumentClass(String className, byte[] classBytes,
ErrorLogManager.logClassTxStatus(className, isRuntime, FAILD);
instrumentedBytes = classBytes;
}
TraceLogger.printTraceCount(startTime, className);

return instrumentedBytes;
}

Expand Down
12 changes: 9 additions & 3 deletions src/org/spideruci/analysis/dynamic/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Profiler {
public static boolean logInvokeRuntimeSign = false;
public static boolean logEnterRuntimeSign = false;

public static boolean log = true;
public static boolean log = false;

public static PrintStream REAL_OUT = System.out;
public static PrintStream REAL_ERR = System.err;
Expand Down Expand Up @@ -67,7 +67,8 @@ synchronized static public void setLogFlags(final boolean value) {
logSwitch =
// logInvokeRuntimeSign =
logEnterRuntimeSign =
log = value;
// log =
value;
}

synchronized static public void initProfiler(String args) {
Expand Down Expand Up @@ -504,7 +505,12 @@ synchronized static public void unsetGuard1() {

synchronized static public void setGuard1() {
$guard1$ = true;
TraceLogger.printTraceCount();

if(TraceLogger.profiler == null) {
TraceLogger.printTraceCount();
return;
}

TraceLogger.profiler.endProfiling();
}

Expand Down
44 changes: 35 additions & 9 deletions src/org/spideruci/analysis/dynamic/TraceLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import static org.spideruci.analysis.dynamic.Profiler.REAL_OUT;

import org.spideruci.analysis.dynamic.api.EmptyProfiler;
import org.spideruci.analysis.dynamic.api.IProfiler;
import org.spideruci.analysis.dynamic.profilers.TimeAndCountTracker;
import org.spideruci.analysis.statik.instrumentation.Config;
import org.spideruci.analysis.trace.EventBuilder;
import org.spideruci.analysis.trace.EventType;
Expand Down Expand Up @@ -100,8 +98,13 @@ synchronized static public void handleEnterLog(String insnId, String tag, EventT
final String runtimeSignature = RuntimeTypeProfiler.getEnterRuntimeSignature(null);
TraceEvent event = EventBuilder.buildEnterExecEvent(++count, tag, insnId,
insnType, vitalState, runtimeSignature);

if(profiler == null) {
printEventlog(event);
return;
}

profiler.profileMethodEntry(event);
printEventlog(event);
}

synchronized static public void handleInvokeLog(String insnId, String tag, EventType insnType) {
Expand All @@ -111,50 +114,73 @@ synchronized static public void handleInvokeLog(String insnId, String tag, Event
RuntimeTypeProfiler.getInvokeRuntimeSignature();
TraceEvent event = EventBuilder.buildInvokeInsnExecEvent(++count, tag,
insnId, insnType, vitalState, runtimeSignature);

if(profiler == null) {
printEventlog(event);
return;
}

profiler.profileMethodInvoke(event);
printEventlog(event);
}

synchronized static public void handleLog(String insnId, String tag, EventType insnType) {
long[] vitalState = getVitalExecState();

TraceEvent event = EventBuilder.buildInsnExecEvent(++count, tag, insnId,
insnType, vitalState);

if(profiler == null) {
printEventlog(event);
return;
}

if (insnType == EventType.$exit$) {
profiler.profileMethodExit(event);
} else {
profiler.profileInsn(event);
}

printEventlog(event);
}

synchronized static public void handleArrayLog(String insnId, String tag, EventType insnType, int arrayrefId, int index, String elementId, int length) {
long[] vitalState = getVitalExecState();

TraceEvent event = EventBuilder.buildArrayInsnExecEvent(++count, tag,
insnId, insnType, vitalState, arrayrefId, index, elementId, length);

if(profiler == null) {
printEventlog(event);
return;
}

profiler.profileArrayInsn(event);
printEventlog(event);
}

synchronized static public void handleVarLog(String insnId, String tag, String varId) {
long[] vitalState = getVitalExecState();

TraceEvent event = EventBuilder.buildVarInsnExecEvent(++count, tag,
insnId, EventType.$var$, vitalState, varId);

if(profiler == null) {
printEventlog(event);
return;
}

profiler.profileVarInsn(event);
printEventlog(event);
}

synchronized static public void handleFieldLog(String insnId, String tag, String fieldId, String fieldOwnerId) {
long[] vitalState = getVitalExecState();

TraceEvent event = EventBuilder.buildFieldInsnExecEvent(++count, tag,
insnId, EventType.$field$, vitalState, fieldId, fieldOwnerId);

if(profiler == null) {
printEventlog(event);
return;
}

profiler.profileFieldInsn(event);
printEventlog(event);
}

synchronized static public void handleArgLog(String argType, String index, EventType type, boolean isFirst, boolean isLast) {
Expand Down
5 changes: 5 additions & 0 deletions src/org/spideruci/analysis/dynamic/api/EmptyProfiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
public class EmptyProfiler implements IProfiler {

@Override
public String description() {
return "EmptyProfiler";
}

@Override
public void willProfile() {
// Convenience stub. Subclasses should appropriate implementation.
Expand Down
2 changes: 2 additions & 0 deletions src/org/spideruci/analysis/dynamic/api/IProfiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.spideruci.analysis.trace.TraceEvent;

public interface IProfiler {

public String description();

public void startProfiling();
public void endProfiling();
Expand Down
Loading

0 comments on commit f7132da

Please sign in to comment.