Skip to content

Commit

Permalink
instrumentation event handling improved (related to issue #58)
Browse files Browse the repository at this point in the history
- timestamp works, toString implemented for logging and debugging
  • Loading branch information
miho committed Aug 10, 2015
1 parent 205b915 commit 734e6e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InstrumentationEventImpl implements InstrumentationEvent{
this.type = type;
this.source = source;
this.timeStamp = System.nanoTime();
this.date = new Date(timeStamp);
this.date = new Date();
}

/**
Expand Down Expand Up @@ -71,6 +71,6 @@ public String toString() {
}


return "[ type: " + evtType + ", src: " + getSource() + ", time-stamp: " + date.toString() + "]";
return "[ time-stamp: " + date.toString() + ", type: " + evtType + ", src: " + getSource() + " ]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package eu.mihosoft.vrl.lang.model.transform;

import eu.mihosoft.vrl.base.IOUtil;
import eu.mihosoft.vrl.instrumentation.InstrumentationEventType;
import eu.mihosoft.vrl.instrumentation.VRLInstrumentationUtil;
import eu.mihosoft.vrl.lang.model.CommentTest;
import eu.mihosoft.vrl.lang.model.CompilationUnitDeclaration;
import eu.mihosoft.vrl.lang.model.LangModelTest;
Expand Down Expand Up @@ -47,11 +49,11 @@ public static String getResourceAsString(String resourceName) {

@Test
public void instrumentationTest() {

UIBinding.scopes.clear();

String fileName = "Instrumentation02.groovy";

String code = getResourceAsString(fileName);

// checking whether sample code compiles and generate model
Expand All @@ -75,29 +77,38 @@ public void instrumentationTest() {
for (Collection<Scope> scopeList : UIBinding.scopes.values()) {
for (Scope s : scopeList) {
if (s instanceof CompilationUnitDeclaration) {

cu = (CompilationUnitDeclaration) s;
newCode = Scope2Code.getCode(cu);
break;
}
}
}

System.out.println(newCode);

InstrumentCode instrumentCode = new InstrumentCode();
CompilationUnitDeclaration newCu = instrumentCode.transform(cu,"--|");

CompilationUnitDeclaration newCu = instrumentCode.transform(cu, "--|");

String instrumentedCode = Scope2Code.getCode(newCu);


VRLInstrumentationUtil.addEventHandler(InstrumentationEventType.PRE_INVOCATION,
(evt) -> {
System.out.println(" !!pre-evt: " + evt.toString());
});
VRLInstrumentationUtil.addEventHandler(InstrumentationEventType.POST_INVOCATION,
(evt) -> {
System.out.println("!!post-evt: " + evt.toString());
});

System.out.println(instrumentedCode);

try {
GroovyClassLoader gcl = new GroovyClassLoader();
Class<?> instrumentedCodeClass = gcl.parseClass(instrumentedCode);
instrumentedCodeClass.getMethod("main", String[].class).
invoke(instrumentedCodeClass, (Object)new String[0]);
invoke(instrumentedCodeClass, (Object) new String[0]);

} catch (CompilationFailedException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Logger.getLogger(LangModelTest.class.getName()).log(Level.SEVERE, null, ex);
Expand Down

0 comments on commit 734e6e5

Please sign in to comment.