CpuProfilerStage extends StreamingStage implements CodeNavigator.Listener { @Nullable CpuTraceInfo getIntersectingTraceInfo(Range range) { List<SeriesData<CpuTraceInfo>> infoList = getTraceDurations().getSeries().getSeriesForRange(range); for (SeriesData<CpuTraceInfo> info : infoList) { Range captureRange = info.value.getRange(); if (!captureRange.getIntersection(range).isEmpty()) { return info.value; } } return null; } CpuProfilerStage(@NotNull StudioProfilers profilers);  CpuProfilerStage(@NotNull StudioProfilers profilers, @Nullable File importedTrace); @VisibleForTesting  CpuProfilerStage(@NotNull StudioProfilers profilers, @Nullable File importedTrace, @NotNull CpuCaptureParser captureParser); boolean isImportTraceMode(); boolean hasUserUsedCpuCapture(); @NotNull RangeSelectionModel getRangeSelectionModel(); @NotNull EaseOutModel getInstructionsEaseOutModel(); AxisComponentModel getCpuUsageAxis(); AxisComponentModel getThreadCountAxis(); AxisComponentModel getTimeAxisGuide(); DetailedCpuUsage getCpuUsage(); CpuStageLegends getLegends(); DurationDataModel<CpuTraceInfo> getTraceDurations(); String getName(); EventMonitor getEventMonitor(); @NotNull CpuProfilerConfigModel getProfilerConfigModel(); @Override void enter(); @Override void exit(); @NotNull UpdatableManager getUpdatableManager(); AspectModel<CpuProfilerAspect> getAspect(); void toggleCapturing(); void startCapturing(); long getCaptureStartTimeNs(); long getCaptureStopTimeNs(); @NotNull TraceIdsIterator getTraceIdsIterator(); @NotNull CpuCaptureParser getCaptureParser(); long currentTimeNs(); @VisibleForTesting void setCapture(@Nullable CpuCapture capture); void setAndSelectCapture(long traceId); @VisibleForTesting void setAndSelectCapture(@NotNull CpuCapture capture); int getSelectedThread(); void setSelectedThread(int id); @NotNull List<ClockType> getClockTypes(); @NotNull ClockType getClockType(); void setClockType(@NotNull ClockType clockType); @Nullable CpuCapture getCapture(); @NotNull CaptureState getCaptureState(); @NotNull TraceInitiationType getCaptureInitiationType(); void setCaptureState(@NotNull CaptureState captureState); @NotNull FilterResult applyCaptureFilter(@NotNull Filter filter); boolean isApiInitiatedTracingInProgress(); @NotNull CpuTraceDataSeries getCpuTraceDataSeries(); @NotNull CpuThreadsModel getThreadStates(); @NotNull CpuKernelModel getCpuKernelModel(); @NotNull CpuFramesModel getFramesModel(); @NotNull CaptureModel getCaptureModel(); void setCaptureDetails(@Nullable CaptureDetails.Type type); @Nullable CaptureDetails getCaptureDetails(); @Override void onNavigated(@NotNull CodeLocation location); static final int CPU_ART_STOP_TIMEOUT_SEC; }
@Test public void rangeIntersectionReturnsASingleTraceId() { int traceId1 = 1; int traceId2 = 2; addTraceInfoHelper(traceId1, FAKE_DEVICE_ID, FAKE_PROCESS.getPid(), TimeUnit.MICROSECONDS.toNanos(10), TimeUnit.MICROSECONDS.toNanos(20), Cpu.CpuTraceConfiguration.getDefaultInstance()); addTraceInfoHelper(traceId2, FAKE_DEVICE_ID, FAKE_PROCESS.getPid(), TimeUnit.MICROSECONDS.toNanos(30), TimeUnit.MICROSECONDS.toNanos(40), Cpu.CpuTraceConfiguration.getDefaultInstance()); CpuTraceInfo traceInfo = myStage.getIntersectingTraceInfo(new Range(0, 5)); assertThat(traceInfo).isNull(); traceInfo = myStage.getIntersectingTraceInfo(new Range(5, 15)); assertThat(traceInfo).isNotNull(); assertThat(traceInfo.getTraceId()).isEqualTo(traceId1); traceInfo = myStage.getIntersectingTraceInfo(new Range(25, 35)); assertThat(traceInfo).isNotNull(); assertThat(traceInfo.getTraceId()).isEqualTo(traceId2); traceInfo = myStage.getIntersectingTraceInfo(new Range(0, 50)); assertThat(traceInfo).isNotNull(); assertThat(traceInfo.getTraceId()).isEqualTo(traceId1); }