HeapDumpSampleDataSeries extends CaptureDataSeries<CaptureObject> { @Override public List<SeriesData<CaptureDurationData<CaptureObject>>> getDataForRange(Range range) { List<HeapDumpInfo> infos = MemoryProfiler.getHeapDumpsForSession(myClient, mySession, range, myStage.getStudioProfilers().getIdeServices()); List<SeriesData<CaptureDurationData<CaptureObject>>> seriesData = new ArrayList<>(); for (HeapDumpInfo info : infos) { seriesData.add(new SeriesData<>( getHostTime(info.getStartTime()), new CaptureDurationData<>( getDurationUs(info.getStartTime(), info.getEndTime()), false, false, new CaptureEntry<>( info, () -> new HeapDumpCaptureObject(myClient, mySession, info, null, myFeatureTracker, myStage))))); } return seriesData; } HeapDumpSampleDataSeries(@NotNull ProfilerClient client,
                                  @Nullable Common.Session session,
                                  @NotNull FeatureTracker featureTracker,
                                  @NotNull MemoryProfilerStage stage); @Override List<SeriesData<CaptureDurationData<CaptureObject>>> getDataForRange(Range range);  }
@Test public void testGetDataForXRange() { myIdeProfilerServices.enableEventsPipeline(true); myTransportService.addEventToStream(ProfilersTestData.SESSION_DATA.getStreamId(), ProfilersTestData.generateMemoryHeapDumpData(INFO1.getStartTime(), INFO1.getStartTime(), INFO1) .setPid(ProfilersTestData.SESSION_DATA.getPid()) .build()); myTransportService.addEventToStream(ProfilersTestData.SESSION_DATA.getStreamId(), ProfilersTestData.generateMemoryHeapDumpData(INFO2.getStartTime(), INFO2.getStartTime(), INFO2) .setPid(ProfilersTestData.SESSION_DATA.getPid()) .build()); HeapDumpSampleDataSeries series = new HeapDumpSampleDataSeries(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(2, data1.x); assertEquals(5, data1.value.getDurationUs()); CaptureObject capture1 = data1.value.getCaptureEntry().getCaptureObject(); assertEquals(TimeUnit.MICROSECONDS.toNanos(2), capture1.getStartTimeNs()); assertEquals(TimeUnit.MICROSECONDS.toNanos(7), capture1.getEndTimeNs()); SeriesData<CaptureDurationData<CaptureObject>> data2 = dataList.get(1); assertEquals(17, data2.x); assertEquals(Long.MAX_VALUE, data2.value.getDurationUs()); CaptureObject capture2 = data2.value.getCaptureEntry().getCaptureObject(); assertEquals(TimeUnit.MICROSECONDS.toNanos(17), capture2.getStartTimeNs()); assertEquals(Long.MAX_VALUE, capture2.getEndTimeNs()); }
@Test public void testLegacyGetDataForXRange() { myIdeProfilerServices.enableEventsPipeline(false); myService.addExplicitHeapDumpInfo(INFO1); myService.addExplicitHeapDumpInfo(INFO2); HeapDumpSampleDataSeries series = new HeapDumpSampleDataSeries(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(2, data1.x); assertEquals(5, data1.value.getDurationUs()); CaptureObject capture1 = data1.value.getCaptureEntry().getCaptureObject(); assertEquals(TimeUnit.MICROSECONDS.toNanos(2), capture1.getStartTimeNs()); assertEquals(TimeUnit.MICROSECONDS.toNanos(7), capture1.getEndTimeNs()); SeriesData<CaptureDurationData<CaptureObject>> data2 = dataList.get(1); assertEquals(17, data2.x); assertEquals(Long.MAX_VALUE, data2.value.getDurationUs()); CaptureObject capture2 = data2.value.getCaptureEntry().getCaptureObject(); assertEquals(TimeUnit.MICROSECONDS.toNanos(17), capture2.getStartTimeNs()); assertEquals(Long.MAX_VALUE, capture2.getEndTimeNs()); }