use of com.android.tools.idea.monitor.ui.cpu.model.AppTrace 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();
}
}
use of com.android.tools.idea.monitor.ui.cpu.model.AppTrace in project android by JetBrains.
the class CpuProfilerUiManager method onSelected.
@Override
public void onSelected(@NotNull List<ThreadStateDataSeries> selectedThreads) {
// TODO: Only support mono-selection for now:
if (selectedThreads.size() != 1) {
return;
}
myEventDispatcher.getMulticaster().profilerExpanded(ProfilerType.CPU);
resetDetailedComponents();
ThreadStateDataSeries selectedThread = selectedThreads.get(0);
int threadId = selectedThread.getProcessId();
AppTrace trace = TraceDataStore.getInstance().getLastThreadsActivity(myProject.getName());
if (trace == null) {
// No trace have been generated.
return;
}
SparseArray<HNode<Method>> availableThreads = trace.getThreadsGraph();
if (availableThreads.get(threadId) == null) {
return;
}
// Setup topdown panel
SparseArray<JComponent> topDownTrees = trace.getTopDownTrees();
myTopdownJpanel.add(topDownTrees.get(threadId), BorderLayout.CENTER);
// Setup bottomup panel
SparseArray<JComponent> bottomUpTrees = trace.getBottomUpTrees();
myBottomupJPanel.add(bottomUpTrees.get(threadId), BorderLayout.CENTER);
// Setup execution panel
HNode<Method> executionTree = availableThreads.get(threadId);
myExecutionChart.setHTree(executionTree);
if (AppTrace.Source.ART == trace.getSource()) {
myExecutionChart.setHRenderer(new NativeMethodHRenderer());
} else {
myExecutionChart.setHRenderer(new JavaMethodHRenderer());
}
// Setup flame graph
SparseArray<HNode<MethodUsage>> usageTrees = trace.getTopdownStats();
HNode<MethodUsage> usageTree = usageTrees.get(threadId);
myFlameChart.setHTree(usageTree);
myFlameChartRange.set(usageTree.getStart(), usageTree.getEnd());
myFlameChart.setXRange(myFlameChartRange);
if (AppTrace.Source.ART == trace.getSource()) {
myFlameChart.setHRenderer(new NativeMethodUsageHRenderer());
} else {
myFlameChart.setHRenderer(new JavaMethodUsageHRenderer());
}
// TODO: Selection doesn't seem right. Fix it and also set the proper color (red highlight).
// TODO: Reinvestigate sycning selection with the LineChart
myTimeSelectionRangeUs.set(executionTree.getStart(), executionTree.getEnd());
//myTimeSelectionRangeUs.lockValues();
// Setup view with a little bit of margin so selection can be seen.
//long duration = executionTree.getEnd() - executionTree.getStart();
//long durationMargin = duration / 10;
//myTimeCurrentRangeUs.set(executionTree.getStart() - durationMargin, executionTree.getEnd() + durationMargin);
//myTimeCurrentRangeUs.lockValues();
}
Aggregations