MemoryProfilerStage extends StreamingStage implements CodeNavigator.Listener { public void requestHeapDump() { if (getStudioProfilers().getIdeServices().getFeatureConfig().isUnifiedPipelineEnabled()) { assert getStudioProfilers().getProcess() != null; Commands.Command dumpCommand = Commands.Command.newBuilder() .setStreamId(mySessionData.getStreamId()) .setPid(mySessionData.getPid()) .setType(Commands.Command.CommandType.HEAP_DUMP) .build(); Transport.ExecuteResponse response = getStudioProfilers().getClient().getTransportClient().execute( Transport.ExecuteRequest.newBuilder().setCommand(dumpCommand).build()); TransportEventListener statusListener = new TransportEventListener(Common.Event.Kind.MEMORY_HEAP_DUMP_STATUS, getStudioProfilers().getIdeServices().getMainExecutor(), event -> event.getCommandId() == response.getCommandId(), () -> mySessionData.getStreamId(), () -> mySessionData.getPid(), event -> { handleHeapDumpStart(event.getMemoryHeapdumpStatus().getStatus()); return true; }); getStudioProfilers().getTransportPoller().registerListener(statusListener); } else { TriggerHeapDumpResponse response = myClient.triggerHeapDump(TriggerHeapDumpRequest.newBuilder().setSession(mySessionData).build()); handleHeapDumpStart(response.getStatus()); } getTimeline().setStreaming(true); getStudioProfilers().getIdeServices().getTemporaryProfilerPreferences().setBoolean(HAS_USED_MEMORY_CAPTURE, true); myInstructionsEaseOutModel.setCurrentPercentage(1); } MemoryProfilerStage(@NotNull StudioProfilers profilers); @VisibleForTesting  MemoryProfilerStage(@NotNull StudioProfilers profilers, @NotNull CaptureObjectLoader loader); boolean hasUserUsedMemoryCapture(); DetailedMemoryUsage getDetailedMemoryUsage(); @Override void enter(); @Override void exit(); @NotNull RangeSelectionModel getRangeSelectionModel(); @NotNull StackTraceModel getAllocationStackTraceModel(); @NotNull StackTraceModel getDeallocationStackTraceModel(); void enableSelectLatestCapture(boolean enable, @Nullable Executor loadJoiner); boolean isMemoryCaptureOnly(); void setPendingCaptureStartTime(long pendingCaptureStartTime); @NotNull AspectModel<MemoryProfilerAspect> getAspect(); void requestHeapDump(); void forceGarbageCollection(); DurationDataModel<CaptureDurationData<CaptureObject>> getHeapDumpSampleDurations(); void trackAllocations(boolean enable); boolean isTrackingAllocations(); long getAllocationTrackingElapsedTimeNs(); @Nullable CaptureDurationData<? extends CaptureObject> getIntersectingCaptureDuration(@NotNull Range range); boolean useLiveAllocationTracking(); @NotNull DurationDataModel<CaptureDurationData<CaptureObject>> getAllocationInfosDurations(); void selectFieldObjectPath(@NotNull List<FieldObject> fieldObjectPath); @NotNull List<FieldObject> getSelectedFieldObjectPath(); void selectInstanceObject(@Nullable InstanceObject instanceObject); @Nullable InstanceObject getSelectedInstanceObject(); void selectClassSet(@Nullable ClassSet classSet); @Nullable ClassSet getSelectedClassSet(); void refreshSelectedHeap(); void selectHeapSet(@Nullable HeapSet heapSet); @Nullable HeapSet getSelectedHeapSet(); @NotNull FilterHandler getFilterHandler(); @NotNull List<LiveAllocationSamplingMode> getSupportedLiveAllocationSamplingMode(); @NotNull LiveAllocationSamplingMode getLiveAllocationSamplingMode(); void requestLiveAllocationSamplingModeUpdate(@NotNull LiveAllocationSamplingMode mode); @Nullable CaptureObject getSelectedCapture(); @NotNull MemoryProfilerConfiguration getConfiguration(); AxisComponentModel getMemoryAxis(); AxisComponentModel getObjectsAxis(); MemoryStageLegends getLegends(); MemoryStageLegends getTooltipLegends(); @NotNull EaseOutModel getInstructionsEaseOutModel(); EventMonitor getEventMonitor(); @NotNull DurationDataModel<GcDurationData> getGcStatsModel(); String getName(); @Override void onNavigated(@NotNull CodeLocation location); static boolean canSafelyLoadHprof(long fileSize); static final String LIVE_ALLOCATION_SAMPLING_PREF; static final LiveAllocationSamplingMode DEFAULT_LIVE_ALLOCATION_SAMPLING_MODE; static final int MEMORY_HPROF_SAFE_FACTOR; }
@Test public void testRequestHeapDump() { myMockLoader.setReturnImmediateFuture(true); MemoryProfilerTestUtils.heapDumpHelper(myStage, myUnifiedPipeline, myTransportService, myService, -1, -1, Memory.HeapDumpStatus.Status.FAILURE_UNKNOWN); assertThat(myStage.getSelectedCapture()).isNull(); assertThat(myStage.getProfilerMode()).isEqualTo(ProfilerMode.NORMAL); MemoryProfilerTestUtils.heapDumpHelper(myStage, myUnifiedPipeline, myTransportService, myService, -1, -1, Memory.HeapDumpStatus.Status.IN_PROGRESS); assertThat(myStage.getSelectedCapture()).isNull(); assertThat(myStage.getProfilerMode()).isEqualTo(ProfilerMode.NORMAL); MemoryProfilerTestUtils.heapDumpHelper(myStage, myUnifiedPipeline, myTransportService, myService, -1, -1, Memory.HeapDumpStatus.Status.UNSPECIFIED); assertThat(myStage.getSelectedCapture()).isNull(); assertThat(myStage.getProfilerMode()).isEqualTo(ProfilerMode.NORMAL); }
@Test public void testHeapDumpSetStreaming() { myStage.getTimeline().setStreaming(false); assertThat(myStage.getTimeline().isStreaming()).isFalse(); myMockLoader.setReturnImmediateFuture(true); myStage.requestHeapDump(); assertThat(myStage.getTimeline().isStreaming()).isTrue(); }