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();
}
}
Aggregations