tmf: Introduce dependency level for event requests
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Mon, 18 Apr 2016 10:58:43 +0000 (06:58 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 4 May 2016 10:37:40 +0000 (06:37 -0400)
Requests with the same dependency level that are compatible otherwise
can be serviced by the event provider together. In TMF, the
TmfEventProvider will coalesce these requests together to a coalesced
event request so the trace is read once and the events are dispatched
to each sub-request.

If these request are not on the same dependency level, then each
request will be serviced separately by the event provider.

This can be useful, when a request has to wait for a condition to
happen in another event request. It can block its request till that
condition is met. If both request were coalesced the coalesced request
will deadlock by one request.

Side effects of this patch:
- Traces (TmfTrace) will be read concurrently when using different
dependency levels. The event request scheduler of the TmfEventProvider
will take care of scheduling each request.
- In an experiment, requests may not be serviced by the same
TmfEventProvider, some may be serviced by the TmfExperiment, some
by the children traces (TmfTrace).

Change-Id: I2b2e143bc8dc9cd8d1707b033715cbb05a529401
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/70864
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/component/TmfEventProviderCoalescingTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/request/TmfCoalescedEventRequestTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/request/TmfEventRequestTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/request/TmfEventRequestStub.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/request/TmfCoalescedEventRequest.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/component/TmfEventProvider.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/request/ITmfEventRequest.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/request/TmfEventRequest.java

index cdc26ac1d105dd167abd6d8144c41879c0772af0..58ef6d6fabdc48a5f8223ec2316f3b06d764e3e2 100644 (file)
@@ -28,6 +28,7 @@ import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
 import org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfStartSynchSignal;
 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub;
 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
@@ -41,6 +42,9 @@ import org.junit.Test;
  */
 public class TmfEventProviderCoalescingTest {
 
+    private static final int TRACE1_NB_EVENT = 10000;
+    private static final int TRACE2_NB_EVENT = 702;
+    private static final int TRACE3_NB_EVENT = 10000;
     private static TmfTraceStub fTmfTrace1;
     private static TmfTraceStub fTmfTrace2;
     private static TmfTraceStub fTmfTrace3;
@@ -374,6 +378,257 @@ public class TmfEventProviderCoalescingTest {
         assertFalse(trace2Req.isTraceHandled(fTmfTrace3));
     }
 
+    /**
+     * Verify coalescing for a trace with different dependency level. Requests
+     * on the same dependency level are coalesced together.
+     *
+     * @throws Exception
+     *             if an error occurred
+     */
+    @Test
+    public void testTraceDependencyBackground() throws Exception {
+        InnerEventRequest traceReqLevel0 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND);
+        InnerEventRequest traceReq2Level0 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND);
+        InnerEventRequest traceReqLevel1 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND, 1);
+        InnerEventRequest traceReq2Level1 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND, 1);
+        fTmfTrace1.sendRequest(traceReqLevel0);
+        fTmfTrace1.sendRequest(traceReq2Level0);
+        fTmfTrace1.sendRequest(traceReqLevel1);
+        fTmfTrace1.sendRequest(traceReq2Level1);
+
+        // Verify that requests are coalesced properly with the experiment
+        // request
+        List<TmfCoalescedEventRequest> pending = fTmfTrace1.getAllPendingRequests();
+        assertEquals(2, pending.size());
+
+        // Now trigger manually the sending of the request
+        fTmfTrace1.notifyPendingRequest(false);
+
+        /*
+         * traceReqLevel0 and trace1Req are coalesced together
+         */
+        String expectedIds = "[" + traceReqLevel0.getRequestId() + ", "
+                + traceReq2Level0.getRequestId() + "]";
+        TmfCoalescedEventRequest coalescedRequest = pending.get(0);
+        assertEquals(expectedIds, coalescedRequest.getSubRequestIds());
+
+        /*
+         * traceReqLevel1 and traceReq2Level1 are coalesced together
+         */
+        expectedIds = "[" + traceReqLevel1.getRequestId() + ", "
+                + traceReq2Level1.getRequestId() + "]";
+        coalescedRequest = pending.get(1);
+        assertEquals(expectedIds, coalescedRequest.getSubRequestIds());
+
+        traceReqLevel0.waitForCompletion();
+        traceReq2Level0.waitForCompletion();
+        traceReqLevel1.waitForCompletion();
+        traceReq2Level1.waitForCompletion();
+
+        assertEquals(TRACE1_NB_EVENT, traceReqLevel0.getNbRead());
+        assertEquals(TRACE1_NB_EVENT, traceReq2Level0.getNbRead());
+        assertEquals(TRACE1_NB_EVENT, traceReqLevel1.getNbRead());
+        assertEquals(TRACE1_NB_EVENT, traceReq2Level1.getNbRead());
+    }
+
+    /**
+     * Verify coalescing for a trace with different dependency level. Requests
+     * on the same dependency level are coalesced together.
+     *
+     * @throws Exception
+     *             if an error occurred
+     */
+    @Test
+    public void testTraceDependencyForeground() throws Exception {
+        InnerEventRequest traceReqLevel0 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND);
+        InnerEventRequest traceReq2Level0 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND);
+        InnerEventRequest traceReqLevel1 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND, 1);
+        InnerEventRequest traceReq2Level1 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND, 1);
+        sendSync(true);
+        fTmfTrace1.sendRequest(traceReqLevel0);
+        fTmfTrace1.sendRequest(traceReq2Level0);
+        fTmfTrace1.sendRequest(traceReqLevel1);
+        fTmfTrace1.sendRequest(traceReq2Level1);
+
+        // Verify that requests are coalesced properly with the experiment
+        // request
+        List<TmfCoalescedEventRequest> pending = fTmfTrace1.getAllPendingRequests();
+        assertEquals(2, pending.size());
+
+        sendSync(false);
+        /*
+         * traceReqLevel0 and trace1Req are coalesced together
+         */
+        String expectedIds = "[" + traceReqLevel0.getRequestId() + ", "
+                + traceReq2Level0.getRequestId() + "]";
+        TmfCoalescedEventRequest coalescedRequest = pending.get(0);
+        assertEquals(expectedIds, coalescedRequest.getSubRequestIds());
+
+        /*
+         * traceReqLevel1 and traceReq2Level1 are coalesced together
+         */
+        expectedIds = "[" + traceReqLevel1.getRequestId() + ", "
+                + traceReq2Level1.getRequestId() + "]";
+        coalescedRequest = pending.get(1);
+        assertEquals(expectedIds, coalescedRequest.getSubRequestIds());
+
+        traceReqLevel0.waitForCompletion();
+        traceReq2Level0.waitForCompletion();
+        traceReqLevel1.waitForCompletion();
+        traceReq2Level1.waitForCompletion();
+
+        assertEquals(TRACE1_NB_EVENT, traceReqLevel0.getNbRead());
+        assertEquals(TRACE1_NB_EVENT, traceReq2Level0.getNbRead());
+        assertEquals(TRACE1_NB_EVENT, traceReqLevel1.getNbRead());
+        assertEquals(TRACE1_NB_EVENT, traceReq2Level1.getNbRead());
+    }
+
+    /**
+     * Verify coalescing across providers where a parent request is sent first
+     * before the children requests. One child request has a dependency on the
+     * other child so that it is not coalesced with the other requests.
+     *
+     * @throws Exception if an error occurred
+     */
+    @Test
+    public void testParentDependencyBackground() throws Exception {
+        InnerEventRequest expReq = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND);
+        InnerEventRequest expReq2 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND, 1);
+        InnerEventRequest trace1Req = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND);
+        InnerEventRequest trace2Req = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND, 1);
+
+        fExperiment.sendRequest(expReq);
+        fTmfTrace1.sendRequest(trace1Req);
+        fExperiment.sendRequest(expReq2);
+        fTmfTrace2.sendRequest(trace2Req);
+
+        // Verify that requests are coalesced properly with the experiment request
+        List<TmfCoalescedEventRequest> pending = fExperiment.getAllPendingRequests();
+        assertEquals(2, pending.size());
+
+        assertEquals(0, fTmfTrace1.getAllPendingRequests().size());
+        assertEquals(0, fTmfTrace2.getAllPendingRequests().size());
+
+        // Now trigger manually the sending of the request
+        fExperiment.notifyPendingRequest(false);
+
+        /*
+         * expReq and trace1Req are coalesced together
+         */
+        String expectedIds = "[" + expReq.getRequestId() + ", "
+                + trace1Req.getRequestId() + "]";
+        TmfCoalescedEventRequest coalescedRequest = pending.get(0);
+        assertEquals(expectedIds, coalescedRequest.getSubRequestIds());
+
+        /*
+         * expReq2 and trace2Req are coalesced together
+         */
+        expectedIds = "[" + expReq2.getRequestId() + ", "
+                + trace2Req.getRequestId() + "]";
+        coalescedRequest = pending.get(1);
+        assertEquals(expectedIds, coalescedRequest.getSubRequestIds());
+
+        expReq.waitForCompletion();
+        expReq2.waitForCompletion();
+        trace1Req.waitForCompletion();
+        trace2Req.waitForCompletion();
+
+        assertTrue(expReq.isTraceHandled(fTmfTrace1));
+        assertTrue(expReq.isTraceHandled(fTmfTrace2));
+        assertTrue(expReq.isTraceHandled(fTmfTrace3));
+
+        assertTrue(trace1Req.isTraceHandled(fTmfTrace1));
+        assertFalse(trace1Req.isTraceHandled(fTmfTrace2));
+        assertFalse(trace1Req.isTraceHandled(fTmfTrace3));
+
+        assertTrue(expReq2.isTraceHandled(fTmfTrace1));
+        assertTrue(expReq2.isTraceHandled(fTmfTrace2));
+        assertTrue(expReq2.isTraceHandled(fTmfTrace3));
+
+        assertFalse(trace2Req.isTraceHandled(fTmfTrace1));
+        assertTrue(trace2Req.isTraceHandled(fTmfTrace2));
+        assertFalse(trace2Req.isTraceHandled(fTmfTrace3));
+
+        assertEquals(TRACE1_NB_EVENT + TRACE2_NB_EVENT + TRACE3_NB_EVENT, expReq.getNbRead());
+        assertEquals(TRACE1_NB_EVENT, trace1Req.getNbRead());
+        assertEquals(TRACE2_NB_EVENT, trace2Req.getNbRead());
+    }
+
+    /**
+     * Verify coalescing across providers where a child request is sent first
+     * before the children requests. One child request is deferred so that it is
+     * not coalesced at the top level parent.
+     *
+     * @throws Exception
+     *             if an error occurred
+     */
+    @Test
+    public void testChildFirstDependencyBackground() throws Exception {
+        InnerEventRequest expReq = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND);
+        InnerEventRequest expReq2 = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND, 1);
+        InnerEventRequest trace1Req = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND);
+        InnerEventRequest trace2Req = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND, 1);
+
+        fTmfTrace1.sendRequest(trace1Req);
+        fExperiment.sendRequest(expReq);
+        fTmfTrace2.sendRequest(trace2Req);
+        fExperiment.sendRequest(expReq2);
+
+        // Verify that requests are coalesced properly with the experiment
+        // request
+        List<TmfCoalescedEventRequest> pending = fExperiment.getAllPendingRequests();
+        assertEquals(2, pending.size());
+
+        assertEquals(0, fTmfTrace1.getAllPendingRequests().size());
+        assertEquals(0, fTmfTrace2.getAllPendingRequests().size());
+
+        // Now trigger manually the sending of the request
+        fExperiment.notifyPendingRequest(false);
+        fTmfTrace1.notifyPendingRequest(false);
+        fTmfTrace2.notifyPendingRequest(false);
+
+        /*
+         * expReq and trace1Req are coalesced together
+         */
+        String expectedIds = "[" + expReq.getRequestId() + ", "
+                + trace1Req.getRequestId() + "]";
+        TmfCoalescedEventRequest coalescedRequest = pending.get(0);
+        assertEquals(expectedIds, coalescedRequest.getSubRequestIds());
+
+        /*
+         * expReq2 and trace2Req are coalesced together
+         */
+        expectedIds = "[" + expReq2.getRequestId() + ", "
+                + trace2Req.getRequestId() + "]";
+        coalescedRequest = pending.get(1);
+        assertEquals(expectedIds, coalescedRequest.getSubRequestIds());
+
+        expReq.waitForCompletion();
+        expReq2.waitForCompletion();
+        trace1Req.waitForCompletion();
+        trace2Req.waitForCompletion();
+
+        assertTrue(expReq.isTraceHandled(fTmfTrace1));
+        assertTrue(expReq.isTraceHandled(fTmfTrace2));
+        assertTrue(expReq.isTraceHandled(fTmfTrace3));
+
+        assertTrue(trace1Req.isTraceHandled(fTmfTrace1));
+        assertFalse(trace1Req.isTraceHandled(fTmfTrace2));
+        assertFalse(trace1Req.isTraceHandled(fTmfTrace3));
+
+        assertTrue(expReq2.isTraceHandled(fTmfTrace1));
+        assertTrue(expReq2.isTraceHandled(fTmfTrace2));
+        assertTrue(expReq2.isTraceHandled(fTmfTrace3));
+
+        assertFalse(trace2Req.isTraceHandled(fTmfTrace1));
+        assertTrue(trace2Req.isTraceHandled(fTmfTrace2));
+        assertFalse(trace2Req.isTraceHandled(fTmfTrace3));
+
+        assertEquals(TRACE1_NB_EVENT + TRACE2_NB_EVENT + TRACE3_NB_EVENT, expReq.getNbRead());
+        assertEquals(TRACE1_NB_EVENT, trace1Req.getNbRead());
+        assertEquals(TRACE2_NB_EVENT, trace2Req.getNbRead());
+    }
+
     // ------------------------------------------------------------------------
     // Helper methods
     // ------------------------------------------------------------------------
