diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-22 07:17:10 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-22 07:17:10 +0200 |
commit | 4002407c3ae5e4ccb7a04974f616db63267115bf (patch) | |
tree | 06775decc85589f44416bff9b767e7c8ed30070b /vespajlib/src | |
parent | 1b688e7a77055d555c8fbe90856593b15c10cfa8 (diff) |
Dump heap of live objects on failed application shutdown.
Diffstat (limited to 'vespajlib/src')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/protect/Process.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/protect/Process.java b/vespajlib/src/main/java/com/yahoo/protect/Process.java index 4d2fafd4665..bc5f0d8f876 100644 --- a/vespajlib/src/main/java/com/yahoo/protect/Process.java +++ b/vespajlib/src/main/java/com/yahoo/protect/Process.java @@ -1,7 +1,11 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.protect; +import com.sun.management.HotSpotDiagnosticMXBean; +import javax.management.MBeanServer; +import java.io.IOException; +import java.lang.management.ManagementFactory; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; @@ -70,6 +74,15 @@ public final class Process { } } + public static void dumpHeap(String filePath, boolean live) throws IOException { + getHotspotMXBean().dumpHeap(filePath, live); + } + + private static HotSpotDiagnosticMXBean getHotspotMXBean() throws IOException { + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + return ManagementFactory.newPlatformMXBeanProxy( + server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class); + } public static void dumpThreads() { boolean alreadyDumpingThreads = busyDumpingThreads.getAndSet(true); |