MemoryProfiler extends StudioProfiler { @Override public void stopProfiling(Common.Session session) { try { trackAllocations(myProfilers, session, false, null); } catch (StatusRuntimeException e) { getLogger().info(e); } myProfilers.getClient().getMemoryClient().stopMonitoringApp(MemoryStopRequest.newBuilder().setSession(session).build()); } MemoryProfiler(@NotNull StudioProfilers profilers); @Override ProfilerMonitor newMonitor(); @Override void startProfiling(Common.Session session); @Override void stopProfiling(Common.Session session); static boolean hasOnlyFullAllocationTrackingWithinRegion(@NotNull StudioProfilers profilers,
                                                                  @NotNull Common.Session session, long startTimeUs, long endTimeUs); static void saveHeapDumpToFile(@NotNull ProfilerClient client,
                                        @NotNull Common.Session session,
                                        @NotNull HeapDumpInfo info,
                                        @NotNull OutputStream outputStream,
                                        @NotNull FeatureTracker featureTracker); static void saveLegacyAllocationToFile(@NotNull ProfilerClient client,
                                                @NotNull Common.Session session,
                                                @NotNull AllocationsInfo info,
                                                @NotNull OutputStream outputStream,
                                                @NotNull FeatureTracker featureTracker); static List<HeapDumpInfo> getHeapDumpsForSession(@NotNull ProfilerClient client,
                                                          @NotNull Common.Session session,
                                                          @NotNull Range rangeUs,
                                                          @NotNull IdeProfilerServices profilerService); static List<AllocationsInfo> getAllocationInfosForSession(@NotNull ProfilerClient client,
                                                                   @NotNull Common.Session session,
                                                                   @NotNull Range rangeUs,
                                                                   @NotNull IdeProfilerServices profilerService); static void trackAllocations(@NotNull StudioProfilers profilers,
                                      @NotNull Common.Session session,
                                      boolean enable,
                                      @Nullable Consumer<Memory.TrackStatus> responseHandler);  }
@Test public void testStopMonitoring() { Assume.assumeFalse("Unified pipeline does not go through StopMonitoringApp", myUnifiedPipeline); MemoryProfiler memoryProfiler = new MemoryProfiler(myStudioProfiler); memoryProfiler.stopProfiling(TEST_SESSION); Truth.assertThat(myMemoryService.getProcessId()).isEqualTo(FAKE_PID); }
@Test public void testStopMonitoringCallsStopTracking() { MemoryAllocTracking allocTrackingHandler = (MemoryAllocTracking)myTransportService.getRegisteredCommand(Commands.Command.CommandType.STOP_ALLOC_TRACKING); MemoryProfiler memoryProfiler = new MemoryProfiler(myStudioProfiler); 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); } }