MemoryProfilerStageView extends StageView<MemoryProfilerStage> { @VisibleForTesting DurationDataRenderer<AllocationSamplingRateDurationData> getAllocationSamplingRateRenderer() { return myAllocationSamplingRateRenderer; } 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 testAllocationSamplingRateAttachment() { Common.Device device = Common.Device.newBuilder().setDeviceId(1).setFeatureLevel(AndroidVersion.VersionCodes.O).setState(Common.Device.State.ONLINE).build(); Common.Process process = Common.Process.newBuilder().setDeviceId(1).setPid(2).setState(Common.Process.State.ALIVE).build(); if (myUnifiedPipeline) { myTransportService.addEventToStream( device.getDeviceId(), ProfilersTestData.generateMemoryAllocStatsData(process.getPid(), 0, 0).build()); myTransportService.addEventToStream( device.getDeviceId(), ProfilersTestData.generateMemoryAllocStatsData(process.getPid(), 10, 100).build()); myTransportService.addEventToStream( device.getDeviceId(), ProfilersTestData .generateMemoryAllocSamplingData(process.getPid(), 1, MemoryProfilerStage.LiveAllocationSamplingMode.FULL.getValue()).build()); myTransportService.addEventToStream( device.getDeviceId(), ProfilersTestData .generateMemoryAllocSamplingData(process.getPid(), 5, MemoryProfilerStage.LiveAllocationSamplingMode.SAMPLED.getValue()).build()); myTransportService.addEventToStream( device.getDeviceId(), ProfilersTestData .generateMemoryAllocSamplingData(process.getPid(), 8, MemoryProfilerStage.LiveAllocationSamplingMode.NONE.getValue()).build()); myTransportService.addEventToStream( device.getDeviceId(), ProfilersTestData .generateMemoryAllocSamplingData(process.getPid(), 10, MemoryProfilerStage.LiveAllocationSamplingMode.FULL.getValue()).build()); } else { MemoryData data = MemoryData.newBuilder() .addAllocStatsSamples(MemoryData.AllocStatsSample.newBuilder().setTimestamp(0) .setAllocStats(Memory.MemoryAllocStatsData.newBuilder().setJavaAllocationCount(0))) .addAllocStatsSamples(MemoryData.AllocStatsSample.newBuilder().setTimestamp(10000) .setAllocStats(Memory.MemoryAllocStatsData.newBuilder().setJavaAllocationCount(100))) .addAllocSamplingRateEvents(AllocationSamplingRateEvent.newBuilder() .setTimestamp(1000) .setSamplingRate(MemoryAllocSamplingData.newBuilder() .setSamplingNumInterval( MemoryProfilerStage.LiveAllocationSamplingMode.FULL.getValue()))) .addAllocSamplingRateEvents(AllocationSamplingRateEvent.newBuilder() .setTimestamp(5000) .setSamplingRate(MemoryAllocSamplingData.newBuilder() .setSamplingNumInterval( MemoryProfilerStage.LiveAllocationSamplingMode.SAMPLED.getValue()))) .addAllocSamplingRateEvents(AllocationSamplingRateEvent.newBuilder() .setTimestamp(8000) .setSamplingRate(MemoryAllocSamplingData.newBuilder() .setSamplingNumInterval( MemoryProfilerStage.LiveAllocationSamplingMode.NONE.getValue()))) .addAllocSamplingRateEvents(AllocationSamplingRateEvent.newBuilder() .setTimestamp(10000) .setSamplingRate(MemoryAllocSamplingData.newBuilder() .setSamplingNumInterval( MemoryProfilerStage.LiveAllocationSamplingMode.FULL.getValue()))) .build(); myService.setMemoryData(data); } myTransportService.setAgentStatus(Common.AgentData.newBuilder().setStatus(Common.AgentData.Status.ATTACHED).build()); myProfilers.getSessionsManager().endCurrentSession(); myTimer.tick(FakeTimer.ONE_SECOND_IN_NS); myProfilers.getSessionsManager().beginSession(device.getDeviceId(), device, process); myTimer.tick(FakeTimer.ONE_SECOND_IN_NS); myProfilers.setStage(myStage); myStage.getTimeline().reset(0, TimeUnit.MICROSECONDS.toNanos(10)); myStage.getTimeline().getViewRange().set(0, 10); MemoryProfilerStageView view = new MemoryProfilerStageView(myProfilersView, myStage); myTimer.tick(FakeTimer.ONE_SECOND_IN_NS * 10); DurationDataRenderer<AllocationSamplingRateDurationData> durationDataRenderer = view.getAllocationSamplingRateRenderer(); java.util.List<Rectangle2D.Float> renderedRegions = durationDataRenderer.getClickRegionCache(); assertThat(renderedRegions.size()).isEqualTo(4); int iconWidth = StudioIcons.Profiler.Events.ALLOCATION_TRACKING_NONE.getIconWidth(); int iconHeight = StudioIcons.Profiler.Events.ALLOCATION_TRACKING_NONE.getIconHeight(); validateRegion(renderedRegions.get(0), 0.1f, 0.9f, iconWidth, iconHeight); validateRegion(renderedRegions.get(1), 0.5f, 0.5f, iconWidth, iconHeight); validateRegion(renderedRegions.get(2), 0.8f, 1f, iconWidth, iconHeight); validateRegion(renderedRegions.get(3), 1f, 0f, iconWidth, iconHeight); }