/** * 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 null if there was an error getting the summary. */ @Nullable static Nmt get() { final String nmt = invoke(); if (nmt == null) { return null; } try { return parse(nmt); } catch (IllegalArgumentException e) { LOG.warn("un-parseable NMT data:\n{}", nmt, e); return null; } }
@Test(expected = IllegalArgumentException.class) public void parseTooFewLines() { Nmt.parse("a\nb"); }
@Test public void parse() { final String s = "\n" + "Native Memory Tracking:\n" + "\n" + "Total: reserved=5710704KB, committed=471520KB\n" + "- Java Heap (reserved=4194304KB, committed=262144KB)\n" + " (mmap: reserved=4194304KB, committed=262144KB) \n" + " \n" + "- Class (reserved=1066181KB, committed=18885KB)\n" + " (classes #1722)\n" + " (malloc=9413KB #951) \n" + " (mmap: reserved=1056768KB, committed=9472KB) \n" + " \n" + "- Thread (reserved=20756KB, committed=20756KB)\n" + " (thread #20)\n" + " (stack: reserved=20480KB, committed=20480KB)\n" + " (malloc=60KB #110) \n" + " (arena=215KB #40)\n"; final Nmt nmt = Nmt.parse(s); validate(nmt); Assert.assertEquals(nmt.categories.size(), 3); Assert.assertEquals(nmt.categories.get("Class").committed, 18885 * Nmt.K); }