@@ -419,6 +674,10 @@ public class TmfEventProviderCoalescingTest {
             super(dataType, index, nbRequested, priority);
         }
 
+        public InnerEventRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, ExecutionType priority, int dependency) {
+            super(dataType, TmfTimeRange.ETERNITY, index, nbRequested, priority, dependency);
+        }
+
         @Override
         public void handleData(ITmfEvent event) {
             super.handleData(event);
@@ -431,4 +690,5 @@ public class TmfEventProviderCoalescingTest {
             return traces.contains(trace.getName());
         }
     }
+
 }
index e9ad4cadd6514407e65909b8d01082984cf5c7e2..e2f8395c8b669afff017bcff09766db92403ed5e 100644 (file)
@@ -73,19 +73,19 @@ public class TmfCoalescedEventRequestTest {
 
     @Before
     public void setUp() {
-        fRequest1 = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND);
-        fRequest2 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 100, ExecutionType.FOREGROUND);
-        fRequest3 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 200, ExecutionType.FOREGROUND);
-        fRequest4 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 200, ExecutionType.FOREGROUND);
+        fRequest1 = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND, 0);
+        fRequest2 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 100, ExecutionType.FOREGROUND, 0);
+        fRequest3 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 200, ExecutionType.FOREGROUND, 0);
+        fRequest4 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 200, ExecutionType.FOREGROUND, 0);
 
-        fRequest1c = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND);
+        fRequest1c = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND, 0);
 
         fRequestCount = fRequest1c.getRequestId() + 1;
     }
 
     private TmfCoalescedEventRequest setupTestRequest(final boolean[] flags) {
 
-        TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND) {
+        TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND, 0) {
             @Override
             public void handleCompleted() {
                 super.handleCompleted();
@@ -119,7 +119,7 @@ public class TmfCoalescedEventRequestTest {
 
     @Test
     public void testTmfCoalescedEventRequestIndexNbEventsBlocksize() {
-        TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND);
+        TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND, 0);
 
         assertEquals("getRequestId", fRequestCount++, request.getRequestId());
         assertEquals("getDataType", ITmfEvent.class, request.getDataType());
@@ -173,7 +173,7 @@ public class TmfCoalescedEventRequestTest {
 
     @Test
     public void testIsCompatible() {
-        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND);
+        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND, 0);
         TmfEventRequest req1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200);
         TmfEventRequest req2 = new TmfEventRequestStub(ITmfEvent.class, range2, 100, 200);
         TmfEventRequest req3 = new TmfEventRequestStub(ITmfEvent.class, range1, 101, 200);
@@ -183,13 +183,31 @@ public class TmfCoalescedEventRequestTest {
         assertTrue("isCompatible", coalescedRequest.isCompatible(req3));
     }
 
+    @Test
+    public void testIsCompatibleDependency() {
+        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND, 1);
+        TmfEventRequest req1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200, ExecutionType.FOREGROUND, 0);
+        TmfEventRequest req2 = new TmfEventRequestStub(ITmfEvent.class, range2, 100, 2000, ExecutionType.FOREGROUND, 1);
+        TmfEventRequest req3 = new TmfEventRequestStub(ITmfEvent.class, range1, 101, 200, ExecutionType.FOREGROUND, 2);
+
+        assertFalse("isCompatible", coalescedRequest.isCompatible(req1));
+        assertTrue("isCompatible", coalescedRequest.isCompatible(req2));
+        assertFalse("isCompatible", coalescedRequest.isCompatible(req3));
+
+        coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, ExecutionType.FOREGROUND, 0);
+        assertTrue("isCompatible", coalescedRequest.isCompatible(req1));
+        assertFalse("isCompatible", coalescedRequest.isCompatible(req2));
+        assertFalse("isCompatible", coalescedRequest.isCompatible(req3));
+
+    }
+
     // ------------------------------------------------------------------------
     // addEvent
     // ------------------------------------------------------------------------
 
     @Test
     public void testAddEvent1() {
-        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 2147483647, ExecutionType.FOREGROUND);
+        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 2147483647, ExecutionType.FOREGROUND, 0);
         TmfEventRequest req1 = new TmfEventRequestStub(ITmfEvent.class, range1, 0, 2147483647, 200);
         TmfEventRequest req2 = new TmfEventRequestStub(ITmfEvent.class, range1, 1, 2147483647, 200);
 
@@ -205,7 +223,7 @@ public class TmfCoalescedEventRequestTest {
 
     @Test
     public void testAddEvent2() {
-        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 1, 2147483647, ExecutionType.FOREGROUND);
+        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 1, 2147483647, ExecutionType.FOREGROUND, 0);
         TmfEventRequest req1 = new TmfEventRequestStub(ITmfEvent.class, range1, 1, 2147483647, 200);
         TmfEventRequest req2 = new TmfEventRequestStub(ITmfEvent.class, range1, 0, 2147483647, 200);
 
index fbc536567c06147d7d6d69e02ba9244f5e12d2be..622dd35ca29a122fa478afea3ee2c95315306c24 100644 (file)
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue;
 
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType;
 import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
@@ -44,6 +45,7 @@ public class TmfEventRequestTest {
     private static TmfEventRequest fRequest2;
     private static TmfEventRequest fRequest3;
     private static TmfEventRequest fRequest4;
+    private static TmfEventRequest fRequest5;
 
     // ------------------------------------------------------------------------
     // Housekeeping
@@ -55,6 +57,7 @@ public class TmfEventRequestTest {
         fRequest2 = new TmfEventRequestStub(ITmfEvent.class, range2, 100, 200);
         fRequest3 = new TmfEventRequestStub(ITmfEvent.class, range2, 200, 200);
         fRequest4 = new TmfEventRequestStub(ITmfEvent.class, range2, 200, 300);
+        fRequest5 = new TmfEventRequestStub(ITmfEvent.class, range2, 200, 300, ExecutionType.FOREGROUND, 1);
     }
 
     private static TmfEventRequest setupTestRequest(final boolean[] flags) {
@@ -111,6 +114,7 @@ public class TmfEventRequestTest {
         assertFalse("isCancelled", request.isCancelled());
 
         assertEquals("getNbRead", 0, request.getNbRead());
+        assertEquals("getDependencyLevel", 0, request.getDependencyLevel());
     }
 
     @Test
@@ -131,6 +135,7 @@ public class TmfEventRequestTest {
         assertFalse("isCancelled", request.isCancelled());
 
         assertEquals("getNbRead", 0, request.getNbRead());
+        assertEquals("getDependencyLevel", 0, request.getDependencyLevel());
     }
 
     @Test
@@ -151,6 +156,7 @@ public class TmfEventRequestTest {
         assertFalse("isCancelled", request.isCancelled());
 
         assertEquals("getNbRead", 0, request.getNbRead());
+        assertEquals("getDependencyLevel", 0, request.getDependencyLevel());
     }
 
     @Test
@@ -171,6 +177,28 @@ public class TmfEventRequestTest {
         assertFalse("isCancelled", request.isCancelled());
 
         assertEquals("getNbRead", 0, request.getNbRead());
+        assertEquals("getDependencyLevel", 0, request.getDependencyLevel());
+    }
+
+    @Test
+    public void testTmfEventRequestWithDependencyLevel() {
+        TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromSeconds(0), TmfTimestamp.BIG_CRUNCH);
+        TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class, range, 100, 200, ExecutionType.FOREGROUND, 1);
+
+        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
+
+        assertEquals("StartTime", TmfTimestamp.fromSeconds(0), request.getRange().getStartTime());
+        assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime());
+
+        assertEquals("getIndex", 0, request.getIndex());
+        assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
+
+        assertFalse("isCompleted", request.isCompleted());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        assertEquals("getNbRead", 0, request.getNbRead());
+        assertEquals("getDependencyLevel", 1, request.getDependencyLevel());
     }
 
     // ------------------------------------------------------------------------
