class AllocStatsDataSeries implements DataSeries<Long> {

  @Override
  public List<SeriesData<Long>> getDataForRange(@NotNull Range rangeUs) {
    if (!myIsAgentAttached) {
      return Collections.emptyList();
    }

    if (!myProfilers.getIdeServices().getFeatureConfig().isUnifiedPipelineEnabled()) {
      return getLegacyAllocationStats(rangeUs);
    }

    Transport.GetEventGroupsRequest request = Transport.GetEventGroupsRequest.newBuilder()
      .setStreamId(mySession.getStreamId())
      .setPid(mySession.getPid())
      .setKind(Common.Event.Kind.MEMORY_ALLOC_STATS)
      .setFromTimestamp(TimeUnit.MICROSECONDS.toNanos((long)rangeUs.getMin()))
      .setToTimestamp(TimeUnit.MICROSECONDS.toNanos((long)rangeUs.getMax()))
      .build();
    Transport.GetEventGroupsResponse response = myClient.getTransportClient().getEventGroups(request);

    // No group ids for allocation stats so there shouldn't be more than one group.
    assert response.getGroupsCount() <= 1;

    List<SeriesData<Long>> seriesData = new ArrayList<>();
    if (response.getGroupsCount() > 0) {

      response.getGroups(0).getEventsList().forEach(event -> {
        long dataTimestamp = TimeUnit.NANOSECONDS.toMicros(event.getTimestamp());
        seriesData.add(new SeriesData<>(dataTimestamp, myFilter.apply(event.getMemoryAllocStats())));
      });
    }

    return seriesData;
  }

  public  AllocStatsDataSeries(@NotNull StudioProfilers profilers,
                              @NotNull Function<MemoryAllocStatsData, Long> filter);

}