Search in sources :

Example 1 with CallsiteAnalysis

use of org.eclipse.tracecompass.internal.tmf.core.analysis.callsite.CallsiteAnalysis in project tracecompass by tracecompass.

the class CallStackDataProvider method fetchTooltip.

@Override
@NonNull
public TmfModelResponse<@NonNull Map<@NonNull String, @NonNull String>> fetchTooltip(Map<String, Object> parameters, @Nullable IProgressMonitor monitor) {
    CallStackAnalysis analysis = getAnalysisModule();
    Map<String, String> tooltips = new HashMap<>();
    List<@NonNull Long> selected = DataProviderParameterUtils.extractSelectedItems(parameters);
    List<@NonNull Long> times = DataProviderParameterUtils.extractTimeRequested(parameters);
    // This data provider doesn't have any annotations or arrows
    Object element = parameters.get(DataProviderParameterUtils.REQUESTED_ELEMENT_KEY);
    if (element instanceof IAnnotation || element instanceof ITimeGraphArrow) {
        return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    if (selected != null && times != null) {
        Map<@NonNull Long, @NonNull Integer> md = getSelectedEntries(selected);
        ITmfTrace trace = getTrace();
        for (Long time : times) {
            for (Entry<@NonNull Long, @NonNull Integer> entry : md.entrySet()) {
                Long result = analysis.resolveDeviceId(entry.getValue(), time);
                if (result != null) {
                    String deviceId = String.valueOf(result);
                    String deviceType = analysis.resolveDeviceType(entry.getValue(), time);
                    tooltips.put(deviceType, deviceId);
                    Iterable<@NonNull CallsiteAnalysis> csas = TmfTraceUtils.getAnalysisModulesOfClass(trace, CallsiteAnalysis.class);
                    for (CallsiteAnalysis csa : csas) {
                        List<@NonNull ITmfCallsite> res = csa.getCallsites(String.valueOf(trace.getUUID()), deviceType, deviceId, time);
                        if (!res.isEmpty()) {
                            tooltips.put(TmfStrings.source(), String.valueOf(res.get(0)));
                        }
                    }
                    return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
                }
                ITmfStateSystem stateSystem = analysis.getStateSystem();
                if (stateSystem != null) {
                    try {
                        Collection<@NonNull ISymbolProvider> symbolProviders = SymbolProviderManager.getInstance().getSymbolProviders(trace);
                        ITmfStateInterval interval = stateSystem.querySingleState(Objects.requireNonNull(time), Objects.requireNonNull(entry.getValue()));
                        Object value = interval.getValue();
                        if (value instanceof Number) {
                            long longValue = ((Number) value).longValue();
                            for (ISymbolProvider provider : symbolProviders) {
                                TmfResolvedSymbol symbol = provider.getSymbol(longValue);
                                if (symbol != null) {
                                    tooltips.put(Messages.CallStackDataProvider_toolTipState, symbol.getSymbolName());
                                    tooltips.put(Messages.CallStackDataProvider_toolTipAddress, String.format(ADDRESS_FORMAT, symbol.getBaseAddress()));
                                    break;
                                }
                            }
                            tooltips.computeIfAbsent(Messages.CallStackDataProvider_toolTipState, unused -> String.format(ADDRESS_FORMAT, longValue));
                        } else if (value != null) {
                            tooltips.put(Messages.CallStackDataProvider_toolTipState, interval.getValueString());
                        }
                    } catch (StateSystemDisposedException e) {
                        // $NON-NLS-1$
                        Activator.getInstance().logError("State System Disposed", e);
                    }
                }
            }
        }
    }
    return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : IAnnotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IAnnotation) HashMap(java.util.HashMap) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) CallsiteAnalysis(org.eclipse.tracecompass.internal.tmf.core.analysis.callsite.CallsiteAnalysis) ISymbolProvider(org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) ITimeGraphArrow(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow) CallStackAnalysis(org.eclipse.tracecompass.analysis.profiling.core.callstack.CallStackAnalysis) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfResolvedSymbol(org.eclipse.tracecompass.tmf.core.symbols.TmfResolvedSymbol) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 2 with CallsiteAnalysis

use of org.eclipse.tracecompass.internal.tmf.core.analysis.callsite.CallsiteAnalysis in project tracecompass by tracecompass.

the class CallsiteTest method testCallsiteAnalysis.

/**
 * Test the {@link ThreadStatusDataProvider} for the XML kernel test trace
 */
@Test
public void testCallsiteAnalysis() {
    TmfXmlKernelTraceStub trace = fTrace;
    assertNotNull(trace);
    CallsiteAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, CallsiteAnalysis.class, CallsiteAnalysis.ID);
    assertNotNull(module);
    assertTrue(module.schedule().isOK());
    assertTrue(module.waitForCompletion());
    String uuid = String.valueOf(fTrace.getUUID());
    String cpu = "cpu";
    assertEquals(Collections.emptyList(), module.getCallsites(uuid, cpu, "0", 39));
    assertEquals(EXPECTED_40, module.getCallsites(uuid, cpu, "0", 40));
    assertEquals(EXPECTED_40, module.getCallsites(uuid, cpu, "0", 41));
    assertEquals(EXPECTED_40, module.getCallsites(uuid, cpu, "0", 70));
    assertEquals(EXPECTED_71, module.getCallsites(uuid, cpu, "0", 71));
    assertEquals(EXPECTED_71, module.getCallsites(uuid, cpu, "0", 72));
    assertEquals(Collections.emptyList(), module.getCallsites("Hello", cpu, "0", 42));
    assertEquals(Collections.emptyList(), module.getCallsites(uuid, cpu, "1", 42));
    assertEquals(Collections.emptyList(), module.getCallsites(uuid, cpu, "0", 12));
    assertEquals(Collections.emptyList(), module.getCallsites(uuid, cpu, "..", 42));
}
Also used : TmfXmlKernelTraceStub(org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.TmfXmlKernelTraceStub) CallsiteAnalysis(org.eclipse.tracecompass.internal.tmf.core.analysis.callsite.CallsiteAnalysis) Test(org.junit.Test)

Example 3 with CallsiteAnalysis

use of org.eclipse.tracecompass.internal.tmf.core.analysis.callsite.CallsiteAnalysis in project tracecompass by tracecompass.

the class CallsiteTest method testIterator.

/**
 * Test callsite iterator
 */
@Test
public void testIterator() {
    TmfXmlKernelTraceStub trace = fTrace;
    assertNotNull(trace);
    CallsiteAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, CallsiteAnalysis.class, CallsiteAnalysis.ID);
    assertNotNull(module);
    assertTrue(module.schedule().isOK());
    assertTrue(module.waitForCompletion());
    UUID uuid = trace.getUUID();
    assertNotNull(uuid);
    String cpu = "cpu";
    ITmfCallsiteIterator iter = module.iterator(uuid.toString(), cpu, "0", 1);
    evaluateNextIterator(iter, 40, new TmfCallsite("fs/open.c", 0L));
    evaluateNextIterator(iter, 71, new TmfCallsite("fs/read_write.c", 0L));
    evaluateEmptyNextIterator(iter);
    evaluateEmptyNextIterator(iter);
    iter = module.iterator(uuid.toString(), cpu, "0", 40);
    evaluateNextIterator(iter, 40, new TmfCallsite("fs/open.c", 0L));
    iter = module.iterator(uuid.toString(), cpu, "0", 71);
    evaluateNextIterator(iter, 71, new TmfCallsite("fs/read_write.c", 0L));
    iter = module.iterator(uuid.toString(), cpu, "0", 72);
    evaluateEmptyNextIterator(iter);
    iter = module.iterator(uuid.toString(), cpu, "0", 99);
    evaluatePrevIterator(iter, 71, new TmfCallsite("fs/read_write.c", 0L));
    evaluatePrevIterator(iter, 40, new TmfCallsite("fs/open.c", 0L));
    evaluateEmptyPrevIterator(iter);
    evaluateEmptyPrevIterator(iter);
    iter = module.iterator(uuid.toString(), cpu, "0", 71);
    evaluatePrevIterator(iter, 71, new TmfCallsite("fs/read_write.c", 0L));
    iter = module.iterator(uuid.toString(), cpu, "0", 40);
    evaluatePrevIterator(iter, 40, new TmfCallsite("fs/open.c", 0L));
    iter = module.iterator(uuid.toString(), cpu, "0", 39);
    evaluateEmptyPrevIterator(iter);
    iter = module.iterator(uuid.toString(), cpu, "0", 42);
    for (int i = 0; i < 10; i++) {
        evaluateNextIterator(iter, 71, new TmfCallsite("fs/read_write.c", 0L));
        evaluateEmptyNextIterator(iter);
        evaluatePrevIterator(iter, 40, new TmfCallsite("fs/open.c", 0L));
        evaluateEmptyPrevIterator(iter);
    }
    iter = module.iterator(uuid.toString(), cpu, "0", 42);
    for (int i = 0; i < 10; i++) {
        evaluatePrevIterator(iter, 40, new TmfCallsite("fs/open.c", 0L));
        evaluateEmptyPrevIterator(iter);
        evaluateNextIterator(iter, 71, new TmfCallsite("fs/read_write.c", 0L));
        evaluateEmptyNextIterator(iter);
    }
    iter = module.iterator("", cpu, "0", 42);
    evaluateEmptyNextIterator(iter);
    evaluateEmptyPrevIterator(iter);
    iter = module.iterator(uuid.toString(), cpu, "elephant", 42);
    evaluateEmptyNextIterator(iter);
    evaluateEmptyPrevIterator(iter);
}
Also used : ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) TmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite) TmfXmlKernelTraceStub(org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.TmfXmlKernelTraceStub) CallsiteAnalysis(org.eclipse.tracecompass.internal.tmf.core.analysis.callsite.CallsiteAnalysis) UUID(java.util.UUID) ITmfCallsiteIterator(org.eclipse.tracecompass.tmf.core.analysis.callsite.ITmfCallsiteIterator) Test(org.junit.Test)

Aggregations

CallsiteAnalysis (org.eclipse.tracecompass.internal.tmf.core.analysis.callsite.CallsiteAnalysis)3 TmfXmlKernelTraceStub (org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.TmfXmlKernelTraceStub)2 ITmfCallsite (org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 CallStackAnalysis (org.eclipse.tracecompass.analysis.profiling.core.callstack.CallStackAnalysis)1 IAnnotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IAnnotation)1 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)1 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)1 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)1 ITmfCallsiteIterator (org.eclipse.tracecompass.tmf.core.analysis.callsite.ITmfCallsiteIterator)1 TmfCallsite (org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite)1 ITimeGraphArrow (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow)1 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)1 ISymbolProvider (org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider)1 TmfResolvedSymbol (org.eclipse.tracecompass.tmf.core.symbols.TmfResolvedSymbol)1 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)1