Search in sources :

Example 1 with TraceSimplePerf

use of com.android.tools.idea.monitor.ui.cpu.model.TraceSimplePerf in project android by JetBrains.

the class TraceRequestHandler method stopTracing.

public void stopTracing(Profiler profiler) {
    CpuServiceGrpc.CpuServiceBlockingStub cpuService = mySelectedDeviceProfilerService.getCpuService();
    String appPackageName = myDeviceContext.getSelectedClient().getClientData().getPackageName();
    // Stop profiling.
    CpuProfiler.CpuProfilingAppStopRequest.Builder requestBuilder = CpuProfiler.CpuProfilingAppStopRequest.newBuilder().setAppPkgName(appPackageName);
    if (profiler == Profiler.ART) {
        requestBuilder.setProfiler(CpuProfiler.CpuProfilingAppStopRequest.Profiler.ART);
    } else {
        requestBuilder.setProfiler(CpuProfiler.CpuProfilingAppStopRequest.Profiler.SIMPLE_PERF);
    }
    CpuProfiler.CpuProfilingAppStopResponse response = cpuService.stopProfilingApp(requestBuilder.build());
    if (!response.getStatus().equals(CpuProfiler.CpuProfilingAppStopResponse.Status.SUCCESS)) {
        LOG.error("Unable to stop tracing:" + response.getStatus());
        LOG.error(response.getErrorMessage());
        return;
    }
    // Save the trace data into a file, process it and store it in the datastore.
    final File[] dst = { null };
    try {
        ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<Object, IOException>() {

            @Override
            public Object compute() throws IOException {
                dst[0] = createLocalFile(createATraceFileName());
                Files.write(dst[0].toPath(), response.getTrace().toByteArray());
                return null;
            }
        });
        AppTrace trace;
        if (profiler == Profiler.ART) {
            trace = new TraceArt(dst[0]);
        } else {
            trace = new TraceSimplePerf(dst[0]);
        }
        trace.parse();
        TraceDataStore.getInstance().addTrace(myProject.getName(), trace);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : CpuServiceGrpc(com.android.tools.profiler.proto.CpuServiceGrpc) IOException(java.io.IOException) TraceArt(com.android.tools.idea.monitor.ui.cpu.model.TraceArt) CpuProfiler(com.android.tools.profiler.proto.CpuProfiler) TraceSimplePerf(com.android.tools.idea.monitor.ui.cpu.model.TraceSimplePerf) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AppTrace(com.android.tools.idea.monitor.ui.cpu.model.AppTrace)

Aggregations

AppTrace (com.android.tools.idea.monitor.ui.cpu.model.AppTrace)1 TraceArt (com.android.tools.idea.monitor.ui.cpu.model.TraceArt)1 TraceSimplePerf (com.android.tools.idea.monitor.ui.cpu.model.TraceSimplePerf)1 CpuProfiler (com.android.tools.profiler.proto.CpuProfiler)1 CpuServiceGrpc (com.android.tools.profiler.proto.CpuServiceGrpc)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 IOException (java.io.IOException)1