@Test public void testHistor() { ForcedGcMemoryProfiler.printHeapHistogram(System.out, 20); }
public static long printHeapHistogram(PrintStream out, int _maxLines) { long _totalBytes = 0; boolean _partial = false; try { Process proc = Runtime.getRuntime().exec(new String[]{ getJmapExcutable(), "-histo", Long.toString(Utils.getPid())}); InputStream in = proc.getInputStream(); LineNumberReader r = new LineNumberReader(new InputStreamReader(in)); String s; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(buffer); while ((s = r.readLine()) != null) { if ( s.startsWith("Total")) { ps.println(s); String[] sa = s.split("\\s+"); _totalBytes = Long.parseLong(sa[2]); } else if (r.getLineNumber() <= _maxLines) { ps.println(s); } else { if (!_partial) { ps.println("[ ... truncated ... ]"); } _partial = true; } } r.close(); in.close(); ps.close(); byte[] _histoOuptut = buffer.toByteArray(); buffer = new ByteArrayOutputStream(); ps = new PrintStream(buffer); ps.println("[Heap Histogram Live Objects] used=" + _totalBytes); ps.write(_histoOuptut); ps.println(); ps.close(); out.write(buffer.toByteArray()); } catch (Exception ex) { System.err.println("ForcedGcMemoryProfiler: error attaching / reading histogram"); ex.printStackTrace(); } return _totalBytes; }
ForcedGcMemoryProfiler implements InternalProfiler { public static long printHeapHistogram(PrintStream out, int _maxLines) { long _totalBytes = 0; boolean _partial = false; try { Process proc = Runtime.getRuntime().exec(new String[]{ getJmapExcutable(), "-histo", Long.toString(Utils.getPid())}); InputStream in = proc.getInputStream(); LineNumberReader r = new LineNumberReader(new InputStreamReader(in)); String s; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(buffer); while ((s = r.readLine()) != null) { if ( s.startsWith("Total")) { ps.println(s); String[] sa = s.split("\\s+"); _totalBytes = Long.parseLong(sa[2]); } else if (r.getLineNumber() <= _maxLines) { ps.println(s); } else { if (!_partial) { ps.println("[ ... truncated ... ]"); } _partial = true; } } r.close(); in.close(); ps.close(); byte[] _histoOuptut = buffer.toByteArray(); buffer = new ByteArrayOutputStream(); ps = new PrintStream(buffer); ps.println("[Heap Histogram Live Objects] used=" + _totalBytes); ps.write(_histoOuptut); ps.println(); ps.close(); out.write(buffer.toByteArray()); } catch (Exception ex) { System.err.println("ForcedGcMemoryProfiler: error attaching / reading histogram"); ex.printStackTrace(); } return _totalBytes; } }
ForcedGcMemoryProfiler implements InternalProfiler { public static long printHeapHistogram(PrintStream out, int _maxLines) { long _totalBytes = 0; boolean _partial = false; try { Process proc = Runtime.getRuntime().exec(new String[]{ getJmapExcutable(), "-histo", Long.toString(Utils.getPid())}); InputStream in = proc.getInputStream(); LineNumberReader r = new LineNumberReader(new InputStreamReader(in)); String s; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(buffer); while ((s = r.readLine()) != null) { if ( s.startsWith("Total")) { ps.println(s); String[] sa = s.split("\\s+"); _totalBytes = Long.parseLong(sa[2]); } else if (r.getLineNumber() <= _maxLines) { ps.println(s); } else { if (!_partial) { ps.println("[ ... truncated ... ]"); } _partial = true; } } r.close(); in.close(); ps.close(); byte[] _histoOuptut = buffer.toByteArray(); buffer = new ByteArrayOutputStream(); ps = new PrintStream(buffer); ps.println("[Heap Histogram Live Objects] used=" + _totalBytes); ps.write(_histoOuptut); ps.println(); ps.close(); out.write(buffer.toByteArray()); } catch (Exception ex) { System.err.println("ForcedGcMemoryProfiler: error attaching / reading histogram"); ex.printStackTrace(); } return _totalBytes; }  }
ForcedGcMemoryProfiler implements InternalProfiler { public static long printHeapHistogram(PrintStream out, int _maxLines) { long _totalBytes = 0; boolean _partial = false; try { Process proc = Runtime.getRuntime().exec(new String[]{ getJmapExcutable(), "-histo", Long.toString(Utils.getPid())}); InputStream in = proc.getInputStream(); LineNumberReader r = new LineNumberReader(new InputStreamReader(in)); String s; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(buffer); while ((s = r.readLine()) != null) { if ( s.startsWith("Total")) { ps.println(s); String[] sa = s.split("\\s+"); _totalBytes = Long.parseLong(sa[2]); } else if (r.getLineNumber() <= _maxLines) { ps.println(s); } else { if (!_partial) { ps.println("[ ... truncated ... ]"); } _partial = true; } } r.close(); in.close(); ps.close(); byte[] _histoOuptut = buffer.toByteArray(); buffer = new ByteArrayOutputStream(); ps = new PrintStream(buffer); ps.println("[Heap Histogram Live Objects] used=" + _totalBytes); ps.write(_histoOuptut); ps.println(); ps.close(); out.write(buffer.toByteArray()); } catch (Exception ex) { System.err.println("ForcedGcMemoryProfiler: error attaching / reading histogram"); ex.printStackTrace(); } return _totalBytes; }  static void keepReference(Object _rootReferenceToKeep); static UsageTuple getUsage(); static void recordUsedMemory(); static boolean runSystemGC(); static String getJmapExcutable(); static long printHeapHistogram(PrintStream out, int _maxLines); @Override Collection<? extends Result> afterIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams, final IterationResult result); @Override void beforeIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams); @Override String getDescription(); }
ForcedGcMemoryProfiler implements InternalProfiler { public static long printHeapHistogram(PrintStream out, int _maxLines) { long _totalBytes = 0; boolean _partial = false; try { Process proc = Runtime.getRuntime().exec(new String[]{ getJmapExcutable(), "-histo", Long.toString(Utils.getPid())}); InputStream in = proc.getInputStream(); LineNumberReader r = new LineNumberReader(new InputStreamReader(in)); String s; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(buffer); while ((s = r.readLine()) != null) { if ( s.startsWith("Total")) { ps.println(s); String[] sa = s.split("\\s+"); _totalBytes = Long.parseLong(sa[2]); } else if (r.getLineNumber() <= _maxLines) { ps.println(s); } else { if (!_partial) { ps.println("[ ... truncated ... ]"); } _partial = true; } } r.close(); in.close(); ps.close(); byte[] _histoOuptut = buffer.toByteArray(); buffer = new ByteArrayOutputStream(); ps = new PrintStream(buffer); ps.println("[Heap Histogram Live Objects] used=" + _totalBytes); ps.write(_histoOuptut); ps.println(); ps.close(); out.write(buffer.toByteArray()); } catch (Exception ex) { System.err.println("ForcedGcMemoryProfiler: error attaching / reading histogram"); ex.printStackTrace(); } return _totalBytes; }  static void keepReference(Object _rootReferenceToKeep); static UsageTuple getUsage(); static void recordUsedMemory(); static boolean runSystemGC(); static String getJmapExcutable(); static long printHeapHistogram(PrintStream out, int _maxLines); @Override Collection<? extends Result> afterIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams, final IterationResult result); @Override void beforeIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams); @Override String getDescription();  }