LegacyGcStatsDataSeries implements DataSeries<GcDurationData> { @Override public List<SeriesData<GcDurationData>> getDataForRange(@NotNull Range timeCurrentRangeUs) { long bufferNs = TimeUnit.SECONDS.toNanos(1); MemoryProfiler.MemoryRequest.Builder dataRequestBuilder = MemoryProfiler.MemoryRequest.newBuilder() .setSession(mySession) .setStartTime(TimeUnit.MICROSECONDS.toNanos((long)timeCurrentRangeUs.getMin()) - bufferNs) .setEndTime(TimeUnit.MICROSECONDS.toNanos((long)timeCurrentRangeUs.getMax()) + bufferNs); MemoryProfiler.MemoryData response = myClient.getData(dataRequestBuilder.build()); List<SeriesData<GcDurationData>> seriesData = new ArrayList<>(); for (MemoryProfiler.MemoryData.GcStatsSample sample : response.getGcStatsSamplesList()) { long dataTimestamp = TimeUnit.NANOSECONDS.toMicros(sample.getStartTime()); long duration = TimeUnit.NANOSECONDS.toMicros(sample.getEndTime() - sample.getStartTime()); seriesData.add(new SeriesData<>(dataTimestamp, new GcDurationData(duration))); } return seriesData; } LegacyGcStatsDataSeries(@NotNull MemoryServiceGrpc.MemoryServiceBlockingStub client, @NotNull Common.Session session); @Override List<SeriesData<GcDurationData>> getDataForRange(@NotNull Range timeCurrentRangeUs);  }
@Test public void testGetDataForXRange() throws Exception { MemoryData memoryData = MemoryData.newBuilder() .setEndTimestamp(1) .addGcStatsSamples( MemoryData.GcStatsSample.newBuilder().setStartTime(TimeUnit.MICROSECONDS.toNanos(3)) .setEndTime(TimeUnit.MICROSECONDS.toNanos(7))) .addGcStatsSamples( MemoryData.GcStatsSample.newBuilder().setStartTime(TimeUnit.MICROSECONDS.toNanos(14)) .setEndTime(TimeUnit.MICROSECONDS.toNanos(17))) .build(); myService.setMemoryData(memoryData); LegacyGcStatsDataSeries series = new LegacyGcStatsDataSeries(new ProfilerClient(myGrpcChannel.getName()).getMemoryClient(), ProfilersTestData.SESSION_DATA); List<SeriesData<GcDurationData>> dataList = series.getDataForRange(new Range(0, Double.MAX_VALUE)); assertEquals(2, dataList.size()); SeriesData<GcDurationData> data1 = dataList.get(0); assertEquals(3, data1.x); assertEquals(4, data1.value.getDurationUs()); SeriesData<GcDurationData> data2 = dataList.get(1); assertEquals(14, data2.x); assertEquals(3, data2.value.getDurationUs()); }