Search in sources :

Example 51 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent 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 52 with ITmfEvent

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

the class TmfXmlTraceStub method getNext.

@Override
@Nullable
public synchronized ITmfEvent getNext(@Nullable ITmfContext context) {
    if (context == null) {
        return null;
    }
    final ITmfContext savedContext = new TmfContext(context.getLocation(), context.getRank());
    CustomXmlEvent event = fTrace.getNext(context);
    if (event == null) {
        return null;
    }
    /* Translate the content of the event */
    /* The "fields" field contains a | separated list of field names */
    /* The "values" field contains a | separated list of field values */
    /* the "type" field contains a | separated list of field types */
    ITmfEventField content = event.getContent();
    if (content == null) {
        return null;
    }
    String fieldString = getStringValue(content, FIELD_NAMES_FIELD);
    String valueString = getStringValue(content, VALUES_FIELD);
    String typeString = getStringValue(content, TYPES_FIELD);
    String[] fields = fieldString.split(VALUES_SEPARATOR);
    String[] values = valueString.split(VALUES_SEPARATOR);
    String[] types = typeString.split(VALUES_SEPARATOR);
    ITmfEventField[] fieldsArray = new TmfEventField[fields.length];
    for (int i = 0; i < fields.length; i++) {
        String value = EMPTY;
        if (values.length > i) {
            value = values[i];
        }
        String type = null;
        if (types.length > i) {
            type = types[i];
        }
        Object val = value;
        if (type != null) {
            switch(type) {
                case TYPE_INTEGER:
                    {
                        try {
                            val = Integer.valueOf(value);
                        } catch (NumberFormatException e) {
                            // $NON-NLS-1$
                            Activator.logError(String.format("Get next XML event: cannot cast value %s to integer", value), e);
                            val = 0;
                        }
                        break;
                    }
                case TYPE_LONG:
                    {
                        try {
                            val = Long.valueOf(value);
                        } catch (NumberFormatException e) {
                            // $NON-NLS-1$
                            Activator.logError(String.format("Get next XML event: cannot cast value %s to long", value), e);
                            val = 0L;
                        }
                        break;
                    }
                case TYPE_LONG_ARRAY:
                    {
                        try {
                            String[] split = value.split(",");
                            long[] arr = new long[split.length];
                            for (int j = 0; j < split.length; j++) {
                                arr[j] = Long.valueOf(split[j]);
                            }
                            val = arr;
                        } catch (NumberFormatException e) {
                            // $NON-NLS-1$
                            Activator.logError(String.format("Get next XML event: cannot cast one of the comma-separated values of %s to long", value), e);
                            val = new long[0];
                        }
                        break;
                    }
                case TYPE_INT_ARRAY:
                    {
                        try {
                            String[] split = value.split(",");
                            int[] arr = new int[split.length];
                            for (int j = 0; j < split.length; j++) {
                                arr[j] = Integer.valueOf(split[j]);
                            }
                            val = arr;
                        } catch (NumberFormatException e) {
                            // $NON-NLS-1$
                            Activator.logError(String.format("Get next XML event: cannot cast one of the comma-separated values of %s to int", value), e);
                            val = new int[0];
                        }
                        break;
                    }
                default:
                    break;
            }
        }
        fieldsArray[i] = new TmfEventField(checkNotNull(fields[i]), val, null);
    }
    /*
         * Generate the aspects for this trace if it is the 'set_aspects'
         * definition
         */
    if (fTrace.getDefinition() != fDefinition) {
        generateAspects(fieldsArray);
        return null;
    }
    /* Create a new event with new fields and name */
    ITmfEventType customEventType = event.getType();
    String eventName = getStringValue(content, EVENT_NAME_FIELD);
    TmfEventType eventType = new TmfEventType(eventName, customEventType.getRootField());
    ITmfEventField eventFields = new CustomEventContent(content.getName(), content.getValue(), fieldsArray);
    /*
         * TODO: Timestamps for these traces are in nanos, but since the
         * CustomXmlTrace does not support this format, the timestamp of the
         * original is in second and we need to convert it. We should do that at
         * the source when it is supported
         */
    TmfEvent newEvent = new TmfEvent(this, ITmfContext.UNKNOWN_RANK, event.getTimestamp(), eventType, eventFields);
    updateAttributes(savedContext, event);
    return newEvent;
}
Also used : CustomXmlEvent(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent) TmfContext(org.eclipse.tracecompass.tmf.core.trace.TmfContext) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEventType(org.eclipse.tracecompass.tmf.core.event.ITmfEventType) CustomEventContent(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEventContent) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfEventField(org.eclipse.tracecompass.tmf.core.event.TmfEventField) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) TmfEventType(org.eclipse.tracecompass.tmf.core.event.TmfEventType) ITmfEventType(org.eclipse.tracecompass.tmf.core.event.ITmfEventType) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 53 with ITmfEvent

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

the class TmfEventTableDataProvider method fetchIndex.

/**
 * Find the index in the table of an event using the rank in the trace or
 * the timestamp value. It will take any filter into consideration.
 *
 * @param fetchParameters
 *            Map of parameters that contain the filter applied to the
 *            table, if any. Everything else is ignored.
 * @param traceRank
 *            Rank of the event in the trace
 * @param timeBegin
 *            Timestamp of the event
 * @param monitor
 *            Progress monitor
 * @return Index in the table
 */
public TmfModelResponse<List<Long>> fetchIndex(Map<String, Object> fetchParameters, long traceRank, long timeBegin, @Nullable IProgressMonitor monitor) {
    @Nullable ITmfFilter filter = extractFilter(fetchParameters);
    long rank;
    if (traceRank == -1) {
        ITmfContext context = getTrace().seekEvent(TmfTimestamp.fromNanos(timeBegin));
        rank = context.getRank();
    } else {
        rank = traceRank;
    }
    if (filter == null) {
        return new TmfModelResponse<>(Collections.singletonList(rank), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    applyFilter(filter);
    Entry<Long, Long> nearestEntry = fRankToIndexMap.floorEntry(rank);
    long startingIndex = nearestEntry != null ? nearestEntry.getValue() : 0L;
    long startingRank = nearestEntry != null ? nearestEntry.getKey() : 0L;
    List<Long> foundIndex = new ArrayList<>();
    TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, startingRank, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND) {

        private long currentIndex = startingIndex;

        private long fRank = startingRank;

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            if (monitor != null && monitor.isCanceled()) {
                cancel();
                return;
            }
            if (fRank >= rank) {
                foundIndex.add(currentIndex);
                done();
                return;
            }
            if (filter.matches(event)) {
                currentIndex++;
            }
            fRank++;
        }
    };
    getTrace().sendRequest(request);
    try {
        request.waitForCompletion();
    } catch (InterruptedException e) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, NonNullUtils.nullToEmptyString(e.getMessage()));
    }
    return new TmfModelResponse<>(foundIndex, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 54 with ITmfEvent

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

the class AbstractTmfStateProvider method processEvent.

@Override
public void processEvent(ITmfEvent event) {
    /* Make sure the target state system has been assigned */
    if (!fStateSystemAssigned) {
        // $NON-NLS-1$
        throw new IllegalStateException("Cannot process event without a target state system. ID: " + getClass().getSimpleName());
    }
    fPropagateExceptions.run();
    /* Insert the event we're received into the events queue */
    ITmfEvent curEvent = event;
    fEventsQueue.put(curEvent);
}
Also used : ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent)

Example 55 with ITmfEvent

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

the class ITmfTrace method readStart.

/**
 * Read the start time of the trace quickly, without requiring it to be
 * indexed.
 *
 * @return the trace's start time. Null if the trace is empty or failed.
 * @since 3.0
 */
default ITmfTimestamp readStart() {
    ITmfContext context = seekEvent(0L);
    ITmfEvent event = getNext(context);
    context.dispose();
    return (event != null) ? event.getTimestamp() : null;
}
Also used : ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent)

Aggregations

ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)182 Test (org.junit.Test)127 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)112 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)40 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)30 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)27 ITmfLocation (org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)25 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)24 NonNull (org.eclipse.jdt.annotation.NonNull)20 TmfEvent (org.eclipse.tracecompass.tmf.core.event.TmfEvent)17 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)16 Vector (java.util.Vector)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 Predicate (java.util.function.Predicate)14 TmfTraceUtils (org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 CtfTestTrace (org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace)13 CtfTmfTestTraceUtils (org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils)13 Assert.assertEquals (org.junit.Assert.assertEquals)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)13