MemoryMonitor implements Runnable, StatusDataProvider { public File dumpHeap() throws MalformedObjectNameException, InstanceNotFoundException, ReflectionException, MBeanException, IOException { return dumpHeap(localDumpFolder); } private  MemoryMonitor(
      GCStatsProvider gcStatsProvider,
      long sleepTimeMillis,
      int shutDownAfterNumGCThrashing,
      boolean canDumpHeap,
      double gcThrashingPercentagePerPeriod,
      @Nullable String uploadToGCSPath,
      File localDumpFolder); static MemoryMonitor fromOptions(PipelineOptions options); @VisibleForTesting void waitForThrashingState(boolean desiredThrashingState); void stop(); boolean isThrashing(); @Nullable File tryToDumpHeap(); @Override void run(); void waitForResources(String context); File dumpHeap(); @Override void appendSummaryHtml(PrintWriter writer); static final long DEFAULT_SLEEP_TIME_MILLIS; }
@Test public void heapDumpOnce() throws Exception { File folder = tempFolder.newFolder(); File dump1 = MemoryMonitor.dumpHeap(folder); assertNotNull(dump1); assertTrue(dump1.exists()); assertThat(dump1.getParentFile(), Matchers.equalTo(folder)); }
@Test public void heapDumpTwice() throws Exception { File folder = tempFolder.newFolder(); File dump1 = MemoryMonitor.dumpHeap(folder); assertNotNull(dump1); assertTrue(dump1.exists()); assertThat(dump1.getParentFile(), Matchers.equalTo(folder)); File dump2 = MemoryMonitor.dumpHeap(folder); assertNotNull(dump2); assertTrue(dump2.exists()); assertThat(dump2.getParentFile(), Matchers.equalTo(folder)); }