Skip to content

Instantly share code, notes, and snippets.

@matthewdowney
Created March 27, 2020 23:56
Show Gist options
  • Select an option

  • Save matthewdowney/146ed6703d14622f46872a03e23d65e5 to your computer and use it in GitHub Desktop.

Select an option

Save matthewdowney/146ed6703d14622f46872a03e23d65e5 to your computer and use it in GitHub Desktop.
Clojure snippet to cause a JVM heap dump programmatically
(import 'java.lang.management.ManagementFactory)
(import 'com.sun.management.HotSpotDiagnosticMXBean)
(let [server (ManagementFactory/getPlatformMBeanServer)
bean-name "com.sun.management:type=HotSpotDiagnostic"
bean (ManagementFactory/newPlatformMXBeanProxy server bean-name HotSpotDiagnosticMXBean)
live-objects-only? true]
(.dumpHeap bean "heapdump.hprof" live-objects-only?))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment