MemoryProfilerStageView extends StageView<MemoryProfilerStage> { @VisibleForTesting @NotNull JLabel getCaptureElapsedTimeLabel() { return myCaptureElapsedTime; } MemoryProfilerStageView(@NotNull StudioProfilersView profilersView, @NotNull MemoryProfilerStage stage); @Override boolean isToolbarVisible(); @Override JComponent getToolbar(); @VisibleForTesting @NotNull Splitter getMainSplitter(); @VisibleForTesting @NotNull Splitter getChartCaptureSplitter(); @VisibleForTesting @NotNull JPanel getCapturePanel();  }
@Test public void testCaptureElapsedTime() { final int startTime = 1; final int endTime = 5; long deltaUs = TimeUnit.SECONDS.toMicros(endTime - startTime); long startTimeNs = TimeUnit.SECONDS.toNanos(startTime); long endTimeNs = TimeUnit.SECONDS.toNanos(endTime); assertThat(myStage.isTrackingAllocations()).isFalse(); MemoryProfilerStageView stageView = (MemoryProfilerStageView)myProfilersView.getStageView(); myTimer.setCurrentTimeNs(TimeUnit.SECONDS.toNanos(startTime)); assertThat(stageView.getCaptureElapsedTimeLabel().getText()).isEmpty(); MemoryProfilerTestUtils .startTrackingHelper(myStage, myUnifiedPipeline, myTransportService, myService, myTimer, startTimeNs, Status.SUCCESS, true); assertThat(stageView.getCaptureElapsedTimeLabel().getText()) .isEqualTo(TimeFormatter.getSemiSimplifiedClockString(0)); myTimer.setCurrentTimeNs(TimeUnit.SECONDS.toNanos(endTime)); myStage.getAspect().changed(MemoryProfilerAspect.CURRENT_CAPTURE_ELAPSED_TIME); assertThat(stageView.getCaptureElapsedTimeLabel().getText()) .isEqualTo(TimeFormatter.getSemiSimplifiedClockString(deltaUs)); MemoryProfilerTestUtils.heapDumpHelper(myStage, myUnifiedPipeline, myTransportService, myService, myTimer.getCurrentTimeNs(), Long.MAX_VALUE, Memory.HeapDumpStatus.Status.SUCCESS); myStage.getAspect().changed(MemoryProfilerAspect.CURRENT_CAPTURE_ELAPSED_TIME); assertThat(stageView.getCaptureElapsedTimeLabel().getText()).isEqualTo(TimeFormatter.getSemiSimplifiedClockString(deltaUs)); MemoryProfilerTestUtils .stopTrackingHelper(myStage, myUnifiedPipeline, myTransportService, myService, myTimer, startTimeNs, endTimeNs, Status.SUCCESS, true); assertThat(stageView.getCaptureElapsedTimeLabel().getText()).isEmpty(); }