Search in sources :

Example 1 with CallGraphAnalysis

use of org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis in project tracecompass by tracecompass.

the class CallGraphWithCallStackAnalysisTest method testCallGraph.

/**
 * Test the callgraph with the expected
 */
@Test
public void testCallGraph() {
    CallStackAnalysisStub cga = getModule();
    ICallGraphProvider cg = cga.getCallGraph();
    assertTrue(cg instanceof CallGraphAnalysis);
    CallGraphAnalysis callgraph = (CallGraphAnalysis) cg;
    callgraph.schedule();
    assertTrue(callgraph.waitForCompletion());
    List<@NonNull ThreadNode> threadNodes = callgraph.getThreadNodes();
    assertFalse(threadNodes.isEmpty());
    Map<Integer, Map<String, AggregateData>> expected = getTraceData().getExpectedCallGraph();
    assertEquals("Number of threads", expected.size(), threadNodes.size());
    for (ThreadNode threadNode : threadNodes) {
        Map<String, AggregateData> expectedCg = expected.get((int) threadNode.getId());
        assertNotNull(expectedCg);
        compareCallGraphs(expectedCg, threadNode.getChildren(), 0);
    }
}
Also used : CallStackAnalysisStub(org.eclipse.tracecompass.analysis.profiling.core.tests.stubs.CallStackAnalysisStub) ThreadNode(org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.ThreadNode) CallGraphAnalysis(org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis) ICallGraphProvider(org.eclipse.tracecompass.analysis.profiling.core.callgraph.ICallGraphProvider) AggregateData(org.eclipse.tracecompass.analysis.profiling.core.tests.data.CallStackTestData.AggregateData) Map(java.util.Map) Test(org.junit.Test)

Example 2 with CallGraphAnalysis

use of org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis in project tracecompass by tracecompass.

the class CallGraphTableViewer method getSegmentStoreProvider.

// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
@Nullable
protected ISegmentStoreProvider getSegmentStoreProvider(@NonNull ITmfTrace trace) {
    Iterable<CallStackAnalysis> csModules = TmfTraceUtils.getAnalysisModulesOfClass(trace, CallStackAnalysis.class);
    @Nullable CallStackAnalysis csModule = Iterables.getFirst(csModules, null);
    if (csModule == null) {
        return null;
    }
    csModule.schedule();
    ICallGraphProvider cgModule = csModule.getCallGraph();
    if (!(cgModule instanceof CallGraphAnalysis)) {
        return null;
    }
    CallGraphAnalysis module = (CallGraphAnalysis) cgModule;
    Job job = new Job(Messages.CallGraphAnalysis) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // The callgraph module will be scheduled by the callstack analysis, but we need
            // to wait for its specific termination
            module.waitForCompletion(Objects.requireNonNull((monitor)));
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
    return csModule;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CallGraphAnalysis(org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis) ICallGraphProvider(org.eclipse.tracecompass.analysis.profiling.core.callgraph.ICallGraphProvider) Job(org.eclipse.core.runtime.jobs.Job) Nullable(org.eclipse.jdt.annotation.Nullable) CallStackAnalysis(org.eclipse.tracecompass.analysis.profiling.core.callstack.CallStackAnalysis) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with CallGraphAnalysis

use of org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis in project tracecompass by tracecompass.

the class FlameGraphView method buildFlameGraph.

/**
 * Get the necessary data for the flame graph and display it
 *
 * @param callGraphProviders
 *            the callGraphAnalysis
 */
@VisibleForTesting
public void buildFlameGraph(Iterable<CallGraphAnalysis> callGraphProviders) {
    /*
         * Note for synchronization:
         *
         * Acquire the lock at entry. then we have 4 places to release it
         *
         * 1- if the lock failed
         *
         * 2- if the data is null and we have no UI to update
         *
         * 3- if the request is cancelled before it gets to the display
         *
         * 4- on a clean execution
         */
    Job job = fJob;
    if (job != null) {
        job.cancel();
    }
    try {
        fLock.acquire();
    } catch (InterruptedException e) {
        Activator.getDefault().logError(e.getMessage(), e);
        fLock.release();
        Thread.currentThread().interrupt();
    }
    if (!callGraphProviders.iterator().hasNext()) {
        fTimeGraphViewer.setInput(null);
        fLock.release();
        return;
    }
    for (CallGraphAnalysis provider : callGraphProviders) {
        provider.schedule();
    }
    job = new Job(Messages.CallGraphAnalysis_Execution) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                List<ThreadNode> input = new ArrayList<>();
                for (CallGraphAnalysis callGraphAnalysis : callGraphProviders) {
                    callGraphAnalysis.waitForCompletion(monitor);
                    input.addAll(fContentPresentation == ContentPresentation.BY_THREAD ? callGraphAnalysis.getThreadNodes() : callGraphAnalysis.getFlameGraph());
                }
                // compute input outside of display thread.
                Display.getDefault().asyncExec(() -> {
                    fTimeGraphViewer.setInput(input);
                    fTimeGraphViewer.resetStartFinishTime();
                });
                return Status.OK_STATUS;
            } finally {
                fJob = null;
                fLock.release();
            }
        }
    };
    fJob = job;
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CallGraphAnalysis(org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis) List(java.util.List) ArrayList(java.util.ArrayList) Job(org.eclipse.core.runtime.jobs.Job) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with CallGraphAnalysis

