Last active
January 30, 2017 09:19
-
-
Save autoletics/a0362caeb51a38c0d9406799178800ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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