Skip to content

Instantly share code, notes, and snippets.

@autoletics
Last active January 30, 2017 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autoletics/a0362caeb51a38c0d9406799178800ad to your computer and use it in GitHub Desktop.
Save autoletics/a0362caeb51a38c0d9406799178800ad to your computer and use it in GitHub Desktop.
package org.jinspired.jxinsight.probes.reflection;
import java.io.PrintStream;
import org.jinspired.probes.interceptor.*;
import static org.jinspired.probes.Probes.*;
public final class InterceptorFactory implements ProbesInterceptorFactory {
@Override
public void init(Environment env) {}
@Override
public ProbesInterceptor create(Context ctx) { return new Interceptor(ctx); }
private static final class Interceptor implements ProbesInterceptor {
private final Context context;
private Probe probe;
private SavePoint savepoint;
Interceptor(Context ctx) { context = ctx; }
@Override
public void begin(Probe p) {
if(p == null) {
probe = p;
savepoint = context.savepoint();
}
}
@Override
public void end(Probe p) {
if(probe == p) {
final PrintStream out = System.out;
context.compare(savepoint).changepoints()
.forEachRemaining(cp -> cp.changes()
.forEachRemaining(c -> {
out.format("%s %6d %6d %2d %s\n",
c.getName(),
c.getTotal(),
c.getInherentTotal(),
c.getCount(),
cp.getName());
}));
savepoint = null;
probe = null;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment