Search in sources :

Example 96 with ITmfEvent

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

the class CustomTxtTrace method readEnd.

/**
 * @since 3.0
 */
@Override
public synchronized ITmfTimestamp readEnd() {
    try {
        Long pos = fFile.length() - 1;
        /* Outer loop to find the first line of a matcher group. */
        while (pos > 0) {
            /* Inner loop to find line beginning */
            while (pos > 0) {
                fFile.seek(pos - 1);
                if (fFile.read() == '\n') {
                    break;
                }
                pos--;
            }
            ITmfLocation location = new TmfLongLocation(pos);
            ITmfContext context = seekEvent(location);
            ITmfEvent event = parseEvent(context);
            context.dispose();
            if (event != null) {
                /* The last event in the trace was successfully parsed. */
                return event.getTimestamp();
            }
            /* pos was after the beginning of the lines of the last event. */
            pos--;
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        Activator.logError("Error seeking last event. File: " + getPath(), e);
    }
    /* Empty trace */
    return null;
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) IOException(java.io.IOException) ITmfLocation(org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)

Example 97 with ITmfEvent

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

the class CustomXmlTrace method readEnd.

/**
 * @since 3.0
 */
@Override
public synchronized ITmfTimestamp readEnd() {
    // $NON-NLS-1$
    byte[] inputNameBytes = ("<" + fRecordInputElement.getElementName()).getBytes();
    byte[] testBytes = new byte[inputNameBytes.length];
    try {
        Long pos = fFile.length() - inputNameBytes.length;
        /* Outer loop to find the position of a matcher group. */
        while (pos >= 0) {
            /* Inner loop to find matching tag */
            while (pos >= 0) {
                fFile.seek(pos);
                /* Make sure we have the right tag. */
                fFile.read(testBytes, 0, testBytes.length);
                if (Arrays.equals(inputNameBytes, testBytes)) {
                    break;
                }
                pos--;
            }
            ITmfLocation location = new TmfLongLocation(pos);
            ITmfContext context = seekEvent(location);
            ITmfEvent event = parseEvent(context);
            context.dispose();
            if (event != null) {
                /* The last event in the trace was successfully parsed. */
                return event.getTimestamp();
            }
            /*
                 * pos was after the beginning of the tag of the last event.
                 */
            pos -= inputNameBytes.length;
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        Activator.logError("Error seeking last event. File: " + getPath(), e);
    }
    /* Empty trace */
    return null;
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) IOException(java.io.IOException) ITmfLocation(org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)

Example 98 with ITmfEvent

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

the class TmfTraceElement method instantiateEvent.

/**
 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
 * the corresponding extension.
 *
 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
 */
public ITmfEvent instantiateEvent() {
    try {
        String traceTypeId = getTraceType();
        if (traceTypeId != null) {
            if (CustomTxtTrace.isCustomTraceTypeId(traceTypeId)) {
                for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
                    String id = CustomTxtTrace.buildTraceTypeId(def.categoryName, def.definitionName);
                    if (traceTypeId.equals(id)) {
                        return new CustomTxtEvent(def);
                    }
                }
            }
            if (CustomXmlTrace.isCustomTraceTypeId(traceTypeId)) {
                for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
                    String id = CustomXmlTrace.buildTraceTypeId(def.categoryName, def.definitionName);
                    if (traceTypeId.equals(id)) {
                        return new CustomXmlEvent(def);
                    }
                }
            }
            IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(traceTypeId);
            if (ce == null) {
                return null;
            }
            ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
            return event;
        }
    } catch (CoreException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e);
    }
    return null;
}
Also used : CustomTxtEvent(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent) CustomXmlEvent(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent) CustomXmlTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition) CoreException(org.eclipse.core.runtime.CoreException) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) CustomTxtTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 99 with ITmfEvent

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

the class TmfEventProviderTest method testCancelRequests.

/**
 * Test canceling requests.
 */
@Test
public void testCancelRequests() {
    final int NB_EVENTS = 1000;
    final int NUMBER_EVENTS_BEFORE_CANCEL_REQ1 = 10;
    final int NUMBER_EVENTS_BEFORE_CANCEL_REQ2 = 800;
    final Vector<ITmfEvent> requestedEventsReq1 = new Vector<>();
    final Vector<ITmfEvent> requestedEventsReq2 = new Vector<>();
    // Get the TmfSyntheticEventStub provider
    ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
    ITmfEventProvider provider = eventProviders[0];
    TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
    // Create first request
    final TmfEventRequest request1 = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEventsReq1.add(event);
            // cancel sub request
            if (getNbRead() == NUMBER_EVENTS_BEFORE_CANCEL_REQ1) {
                cancel();
            }
        }
    };
    // Synchronize requests
    ((TmfEventProviderStub) provider).startSynch(new TmfStartSynchSignal(0));
    // Additionally, notify provider for up-coming requests
    provider.notifyPendingRequest(true);
    // Call sendRequest, which will create a coalescing request, but it
    // doesn't send request1 yet
    provider.sendRequest(request1);
    // Check if request1 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    // Create second request
    final TmfEventRequest request2 = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEventsReq2.add(event);
            // cancel sub request which will cancel also main request
            if (getNbRead() == NUMBER_EVENTS_BEFORE_CANCEL_REQ2) {
                cancel();
            }
        }
    };
    // Call sendRequest, which will create a coalescing request, but it
    // doesn't send request2 yet
    provider.sendRequest(request2);
    // Check if request1/2 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    assertFalse("isRunning", request2.isRunning());
    // Send end synch signal, however requests won't be sent
    ((TmfEventProviderStub) provider).endSynch(new TmfEndSynchSignal(0));
    // Check if request1/2 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    assertFalse("isRunning", request2.isRunning());
    // Finally, trigger sending of requests
    provider.notifyPendingRequest(false);
    try {
        // Wait until requests start
        request1.waitForStart();
        request2.waitForStart();
        // // Verify that the requests are running
        // assertTrue("isRunning", request1.isRunning());
        // assertTrue("isRunning", request2.isRunning());
        request1.waitForCompletion();
        // // Check if request2 is still running
        // assertTrue("isRunning",  request2.isRunning());
        // Verify result (request1)
        assertEquals("nbEvents", NUMBER_EVENTS_BEFORE_CANCEL_REQ1, requestedEventsReq1.size());
        assertTrue("isCompleted", request1.isCompleted());
        assertTrue("isCancelled", request1.isCancelled());
        request2.waitForCompletion();
        // Verify result (request2)
        assertEquals("nbEvents", NUMBER_EVENTS_BEFORE_CANCEL_REQ2, requestedEventsReq2.size());
        assertTrue("isCompleted", request2.isCompleted());
        assertTrue("isCancelled", request2.isCancelled());
    } catch (InterruptedException e) {
        fail();
    }
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) TmfEventProviderStub(org.eclipse.tracecompass.tmf.tests.stubs.component.TmfEventProviderStub) TmfStartSynchSignal(org.eclipse.tracecompass.tmf.core.signal.TmfStartSynchSignal) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) Vector(java.util.Vector) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) TmfEndSynchSignal(org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal) Test(org.junit.Test)

Example 100 with ITmfEvent

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

the class TmfEventProviderTest method testGetPlainEvents.

// ------------------------------------------------------------------------
// getSyntheticEvent
// ------------------------------------------------------------------------
/**
 * Test getPlainEvents
 */
@Test
public void testGetPlainEvents() {
    final int NB_EVENTS = 1000;
    final Vector<ITmfEvent> requestedEvents = new Vector<>();
    // Get the TmfSyntheticEventStub provider
    ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
    ITmfEventProvider provider = eventProviders[0];
    TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
    final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEvents.add(event);
        }
    };
    provider.sendRequest(request);
    try {
        request.waitForCompletion();
        assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
        assertTrue("isCompleted", request.isCompleted());
        assertFalse("isCancelled", request.isCancelled());
        // Don't go overboard: we are not validating the stub!
        for (int i = 0; i < NB_EVENTS; i++) {
            assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue());
        }
    } catch (InterruptedException e) {
        fail();
    }
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) Vector(java.util.Vector) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Test(org.junit.Test)

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