@@ -187,6 +215,9 @@ public class TmfEventRequestTest {
         assertFalse(fRequest1.equals(fRequest2));
         assertFalse(fRequest1.equals(fRequest3));
         assertFalse(fRequest1.equals(fRequest4));
+
+        /* Request with different dependency level, but otherwise identical, are not equal */
+        assertFalse(fRequest4.equals(fRequest5));
     }
 
     // ------------------------------------------------------------------------
@@ -195,15 +226,17 @@ public class TmfEventRequestTest {
 
     @Test
     public void testToString() {
-        String expected1 = "[TmfEventRequestStub(" + fRequest1.getRequestId() + ",ITmfEvent,FOREGROUND," + range1 + ",0,100)]";
-        String expected2 = "[TmfEventRequestStub(" + fRequest2.getRequestId() + ",ITmfEvent,FOREGROUND," + range2 + ",0,100)]";
-        String expected3 = "[TmfEventRequestStub(" + fRequest3.getRequestId() + ",ITmfEvent,FOREGROUND," + range2 + ",0,200)]";
-        String expected4 = "[TmfEventRequestStub(" + fRequest4.getRequestId() + ",ITmfEvent,FOREGROUND," + range2 + ",0,200)]";
+        String expected1 = "[TmfEventRequestStub(" + fRequest1.getRequestId() + ",ITmfEvent,FOREGROUND," + range1 + ",0,100,0)]";
+        String expected2 = "[TmfEventRequestStub(" + fRequest2.getRequestId() + ",ITmfEvent,FOREGROUND," + range2 + ",0,100,0)]";
+        String expected3 = "[TmfEventRequestStub(" + fRequest3.getRequestId() + ",ITmfEvent,FOREGROUND," + range2 + ",0,200,0)]";
+        String expected4 = "[TmfEventRequestStub(" + fRequest4.getRequestId() + ",ITmfEvent,FOREGROUND," + range2 + ",0,200,0)]";
+        String expected5 = "[TmfEventRequestStub(" + fRequest5.getRequestId() + ",ITmfEvent,FOREGROUND," + range2 + ",0,200,1)]";
 
         assertEquals("toString", expected1, fRequest1.toString());
         assertEquals("toString", expected2, fRequest2.toString());
         assertEquals("toString", expected3, fRequest3.toString());
         assertEquals("toString", expected4, fRequest4.toString());
+        assertEquals("toString", expected5, fRequest5.toString());
     }
 
     // ------------------------------------------------------------------------
index 2f75c65f8322b51dcd6a11b424660bc71915ee13..f1fb4a1419e2afc7676d3e90cb6c4805e37b963a 100644 (file)
@@ -66,6 +66,18 @@ public class TmfEventRequestStub extends TmfEventRequest {
         super(dataType, range, index, nbRequested, ExecutionType.FOREGROUND);
     }
 
+    /**
+     * @param dataType the event type
+     * @param range the requested time range
+     * @param nbRequested the number of events requested
+     * @param blockSize the event block size
+     * @param type the execution type
+     * @param dependency the dependency
+     */
+    public TmfEventRequestStub(final Class<? extends ITmfEvent> dataType, final TmfTimeRange range, final int nbRequested, final int blockSize, ExecutionType type, int dependency) {
+        super(dataType, range, 0, nbRequested, type, dependency);
+    }
+
     @Override
     public void handleData(final ITmfEvent data) {
         super.handleData(data);
index ccdf5e06f2b161c1fbc654f2d9003c9f2611e9bf..467e005df898ef29a02aabe00007f2c59d7f87b3 100644 (file)
@@ -74,13 +74,17 @@ public class TmfCoalescedEventRequest extends TmfEventRequest {
      *            {@link TmfEventRequest#ALL_DATA} to request all events.
      * @param priority
      *            The requested execution priority
+     * @param dependencyLevel
+     *            The dependency level. Use 0 if no dependency with other
+     *            requests.
      */
     public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType,
             TmfTimeRange range,
             long index,
             int nbRequested,
-            ExecutionType priority) {
-        super(ITmfEvent.class, null, index, nbRequested, priority);
+            ExecutionType priority,
+            int dependencyLevel) {
+        super(ITmfEvent.class, null, index, nbRequested, priority, dependencyLevel);
         fRange = range;
 
         if (TmfCoreTracer.isRequestTraced()) {
@@ -134,6 +138,7 @@ public class TmfCoalescedEventRequest extends TmfEventRequest {
      */
     public boolean isCompatible(ITmfEventRequest request) {
         if (request.getExecType() == getExecType() &&
+                request.getDependencyLevel() == getDependencyLevel() &&
                 ranksOverlap(request) &&
                 timeRangesOverlap(request)) {
             return true;
index 6f6f4e51f95d8aaf049f9768274aea0094aefd34..61458a773dfe71b9dfd1d60e2f0ca5c8653a2cd4 100644 (file)
@@ -298,7 +298,8 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
                     request.getRange(),
                     request.getIndex(),
                     request.getNbRequested(),
-                    request.getExecType());
+                    request.getExecType(),
+                    request.getDependencyLevel());
             coalescedRequest.addRequest(request);
             coalescedRequest.setProviderFilter(this);
             if (TmfCoreTracer.isRequestTraced()) {
index b3f4cdcc5ecd10a43a7bfd411f7d5e60f7cc703e..7932801e61492b6aedfd2b71b10c743065a83418 100644 (file)
@@ -39,13 +39,13 @@ public interface ITmfEventRequest {
      */
     enum ExecutionType {
         /**
-         * Backgroung, long-running, lower priority request
+         * Background, long-running, lower priority request.
          */
         BACKGROUND,
         /**
-         * Foreground, short-running, high priority request
+         * Foreground, short-running, high priority request.
          */
-        FOREGROUND
+        FOREGROUND,
     }
 
     // ------------------------------------------------------------------------
@@ -67,6 +67,17 @@ public interface ITmfEventRequest {
      */
     ExecutionType getExecType();
 
+    /**
+     * Gets the dependency level. Use different dependency level for requests
+     * that have a dependency with each other. They will be serviced separately.
+     *
+     * @return dependency
+     * @since 2.0
+     */
+    default int getDependencyLevel() {
+        return 0;
+    }
+
     /**
      * @return the index of the first event requested
      */
index 430400fb48eb38bb4a08bd6e675a11a71d6c947e..2663ed3265781b44273e50ec2752de7f6a35867f 100644 (file)
@@ -101,6 +101,8 @@ public abstract class TmfEventRequest implements ITmfEventRequest {
 
     private ITmfFilter fEventFilter;
 
+    private int fDependencyLevel;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -153,6 +155,40 @@ public abstract class TmfEventRequest implements ITmfEventRequest {
             long index,
             int nbRequested,
             ExecutionType priority) {
+        this(dataType, range, index, nbRequested, priority, 0);
+    }
+
+    /**
+     * Request 'n' events of a given type, for the given time range, at the
+     * given priority.
+     *
+     * @param dataType
+     *            The requested data type.
+     * @param range
+     *            The time range of the requested events. You can use
+     *            {@link TmfTimeRange#ETERNITY} to indicate you want to cover
+     *            the whole trace.
+     * @param index
+     *            The index of the first event to retrieve. You can use '0' to
+     *            start at the beginning of the trace.
+     * @param nbRequested
+     *            The number of events requested. You can use
+     *            {@link TmfEventRequest#ALL_DATA} to indicate you want all
+     *            events in the time range.
+     * @param priority
+     *            The requested execution priority.
+     * @param dependencyLevel
+     *            The dependency level. Use different dependency level for
+     *            requests that have a dependency with each other. They will
+     *            be serviced separately.
+     * @since 2.0
+     */
+    public TmfEventRequest(Class<? extends ITmfEvent> dataType,
+            TmfTimeRange range,
+            long index,
+            int nbRequested,
+            ExecutionType priority,
+            int dependencyLevel) {
 
         synchronized (TmfEventRequest.class) {
             fRequestId = fRequestNumber++;
@@ -163,6 +199,7 @@ public abstract class TmfEventRequest implements ITmfEventRequest {
         fExecType = priority;
         fRange = range;
         fNbRead = 0;
+        fDependencyLevel = dependencyLevel;
 
         fRequestRunning = false;
         fRequestCompleted = false;
@@ -178,7 +215,8 @@ public abstract class TmfEventRequest implements ITmfEventRequest {
                     + (getExecType() == ExecutionType.BACKGROUND ? "(BG)" : "(FG)")
                     + " Type=" + type + " Index=" + getIndex() + " NbReq=" + getNbRequested()
                     + " Range=" + getRange()
-                    + " DataType=" + getDataType().getSimpleName();
+                    + " DataType=" + getDataType().getSimpleName()
+                    + " DependencyLevel= " + fDependencyLevel;
             TmfCoreTracer.traceRequest(fRequestId, message);
         }
     }
@@ -252,6 +290,12 @@ public abstract class TmfEventRequest implements ITmfEventRequest {
         fEventFilter = provider;
     }
 
+    /** @since 2.0 */
+    @Override
+    public int getDependencyLevel() {
+        return fDependencyLevel;
+    }
+
     // ------------------------------------------------------------------------
     // Setters
     // ------------------------------------------------------------------------
@@ -404,7 +448,7 @@ public abstract class TmfEventRequest implements ITmfEventRequest {
         }
         return '[' + name + '(' + getRequestId() + ',' + getDataType().getSimpleName() +
                 ',' + getExecType() + ',' + getRange() + ',' + getIndex() +
-                ',' + getNbRequested() + ")]"; //$NON-NLS-1$
+                ',' + getNbRequested() + ','+ getDependencyLevel() + ")]"; //$NON-NLS-1$
     }
 
 }
This page took 0.034445 seconds and 5 git commands to generate.