AllocationInfosDataSeries extends CaptureDataSeries<CaptureObject> { @Override public List<SeriesData<CaptureDurationData<CaptureObject>>> getDataForRange(Range range) { List<Memory.AllocationsInfo> infos = MemoryProfiler.getAllocationInfosForSession(myClient, mySession, range, myStage.getStudioProfilers().getIdeServices()); List<SeriesData<CaptureDurationData<CaptureObject>>> seriesData = new ArrayList<>(); for (Memory.AllocationsInfo info : infos) { long startTimeNs = info.getStartTime(); long durationUs = getDurationUs(startTimeNs, info.getEndTime()); seriesData.add( new SeriesData<>( getHostTime(startTimeNs), new CaptureDurationData<>(durationUs, !info.getLegacy(), !info.getLegacy(), new CaptureEntry<>( info, () -> { if (info.getLegacy()) { return new LegacyAllocationCaptureObject(myClient, mySession, info, myFeatureTracker); } else { return new LiveAllocationCaptureObject(myClient, mySession, startTimeNs, null, myStage); } })))); } return seriesData; } AllocationInfosDataSeries(@NotNull ProfilerClient client,
                                   @NotNull Common.Session session,
                                   @NotNull FeatureTracker featureTracker,
                                   @Nullable MemoryProfilerStage stage); @Override List<SeriesData<CaptureDurationData<CaptureObject>>> getDataForRange(Range range);  }
@Test public void testGetDataForXRange() { long startTimeUs1 = 2; long endTimeUs1 = 7; long startTimeUs2 = 17; AllocationsInfo info1 = AllocationsInfo.newBuilder() .setStartTime(TimeUnit.MICROSECONDS.toNanos(startTimeUs1)).setEndTime(TimeUnit.MICROSECONDS.toNanos(endTimeUs1)).setLegacy(true) .build(); AllocationsInfo info2 = AllocationsInfo.newBuilder() .setStartTime(TimeUnit.MICROSECONDS.toNanos(startTimeUs2)).setEndTime(Long.MAX_VALUE).setLegacy(true).build(); if (myNewEventPipeline) { myTransportService.addEventToStream(ProfilersTestData.SESSION_DATA.getStreamId(), ProfilersTestData.generateMemoryAllocationInfoData(info1.getStartTime(), ProfilersTestData.SESSION_DATA.getPid(), info1).build()); myTransportService.addEventToStream(ProfilersTestData.SESSION_DATA.getStreamId(), ProfilersTestData.generateMemoryAllocationInfoData(info2.getStartTime(), ProfilersTestData.SESSION_DATA.getPid(), info2).build()); } else { MemoryData memoryData = MemoryData.newBuilder() .addAllocationsInfo(info1) .addAllocationsInfo(info2) .build(); myService.setMemoryData(memoryData); } AllocationInfosDataSeries series = new AllocationInfosDataSeries(new ProfilerClient(myGrpcChannel.getName()), ProfilersTestData.SESSION_DATA, myIdeProfilerServices.getFeatureTracker(), myStage); List<SeriesData<CaptureDurationData<CaptureObject>>> dataList = series.getDataForRange(new Range(0, Double.MAX_VALUE)); assertEquals(2, dataList.size()); SeriesData<CaptureDurationData<CaptureObject>> data1 = dataList.get(0); assertEquals(startTimeUs1, data1.x); assertEquals(endTimeUs1 - startTimeUs1, data1.value.getDurationUs()); CaptureObject capture1 = data1.value.getCaptureEntry().getCaptureObject(); assertEquals(TimeUnit.MICROSECONDS.toNanos(startTimeUs1), capture1.getStartTimeNs()); assertEquals(TimeUnit.MICROSECONDS.toNanos(endTimeUs1), capture1.getEndTimeNs()); SeriesData<CaptureDurationData<CaptureObject>> data2 = dataList.get(1); assertEquals(startTimeUs2, data2.x); assertEquals(Long.MAX_VALUE, data2.value.getDurationUs()); CaptureObject capture2 = data2.value.getCaptureEntry().getCaptureObject(); assertEquals(TimeUnit.MICROSECONDS.toNanos(startTimeUs2), capture2.getStartTimeNs()); assertEquals(Long.MAX_VALUE, capture2.getEndTimeNs()); }