use of org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis in project tracecompass by tracecompass.

the class FlameGraphView method traceSelected.

/**
 * Handler for the trace selected signal
 *
 * @param signal
 *            The incoming signal
 */
@TmfSignalHandler
public void traceSelected(final TmfTraceSelectedSignal signal) {
    ITmfTrace trace = signal.getTrace();
    fTrace = trace;
    if (trace != null) {
        Iterable<CallStackAnalysis> csModules = TmfTraceUtils.getAnalysisModulesOfClass(trace, CallStackAnalysis.class);
        List<CallGraphAnalysis> cgModules = new ArrayList<>();
        for (CallStackAnalysis csModule : csModules) {
            csModule.schedule();
            ICallGraphProvider cgModule = csModule.getCallGraph();
            if (cgModule instanceof CallGraphAnalysis) {
                cgModules.add((CallGraphAnalysis) cgModule);
            }
        }
        fFlamegraphModules = cgModules;
        buildFlameGraph(cgModules);
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) CallGraphAnalysis(org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis) ICallGraphProvider(org.eclipse.tracecompass.analysis.profiling.core.callgraph.ICallGraphProvider) ArrayList(java.util.ArrayList) CallStackAnalysis(org.eclipse.tracecompass.analysis.profiling.core.callstack.CallStackAnalysis) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 5 with CallGraphAnalysis

use of org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis in project tracecompass by tracecompass.

the class CallStackAndGraphBenchmark method runCpuBenchmark.

/**
 * Run benchmark for the trace
 *
 * @throws TmfTraceException
 *             Exceptions thrown getting the trace
 */
@Test
public void runCpuBenchmark() throws TmfTraceException {
    Performance perf = Performance.getDefault();
    PerformanceMeter callStackBuildPm = Objects.requireNonNull(perf.createPerformanceMeter(TEST_ID + String.format(TEST_CALLSTACK_BUILD, fName)));
    perf.tagAsSummary(callStackBuildPm, String.format(TEST_CALLSTACK_BUILD, fName), Dimension.CPU_TIME);
    PerformanceMeter callStackSegStorePm = Objects.requireNonNull(perf.createPerformanceMeter(TEST_ID + String.format(TEST_CALLSTACK_PARSESEGSTORE, fName)));
    perf.tagAsSummary(callStackSegStorePm, String.format(TEST_CALLSTACK_PARSESEGSTORE, fName), Dimension.CPU_TIME);
    PerformanceMeter callgraphBuildPm = Objects.requireNonNull(perf.createPerformanceMeter(TEST_ID + String.format(TEST_CALLGRAPH_BUILD, fName)));
    perf.tagAsSummary(callgraphBuildPm, String.format(TEST_CALLGRAPH_BUILD, fName), Dimension.CPU_TIME);
    for (int i = 0; i < fLoopCount; i++) {
        TmfTrace trace = null;
        try {
            trace = getTrace();
            trace.traceOpened(new TmfTraceOpenedSignal(this, trace, null));
            CallStackAnalysis callStackModule = TmfTraceUtils.getAnalysisModuleOfClass(trace, CallStackAnalysis.class, LttngUstCallStackAnalysis.ID);
            assertNotNull(callStackModule);
            callStackModule.triggerAutomatically(false);
            // Benchmark the call stack analysis
            callStackBuildPm.start();
            TmfTestHelper.executeAnalysis(callStackModule);
            callStackBuildPm.stop();
            // Benchmark the segment store iteration
            ISegmentStore<@NonNull ISegment> segmentStore = callStackModule.getSegmentStore();
            assertNotNull(segmentStore);
            callStackSegStorePm.start();
            // Iterate through the whole segment store
            Iterator<ISegment> iterator = segmentStore.iterator();
            while (iterator.hasNext()) {
                iterator.next();
            }
            callStackSegStorePm.stop();
            ICallGraphProvider callGraphModule = callStackModule.getCallGraph();
            assertTrue(callGraphModule instanceof CallGraphAnalysis);
            // Benchmark the call graph analysis
            callgraphBuildPm.start();
            TmfTestHelper.executeAnalysis((CallGraphAnalysis) callGraphModule);
            callgraphBuildPm.stop();
            /*
                 * Delete the supplementary files, so that the next iteration rebuilds the state
                 * system.
                 */
            File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
            for (File file : suppDir.listFiles()) {
                file.delete();
            }
        } finally {
            if (trace != null) {
                trace.dispose();
            }
        }
    }
    callStackBuildPm.commit();
    callgraphBuildPm.commit();
}
Also used : CallGraphAnalysis(org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis) ICallGraphProvider(org.eclipse.tracecompass.analysis.profiling.core.callgraph.ICallGraphProvider) TmfTrace(org.eclipse.tracecompass.tmf.core.trace.TmfTrace) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) PerformanceMeter(org.eclipse.test.performance.PerformanceMeter) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) Performance(org.eclipse.test.performance.Performance) File(java.io.File) LttngUstCallStackAnalysis(org.eclipse.tracecompass.internal.lttng2.ust.core.callstack.LttngUstCallStackAnalysis) CallStackAnalysis(org.eclipse.tracecompass.analysis.profiling.core.callstack.CallStackAnalysis) Test(org.junit.Test)

Aggregations

CallGraphAnalysis (org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.CallGraphAnalysis)5 ICallGraphProvider (org.eclipse.tracecompass.analysis.profiling.core.callgraph.ICallGraphProvider)4 CallStackAnalysis (org.eclipse.tracecompass.analysis.profiling.core.callstack.CallStackAnalysis)3 ArrayList (java.util.ArrayList)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 List (java.util.List)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Performance (org.eclipse.test.performance.Performance)1 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)1 AggregateData (org.eclipse.tracecompass.analysis.profiling.core.tests.data.CallStackTestData.AggregateData)1 CallStackAnalysisStub (org.eclipse.tracecompass.analysis.profiling.core.tests.stubs.CallStackAnalysisStub)1 ThreadNode (org.eclipse.tracecompass.internal.analysis.profiling.core.callgraph.ThreadNode)1 LttngUstCallStackAnalysis (org.eclipse.tracecompass.internal.lttng2.ust.core.callstack.LttngUstCallStackAnalysis)1 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)1