CpuProfiler extends StudioProfiler { @Nullable public File getTraceFile(Common.Session session) { return mySessionTraceFiles.get(session.getSessionId()); } 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 importedSessionListenerShouldBeRegistered() { Assume.assumeFalse("Unified pipeline import cannot yet be tested because of dependencies on TransportService.getInstance().", myUnifiedPipeline); myCpuProfiler = new CpuProfiler(myProfilers); File trace = CpuProfilerTestUtils.getTraceFile("valid_trace.trace"); SessionsManager sessionsManager = myProfilers.getSessionsManager(); sessionsManager.importSessionFromFile(trace); assertThat(myProfilers.getStage()).isInstanceOf(CpuProfilerStage.class); CpuProfilerStage cpuProfilerStage = (CpuProfilerStage)myProfilers.getStage(); assertThat(cpuProfilerStage.isImportTraceMode()).isTrue(); }
@Test public void traceImportHandlerShouldBeRegistered() { Assume.assumeFalse("Unified pipeline import cannot yet be tested because of dependencies on TransportService.getInstance().", myUnifiedPipeline); myCpuProfiler = new CpuProfiler(myProfilers); SessionsManager sessionsManager = myProfilers.getSessionsManager(); File trace = CpuProfilerTestUtils.getTraceFile("valid_trace.trace"); boolean sessionImportedSuccessfully = sessionsManager.importSessionFromFile(trace); assertThat(sessionImportedSuccessfully).isTrue(); assertThat(myProfilerService.getLastImportedSessionType()).isEqualTo(Common.SessionMetaData.SessionType.CPU_CAPTURE); }
@Test public void referenceToTraceFilesAreSavedPerSession() { Assume.assumeFalse("Unified pipeline import cannot yet be tested because of dependencies on TransportService.getInstance().", myUnifiedPipeline); myCpuProfiler = new CpuProfiler(myProfilers); File trace1 = CpuProfilerTestUtils.getTraceFile("valid_trace.trace"); SessionsManager sessionsManager = myProfilers.getSessionsManager(); sessionsManager.importSessionFromFile(trace1); Common.Session session1 = sessionsManager.getSelectedSession(); File trace2 = CpuProfilerTestUtils.getTraceFile("basic.trace"); sessionsManager.importSessionFromFile(trace2); Common.Session session2 = sessionsManager.getSelectedSession(); assertThat(myCpuProfiler.getTraceFile(session1)).isEqualTo(trace1); assertThat(myCpuProfiler.getTraceFile(session2)).isEqualTo(trace2); }
@Test public void importedSessionsStartTimeShouldBeTraceCreationTime() throws IOException { Assume.assumeFalse("Unified pipeline import cannot yet be tested because of dependencies on TransportService.getInstance().", myUnifiedPipeline); myCpuProfiler = new CpuProfiler(myProfilers); File trace = CpuProfilerTestUtils.getTraceFile("valid_trace.trace"); long traceCreationTime = Files.readAttributes(Paths.get(trace.getPath()), BasicFileAttributes.class).creationTime().to(TimeUnit.NANOSECONDS); SessionsManager sessionsManager = myProfilers.getSessionsManager(); sessionsManager.importSessionFromFile(trace); assertThat(sessionsManager.getSelectedSession().getStartTimestamp()).isEqualTo(traceCreationTime); }
@Test public void reimportTraceShouldSelectSameSession() throws IOException { Assume.assumeFalse("Unified pipeline import cannot yet be tested because of dependencies on TransportService.getInstance().", myUnifiedPipeline); myCpuProfiler = new CpuProfiler(myProfilers); File trace = CpuProfilerTestUtils.getTraceFile("valid_trace.trace"); long traceCreationTime = Files.readAttributes(Paths.get(trace.getPath()), BasicFileAttributes.class).creationTime().to(TimeUnit.NANOSECONDS); SessionsManager sessionsManager = myProfilers.getSessionsManager(); sessionsManager.importSessionFromFile(trace); assertThat(sessionsManager.getSelectedSession().getStartTimestamp()).isEqualTo(traceCreationTime); sessionsManager.beginSession(FAKE_DEVICE, FAKE_PROCESS); assertThat(sessionsManager.getSelectedSession().getStartTimestamp()).isNotEqualTo(traceCreationTime); myTimer.tick(FakeTimer.ONE_SECOND_IN_NS); sessionsManager.importSessionFromFile(trace); assertThat(sessionsManager.getSelectedSession().getStartTimestamp()).isEqualTo(traceCreationTime); }