diff options
author | Yi Yang <yiyiyang@google.com> | 2022-06-22 23:54:03 +0000 |
---|---|---|
committer | Yi Yang <yiyiyang@google.com> | 2022-07-12 18:20:42 +0000 |
commit | 5f9584131e3645b7949beb2d34ba79b87a8f2dd8 (patch) | |
tree | 458f937ec2b2cedd34b6e6f240f0378b02cea509 /profilers | |
parent | b8814e65cbc807079dbb893c033fd0a72b536dbf (diff) | |
download | idea-5f9584131e3645b7949beb2d34ba79b87a8f2dd8.tar.gz |
Remove unified pipeline flag in CpuProfilerStage
- Removed dead code in CpuProfilerStage
- Updated tests to use the transport service
Bug: 162494995
Test: updated
Change-Id: Ia9918a2489022e39c7d24a982c5c04ca736332b8
Diffstat (limited to 'profilers')
3 files changed, 64 insertions, 77 deletions
diff --git a/profilers/src/com/android/tools/profilers/cpu/CpuProfilerStage.java b/profilers/src/com/android/tools/profilers/cpu/CpuProfilerStage.java index 39bd5330aa0..15a29404e2c 100644 --- a/profilers/src/com/android/tools/profilers/cpu/CpuProfilerStage.java +++ b/profilers/src/com/android/tools/profilers/cpu/CpuProfilerStage.java @@ -43,7 +43,6 @@ import com.android.tools.profiler.proto.Commands; import com.android.tools.profiler.proto.Common; import com.android.tools.profiler.proto.Cpu; import com.android.tools.profiler.proto.Cpu.TraceInitiationType; -import com.android.tools.profiler.proto.CpuProfiler.CpuProfilingAppStartRequest; import com.android.tools.profiler.proto.CpuServiceGrpc; import com.android.tools.profilers.ProfilerAspect; import com.android.tools.profilers.ProfilerMode; @@ -63,7 +62,6 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -159,8 +157,8 @@ public class CpuProfilerStage extends StreamingStage implements CodeNavigator.Li */ private final Map<Long, CpuTraceInfo> myCompletedTraceIdToInfoMap = new HashMap<>(); - public CpuProfilerStage(@NotNull StudioProfilers profilers){ - this(profilers, new CpuCaptureParser(profilers.getIdeServices())); + public CpuProfilerStage(@NotNull StudioProfilers profilers) { + this(profilers, new CpuCaptureParser(profilers.getIdeServices())); } @VisibleForTesting @@ -202,8 +200,7 @@ public class CpuProfilerStage extends StreamingStage implements CodeNavigator.Li myCaptureParser = captureParser; List<Cpu.CpuTraceInfo> existingCompletedTraceInfoList = - CpuProfiler.getTraceInfoFromSession(getStudioProfilers().getClient(), mySession, - getStudioProfilers().getIdeServices().getFeatureConfig().isUnifiedPipelineEnabled()).stream() + CpuProfiler.getTraceInfoFromSession(getStudioProfilers().getClient(), mySession, true).stream() .filter(info -> info.getToTimestamp() != -1).collect(Collectors.toList()); existingCompletedTraceInfoList.forEach(info -> myCompletedTraceIdToInfoMap.put(info.getTraceId(), new CpuTraceInfo(info))); myInProgressTraceHandler = new InProgressTraceHandler(); @@ -355,40 +352,28 @@ public class CpuProfilerStage extends StreamingStage implements CodeNavigator.Li .build(); Executor poolExecutor = getStudioProfilers().getIdeServices().getPoolExecutor(); - if (getStudioProfilers().getIdeServices().getFeatureConfig().isUnifiedPipelineEnabled()) { - Commands.Command startCommand = Commands.Command.newBuilder() - .setStreamId(mySession.getStreamId()) - .setPid(mySession.getPid()) - .setType(Commands.Command.CommandType.START_CPU_TRACE) - .setStartCpuTrace(Cpu.StartCpuTrace.newBuilder().setConfiguration(configuration).build()) - .build(); - - getStudioProfilers().getClient().executeAsync(startCommand, poolExecutor) - .thenAcceptAsync(response -> { - TransportEventListener statusListener = new TransportEventListener( - Common.Event.Kind.CPU_TRACE_STATUS, - getStudioProfilers().getIdeServices().getMainExecutor(), - event -> event.getCommandId() == response.getCommandId(), - mySession::getStreamId, - mySession::getPid, - event -> { - startCapturingCallback(event.getCpuTraceStatus().getTraceStartStatus()); - // unregisters the listener. - return true; - }); - getStudioProfilers().getTransportPoller().registerListener(statusListener); - }, poolExecutor); - } - else { - CpuProfilingAppStartRequest request = CpuProfilingAppStartRequest.newBuilder() - .setSession(mySession) - .setConfiguration(configuration) - .build(); - CompletableFuture.supplyAsync( - () -> getCpuClient().startProfilingApp(request), poolExecutor) - .thenAcceptAsync(response -> this.startCapturingCallback(response.getStatus()), - getStudioProfilers().getIdeServices().getMainExecutor()); - } + Commands.Command startCommand = Commands.Command.newBuilder() + .setStreamId(mySession.getStreamId()) + .setPid(mySession.getPid()) + .setType(Commands.Command.CommandType.START_CPU_TRACE) + .setStartCpuTrace(Cpu.StartCpuTrace.newBuilder().setConfiguration(configuration).build()) + .build(); + + getStudioProfilers().getClient().executeAsync(startCommand, poolExecutor) + .thenAcceptAsync(response -> { + TransportEventListener statusListener = new TransportEventListener( + Common.Event.Kind.CPU_TRACE_STATUS, + getStudioProfilers().getIdeServices().getMainExecutor(), + event -> event.getCommandId() == response.getCommandId(), + mySession::getStreamId, + mySession::getPid, + event -> { + startCapturingCallback(event.getCpuTraceStatus().getTraceStartStatus()); + // unregisters the listener. + return true; + }); + getStudioProfilers().getTransportPoller().registerListener(statusListener); + }, poolExecutor); getStudioProfilers().getIdeServices().getTemporaryProfilerPreferences().setBoolean(HAS_USED_CPU_CAPTURE, true); myInstructionsEaseOutModel.setCurrentPercentage(1); @@ -413,7 +398,7 @@ public class CpuProfilerStage extends StreamingStage implements CodeNavigator.Li @VisibleForTesting void stopCapturing() { - // We need to send the trace configuration that was used to initiated the capture. Return early if no in-progress trace exists. + // We need to send the trace configuration that was used to initiate the capture. Return early if no in-progress trace exists. if (Cpu.CpuTraceInfo.getDefaultInstance().equals(myInProgressTraceInfo)) { return; } @@ -626,8 +611,7 @@ public class CpuProfilerStage extends StreamingStage implements CodeNavigator.Li // Request for the entire data range as we don't expect too many (100s) traces withing a single session. Range dataRange = getTimeline().getDataRange(); List<Cpu.CpuTraceInfo> traceInfoList = - CpuProfiler.getTraceInfoFromRange(getStudioProfilers().getClient(), mySession, dataRange, - getStudioProfilers().getIdeServices().getFeatureConfig().isUnifiedPipelineEnabled()); + CpuProfiler.getTraceInfoFromRange(getStudioProfilers().getClient(), mySession, dataRange, true); for (int i = 0; i < traceInfoList.size(); i++) { Cpu.CpuTraceInfo trace = traceInfoList.get(i); if (trace.getToTimestamp() == -1) { @@ -728,8 +712,7 @@ public class CpuProfilerStage extends StreamingStage implements CodeNavigator.Li class CpuTraceDataSeries implements DataSeries<CpuTraceInfo> { @Override public List<SeriesData<CpuTraceInfo>> getDataForRange(Range range) { - List<Cpu.CpuTraceInfo> traceInfos = CpuProfiler.getTraceInfoFromRange(getStudioProfilers().getClient(), mySession, range, - getStudioProfilers().getIdeServices().getFeatureConfig().isUnifiedPipelineEnabled()); + List<Cpu.CpuTraceInfo> traceInfos = CpuProfiler.getTraceInfoFromRange(getStudioProfilers().getClient(), mySession, range, true); List<SeriesData<CpuTraceInfo>> seriesData = new ArrayList<>(); for (Cpu.CpuTraceInfo protoTraceInfo : traceInfos) { CpuTraceInfo info = new CpuTraceInfo(protoTraceInfo); diff --git a/profilers/testSrc/com/android/tools/profilers/cpu/CpuProfilerStageTest.java b/profilers/testSrc/com/android/tools/profilers/cpu/CpuProfilerStageTest.java index 79481f0f2d0..306a75c0ea5 100644 --- a/profilers/testSrc/com/android/tools/profilers/cpu/CpuProfilerStageTest.java +++ b/profilers/testSrc/com/android/tools/profilers/cpu/CpuProfilerStageTest.java @@ -93,9 +93,7 @@ public final class CpuProfilerStageTest extends AspectObserver { myTimer.tick(FakeTimer.ONE_SECOND_IN_NS); myStage = new CpuProfilerStage(profilers); myStage.getStudioProfilers().setStage(myStage); - if (myServices.getFeatureConfig().isUnifiedPipelineEnabled()) { - ProfilersTestData.populateThreadData(myTransportService, ProfilersTestData.SESSION_DATA.getStreamId()); - } + ProfilersTestData.populateThreadData(myTransportService, ProfilersTestData.SESSION_DATA.getStreamId()); } @Test @@ -131,7 +129,7 @@ public final class CpuProfilerStageTest extends AspectObserver { // Start a capture using INSTRUMENTED mode List<ProfilingConfiguration> defaultConfigurations = myStage.getProfilerConfigModel().getDefaultProfilingConfigurations(); assertThat(myStage.getRecordingModel().getBuiltInOptions()).hasSize(defaultConfigurations.size()); - for(int i = 0; i < defaultConfigurations.size(); i++) { + for (int i = 0; i < defaultConfigurations.size(); i++) { assertThat(myStage.getRecordingModel().getBuiltInOptions().get(i).getTitle()).isEqualTo(defaultConfigurations.get(i).getName()); } } @@ -855,30 +853,25 @@ public final class CpuProfilerStageTest extends AspectObserver { .setToTimestamp(endTimestampNs) .setConfiguration(configuration) .build(); - if (myServices.getFeatureConfig().isUnifiedPipelineEnabled()) { - Common.Event.Builder traceEventBuilder = Common.Event.newBuilder() - .setGroupId(traceId) - .setPid(pid) - .setKind(Common.Event.Kind.CPU_TRACE); + Common.Event.Builder traceEventBuilder = Common.Event.newBuilder() + .setGroupId(traceId) + .setPid(pid) + .setKind(Common.Event.Kind.CPU_TRACE); + myTransportService.addEventToStream(streamId, traceEventBuilder + .setTimestamp(startTimestampNs) + .setCpuTrace(Cpu.CpuTraceData.newBuilder() + .setTraceStarted(Cpu.CpuTraceData.TraceStarted.newBuilder() + .setTraceInfo(info) + .build()) + .build()) + .build()); + if (endTimestampNs != -1) { myTransportService.addEventToStream(streamId, traceEventBuilder - .setTimestamp(startTimestampNs) + .setTimestamp(endTimestampNs) .setCpuTrace(Cpu.CpuTraceData.newBuilder() - .setTraceStarted(Cpu.CpuTraceData.TraceStarted.newBuilder() - .setTraceInfo(info) - .build()) + .setTraceEnded(Cpu.CpuTraceData.TraceEnded.newBuilder().setTraceInfo(info).build()) .build()) .build()); - if (endTimestampNs != -1) { - myTransportService.addEventToStream(streamId, traceEventBuilder - .setTimestamp(endTimestampNs) - .setCpuTrace(Cpu.CpuTraceData.newBuilder() - .setTraceEnded(Cpu.CpuTraceData.TraceEnded.newBuilder().setTraceInfo(info).build()) - .build()) - .build()); - } - } - else { - myCpuService.addTraceInfo(info); } } diff --git a/profilers/testSrc/com/android/tools/profilers/cpu/CpuTraceDataSeriesTest.java b/profilers/testSrc/com/android/tools/profilers/cpu/CpuTraceDataSeriesTest.java index 748d7d0a9f2..67935d44279 100644 --- a/profilers/testSrc/com/android/tools/profilers/cpu/CpuTraceDataSeriesTest.java +++ b/profilers/testSrc/com/android/tools/profilers/cpu/CpuTraceDataSeriesTest.java @@ -22,9 +22,9 @@ import com.android.tools.adtui.model.Range; import com.android.tools.adtui.model.SeriesData; import com.android.tools.idea.transport.faketransport.FakeGrpcChannel; import com.android.tools.idea.transport.faketransport.FakeTransportService; +import com.android.tools.profiler.proto.Common; import com.android.tools.profiler.proto.Cpu; import com.android.tools.profilers.FakeIdeProfilerServices; -import com.android.tools.profilers.FakeProfilerService; import com.android.tools.profilers.ProfilerClient; import com.android.tools.profilers.StudioProfilers; import java.util.List; @@ -34,20 +34,19 @@ import org.junit.Rule; import org.junit.Test; public class CpuTraceDataSeriesTest { - private final FakeTimer myTimer = new FakeTimer(); - private final FakeCpuService myService = new FakeCpuService(); + private final FakeTransportService myTransportService = new FakeTransportService(myTimer); @Rule - public FakeGrpcChannel myGrpcChannel = - new FakeGrpcChannel("CpuTraceDataSeriesTest", myService, new FakeTransportService(myTimer), new FakeProfilerService(myTimer)); + public FakeGrpcChannel myGrpcChannel = new FakeGrpcChannel("CpuTraceDataSeriesTest", myTransportService); private CpuProfilerStage.CpuTraceDataSeries mySeries; @Before public void setUp() { - - StudioProfilers profilers = new StudioProfilers(new ProfilerClient(myGrpcChannel.getChannel()), new FakeIdeProfilerServices(), myTimer); + FakeIdeProfilerServices ideProfilerServices = new FakeIdeProfilerServices(); + ideProfilerServices.enableEventsPipeline(true); + StudioProfilers profilers = new StudioProfilers(new ProfilerClient(myGrpcChannel.getChannel()), ideProfilerServices, myTimer); // One second must be enough for new devices (and processes) to be picked up myTimer.tick(FakeTimer.ONE_SECOND_IN_NS); CpuProfilerStage stage = new CpuProfilerStage(profilers); @@ -64,10 +63,22 @@ public class CpuTraceDataSeriesTest { public void validTraceSuccessStatus() { Range maxRange = new Range(-Double.MAX_VALUE, Double.MAX_VALUE); Cpu.CpuTraceInfo info = Cpu.CpuTraceInfo.newBuilder() + .setTraceId(1) .setFromTimestamp(TimeUnit.MICROSECONDS.toNanos(1)) .setToTimestamp(TimeUnit.MICROSECONDS.toNanos(3)) .build(); - myService.addTraceInfo(info); + Common.Event.Builder traceEventBuilder = Common.Event.newBuilder() + .setGroupId(1) + .setPid(FakeTransportService.FAKE_PROCESS.getPid()) + .setKind(Common.Event.Kind.CPU_TRACE); + myTransportService.addEventToStream(FakeTransportService.FAKE_DEVICE_ID, + traceEventBuilder.setTimestamp(info.getFromTimestamp()).setCpuTrace( + Cpu.CpuTraceData.newBuilder().setTraceStarted( + Cpu.CpuTraceData.TraceStarted.newBuilder().setTraceInfo(info))).build()); + myTransportService.addEventToStream(FakeTransportService.FAKE_DEVICE_ID, + traceEventBuilder.setTimestamp(info.getToTimestamp()).setCpuTrace( + Cpu.CpuTraceData.newBuilder().setTraceEnded( + Cpu.CpuTraceData.TraceEnded.newBuilder().setTraceInfo(info))).build()); List<SeriesData<CpuTraceInfo>> seriesData = mySeries.getDataForRange(maxRange); assertThat(seriesData).hasSize(1); |