/** * Dumps heap with a name with a human-readable timestamp to the Mesos sandbox, if environment variable * {@code MESOS_SANDBOX} is defined, or to the system temporary directory otherwise. * Logs where the heap dump will be written. * Logs a warning if there was a problem preventing the heap dump from being successfully created. */ public static void dumpHeap() { dumpHeap(getHeapDumpPath()); }
/** * Requires JVM argument {@code -XX:NativeMemoryTracking=summary}. * Logs a warning if there was an error getting the NMT summary or if NMT was disabled. * This warning will be logged only once per process instance. * Produces simpler and more concise human-readable summary of NMT than the native human-readable output from the * JVM. * @return Human-readable NMT summary. null if there was an error getting the summary. * @see #getNmt() */ @Nullable public static String formatNmt() { final Nmt nmt = Nmt.get(); if (nmt == null) { return null; } return nmt.toString(); }
@Test public void parseUsage2() { final Nmt.Usage u = Nmt.parseUsage("reserved=69124KB, committed=26356KB)\n"); Assert.assertNotNull(u); Assert.assertEquals(u.reserved, 69124 * Nmt.K); Assert.assertEquals(u.committed, 26356 * Nmt.K); }
@Test public void formatBytes3() { Assert.assertEquals(Memory.formatBytes(3 * 1024 * 1024), "3.00 MiB"); } }
/** * Requires JVM argument {@code -XX:NativeMemoryTracking=summary}. * Logs a warning if there was an error getting the NMT summary or if NMT was disabled. * This warning will be logged only once per process instance. * @return {@link Nmt} instance. null if there was an error getting the summary. */ @Nullable public static Nmt getNmt() { return Nmt.get(); }
public static void main(String[] args) { Memory.dumpHeap(); } }
@Test(expected = IllegalArgumentException.class) public void parseTooFewLines() { Nmt.parse("a\nb"); }
/** * @see NmtTest */ @Test public void getNmt() { Assert.assertNotNull(Memory.getNmt()); }
/** * @see NmtTest */ @Test public void formatNmt() { Assert.assertNotNull(Memory.formatNmt()); }
public static void main(String[] args) { System.out.print(ThreadInfo.format()); } }
/** * Like {@code jcmd Thread.print -l}. * Logs a warning if there was an error getting the thread dump. * @return Human-readable dump of all thread stacks. {@code null} if there was an error getting it. */ @Nullable public static String format() { return Dcmd.invoke("threadPrint", "-l"); } }
public static void main(String[] args) throws InterruptedException { final Duration aSec = Duration.ofSeconds(1); final Duration toSleep = Duration.ofSeconds(3); try (final Memory.NmtCloseable c = Memory.pollNmt(aSec)) { Thread.sleep(toSleep.toMillis()); } } }
@Test public void parseUsage1() { final Nmt.Usage u = Nmt.parseUsage("reserved=76944KB, committed=48784KB"); Assert.assertNotNull(u); Assert.assertEquals(u.reserved, 76944 * Nmt.K); Assert.assertEquals(u.committed, 48784 * Nmt.K); }
@Test public void formatBytes1() { Assert.assertEquals(Memory.formatBytes(1024), "1.00 KiB"); }
@Test public void format() { Assert.assertNotNull(ThreadInfo.format()); } }
@Test public void parseUsage3() { final Nmt.Usage u = Nmt.parseUsage("reserved=69124KB, committed=26356KB)"); Assert.assertNotNull(u); Assert.assertEquals(u.reserved, 69124 * Nmt.K); Assert.assertEquals(u.committed, 26356 * Nmt.K); }
@Test public void formatBytes2() { Assert.assertEquals(Memory.formatBytes(20), "20 B"); }