Search in sources :

Example 1 with TmfCpuAspect

use of org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect in project tracecompass by tracecompass.

the class XmlStubTraceTest method testAspects.

/**
 * Test the presence and resolve of the aspects for this trace
 */
@Test
public void testAspects() {
    fTestTrace = TmfXmlTraceStubNs.setupTrace(TmfCoreTestPlugin.getAbsoluteFilePath(VALID_FILE));
    ITmfEventAspect<?> cpuAspect = null;
    ITmfEventAspect<?> testAspect = null;
    int aspectCount = 0;
    for (ITmfEventAspect<?> aspect : fTestTrace.getEventAspects()) {
        aspectCount++;
        if (aspect instanceof TmfCpuAspect) {
            cpuAspect = aspect;
        } else if (aspect.getName().equals("test")) {
            testAspect = aspect;
        }
    }
    /* Check the presence of the cpu and test aspects */
    assertEquals("Number of aspects", 5, aspectCount);
    assertNotNull(cpuAspect);
    assertNotNull(testAspect);
    ITmfContext ctx;
    ctx = fTestTrace.seekEvent(0L);
    assertNotNull(ctx);
    ITmfEvent event = fTestTrace.getNext(ctx);
    assertNotNull(event);
    assertEquals("Cpu aspect of event 1", 1, cpuAspect.resolve(event));
    assertEquals("Test aspect of event 1", "abc", testAspect.resolve(event));
    event = fTestTrace.getNext(ctx);
    assertNotNull(event);
    assertEquals("Cpu aspect of event 2", 1, cpuAspect.resolve(event));
    assertEquals("Test aspect of event 2", "abc", testAspect.resolve(event));
    event = fTestTrace.getNext(ctx);
    assertNotNull(event);
    assertEquals("Cpu aspect of event 3", 2, cpuAspect.resolve(event));
    assertEquals("Test aspect of event 3", "def", testAspect.resolve(event));
    event = fTestTrace.getNext(ctx);
    assertNotNull(event);
    assertEquals("Cpu aspect of event 4", 1, cpuAspect.resolve(event));
    assertEquals("Test aspect of event 4", "def", testAspect.resolve(event));
    ctx.dispose();
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) TmfCpuAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Example 2 with TmfCpuAspect

use of org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect in project tracecompass by tracecompass.

the class ResourcesStatusDataProvider method putCpuTooltip.

private void putCpuTooltip(ITmfStateSystem ss, String attributeName, Map<String, String> retMap, List<ITmfStateInterval> full, int status) {
    int currentThreadQuark = ss.optQuarkAbsolute(Attributes.CPUS, attributeName, Attributes.CURRENT_THREAD);
    if (currentThreadQuark == ITmfStateSystem.INVALID_ATTRIBUTE) {
        return;
    }
    Object currentThreadObject = full.get(currentThreadQuark).getValue();
    if (currentThreadObject instanceof Number) {
        String currentThread = currentThreadObject.toString();
        retMap.put(Messages.ResourcesStatusDataProvider_attributeTidName, currentThread);
        int execNameQuark = ss.optQuarkAbsolute(Attributes.THREADS, currentThread, Attributes.EXEC_NAME);
        if (execNameQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
            Object processName = full.get(execNameQuark).getValue();
            if (processName instanceof String) {
                retMap.put(Messages.ResourcesStatusDataProvider_attributeProcessName, (String) processName);
            }
        }
        int syscallQuark = ss.optQuarkAbsolute(Attributes.THREADS, currentThread, Attributes.SYSTEM_CALL);
        if (status == StateValues.CPU_STATUS_RUN_SYSCALL && syscallQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
            ITmfStateInterval interval = full.get(syscallQuark);
            Object syscall = interval.getValue();
            if (syscall instanceof String) {
                retMap.put(Attributes.SYSTEM_CALL, (String) syscall);
                ITmfTrace trace = getTrace();
                ITmfCallsiteResolver csAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, CallsiteAnalysis.class, CallsiteAnalysis.ID);
                if (csAnalysis != null) {
                    for (ITmfEventAspect<?> aspect : trace.getEventAspects()) {
                        if (aspect instanceof TmfCpuAspect) {
                            TmfDeviceAspect deviceAspect = (TmfCpuAspect) aspect;
                            List<@NonNull ITmfCallsite> callsites = csAnalysis.getCallsites(String.valueOf(trace.getUUID()), deviceAspect.getDeviceType(), attributeName, interval.getStartTime() / 2L + interval.getEndTime() / 2L);
                            if (!callsites.isEmpty()) {
                                retMap.put(TmfStrings.source(), callsites.get(0).toString());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) TmfCpuAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfCallsiteResolver(org.eclipse.tracecompass.tmf.core.analysis.callsite.ITmfCallsiteResolver) TmfDeviceAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfDeviceAspect)

Example 3 with TmfCpuAspect

use of org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect in project tracecompass by tracecompass.

the class ThreadStatusDataProvider method fetchTooltip.

@Override
@NonNull
public TmfModelResponse<@NonNull Map<@NonNull String, @NonNull String>> fetchTooltip(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    ITmfStateSystem ss = fModule.getStateSystem();
    if (ss == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    boolean completed = ss.waitUntilBuilt(0);
    ITmfResponse.Status status = completed ? ITmfResponse.Status.COMPLETED : ITmfResponse.Status.RUNNING;
    String statusMessage = completed ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING;
    // TODO server: Parameters validation should be handle separately. It
    // can be either in the data provider itself or before calling it. It
    // will avoid the creation of filters and the content of the map can be
    // use directly.
    List<@NonNull Long> selected = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
    List<@NonNull Long> times = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    if (times == null || times.isEmpty() || selected == null || selected.isEmpty()) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    Integer quark = fQuarkMap.get(selected.get(0));
    if (quark == null) {
        return new TmfModelResponse<>(null, status, statusMessage);
    }
    long start = times.get(0);
    try {
        int currentCpuRqQuark = ss.optQuarkRelative(quark, Attributes.CURRENT_CPU_RQ);
        if (currentCpuRqQuark == ITmfStateSystem.INVALID_ATTRIBUTE || start < ss.getStartTime() || start > ss.getCurrentEndTime()) {
            return new TmfModelResponse<>(null, status, statusMessage);
        }
        ITmfStateInterval mainInterval = null;
        ITmfStateInterval currentCpuInterval = null;
        for (ITmfStateInterval interval : ss.query2D(ImmutableList.of(quark, currentCpuRqQuark), Collections.singleton(start))) {
            if (interval.getAttribute() == quark) {
                mainInterval = interval;
                continue;
            }
            currentCpuInterval = interval;
        }
        if (mainInterval == null || currentCpuInterval == null) {
            return new TmfModelResponse<>(null, status, statusMessage);
        }
        ITmfCallsiteResolver csAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(getTrace(), CallsiteAnalysis.class, CallsiteAnalysis.ID);
        Object value = currentCpuInterval.getValue();
        if (value instanceof Integer) {
            String cpuId = String.valueOf(value);
            Map<String, String> returnValue = new LinkedHashMap<>();
            returnValue.put(TmfStrings.cpu(), cpuId);
            if (csAnalysis != null) {
                Object cpuThreadObj = mainInterval.getValue();
                if (cpuThreadObj instanceof Integer && Objects.equals(ProcessStatus.RUN_SYTEMCALL.getStateValue().unboxInt(), cpuThreadObj)) {
                    ITmfTrace trace = getTrace();
                    for (ITmfEventAspect<?> aspect : trace.getEventAspects()) {
                        if (aspect instanceof TmfCpuAspect) {
                            TmfCpuAspect deviceAspect = (TmfCpuAspect) aspect;
                            List<@NonNull ITmfCallsite> callsites = csAnalysis.getCallsites(String.valueOf(trace.getUUID()), deviceAspect.getDeviceType(), cpuId, start);
                            if (!callsites.isEmpty()) {
                                returnValue.put(TmfStrings.source(), callsites.get(0).toString());
                            }
                        }
                    }
                }
            }
            return new TmfModelResponse<>(returnValue, status, statusMessage);
        }
    } catch (StateSystemDisposedException e) {
    /* Ignored */
    }
    return new TmfModelResponse<>(null, status, statusMessage);
}
Also used : ITmfResponse(org.eclipse.tracecompass.tmf.core.response.ITmfResponse) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfCallsiteResolver(org.eclipse.tracecompass.tmf.core.analysis.callsite.ITmfCallsiteResolver) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) LinkedHashMap(java.util.LinkedHashMap) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) TmfCpuAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect) AtomicLong(java.util.concurrent.atomic.AtomicLong) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 4 with TmfCpuAspect

use of org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect in project tracecompass by tracecompass.

the class TmfXmlTraceStub method generateAspects.

private void generateAspects(ITmfEventField[] fieldsArray) {
    ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
    /* Initialize the first default trace aspects */
    builder.add(TmfBaseAspects.getTimestampAspect());
    builder.add(TmfBaseAspects.getEventTypeAspect());
    /* Add custom aspects in between */
    for (ITmfEventField field : fieldsArray) {
        String name = field.getName();
        final ITmfEventAspect<?> aspect = new TmfContentFieldAspect(name, name);
        if (name.equals(ASPECT_CPU)) {
            builder.add(new TmfCpuAspect() {

                @Override
                @Nullable
                public Integer resolve(ITmfEvent event) {
                    Object result = aspect.resolve(event);
                    if (result instanceof Number) {
                        return ((Number) result).intValue();
                    }
                    return null;
                }
            });
        } else {
            builder.add(aspect);
        }
    }
    /* Add the big content aspect */
    builder.add(TmfBaseAspects.getContentsAspect());
    /* Add the additional aspects */
    builder.addAll(fAdditionalAspects);
    fAspects = builder.build();
}
Also used : ITmfEventAspect(org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect) ImmutableList(com.google.common.collect.ImmutableList) TmfContentFieldAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfCpuAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

TmfCpuAspect (org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect)4 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)2 ITmfCallsiteResolver (org.eclipse.tracecompass.tmf.core.analysis.callsite.ITmfCallsiteResolver)2 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)2 ITmfCallsite (org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite)2 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMap (java.util.LinkedHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)1 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)1 ITmfEventField (org.eclipse.tracecompass.tmf.core.event.ITmfEventField)1 ITmfEventAspect (org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect)1 TmfContentFieldAspect (org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect)1 TmfDeviceAspect (org.eclipse.tracecompass.tmf.core.event.aspect.TmfDeviceAspect)1 ITmfResponse (org.eclipse.tracecompass.tmf.core.response.ITmfResponse)1 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)1 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)1