CpuProfiler extends StudioProfiler { @NotNull public static Common.Event getTraceStatusEventFromId(@NotNull StudioProfilers profilers, long traceId) { if (!profilers.getIdeServices().getFeatureConfig().isUnifiedPipelineEnabled()) { return Common.Event.getDefaultInstance(); } Transport.GetEventGroupsResponse response = profilers.getClient().getTransportClient().getEventGroups( Transport.GetEventGroupsRequest.newBuilder() .setStreamId(profilers.getSession().getStreamId()) .setKind(Common.Event.Kind.CPU_TRACE_STATUS) .setGroupId(traceId) .build()); if (response.getGroupsCount() == 0) { return Common.Event.getDefaultInstance(); } return response.getGroups(0).getEvents(response.getGroups(0).getEventsCount() - 1); } 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 testGetTraceStatusEventFromId() { Assume.assumeTrue(myUnifiedPipeline); Common.Session session = myProfilers.getSession(); int TRACE_ID = 123; Cpu.CpuTraceStatusData status1 = Cpu.CpuTraceStatusData.newBuilder() .setTraceStartStatus(Cpu.TraceStartStatus.newBuilder().setStatus(Cpu.TraceStartStatus.Status.SUCCESS)) .build(); Common.Event event1 = Common.Event.newBuilder().setGroupId(TRACE_ID).setPid(session.getPid()).setKind(Common.Event.Kind.CPU_TRACE_STATUS).setTimestamp(1) .setCpuTraceStatus(status1).build(); myTransportService.addEventToStream(session.getStreamId(), event1); Common.Event event = CpuProfiler.getTraceStatusEventFromId(myProfilers, TRACE_ID); assertThat(event).isEqualTo(event1); Cpu.CpuTraceStatusData status2 = Cpu.CpuTraceStatusData.newBuilder() .setTraceStopStatus(Cpu.TraceStopStatus.newBuilder().setStatus(Cpu.TraceStopStatus.Status.WAIT_TIMEOUT).setErrorMessage("error")) .build(); Common.Event event2 = Common.Event.newBuilder().setGroupId(TRACE_ID).setPid(session.getPid()).setKind(Common.Event.Kind.CPU_TRACE_STATUS).setTimestamp(5) .setCpuTraceStatus(status2).build(); myTransportService.addEventToStream(session.getStreamId(), event2); Common.Event event3 = event2.toBuilder().setGroupId(TRACE_ID + 100).build(); myTransportService.addEventToStream(session.getStreamId(), event3); event = CpuProfiler.getTraceStatusEventFromId(myProfilers, TRACE_ID); assertThat(event).isEqualTo(event2); assertThat(event).isNotEqualTo(event3); }