CpuProfiler extends StudioProfiler { @NotNull public static List<CpuTraceInfo> getTraceInfoFromSession(@NotNull ProfilerClient client, @NotNull Common.Session session, boolean newPipeline) { return getTraceInfoFromRange(client, session, new Range(Long.MIN_VALUE, Long.MAX_VALUE), newPipeline); } CpuProfiler(@NotNull StudioProfilers profilers); @Nullable File getTraceFile(Common.Session session); @Override ProfilerMonitor newMonitor(); @Override void startProfiling(Common.Session session); @Override void stopProfiling(Common.Session session); @NotNull static List<CpuTraceInfo> getTraceInfoFromRange(@NotNull ProfilerClient client,
                                                         @NotNull Common.Session session,
                                                         @NotNull Range rangeUs,
                                                         boolean newPipeline); @NotNull static CpuTraceInfo getTraceInfoFromId(@NotNull StudioProfilers profilers, long traceId); @NotNull static List<CpuTraceInfo> getTraceInfoFromSession(@NotNull ProfilerClient client,
                                                           @NotNull Common.Session session,
                                                           boolean newPipeline); @NotNull static Common.Event getTraceStatusEventFromId(@NotNull StudioProfilers profilers, long traceId); static void stopTracing(@NotNull StudioProfilers profilers,
                                 @NotNull Common.Session session,
                                 @NotNull Cpu.CpuTraceConfiguration configuration,
                                 @Nullable Consumer<Cpu.TraceStopStatus> responseHandler);  }
@Test public void testGetTraceInfoFromSession() { Assume.assumeTrue(myUnifiedPipeline); Common.Session session = myProfilers.getSession(); Cpu.CpuTraceInfo info1 = Cpu.CpuTraceInfo.newBuilder() .setTraceId(1).setFromTimestamp(1).setToTimestamp(2) .setStartStatus(Cpu.TraceStartStatus.newBuilder().setStatus(Cpu.TraceStartStatus.Status.SUCCESS)) .setStopStatus(Cpu.TraceStopStatus.newBuilder().setStatus(Cpu.TraceStopStatus.Status.SUCCESS)) .build(); myTransportService.addEventToStream( session.getStreamId(), Common.Event.newBuilder().setGroupId(1).setPid(session.getPid()) .setIsEnded(true).setKind(Common.Event.Kind.CPU_TRACE).setTimestamp(1) .setCpuTrace(Cpu.CpuTraceData.newBuilder().setTraceEnded(Cpu.CpuTraceData.TraceEnded.newBuilder().setTraceInfo(info1))).build()); List<Cpu.CpuTraceInfo> infos = CpuProfiler.getTraceInfoFromSession(myProfilers.getClient(), session, myUnifiedPipeline); assertThat(infos).containsExactly(info1); Cpu.CpuTraceInfo info2 = Cpu.CpuTraceInfo.newBuilder() .setTraceId(5).setFromTimestamp(5).setToTimestamp(-1) .setStartStatus(Cpu.TraceStartStatus.newBuilder().setStatus(Cpu.TraceStartStatus.Status.SUCCESS)) .build(); myTransportService.addEventToStream( session.getStreamId(), Common.Event.newBuilder().setGroupId(5).setPid(session.getPid()).setKind(Common.Event.Kind.CPU_TRACE).setTimestamp(5) .setCpuTrace(Cpu.CpuTraceData.newBuilder().setTraceStarted(Cpu.CpuTraceData.TraceStarted.newBuilder().setTraceInfo(info2))) .build()); myTransportService.addEventToStream( session.getStreamId(), Common.Event.newBuilder() .setTimestamp(10).setGroupId(5).setKind(Common.Event.Kind.CPU_TRACE).setPid(session.getPid()).setIsEnded(true).build()); infos = CpuProfiler.getTraceInfoFromSession(myProfilers.getClient(), session, myUnifiedPipeline); assertThat(infos) .containsExactly(info1, info2.toBuilder().setToTimestamp(session.getEndTimestamp()) .setStopStatus(Cpu.TraceStopStatus.newBuilder().setStatus(Cpu.TraceStopStatus.Status.APP_PROCESS_DIED)).build()); }