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 7129c3d commit 205b915
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import eu.mihosoft.vrl.lang.model.CodeEntity;
import eu.mihosoft.vrl.lang.model.ICodeEventType;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
*
Expand All @@ -16,13 +18,15 @@ class InstrumentationEventImpl implements InstrumentationEvent{
private final InstrumentationEventType type;
private final InstrumentationSource source;
private final long timeStamp;
private final Date date;

InstrumentationEventImpl(
InstrumentationEventType type,
InstrumentationSource source) {
this.type = type;
this.source = source;
this.timeStamp = System.nanoTime();
this.date = new Date(timeStamp);
}

/**
Expand Down Expand Up @@ -51,4 +55,22 @@ public InstrumentationSource getSource() {
public long getTimeStamp() {
return this.timeStamp;
}

/**
*
* @return
*/
@Override
public String toString() {
String evtType = "ANY";

if(getType()==InstrumentationEventType.PRE_INVOCATION) {
evtType = "PRE_INV";
} else if (getType()==InstrumentationEventType.POST_INVOCATION) {
evtType = "POST_INV";
}


return "[ type: " + evtType + ", src: " + getSource() + ", time-stamp: " + date.toString() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class InstrumentationSourceImpl implements InstrumentationSource {
private final Optional<Object> retVal;
private final boolean invocation;
private static final Object[] EMPTY_ARGS = new Object[0];

private final String argsString;
private final String retValString;

public InstrumentationSourceImpl(
String id,
Expand All @@ -35,6 +38,18 @@ public InstrumentationSourceImpl(
this.args = args;
this.retVal = Optional.ofNullable(retVal);
this.invocation = invocation;


String[] argsStr = new String[args.length];

for (int i = 0; i < argsStr.length; i++) {
String s = args[i] != null ? args[i].toString() : "null";
argsStr[i] = "'" + s + "'";
}

argsString = String.join(", ", argsStr);

retValString = "[" + this.retVal.orElse("null").toString() + "]";
}

/**
Expand Down Expand Up @@ -82,4 +97,12 @@ public Object[] getArguments() {
public boolean isInvocation() {
return this.invocation;
}

@Override
public String toString() {
return "[ id: " + id + ", name: " + name
+ ", args: [" + argsString + "], ret-val: " + retValString + " ]";
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ public static Invocation generatePostEvent(ControlFlow cf,
*/
@Deprecated()
public static void __preEvent(String id, String invName, Object... args) {
String[] argsStr = new String[args.length];

for (int i = 0; i < argsStr.length; i++) {
String s = args[i] != null ? args[i].toString() : "null";
argsStr[i] = "'" + s + "'";
}

System.out.println("pre-event: " + invName + ", id: '" + id
+ "', args: [ " + String.join(", ", argsStr) + " ]");

InstrumentationEvent evt = new InstrumentationEventImpl(
InstrumentationEventType.PRE_INVOCATION,
Expand All @@ -140,10 +131,6 @@ public static void __preEvent(String id, String invName, Object... args) {
*/
@Deprecated()
public static void __postEvent(String id, String invName, Object retVal) {
String retValStr = "'" + retVal != null ? retVal.toString() : "null" + "'";

System.out.println("post-event: '" + invName + "', id: '" + id
+ "', ret: [ '" + retValStr + "' ]");

InstrumentationEvent evt = new InstrumentationEventImpl(
InstrumentationEventType.POST_INVOCATION,
Expand All @@ -163,9 +150,6 @@ public static void __postEvent(String id, String invName, Object retVal) {
@Deprecated()
public static void __postEvent(String id, String invName) {

System.out.println("post-event: '" + invName + "', id: '" + id
+ "', ret: [ void ]");

InstrumentationEvent evt = new InstrumentationEventImpl(
InstrumentationEventType.POST_INVOCATION,
new InstrumentationSourceImpl(id, invName, null, null, true));
Expand Down

0 comments on commit 205b915

Please sign in to comment.