Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
YourKit probe class that allows one to capture memory snapshots after certain phases has run in the Scala compiler.
import com.yourkit.probes.*;
import com.yourkit.api.*;
@MethodPattern("scala.tools.nsc.Global$Run:advancePhase()")
public class MemoryProbe {
public static void onEnter(@This scala.tools.nsc.Global.Run run) {
scala.reflect.internal.Phase patmatPhase = run.phaseNamed("patmat");
scala.reflect.internal.Phase postErasurePhase = run.phaseNamed("posterasure");
scala.reflect.internal.Phase icodePhase = run.phaseNamed("icode");
if (run.runIsAt(patmatPhase)) {
handlePhase(patmatPhase);
} else if (run.runIsAt(postErasurePhase)) {
handlePhase(postErasurePhase);
} else if (run.runIsAt(icodePhase)) {
handlePhase(icodePhase);
}
}
private static void handlePhase(scala.reflect.internal.Phase phase) {
try {
String name = phase.name();
System.out.println("After phase " + name);
Controller controller = new Controller();
controller.advanceGeneration(name);
System.gc();
System.gc();
controller.captureMemorySnapshot();
} catch (Exception e) {
System.out.println("Exception during taking memory dump " + e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment