Skip to content

Instantly share code, notes, and snippets.

@jerolba
Created March 19, 2019 19:41
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 jerolba/a1baa6279d0ea704f45e5288fc4363f5 to your computer and use it in GitHub Desktop.
Save jerolba/a1baa6279d0ea704f45e5288fc4363f5 to your computer and use it in GitHub Desktop.
public void memoryHistogram() {
String name = ManagementFactory.getRuntimeMXBean().getName();
String PID = name.substring(0, name.indexOf("@"));
Process p = Runtime.getRuntime().exec("jcmd " + PID + " GC.class_histogram");
try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
input.lines().forEach(System.out::println);
}
}
public void memoryAnalysis(){
memoryHistogram();
Object instance = codeThatCreatesComplexDataStructure();
memoryHistogram();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment