@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));
  // Triggering a heap dump should not affect the allocation recording duration
  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();
}