@Test
public void testStopMonitoringCallsStopTracking() {

  MemoryAllocTracking allocTrackingHandler =
    (MemoryAllocTracking)myTransportService.getRegisteredCommand(Commands.Command.CommandType.STOP_ALLOC_TRACKING);
  MemoryProfiler memoryProfiler = new MemoryProfiler(myStudioProfiler);
  // We stop any ongoing (legacy or jvmti) allocation tracking session before stopping the memory profiler.
  if (myUnifiedPipeline) {
    Truth.assertThat(allocTrackingHandler.getLastInfo()).isEqualTo(Memory.AllocationsInfo.getDefaultInstance());
    memoryProfiler.stopProfiling(TEST_SESSION);
    Truth.assertThat(allocTrackingHandler.getLastInfo()).isNotEqualTo(Memory.AllocationsInfo.getDefaultInstance());
  }
  else {
    Truth.assertThat(myMemoryService.getTrackAllocationCount()).isEqualTo(0);
    memoryProfiler.stopProfiling(TEST_SESSION);
    Truth.assertThat(myMemoryService.getTrackAllocationCount()).isEqualTo(1);
  }
}