* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
+ * Francois Chouinard - Initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.tmf.event;
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TmfEventRequestTest.class,
- TmfEventStreamTest.class,
- TmfEventLogTest.class
-})
-
-public class AllEventLogTests {
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Vector;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * <b><u>TmfEventLogTest</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfEventLogTest {
-
- private static String filename = "Test-10K";
- private static int fTotalNbEvents = 10000;
- private static ITmfEventParser fParser;
- private static TmfEventStream fStream;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- fParser = new TmfEventParserStub();
- fStream = new TmfEventStreamStub(filename, fParser);
- }
-
- // ========================================================================
- // Constructor
- // ========================================================================
-
- @Test
- public void testBasicTmfEventLog() {
- TmfTrace eventLog = new TmfTrace("MyEventLog", fStream);
-
- assertEquals("GetId", "MyEventLog", eventLog.getId());
- assertEquals("GetEpoch", TmfTimestamp.BigBang, eventLog.getEpoch());
- assertEquals("GetNbEvents", fTotalNbEvents, eventLog.getNbEvents());
-
- TmfTimeRange timeRange = eventLog.getTimeRange();
- assertEquals("GetTimeRange", 0, timeRange.getStartTime().getValue());
- assertEquals("GetTimeRange", fTotalNbEvents - 1, timeRange.getEndTime().getValue());
- }
-
- @Test
- public void testTmfEventLogWithEpoch() {
- TmfTimestamp epoch = new TmfTimestamp(100, (byte) 0, 0);
- TmfTrace eventLog = new TmfTrace("MyEventLog", fStream, epoch);
-
- assertEquals("GetId", "MyEventLog", eventLog.getId());
- assertEquals("GetEpoch", epoch, eventLog.getEpoch());
- assertEquals("GetNbEvents", fTotalNbEvents, eventLog.getNbEvents());
-
- TmfTimeRange timeRange = eventLog.getTimeRange();
- assertEquals("GetTimeRange", 0, timeRange.getStartTime().getValue());
- assertEquals("GetTimeRange", fTotalNbEvents - 1, timeRange.getEndTime().getValue());
- }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- @Test
- public void testProcessRequestForNbEvents() throws Exception {
-
- TmfTrace eventLog = new TmfTrace("MyEventLog", fStream);
-
- final int NB_EVENTS = 10 * 1000;
- final int BLOCK_SIZE = 100;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, 0, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
- };
- eventLog.process(request, true);
-
- assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < NB_EVENTS; i++) {
- assertEquals("Distinct events", i, requestedEvents.get(i).getTimestamp().getValue());
- }
- }
-
- @Test
- public void testProcessRequestForAllEvents() throws Exception {
-
- TmfTrace eventLog = new TmfTrace("MyEventLog", fStream);
-
- final int NB_EVENTS = -1;
- final int BLOCK_SIZE = 1;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
- int nbExpectedEvents = eventLog.getNbEvents();
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, 0, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
- };
- eventLog.process(request, true);
-
- assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbExpectedEvents; i++) {
- assertEquals("Distinct events", i, requestedEvents.get(i).getTimestamp().getValue());
- }
- }
-
- // @Test
- public void testProcessRequestWithOffset() throws Exception {
-
- TmfTrace eventLog = new TmfTrace("MyEventLog", fStream);
-
- final int NB_EVENTS = -1;
- final int BLOCK_SIZE = 1;
- final int OFFSET = 5;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
- int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
- };
- eventLog.process(request, true);
-
- assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbExpectedEvents; i++) {
- assertEquals("Distinct events", i + OFFSET, requestedEvents.get(i).getTimestamp().getValue());
- }
- }
-
- // l@Test
- public void testProcessRequestWithNegativeOffset() throws Exception {
-
- TmfTrace eventLog = new TmfTrace("MyEventLog", fStream);
-
- final int NB_EVENTS = -1;
- final int BLOCK_SIZE = 1;
- final int OFFSET = -5;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
- int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
- };
- eventLog.process(request, true);
-
- assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbExpectedEvents; i++) {
- assertEquals("Distinct events", i + OFFSET, requestedEvents.get(i).getTimestamp().getValue());
- }
- }
-
- // ========================================================================
- // cancel
- // ========================================================================
-
- @Test
- public void testCancel() throws Exception {
-
- TmfTrace eventLog = new TmfTrace("MyEventLog", fStream);
-
- final int NB_EVENTS = 10 * 1000;
- final int BLOCK_SIZE = 100;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, 0, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- // Cancel request after the first chunk is received
- cancel();
- }
- };
- eventLog.process(request, true);
-
- assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertTrue("isCancelled", request.isCancelled());
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import static org.junit.Assert.*;
-
-import java.util.Vector;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * <b><u>TmfEventRequestTest</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfEventRequestTest {
-
- private static ITmfRequestHandler fProcessor = null;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- fProcessor = new TmfRequestHandlerStub();
- }
-
- // ========================================================================
- // Constructor
- // ========================================================================
-
- @Test
- public void testConstructorForRange() throws Exception {
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- TmfEventRequest request = new TmfEventRequest(range, 0, -1, 1);
-
- assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime());
- assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime());
- assertEquals("Offset", 0, request.getOffset());
- assertEquals("NbRequestedEvents", -1, request.getNbRequestedEvents());
- }
-
- @Test
- public void testConstructorForNbEvents() throws Exception {
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- TmfEventRequest request = new TmfEventRequest(range, 0, 10, 1);
-
- assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime());
- assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime());
- assertEquals("Offset", 0, request.getOffset());
- assertEquals("NbRequestedEvents", 10, request.getNbRequestedEvents());
- }
-
- @Test
- public void testConstructorWithOffset() throws Exception {
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- TmfEventRequest request = new TmfEventRequest(range, 5, 10, 1);
-
- assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime());
- assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime());
- assertEquals("Offset", 5, request.getOffset());
- assertEquals("NbRequestedEvents", 10, request.getNbRequestedEvents());
- }
-
- @Test
- public void testConstructorWithNegativeOffset() throws Exception {
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- TmfEventRequest request = new TmfEventRequest(range, -5, 10, 1);
-
- assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime());
- assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime());
- assertEquals("Offset", -5, request.getOffset());
- assertEquals("NbRequestedEvents", 10, request.getNbRequestedEvents());
- }
-
- // ========================================================================
- // process
- // ========================================================================
-
- @Test
- public void testProcessRequestForNbEvents() throws Exception {
-
- final int NB_EVENTS = 10 * 1000;
- final int BLOCK_SIZE = 100;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, 0, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
- };
- fProcessor.process(request, true);
-
- assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < NB_EVENTS; i++) {
- assertEquals("Distinct events", i, requestedEvents.get(i).getTimestamp().getValue());
- }
- }
-
- @Test
- public void testProcessRequestForAllEvents() throws Exception {
-
- final int NB_EVENTS = -1;
- final int BLOCK_SIZE = 1;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
- int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, 0, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
- };
- fProcessor.process(request, true);
-
- assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbExpectedEvents; i++) {
- assertEquals("Distinct events", i, requestedEvents.get(i).getTimestamp().getValue());
- }
- }
-
- // @Test
- public void testProcessRequestWithOffset() throws Exception {
-
- final int NB_EVENTS = -1;
- final int BLOCK_SIZE = 1;
- final int OFFSET = 5;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
- int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
- };
- fProcessor.process(request, true);
-
- assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbExpectedEvents; i++) {
- assertEquals("Distinct events", i + OFFSET, requestedEvents.get(i).getTimestamp().getValue());
- }
- }
-
- // l@Test
- public void testProcessRequestWithNegativeOffset() throws Exception {
-
- final int NB_EVENTS = -1;
- final int BLOCK_SIZE = 1;
- final int OFFSET = -5;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
- int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
- };
- fProcessor.process(request, true);
-
- assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbExpectedEvents; i++) {
- assertEquals("Distinct events", i + OFFSET, requestedEvents.get(i).getTimestamp().getValue());
- }
- }
-
- // ========================================================================
- // cancel
- // ========================================================================
-
- @Test
- public void testCancel() throws Exception {
-
- final int NB_EVENTS = 10 * 1000;
- final int BLOCK_SIZE = 100;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
-
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest request = new TmfEventRequest(range, 0, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void newEvents(Vector<TmfEvent> events) {
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- // Cancel request after the first chunk is received
- cancel();
- }
- };
- fProcessor.process(request, true);
-
- assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertTrue("isCancelled", request.isCancelled());
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import static org.junit.Assert.*;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * <b><u>TmfEventStreamTest</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfEventStreamTest {
-
- private static final String TEST_STREAM = "Test-10K";
- private static final int NB_EVENTS = 10000;
- private static TmfEventStreamStub fStream;
-
- /**
- * @throws java.lang.Exception
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- TmfEventParserStub parser = new TmfEventParserStub();
- fStream = new TmfEventStreamStub(TEST_STREAM, parser, 500);
- }
-
- // ========================================================================
- // Constructor
- // ========================================================================
-
- @Test
- public void testDefaultConstructor() throws Exception {
- TmfEventParserStub parser = new TmfEventParserStub();
- TmfEventStreamStub stream = new TmfEventStreamStub(TEST_STREAM, parser);
-
- assertEquals("getCacheSize", TmfEventStream.DEFAULT_CACHE_SIZE, stream.getCacheSize());
- assertEquals("getTraceSize", NB_EVENTS, stream.getNbEvents());
- assertEquals("getRange-start", 0, stream.getTimeRange().getStartTime().getValue());
- assertEquals("getRange-end", NB_EVENTS - 1, stream.getTimeRange().getEndTime().getValue());
- }
-
- @Test
- public void testNormalConstructor() throws Exception {
- TmfEventParserStub parser = new TmfEventParserStub();
- TmfEventStreamStub stream = new TmfEventStreamStub(TEST_STREAM, parser, 500);
-
- assertEquals("getCacheSize", 500, stream.getCacheSize());
- assertEquals("getTraceSize", NB_EVENTS, stream.getNbEvents());
- assertEquals("getRange-start", 0, stream.getTimeRange().getStartTime().getValue());
- assertEquals("getRange-end", NB_EVENTS - 1, stream.getTimeRange().getEndTime().getValue());
- }
-
- // ========================================================================
- // seek
- // ========================================================================
-
- @Test
- public void testSeekOnCacheBoundary() throws Exception {
- TmfEvent event = fStream.seek(new TmfTimestamp(0, (byte) 0, 0));
- assertEquals("Event timestamp", 0, event.getTimestamp().getValue());
-
- event = fStream.seek(new TmfTimestamp(1000, (byte) 0, 0));
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
-
- event = fStream.seek(new TmfTimestamp(4000, (byte) 0, 0));
- assertEquals("Event timestamp", 4000, event.getTimestamp().getValue());
- }
-
- @Test
- public void testSeekNotOnCacheBoundary() throws Exception {
- TmfEvent event = fStream.seek(new TmfTimestamp(1, (byte) 0, 0));
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
-
- event = fStream.seek(new TmfTimestamp(999, (byte) 0, 0));
- assertEquals("Event timestamp", 999, event.getTimestamp().getValue());
-
- event = fStream.seek(new TmfTimestamp(4499, (byte) 0, 0));
- assertEquals("Event timestamp", 4499, event.getTimestamp().getValue());
- }
-
- @Test
- public void testSeekForEventOutOfBounds() throws Exception {
- // On lower bound, returns the first event (ts = 0)
- TmfEvent event = fStream.seek(new TmfTimestamp(-1, (byte) 0, 0));
- assertEquals("Event timestamp", 0, event.getTimestamp().getValue());
-
- // On higher bound, returns null (no event)
- event = fStream.seek(new TmfTimestamp(NB_EVENTS, (byte) 0, 0));
- assertEquals("Event timestamp", null, event);
- }
-
- // ========================================================================
- // getNextEvent
- // ========================================================================
-
- @Test
- public void testGetNextEvent() throws Exception {
- // On lower bound, returns the first event (ts = 0)
- TmfEvent event = fStream.seek(new TmfTimestamp(0, (byte) 0, 0));
- assertEquals("Event timestamp", 0, event.getTimestamp().getValue());
-
- for (int i = 0; i < 10; i++) {
- event = fStream.getNextEvent();
- assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue());
- }
- }
-
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.request;
+
+import org.eclipse.linuxtools.tmf.request.TmfDataRequestTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TmfDataRequestTest.class,
+})
+
+public class AllRequestTests {
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Vector;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.request.ITmfRequestHandler;
+import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * <b><u>TmfDataRequestTest</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfDataRequestTest {
+
+ private static ITmfRequestHandler<TmfEvent> fProcessor = null;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ fProcessor = new TmfRequestHandlerStub();
+ }
+
+ // ========================================================================
+ // Constructor
+ // ========================================================================
+
+ @Test
+ public void testConstructorForRange() throws Exception {
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, -1, 1);
+
+ assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime());
+ assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime());
+ assertEquals("Offset", 0, request.getOffset());
+ assertEquals("NbRequestedEvents", -1, request.getNbRequestedItems());
+ }
+
+ @Test
+ public void testConstructorForNbEvents() throws Exception {
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, 10, 1);
+
+ assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime());
+ assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime());
+ assertEquals("Offset", 0, request.getOffset());
+ assertEquals("NbRequestedEvents", 10, request.getNbRequestedItems());
+ }
+
+ @Test
+ public void testConstructorWithOffset() throws Exception {
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 5, 10, 1);
+
+ assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime());
+ assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime());
+ assertEquals("Offset", 5, request.getOffset());
+ assertEquals("NbRequestedEvents", 10, request.getNbRequestedItems());
+ }
+
+ @Test
+ public void testConstructorWithNegativeOffset() throws Exception {
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, -5, 10, 1);
+
+ assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime());
+ assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime());
+ assertEquals("Offset", -5, request.getOffset());
+ assertEquals("NbRequestedEvents", 10, request.getNbRequestedItems());
+ }
+
+ // ========================================================================
+ // process
+ // ========================================================================
+
+ @Test
+ public void testProcessRequestForNbEvents() throws Exception {
+
+ final int NB_EVENTS = 10 * 1000;
+ final int BLOCK_SIZE = 100;
+ final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
+ @Override
+ public void handlePartialResult() {
+ TmfEvent[] events = getData();
+ for (TmfEvent e : events) {
+ requestedEvents.add(e);
+ }
+ }
+ };
+ fProcessor.processRequest(request, true);
+
+ assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
+ assertTrue("isCompleted", request.isCompleted());
+ assertFalse("isCancelled", request.isCancelled());
+
+ // Ensure that we have distinct events.
+ // 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());
+ }
+ }
+
+ @Test
+ public void testProcessRequestForAllEvents() throws Exception {
+
+ final int NB_EVENTS = -1;
+ final int BLOCK_SIZE = 1;
+ final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+ int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
+
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
+ @Override
+ public void handlePartialResult() {
+ TmfEvent[] events = getData();
+ for (TmfEvent e : events) {
+ requestedEvents.add(e);
+ }
+ }
+ };
+ fProcessor.processRequest(request, true);
+
+ assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
+ assertTrue("isCompleted", request.isCompleted());
+ assertFalse("isCancelled", request.isCancelled());
+
+ // Ensure that we have distinct events.
+ // Don't go overboard: we are not validating the stub!
+ for (int i = 0; i < nbExpectedEvents; i++) {
+ assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue());
+ }
+ }
+
+ // @Test
+ public void testProcessRequestWithOffset() throws Exception {
+
+ final int NB_EVENTS = -1;
+ final int BLOCK_SIZE = 1;
+ final int OFFSET = 5;
+ final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+ int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
+
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
+ @Override
+ public void handlePartialResult() {
+ TmfEvent[] events = getData();
+ for (TmfEvent e : events) {
+ requestedEvents.add(e);
+ }
+ }
+ };
+ fProcessor.processRequest(request, true);
+
+ assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
+ assertTrue("isCompleted", request.isCompleted());
+ assertFalse("isCancelled", request.isCancelled());
+
+ // Ensure that we have distinct events.
+ // Don't go overboard: we are not validating the stub!
+ for (int i = 0; i < nbExpectedEvents; i++) {
+ assertEquals("Distinct events", i + OFFSET, requestedEvents.get(i).getTimestamp().getValue());
+ }
+ }
+
+ // l@Test
+ public void testProcessRequestWithNegativeOffset() throws Exception {
+
+ final int NB_EVENTS = -1;
+ final int BLOCK_SIZE = 1;
+ final int OFFSET = -5;
+ final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+ int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
+
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
+ @Override
+ public void handlePartialResult() {
+ TmfEvent[] events = getData();
+ for (TmfEvent e : events) {
+ requestedEvents.add(e);
+ }
+ }
+ };
+ fProcessor.processRequest(request, true);
+
+ assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
+ assertTrue("isCompleted", request.isCompleted());
+ assertFalse("isCancelled", request.isCancelled());
+
+ // Ensure that we have distinct events.
+ // Don't go overboard: we are not validating the stub!
+ for (int i = 0; i < nbExpectedEvents; i++) {
+ assertEquals("Distinct events", i + OFFSET, requestedEvents.get(i).getTimestamp().getValue());
+ }
+ }
+
+ // ========================================================================
+ // cancel
+ // ========================================================================
+
+ @Test
+ public void testCancel() throws Exception {
+
+ final int NB_EVENTS = 10 * 1000;
+ final int BLOCK_SIZE = 100;
+ final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
+ @Override
+ public void handlePartialResult() {
+ TmfEvent[] events = getData();
+ for (TmfEvent e : events) {
+ requestedEvents.add(e);
+ }
+ // Cancel request after the first chunk is received
+ cancel();
+ }
+ };
+ fProcessor.processRequest(request, true);
+
+ assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size());
+ assertTrue("isCompleted", request.isCompleted());
+ assertTrue("isCancelled", request.isCancelled());
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.stream;
+
+import org.eclipse.linuxtools.tmf.stream.TmfEventStreamTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TmfEventStreamTest.class
+})
+
+public class AllStreamTests {
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.stream;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventStream.StreamContext;
+import org.eclipse.linuxtools.tmf.trace.TmfEventParserStub;
+import org.eclipse.linuxtools.tmf.trace.TmfEventStreamStub;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * <b><u>TmfEventStreamTest</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfEventStreamTest {
+
+ private static final String TEST_STREAM = "M-Test-100K";
+ private static String testfile;
+ private static final int NB_EVENTS = 100000;
+ private static TmfEventStreamStub fStream;
+
+ private static byte SCALE = (byte) -3;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ String directory = new File(".").getCanonicalPath() + File.separator + "testfiles";
+ testfile = directory + File.separator + TEST_STREAM;
+
+ TmfEventParserStub parser = new TmfEventParserStub();
+ fStream = new TmfEventStreamStub(testfile, parser, 500);
+ fStream.indexStream(true);
+
+ }
+
+ // ========================================================================
+ // Constructor
+ // ========================================================================
+
+ @Test
+ public void testDefaultConstructor() throws Exception {
+ TmfEventParserStub parser = new TmfEventParserStub();
+ TmfEventStreamStub stream = new TmfEventStreamStub(testfile, parser);
+ stream.indexStream(true);
+
+ assertEquals("getCacheSize", TmfEventStreamStub.DEFAULT_CACHE_SIZE, stream.getCacheSize());
+ assertEquals("getTraceSize", NB_EVENTS, stream.getNbEvents());
+ assertEquals("getRange-start", 1, stream.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, stream.getTimeRange().getEndTime().getValue());
+ }
+
+ @Test
+ public void testNormalConstructor() throws Exception {
+ TmfEventParserStub parser = new TmfEventParserStub();
+ TmfEventStreamStub stream = new TmfEventStreamStub(testfile, parser, 500);
+ stream.indexStream(true);
+
+ assertEquals("getCacheSize", 500, stream.getCacheSize());
+ assertEquals("getTraceSize", NB_EVENTS, stream.getNbEvents());
+ assertEquals("getRange-start", 1, stream.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, stream.getTimeRange().getEndTime().getValue());
+ }
+
+ // ========================================================================
+ // seek
+ // ========================================================================
+
+ @Test
+ public void testSeekOnCacheBoundary() throws Exception {
+ StreamContext context = new StreamContext(null);
+
+ TmfEvent event = fStream.getEvent(context, new TmfTimestamp(0, SCALE, 0));
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+
+ event = fStream.getEvent(context, new TmfTimestamp(1000, SCALE, 0));
+ assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
+
+ event = fStream.getEvent(context, new TmfTimestamp(4000, SCALE, 0));
+ assertEquals("Event timestamp", 4000, event.getTimestamp().getValue());
+ }
+
+ @Test
+ public void testSeekNotOnCacheBoundary() throws Exception {
+ StreamContext context = new StreamContext(null);
+
+ TmfEvent event = fStream.getEvent(context, new TmfTimestamp(1, SCALE, 0));
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+
+ event = fStream.getEvent(context, new TmfTimestamp(999, SCALE, 0));
+ assertEquals("Event timestamp", 999, event.getTimestamp().getValue());
+
+ event = fStream.getEvent(context, new TmfTimestamp(4499, SCALE, 0));
+ assertEquals("Event timestamp", 4499, event.getTimestamp().getValue());
+ }
+
+ @Test
+ public void testSeekForEventOutOfBounds() throws Exception {
+ StreamContext context = new StreamContext(null);
+
+ // On lower bound, returns the first event (ts = 1)
+ TmfEvent event = fStream.getEvent(context, new TmfTimestamp(-1, SCALE, 0));
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+
+ // On higher bound, returns null (no event)
+ event = fStream.getEvent(context, new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
+ assertEquals("Event timestamp", null, event);
+ }
+
+ // ========================================================================
+ // getNextEvent
+ // ========================================================================
+
+ @Test
+ public void testGetNextEvent() throws Exception {
+ StreamContext context = new StreamContext(null);
+
+ // On lower bound, returns the first event (ts = 0)
+ TmfEvent event = fStream.getEvent(context, new TmfTimestamp(0, SCALE, 0));
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+
+ for (int i = 2; i < 20; i++) {
+ event = fStream.getNextEvent(context);
+ assertEquals("Event timestamp", i, event.getTimestamp().getValue());
+ }
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TmfTraceTest.class
+})
+
+public class AllTraceTests {
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Vector;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * <b><u>TmfEventLogTest</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfTraceTest {
+
+ private static final String TEST_STREAM = "M-Test-100K";
+ private static String testfile;
+ private static int fTotalNbEvents = 100000;
+ private static int fDefaultBlockSize = 1000;
+
+ private static ITmfEventParser fParser;
+ private static ITmfEventStream fStream;
+ private static TmfTrace fTrace;
+
+// private static byte SCALE = (byte) -3;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ String directory = new File(".").getCanonicalPath() + File.separator + "testfiles";
+ testfile = directory + File.separator + TEST_STREAM;
+
+ fParser = new TmfEventParserStub();
+ fStream = new TmfEventStreamStub(testfile, fParser);
+ fTrace = new TmfTrace("MyEventLog", fStream);
+ fStream.indexStream(true);
+ }
+
+ // ========================================================================
+ // Constructor
+ // ========================================================================
+
+ @Test
+ public void testBasicTmfEventLog() {
+ TmfTrace eventLog = new TmfTrace("MyEventLog", fStream);
+
+ assertEquals("GetId", "MyEventLog", eventLog.getId());
+ assertEquals("GetEpoch", TmfTimestamp.BigBang, eventLog.getEpoch());
+ assertEquals("GetNbEvents", fTotalNbEvents, eventLog.getNbEvents());
+
+ TmfTimeRange timeRange = eventLog.getTimeRange();
+ assertEquals("GetTimeRange-start", 1, timeRange.getStartTime().getValue());
+ assertEquals("GetTimeRange-end", fTotalNbEvents, timeRange.getEndTime().getValue());
+ }
+
+// TODO: Fix the test when epoch is implemented
+// @Test
+// public void testTmfEventLogWithEpoch() {
+// TmfTimestamp epoch = new TmfTimestamp(100, SCALE, 0);
+// TmfEventLog eventLog = new TmfEventLog("MyEventLog", fStream, epoch);
+//
+// assertEquals("GetId", "MyEventLog", eventLog.getId());
+// assertEquals("GetEpoch", epoch, eventLog.getEpoch());
+// assertEquals("GetNbEvents", fTotalNbEvents, eventLog.getNbEvents());
+//
+// TmfTimeWindow timeRange = eventLog.getTimeRange();
+// assertEquals("GetTimeRange-start", 1, timeRange.getStartTime().getValue());
+// assertEquals("GetTimeRange-end", fTotalNbEvents, timeRange.getEndTime().getValue());
+// }
+
+ // ========================================================================
+ // Accessors
+ // ========================================================================
+
+ @Test
+ public void testGetNbEvents() throws Exception {
+ TmfTrace eventLog = new TmfTrace("MyEventLog", fStream);
+ assertEquals("nbEvents", fTotalNbEvents, eventLog.getNbEvents());
+ }
+
+ // ========================================================================
+ // Operators
+ // ========================================================================
+
+ @Test
+ public void testProcessRequestForNbEvents() throws Exception {
+ final int NB_EVENTS = fTotalNbEvents;
+ final int BLOCK_SIZE = 100;
+ final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
+ @Override
+ public void handlePartialResult() {
+ TmfEvent[] events = getData();
+ for (TmfEvent e : events) {
+ requestedEvents.add(e);
+ }
+ }
+ };
+ fTrace.processRequest(request, true);
+
+ assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
+ assertTrue("isCompleted", request.isCompleted());
+ assertFalse("isCancelled", request.isCancelled());
+
+ // Ensure that we have distinct events.
+ // 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());
+ }
+ }
+
+ @Test
+ public void testProcessRequestForAllEvents() throws Exception {
+ final int NB_EVENTS = -1;
+ final int BLOCK_SIZE = 1;
+ final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+ int nbExpectedEvents = fTrace.getNbEvents();
+
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
+ @Override
+ public void handlePartialResult() {
+ TmfEvent[] events = getData();
+ for (TmfEvent e : events) {
+ requestedEvents.add(e);
+ }
+ }
+ };
+ fTrace.processRequest(request, true);
+
+ assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
+ assertTrue("isCompleted", request.isCompleted());
+ assertFalse("isCancelled", request.isCancelled());
+
+ // Ensure that we have distinct events.
+ // Don't go overboard: we are not validating the stub!
+ for (int i = 0; i < nbExpectedEvents; i++) {
+ assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue());
+ }
+ }
+
+// // @Test
+// // TODO: Implement offset handling first...
+// public void testProcessRequestWithOffset() throws Exception {
+// final int NB_EVENTS = -1;
+// final int BLOCK_SIZE = 1;
+// final int OFFSET = 5;
+// final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+// int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
+//
+// TmfTimeWindow range = new TmfTimeWindow(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+// final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
+// @Override
+// public void handlePartialResult() {
+// TmfEvent[] events = getData();
+// for (TmfEvent e : events) {
+// requestedEvents.add(e);
+// }
+// }
+// };
+// fEventLog.process(request, true);
+//
+// assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
+// assertTrue("isCompleted", request.isCompleted());
+// assertFalse("isCancelled", request.isCancelled());
+//
+// // Ensure that we have distinct events.
+// // Don't go overboard: we are not validating the stub!
+// for (int i = 0; i < nbExpectedEvents; i++) {
+// assertEquals("Distinct events", i + OFFSET, requestedEvents.get(i).getTimestamp().getValue());
+// }
+// }
+
+// // l@Test
+// public void testProcessRequestWithNegativeOffset() throws Exception {
+// final int NB_EVENTS = -1;
+// final int BLOCK_SIZE = 1;
+// final int OFFSET = -5;
+// final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+// int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS;
+//
+// TmfTimeWindow range = new TmfTimeWindow(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+// final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
+// @Override
+// public void handlePartialResult() {
+// TmfEvent[] events = getData();
+// for (TmfEvent e : events) {
+// requestedEvents.add(e);
+// }
+// }
+// };
+// fEventLog.process(request, true);
+//
+// assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
+// assertTrue("isCompleted", request.isCompleted());
+// assertFalse("isCancelled", request.isCancelled());
+//
+// // Ensure that we have distinct events.
+// // Don't go overboard: we are not validating the stub!
+// for (int i = 0; i < nbExpectedEvents; i++) {
+// assertEquals("Distinct events", i + OFFSET, requestedEvents.get(i).getTimestamp().getValue());
+// }
+// }
+
+ // ========================================================================
+ // cancel
+ // ========================================================================
+
+ @Test
+ public void testCancel() throws Exception {
+ final int NB_EVENTS = fTotalNbEvents;
+ final int BLOCK_SIZE = fDefaultBlockSize;
+ final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
+ @Override
+ public void handlePartialResult() {
+ TmfEvent[] events = getData();
+ for (TmfEvent e : events) {
+ requestedEvents.add(e);
+ }
+ // Cancel request after the first chunk is received
+ cancel();
+ }
+ };
+ fTrace.processRequest(request, true);
+
+ assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size());
+ assertTrue("isCompleted", request.isCompleted());
+ assertTrue("isCancelled", request.isCancelled());
+ }
+
+}
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
+ * Francois Chouinard - Initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.tmf;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Random;
/**
* <b><u>CreateTestFiles</u></b>
// Constants
// ========================================================================
- private static final String FILE_NAMES[] = { "Test-1K", "Test-10K", "Test-100K", "Test-1M"};
- private static final int FILE_SIZES[] = { 1000, 10000, 100000, 1000000 };
+ private static final String FILE_NAMES[] = { "Test-10", "Test-1K", "Test-10K", "Test-100K", "Test-1M", "Test-10M" };
+ private static final int FILE_SIZES[] = { 10 , 1000 , 10000 , 100000 , 1000000 , 10000000 };
- private static final int NB_SOURCES = 3;
- private static final int NB_TYPES = 5;
+ private static final int NB_SOURCES = 15;
+ private static final int NB_TYPES = 7;
// ========================================================================
// Constructors
* @param args
*/
public static void main(String[] args) {
+
+ try {
+ System.out.println("Creating test files in directory: " + new File(".").getCanonicalPath() + File.separator + "testfiles");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
for (int i = 0; i < FILE_SIZES.length; i++) {
try {
- createFile(FILE_NAMES[i], FILE_SIZES[i]);
+ createTestFile("testfiles" + File.separator + "M-" + FILE_NAMES[i], FILE_SIZES[i], true);
+ createTestFile("testfiles" + File.separator + "R-" + FILE_NAMES[i], FILE_SIZES[i], false);
} catch (Exception e) {
}
}
- System.out.println("Done.");
+
+ System.out.println("Done.");
}
// ========================================================================
/**
* @param file
* @param size
+ * @param monotonic
* @throws FileNotFoundException
* @throws IOException
*/
- private static void createFile(String file, int size) throws FileNotFoundException, IOException {
+ private static void createTestFile(String file, int size, boolean monotonic) throws FileNotFoundException, IOException {
DataOutputStream out;
System.out.println("Creating " + file);
out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
+ Random generator = new Random(19580427 + size);
+ long ts = 0;
for (int i = 0; i < size; i++) {
+ ts += monotonic ? 1 : generator.nextInt(10);
int sourceIndex = i % NB_SOURCES;
int typeIndex = i % NB_TYPES;
- out.writeLong(i); // Timestamp
+ out.writeLong(ts); // Timestamp
out.writeUTF("Source-" + sourceIndex); // Source
out.writeUTF("Type-" + typeIndex); // Type
- out.writeInt(i); // Reference
+ out.writeInt(i + 1); // Reference (event #)
for (int j = 0; j < typeIndex; j++) {
out.writeUTF("Field-" + sourceIndex + "-" + j);
}
out.flush();
out.close();
}
+
}
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
+ * Francois Chouinard - Initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.tmf.event;
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import java.io.EOFException;
-import java.io.IOException;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfEventContent;
-import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
-import org.eclipse.linuxtools.tmf.event.TmfEventReference;
-import org.eclipse.linuxtools.tmf.event.TmfEventSource;
-import org.eclipse.linuxtools.tmf.event.TmfEventType;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-
-/**
- * <b><u>TmfEventParserStub</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfEventParserStub implements ITmfEventParser {
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- private final TmfEventFormat[] fFormats;
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- public TmfEventParserStub() {
- fFormats = new TmfEventFormat[] {
- new TmfEventFormat(new String[] { "Fmt1-Fld-1" }),
- new TmfEventFormat(new String[] { "Fmt2-Fld-1", "Fmt2-Fld-2" }),
- new TmfEventFormat(new String[] { "Fmt3-Fld-1", "Fmt3-Fld-2", "Fmt3-Fld-3" }),
- new TmfEventFormat(new String[] { "Fmt4-Fld-1", "Fmt4-Fld-2", "Fmt4-Fld-3", "Fmt4-Fld-4" }),
- new TmfEventFormat(new String[] { "Fmt5-Fld-1", "Fmt5-Fld-2", "Fmt5-Fld-3", "Fmt5-Fld-4", "Fmt5-Fld-5" }),
- };
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
- */
- static final String typePrefix = "Type-";
- public TmfEvent getNextEvent(TmfEventStream stream) throws IOException {
- try {
- long ts = stream.readLong();
- String source = stream.readUTF();
- String type = stream.readUTF();
- int reference = stream.readInt();
- int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
- String[] content = new String[typeIndex];
- for (int i = 0; i < typeIndex; i ++) {
- content[i] = stream.readUTF();
- }
- TmfEvent event = new TmfEvent(
- new TmfTimestamp(ts, (byte) 0, 0),
- new TmfEventSource(source),
- new TmfEventType(type, fFormats[typeIndex]),
- new TmfEventContent(content, fFormats[typeIndex]),
- new TmfEventReference(reference));
- return event;
- } catch (EOFException e) {
- }
- return null;
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-/**
- * <b><u>TmfEventStreamStub</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfEventStreamStub extends TmfEventStream {
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- /**
- * @param filename
- * @throws FileNotFoundException
- */
- public TmfEventStreamStub(String filename, ITmfEventParser parser) throws FileNotFoundException {
- super(filename, parser);
- }
-
- /**
- * @param filename
- * @throws FileNotFoundException
- */
- public TmfEventStreamStub(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
- super(filename, parser, cacheSize);
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- public void seekLocation(Object location) throws IOException {
- seek((Long) location);
- }
-
- public Object getCurrentLocation() {
- try {
- return new Long(getFilePointer());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- // ========================================================================
- // Helper functions
- // ========================================================================
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Vector;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-
-/**
- * <b><u>TmfRequestHandlerStub</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfRequestHandlerStub implements ITmfRequestHandler {
-
- // The test file
- String filename = "Test-100K";
-
- // A constant to limit the number of events for the tests
- public static final int MAX_GENERATED_EVENTS = 1000;
-
- private ITmfEventParser fParser;
- private TmfEventStreamStub fStream;
-
- public TmfRequestHandlerStub() throws FileNotFoundException {
- fParser = new TmfEventParserStub();
- fStream = new TmfEventStreamStub(filename, fParser);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfEventRequest, boolean)
- */
- public void process(final TmfEventRequest request, boolean waitForCompletion) {
-
- Thread thread = new Thread() {
- @Override
- public void run() {
- TmfTimestamp startTime = request.getRange().getStartTime();
- TmfTimestamp endTime = request.getRange().getEndTime();
- int blockSize = request.getBlockize();
-
- int nbRequestedEvents = request.getNbRequestedEvents();
- if (nbRequestedEvents <= 0) {
- nbRequestedEvents = MAX_GENERATED_EVENTS;
- }
-
- Vector<TmfEvent> events = new Vector<TmfEvent>();
- int nbEvents = 0;
- try {
- TmfEvent event = fStream.seek(startTime);
- while (!request.isCancelled() && nbEvents < nbRequestedEvents &&
- event != null && event.getTimestamp().compareTo(endTime, false) <= 0 )
- {
- events.add(event);
- if (++nbEvents % blockSize == 0) {
- request.newEvents(events);
- events.removeAllElements();
- }
- event = fStream.getNextEvent();
- }
- request.newEvents(events);
- request.done();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- };
- thread.start();
-
- if (waitForCompletion) {
- request.waitForCompletion();
- }
- }
-
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.request;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Vector;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventStream.StreamContext;
+import org.eclipse.linuxtools.tmf.trace.TmfEventParserStub;
+import org.eclipse.linuxtools.tmf.trace.TmfEventStreamStub;
+
+/**
+ * <b><u>TmfRequestHandlerStub</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfRequestHandlerStub implements ITmfRequestHandler<TmfEvent> {
+
+ // The test file
+ private static final String TEST_STREAM = "M-Test-100K";
+
+ // A constant to limit the number of events for the tests
+ public static final int MAX_GENERATED_EVENTS = 1000;
+
+ private ITmfEventParser fParser;
+ private TmfEventStreamStub fStream;
+
+ public TmfRequestHandlerStub() throws IOException {
+ String directory = new File(".").getCanonicalPath() + File.separator + "testfiles";
+ String filename = directory + File.separator + TEST_STREAM;
+
+ fParser = new TmfEventParserStub();
+ fStream = new TmfEventStreamStub(filename, fParser);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfEventRequest, boolean)
+ */
+ public void processRequest(final TmfDataRequest<TmfEvent> request, boolean waitForCompletion) {
+
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ TmfTimestamp startTime = request.getRange().getStartTime();
+ TmfTimestamp endTime = request.getRange().getEndTime();
+ int blockSize = request.getBlockize();
+
+ int nbRequestedEvents = request.getNbRequestedItems();
+ if (nbRequestedEvents <= 0) {
+ nbRequestedEvents = MAX_GENERATED_EVENTS;
+ }
+
+ Vector<TmfEvent> events = new Vector<TmfEvent>();
+ int nbEvents = 0;
+ StreamContext context = new StreamContext(null);
+ TmfEvent event = fStream.getEvent(context, startTime);
+ while (!request.isCancelled() && nbEvents < nbRequestedEvents &&
+ event != null && event.getTimestamp().compareTo(endTime, false) <= 0 )
+ {
+ events.add(event);
+ if (++nbEvents % blockSize == 0) {
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+ request.handlePartialResult();
+ events.removeAllElements();
+ }
+ event = fStream.getNextEvent(context);
+ }
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+
+ request.setData(result);
+ request.handlePartialResult();
+ request.done();
+ }
+ };
+ thread.start();
+
+ if (waitForCompletion) {
+ request.waitForCompletion();
+ }
+ }
+
+}
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
+import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
import org.eclipse.linuxtools.tmf.event.TmfEventReference;
import org.eclipse.linuxtools.tmf.event.TmfEventSource;
import org.eclipse.linuxtools.tmf.event.TmfEventType;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
/**
* <b><u>TmfEventParserStub</u></b>
*/
public class TmfEventParserStub implements ITmfEventParser {
- // ------------------------------------------------------------------------
+ // ========================================================================
// Attributes
- // ------------------------------------------------------------------------
+ // ========================================================================
- private final int NB_TYPES = 10;
- private final TmfEventType[] fTypes;
+ private final int NB_FORMATS = 10;
+ private final TmfEventFormat[] fFormats;
- // ------------------------------------------------------------------------
+ // ========================================================================
// Constructors
- // ------------------------------------------------------------------------
+ // ========================================================================
public TmfEventParserStub() {
- fTypes = new TmfEventType[NB_TYPES];
- for (int i = 0; i < NB_TYPES; i++) {
+ fFormats = new TmfEventFormat[NB_FORMATS];
+ for (int i = 0; i < NB_FORMATS; i++) {
Vector<String> format = new Vector<String>();
for (int j = 1; j <= i; j++) {
format.add(new String("Fmt-" + i + "-Fld-" + j));
}
String[] fields = new String[i];
- fTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields));
+ fFormats[i] = new TmfEventFormat(format.toArray(fields));
}
}
- // ------------------------------------------------------------------------
+ // ========================================================================
// Operators
- // ------------------------------------------------------------------------
+ // ========================================================================
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
+ */
static final String typePrefix = "Type-";
- @SuppressWarnings("unchecked")
- public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfContext context) throws IOException {
+ public TmfEvent getNextEvent(ITmfEventStream eventStream) throws IOException {
- if (! (eventStream instanceof TmfTraceStub)) {
+ if (! (eventStream instanceof TmfEventStreamStub)) {
return null;
}
- // Highly inefficient...
- RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
- String name = eventStream.getName();
- name = name.substring(name.lastIndexOf('/') + 1);
-
- synchronized(stream) {
- long location = 0;
- if (context != null)
- location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
- stream.seek(location);
-
- try {
- long ts = stream.readLong();
- String source = stream.readUTF();
- String type = stream.readUTF();
- @SuppressWarnings("unused")
- int reference = stream.readInt();
- int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
- String[] fields = new String[typeIndex];
- for (int i = 0; i < typeIndex; i++) {
- fields[i] = stream.readUTF();
- }
-
- String content = "[";
- if (typeIndex > 0) {
- content += fields[0];
- }
- for (int i = 1; i < typeIndex; i++) {
- content += ", " + fields[i];
- }
- content += "]";
-
- TmfEvent event = new TmfEvent(
- new TmfTimestamp(ts, (byte) -3, 0), // millisecs
- new TmfEventSource(source),
- fTypes[typeIndex],
- new TmfEventReference(name));
- TmfEventContent cnt = new TmfEventContent(event, content);
- event.setContent(cnt);
- return event;
- } catch (EOFException e) {
- }
+ RandomAccessFile stream = ((TmfEventStreamStub) eventStream).getStream();
+
+ try {
+ long ts = stream.readLong();
+ String source = stream.readUTF();
+ String type = stream.readUTF();
+ int reference = stream.readInt();
+ int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
+ String[] fields = new String[typeIndex];
+ for (int i = 0; i < typeIndex; i++) {
+ fields[i] = stream.readUTF();
+ }
+ String content = "[";
+ for (int i = 0; i < typeIndex - 1; i++) {
+ content += fields[i] + ", ";
+ }
+ content += "]";
+
+ TmfEvent event = new TmfEvent(
+ new TmfTimestamp(ts, (byte) -3, 0), // millisecs
+ new TmfEventSource(source),
+ new TmfEventType(type, fFormats[typeIndex]),
+ new TmfEventContent(content, fFormats[typeIndex]),
+ new TmfEventReference(reference));
+ return event;
+ } catch (EOFException e) {
}
return null;
}
-}
\ No newline at end of file
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Map;
+
+import org.eclipse.linuxtools.tmf.stream.AbstractTmfEventStream;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
+
+/**
+ * <b><u>TmfEventStreamStub</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfEventStreamStub extends AbstractTmfEventStream {
+
+ // ========================================================================
+ // Attributes
+ // ========================================================================
+
+ // The actual stream
+ private final RandomAccessFile fStream;
+
+ // ========================================================================
+ // Constructors
+ // ========================================================================
+
+ /**
+ * @param filename
+ * @param parser
+ * @throws FileNotFoundException
+ */
+ public TmfEventStreamStub(String filename, ITmfEventParser parser) throws FileNotFoundException {
+ this(filename, parser, DEFAULT_CACHE_SIZE);
+ }
+
+ /**
+ * @param filename
+ * @param parser
+ * @param cacheSize
+ * @throws FileNotFoundException
+ */
+ public TmfEventStreamStub(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
+ super(filename, parser, cacheSize);
+ fStream = new RandomAccessFile(filename, "r");
+ indexStream(true);
+ }
+
+ // ========================================================================
+ // Accessors
+ // ========================================================================
+
+ public RandomAccessFile getStream() {
+ return fStream;
+ }
+
+ // ========================================================================
+ // Operators
+ // ========================================================================
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
+ */
+ public StreamContext seekLocation(Object location) {
+ StreamContext context = null;
+ try {
+ fStream.seek((location != null) ? (Long) location : 0);
+ context = new StreamContext(getCurrentLocation());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return context;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
+ */
+ public Object getCurrentLocation() {
+ try {
+ return new Long(fStream.getFilePointer());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ // ========================================================================
+ // Helper functions
+ // ========================================================================
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
+ */
+ public Map<String, Object> getAttributes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Import-Package: org.junit.runner
Export-Package: org.eclipse.linuxtools.tmf,
org.eclipse.linuxtools.tmf.event,
- org.eclipse.linuxtools.tmf.eventlog
+ org.eclipse.linuxtools.tmf.request,
+ org.eclipse.linuxtools.tmf.stream,
+ org.eclipse.linuxtools.tmf.trace
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import java.io.IOException;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-
-/**
- * <b><u>ITmfEventParser</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public interface ITmfEventParser {
-
- /**
- * @return
- * @throws IOException
- */
- public TmfEvent getNextEvent(TmfEventStream stream) throws IOException;
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-/**
- * <b><u>ITmfRequestHandler</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public interface ITmfRequestHandler {
-
- /**
- * Process the request. The client thread can be suspended until the
- * request is completed (e.g. for a specific range of events) or it
- * can choose to process the events asynchronously (e.g. for streaming).
- *
- * @param waitForCompletion Suspend the client thread until the request completes or is canceled
- */
- public void process(TmfEventRequest request, boolean waitForCompletion);
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import java.io.IOException;
-
-/**
- * <b><u>ITmfStreamLocator</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public interface ITmfStreamLocator {
-
- public void seekLocation(Object location) throws IOException;
- public Object getCurrentLocation();
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-/**
- * <b><u>TmfEventCache</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfEventCache {
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- // ========================================================================
- // Helper functions
- // ========================================================================
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-/**
- * <b><u>TmfEventLogSet</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfEventLogSet {
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- // ========================================================================
- // Helper functions
- // ========================================================================
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import java.util.Vector;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-
-/**
- * <b><u>TmfEventRequest</u></b>
- * <p>
- * TmfEventRequests are used to obtain blocks of contiguous events from an
- * event stream, either all the events within a given time window or n events
- * starting a a specific timestamp. Open ranges can be used, especially for
- * continuous streaming.
- * <p>
- * The request is processed asynchronously by an ITmfRequestProcessor and,
- * as blocks of events become available, the callback function newEvents()
- * is invoked, synchronously, for each block. When returning from newEvents(),
- * the event instances go out of scope and become eligible for gc. It is
- * is thus the responsibility of the requester to either copy or keep a
- * reference to the events it wishes to track specifically.
- * <p>
- * This event block approach is necessary to avoid busting the heap for very
- * large trace files. The block size is configurable.
- * <p>
- * The ITmfRequestProcessor indicates that the request is completed by
- * calling done(). The request can be canceled at any time with cancel().
- * <p>
- * Typical usage:
- *<pre><code><i>TmfTimeWindow range = new TmfTimewindow(...);
- *TmfEventRequest request = new TmfEventRequest(range, 0, NB_EVENTS, BLOCK_SIZE) {
- * @Override
- * public void newEvents(Vector<TmfEvent> events) {
- * for (TmfEvent e : events) {
- * // do something
- * }
- * }
- *};
- *fProcessor.process(request, true);
- *</i></code></pre>
- *
- * TODO: Consider extending DataRequestMonitor from DSF concurrency plugin.
- * The main issue is the slicing of the result in blocks and continuous
- * streams.
- */
-public class TmfEventRequest {
-
- // ========================================================================
- // Constants
- // ========================================================================
-
- // The default maximum number of events per chunk
- public static final int DEFAULT_BLOCK_SIZE = 1000;
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- private final TmfTimeRange fRange; // The requested events timestamp range
- private final long fOffset; // The synchronization offset to apply
- private final int fNbRequestedEvents; // The number of events to read (-1 == the whole range)
- private final int fBlockSize; // The maximum number of events per chunk
-
- private Object lock = new Object();
- private boolean fRequestCompleted = false;
- private boolean fRequestCanceled = false;
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- /**
- * @param range
- * @param offset
- * @param nbEvents
- */
- public TmfEventRequest(TmfTimeRange range, long offset, int nbEvents) {
- this(range, offset, nbEvents, DEFAULT_BLOCK_SIZE);
- }
-
- /**
- * @param range
- * @param offset
- * @param nbEvents
- * @param maxBlockSize Size of the largest blocks expected
- */
- public TmfEventRequest(TmfTimeRange range, long offset, int nbEvents, int maxBlockSize) {
- fRange = range;
- fOffset = offset;
- fNbRequestedEvents = nbEvents;
- fBlockSize = maxBlockSize;
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- /**
- * @return the requested time range
- */
- public TmfTimeRange getRange() {
- return fRange;
- }
-
- /**
- * @return the offset
- */
- public long getOffset() {
- return fOffset;
- }
-
- /**
- * @return the number of requested events (-1 = all)
- */
- public int getNbRequestedEvents() {
- return fNbRequestedEvents;
- }
-
- /**
- * @return the block size
- */
- public int getBlockize() {
- return fBlockSize;
- }
-
- /**
- * @return indicates if the request is completed
- */
- public boolean isCompleted() {
- return fRequestCompleted;
- }
-
- /**
- * @return indicates if the request is canceled
- */
- public boolean isCancelled() {
- return fRequestCanceled;
- }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- /**
- * newEvents()
- *
- * - Events are received in the order they appear in the stream.
- * - Called by the request processor, in its execution thread, every time a
- * block of events becomes available.
- * - Request processor performs a synchronous call to newEvents()
- * i.e. its execution threads holds until newEvents() returns.
- * - Original events are disposed of on return i.e. keep a reference (or a
- * copy) if some persistence is needed between invocations.
- * - When there are no more events,
- *
- * @param events - an array of events
- */
- public void newEvents(Vector<TmfEvent> events) {
- }
-
- /**
- * To suspend the client thread until the request completes (or is
- * canceled).
- *
- * @throws InterruptedException
- */
- public void waitForCompletion() {
- synchronized (lock) {
- while (!fRequestCompleted)
- try {
- lock.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Complete the request. Called by the request processor upon completion.
- */
- public void done() {
- synchronized(lock) {
- fRequestCompleted = true;
- lock.notify();
- }
- }
-
- /**
- * Cancel the request.
- */
- public void cancel() {
- synchronized(lock) {
- fRequestCanceled = true;
- fRequestCompleted = true;
- lock.notify();
- }
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.util.Collections;
-import java.util.Vector;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-
-/**
- * <b><u>TmfEventStream</u></b>
- * <p>
- * FIXME: Preliminary version that works only for a single file
- * FIXME: Need to handle more generic streams (sockets, pipes, ...), directories, ...
- * FIXME: Will also need to update properly the set of bookmarks for streaming data
- */
-public abstract class TmfEventStream extends RandomAccessFile implements ITmfStreamLocator {
-
- // ========================================================================
- // Constants
- // ========================================================================
-
- // The default number of events to cache
- public static final int DEFAULT_CACHE_SIZE = 1000;
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- // The file parser
- private final ITmfEventParser fParser;
-
- // The cache size
- private final int fCacheSize;
-
- // The set of event stream bookmarks (for random access)
- private Vector<TmfStreamBookmark> fBookmarks = new Vector<TmfStreamBookmark>();
-
- // The number of events collected
- private int fNbEvents = 0;
-
- // The time span of the event stream
- private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- /**
- * @param filename
- * @param parser
- * @throws FileNotFoundException
- */
- public TmfEventStream(String filename, ITmfEventParser parser) throws FileNotFoundException {
- this(filename, parser, DEFAULT_CACHE_SIZE);
- }
-
- /**
- * @param filename
- * @param parser
- * @param cacheSize
- * @throws FileNotFoundException
- */
- public TmfEventStream(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
- super(filename, "r");
- assert(parser != null);
- fParser = parser;
- fCacheSize = cacheSize;
- bookmark();
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- /**
- * @return
- */
- public int getCacheSize() {
- return fCacheSize;
- }
-
- /**
- * @return
- */
- public int getNbEvents() {
- return fNbEvents;
- }
-
- /**
- * @return
- */
- public TmfTimeRange getTimeRange() {
- return fTimeRange;
- }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- /**
- * Positions the stream at the first event with timestamp. If there is no
- * such event, positions the stream at the next event, if any.
- *
- * @param timestamp
- * @return
- * @throws IOException
- */
- public synchronized TmfEvent seek(TmfTimestamp timestamp) throws IOException {
-
- // First, find the right bookmark
- // TODO: Check the performance of bsearch on ordered Vector<>. Should be OK but...
- int index = Collections.binarySearch(fBookmarks, new TmfStreamBookmark(timestamp, 0));
-
- // In the very likely event that the bookmark was not found, bsearch
- // returns its negated would-be location (not an offset...). From that
- // index, we can then position the stream and locate the event.
- if (index < 0) {
- index = Math.max(0, -(index + 2));
- }
-
- seekLocation(fBookmarks.elementAt(index).getLocation());
- TmfEvent event;
- do {
- event = getNextEvent();
- } while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0);
-
- return event;
- }
-
- /**
- * @return
- */
- public synchronized TmfEvent getNextEvent() {
- try {
- return fParser.getNextEvent(this);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- // ========================================================================
- // Helper functions
- // ========================================================================
-
- /**
- * Parse the file and store bookmarks at every fCacheSize event.
- * Done once at the creation of the event stream.
- *
- * TODO: Consider a Job with progress bar, etc...
- */
- protected synchronized void bookmark() {
- try {
- seek(0);
- TmfTimestamp startTime = new TmfTimestamp();
- TmfTimestamp lastTime = new TmfTimestamp();
- Object location = getCurrentLocation();
-
- TmfEvent event = getNextEvent();
- if (event != null) {
- startTime = event.getTimestamp();
- while (event != null) {
- lastTime = event.getTimestamp();
- if ((fNbEvents++ % fCacheSize) == 0) {
- TmfStreamBookmark bookmark = new TmfStreamBookmark(lastTime, location);
- fBookmarks.add(bookmark);
- }
- location = getCurrentLocation();
- event = getNextEvent();
- }
- fTimeRange = new TmfTimeRange(startTime, lastTime);
- }
- seek(0);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-
-/**
- * <b><u>TmfStreamBookmark</u></b>
- * <p>
- * This class maps an event timestamp with a trace location.
- */
-public class TmfStreamBookmark implements Comparable<TmfStreamBookmark> {
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- private final TmfTimestamp fTimestamp;
- private final Object fLocation;
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- /**
- * @param ts
- * @param location
- */
- public TmfStreamBookmark(TmfTimestamp ts, Object location) {
- fTimestamp = ts;
- fLocation = location;
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- /**
- * @return the bookmarked event timestamp
- */
- public TmfTimestamp getTimestamp() {
- return fTimestamp;
- }
-
- /**
- * @return the bookmarked event stream location
- */
- public Object getLocation() {
- return fLocation;
- }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- public int compareTo(TmfStreamBookmark other) {
- return fTimestamp.compareTo(other.fTimestamp, false);
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-/**
- * <b><u>TmfSynchFunction</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfSynchFunction {
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- // ========================================================================
- // Helper functions
- // ========================================================================
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.eventlog;
-
-import java.io.IOException;
-import java.util.Vector;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-
-/**
- * <b><u>TmfEventLog</u></b>
- * <p>
- * TmfEventLog represents a time-ordered set of events tied to a single event
- * stream. It keeps track of the global information about the event log:
- * <ul>
- * <li> the epoch, a reference timestamp for the whole log (t0)
- * <li> the span of the log i.e. the timestamps range
- * <li> the total number of events
- * </ul>
- * As an ITmfRequestHandler, it provides an implementation of process()
- * which handles event requests.
- * <p>
- * TODO: Handle concurrent and possibly overlapping requests in a way that
- * optimizes the stream access and event parsing.
- */
-public class TmfTrace implements ITmfRequestHandler {
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- private final String fId;
- private final TmfEventStream fStream;
- private final TmfTimestamp fEpoch;
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- public TmfTrace(String id, TmfEventStream stream) {
- assert stream != null;
- fId = id;
- fStream = stream;
- fEpoch = TmfTimestamp.BigBang;
- }
-
- public TmfTrace(String id, TmfEventStream stream, TmfTimestamp epoch) {
- assert stream != null;
- fId = id;
- fStream = stream;
- fEpoch = epoch;
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- public String getId() {
- return fId;
- }
-
- public TmfEventStream getStream() {
- return fStream;
- }
-
- public TmfTimestamp getEpoch() {
- return fEpoch;
- }
-
- public TmfTimeRange getTimeRange() {
- return fStream.getTimeRange();
- }
-
- public int getNbEvents() {
- return fStream.getNbEvents();
- }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestExecutor#execute(org.eclipse.linuxtools.tmf.eventlog.TmfEventRequest, boolean)
- */
- public void process(final TmfEventRequest request, boolean waitForCompletion) {
- serviceEventRequest(request);
- if (waitForCompletion) {
- request.waitForCompletion();
- }
- }
-
- // ========================================================================
- // Helper functions
- // ========================================================================
-
- /* (non-Javadoc)
- *
- * @param request
- */
- private void serviceEventRequest(final TmfEventRequest request) {
- Thread thread = new Thread() {
- @Override
- public void run() {
- TmfTimestamp startTime = request.getRange().getStartTime();
- TmfTimestamp endTime = request.getRange().getEndTime();
- int blockSize = request.getBlockize();
-
- int nbRequestedEvents = request.getNbRequestedEvents();
- if (nbRequestedEvents == -1) {
- nbRequestedEvents = Integer.MAX_VALUE;
- }
-
- Vector<TmfEvent> events = new Vector<TmfEvent>();
- int nbEvents = 0;
- try {
- TmfEvent event = fStream.seek(startTime);
- while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null &&
- event.getTimestamp().compareTo(endTime, false) <= 0 )
- {
- events.add(event);
- if (++nbEvents % blockSize == 0) {
- request.newEvents(events);
- events.removeAllElements();
- }
- event = fStream.getNextEvent();
- }
- request.newEvents(events);
- request.done();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- };
- thread.start();
- }
-
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.request;
+
+/**
+ * <b><u>ITmfRequestHandler</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ * @param <V>
+ */
+public interface ITmfRequestHandler<T> {
+
+ /**
+ * Process the request. The client thread can be suspended until the
+ * request is completed (e.g. for a specific range of events) or it
+ * can choose to process the events asynchronously (e.g. for streaming).
+ *
+ * @param waitForCompletion Suspend the client thread until the request completes or is cancelled
+ */
+ public void processRequest(TmfDataRequest<T> request, boolean waitForCompletion);
+
+}
\ No newline at end of file
/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.linuxtools.tmf.request;
-import org.eclipse.linuxtools.tmf.Tracer;
-import org.eclipse.linuxtools.tmf.event.TmfData;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
/**
* <b><u>TmfDataRequest</u></b>
* <p>
* TmfDataRequests are used to obtain blocks of contiguous data from a data
- * provider. Open ranges can be used, especially for continuous streaming.
+ * provider, either all the data within a given time window or n elements
+ * starting at a specific timestamp. Open ranges can be used, especially for
+ * continuous streaming.
* <p>
- * The request is processed asynchronously by a TmfProvider and, as blocks
- * of data become available, handleData() is invoked synchronously for each
- * block. Upon return, the data instances go out of scope and become eligible
- * for gc. It is is thus the responsibility of the requester to either clone
- * or keep a reference to the data it wishes to track specifically.
+ * The request is processed asynchronously by an ITmfRequestProcessor and,
+ * as blocks of data become available, the callback handlePartialData() is
+ * invoked, synchronously, for each block. When returning from the callback,
+ * the data instances go out of scope and become eligible for gc. It is
+ * is thus the responsibility of the requester to either copy or keep a
+ * reference to the data it wishes to track specifically.
* <p>
- * This data block approach is used to avoid busting the heap for very
- * large trace files. The block size is configurable.
+ * This data block approach is necessary to avoid busting the heap for very
+ * large trace files. The block size is configurable.
* <p>
- * The TmfProvider indicates that the request is completed by calling done().
- * The request can be canceled at any time with cancel().
+ * The ITmfRequestProcessor indicates that the request is completed by
+ * calling done(). The request can be canceled at any time with cancel().
* <p>
* Typical usage:
*<pre><code><i>TmfTimeWindow range = new TmfTimewindow(...);
- *TmfDataRequest<DataType[]> request = new TmfDataRequest<DataType[]>(DataType.class, 0, NB_EVENTS, BLOCK_SIZE) {
- * public void handleData() {
+ *TmfDataRequest<DataType[]> request = new TmfDataRequest<DataType[]>(range, 0, NB_EVENTS, BLOCK_SIZE) {
+ * @Override
+ * public void handlePartialResult() {
* DataType[] data = request.getData();
* for (DataType e : data) {
* // do something
* }
* }
- * public void handleSuccess() {
- * // do something
- * }
- * }
- * public void handleFailure() {
- * // do something
- * }
- * }
- * public void handleCancel() {
- * // do something
- * }
- * }
*};
*fProcessor.process(request, true);
*</i></code></pre>
*
- * TODO: Consider decoupling from "time range", "rank", etc and for the more
- * generic notion of "criteria". This would allow to extend for "time range", etc
- * instead of providing specialized constructors. This also means removing the
- * criteria info from the data structure (with the possible exception of fNbRequested).
- * The nice thing about it is that it would prepare us well for the coming generation
- * of analysis tools.
- *
- * TODO: Implement request failures (codes, etc...)
+ * TODO: Consider extending DataRequestMonitor from DSF concurrency plugin.
+ * The main issue is the slicing of the result in blocks and continuous
+ * streams. This would require using a thread executor and to carefully
+ * look at setData() and getData().
*/
-public abstract class TmfDataRequest<T extends TmfData> implements ITmfDataRequest<T> {
+public class TmfDataRequest<V> {
- // ------------------------------------------------------------------------
+ // ========================================================================
// Constants
- // ------------------------------------------------------------------------
+ // ========================================================================
// The default maximum number of events per chunk
public static final int DEFAULT_BLOCK_SIZE = 1000;
// The request count for all the events
- public static final int ALL_DATA = Integer.MAX_VALUE;
+ public static final int ALL_EVENTS = -1;
- private static int fRequestNumber = 0;
-
- // ------------------------------------------------------------------------
+ // ========================================================================
// Attributes
- // ------------------------------------------------------------------------
+ // ========================================================================
- private final Class<T> fDataType;
- private final int fRequestId; // A unique request ID
- private final int fIndex; // The index (rank) of the requested event
- private final int fNbRequested; // The number of requested events (ALL_DATA for all)
- private final int fBlockSize; // The maximum number of events per chunk
- private int fNbRead; // The number of reads so far
+ private final TmfTimeRange fRange; // The requested events timestamp range
+ private final int fIndex; // The event index to get
+ private final long fOffset; // The synchronization offset to apply
+ private final int fNbRequestedItems; // The number of items to read (-1 == the whole range)
+ private final int fBlockSize; // The maximum number of events per chunk
- private final Object lock;
- private boolean fRequestRunning = false;
+ private Object lock = new Object();
private boolean fRequestCompleted = false;
- private boolean fRequestFailed = false;
private boolean fRequestCanceled = false;
- private T[] fData; // Data object
+ private V[] fData; // Data object
- // ------------------------------------------------------------------------
+ // ========================================================================
// Constructors
- // ------------------------------------------------------------------------
+ // ========================================================================
/**
- * Resets the request counter (used for testing)
+ * @param index
+ * @param nbEvents
*/
- public static void reset() {
- fRequestNumber = 0;
+ public TmfDataRequest(int index, long offset, int nbEvents) {
+ this(null, index, offset, nbEvents, DEFAULT_BLOCK_SIZE);
}
/**
- * Default constructor
- *
- * @param dataType the requested data type
+ * @param range
+ * @param offset
+ * @param nbEvents
*/
- public TmfDataRequest(Class<T> dataType) {
- this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE);
+ public TmfDataRequest(TmfTimeRange range, long offset, int nbEvents) {
+ this(range, 0, offset, nbEvents, DEFAULT_BLOCK_SIZE);
}
/**
- * @param dataType the requested data type
- * @param nbRequested the number of data items requested
+ * @param range
+ * @param offset
+ * @param nbItems
+ * @param maxBlockSize Size of the largest blocks expected
*/
- public TmfDataRequest(Class<T> dataType, int index) {
- this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE);
+ public TmfDataRequest(TmfTimeRange range, long offset, int nbEvents, int maxBlockSize) {
+ this(range, 0, offset, nbEvents, maxBlockSize);
}
/**
- * @param dataType the requested data type
- * @param index the index (rank) of the first event requested
- * @param blockSize the number of data items per block
+ * @param range
+ * @param index
+ * @param offset
+ * @param nbItems
+ * @param maxBlockSize Size of the largest blocks expected
*/
- public TmfDataRequest(Class<T> dataType, int index, int nbRequested) {
- this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE);
+ public TmfDataRequest(TmfTimeRange range, int index, long offset, int nbEvents, int maxBlockSize) {
+ fRange = range;
+ fIndex = index;
+ fOffset = offset;
+ fNbRequestedItems = nbEvents;
+ fBlockSize = maxBlockSize;
}
- /**
- * @param dataType the requested data type
- * @param index the index (rank) of the first event requested
- * @param nbRequested the number of data items requested
- * @param blockSize the number of data items per block
- */
- public TmfDataRequest(Class<T> dataType, int index, int nbRequested, int blockSize) {
- fRequestId = fRequestNumber++;
- fDataType = dataType;
- fIndex = index;
- fNbRequested = nbRequested;
- fBlockSize = blockSize;
- fNbRead = 0;
- lock = new Object();
- if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "created");
- }
+ // ========================================================================
+ // Accessors
+ // ========================================================================
/**
- * Copy constructor
+ * @return the requested time range
*/
- @SuppressWarnings("unused")
- private TmfDataRequest(TmfDataRequest<T> other) {
- this(null, 0, ALL_DATA, DEFAULT_BLOCK_SIZE);
+ public TmfTimeRange getRange() {
+ return fRange;
}
- // ------------------------------------------------------------------------
- // Accessors
- // ------------------------------------------------------------------------
-
- /**
- * @return the request ID
- */
- public int getRequestId() {
- return fRequestId;
- }
-
- /**
- * @return the index of the first event requested
- */
- public int getIndex() {
- return fIndex;
- }
-
/**
- * @return the number of requested events (ALL_DATA = all)
+ * @return the index
*/
- public int getNbRequested() {
- return fNbRequested;
+ public int getIndex() {
+ return fIndex;
}
/**
- * @return the block size
+ * @return the offset
*/
- public int getBlockize() {
- return fBlockSize;
+ public long getOffset() {
+ return fOffset;
}
/**
- * @return the number of events read so far
+ * @return the number of requested events (-1 = all)
*/
- public synchronized int getNbRead() {
- return fNbRead;
+ public int getNbRequestedItems() {
+ return fNbRequestedItems;
}
/**
- * @return indicates if the request is completed
+ * @return the block size
*/
- public boolean isRunning() {
- return fRequestRunning;
+ public int getBlockize() {
+ return fBlockSize;
}
/**
return fRequestCompleted;
}
- /**
- * @return indicates if the request is canceled
- */
- public boolean isFailed() {
- return fRequestFailed;
- }
-
/**
* @return indicates if the request is canceled
*/
return fRequestCanceled;
}
- /**
- * @return the requested data type
- */
- public Class<T> getDataType() {
- return fDataType;
- }
-
- // ------------------------------------------------------------------------
+ // ========================================================================
// Operators
- // ------------------------------------------------------------------------
+ // ========================================================================
/**
- * Sets the data object to specified value. To be called by the
+ * Sets the data object to specified value. To be called by the
* asynchronous method implementor.
* @param data Data value to set.
*/
- public synchronized void setData(T[] data) {
- fNbRead += data.length;
+ public synchronized void setData(V[] data) {
fData = data;
}
/**
* Returns the data value, null if not set.
*/
- public synchronized T[] getData() {
+ public synchronized V[] getData() {
return fData;
}
/**
- * Handle a block of incoming data. This method is called every time
- * a block of data becomes available.
+ * handlePartialResult()
*
* - Data items are received in the order they appear in the stream.
* - Called by the request processor, in its execution thread, every time a
*
* @param events - an array of events
*/
- public abstract void handleData();
-
- public void handleStarted() {
+ public void handlePartialResult() {
}
- /**
- * Handle the completion of the request. It is called when there is no more
- * data available either because:
- * - the request completed normally
- * - the request failed
- * - the request was canceled
- *
- * As a convenience, handleXXXX methods are provided. They are meant to be
- * overridden by the application if it needs to handle these conditions.
- */
public void handleCompleted() {
- if (fRequestFailed) {
- if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "failed");
- handleFailure();
- }
- else if (fRequestCanceled) {
- if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "cancelled");
- handleCancel();
- }
- else {
- if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "succeeded");
- handleSuccess();
- }
- }
-
- public void handleSuccess() {
- }
-
- public void handleFailure() {
- }
-
- public void handleCancel() {
}
/**
*
* @throws InterruptedException
*/
- public void waitForCompletion() throws InterruptedException {
+ public void waitForCompletion() {
synchronized (lock) {
while (!fRequestCompleted)
- lock.wait();
- }
- }
-
- /**
- * Called by the request processor upon starting to service the request.
- */
- public void start() {
- if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "starting");
- synchronized(lock) {
- fRequestRunning = true;
- lock.notify();
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
- handleStarted();
- if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "started");
}
/**
- * Called by the request processor upon completion.
+ * Complete the request. Called by the request processor upon completion.
*/
public void done() {
- if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "completing");
synchronized(lock) {
- fRequestRunning = false;
fRequestCompleted = true;
lock.notify();
}
}
/**
- * Called by the request processor upon failure.
- */
- public void fail() {
- synchronized(lock) {
- fRequestFailed = true;
- done();
- }
- }
-
- /**
- * Called by the request processor upon cancellation.
+ * Cancel the request.
*/
public void cancel() {
synchronized(lock) {
fRequestCanceled = true;
- done();
+ fRequestCompleted = true;
+ lock.notify();
}
}
- // ------------------------------------------------------------------------
- // Object
- // ------------------------------------------------------------------------
-
- @Override
- // All requests have a unique id
- public int hashCode() {
- return getRequestId();
- }
-
- @Override
- public boolean equals(Object other) {
- if (other instanceof TmfDataRequest<?>) {
- TmfDataRequest<?> request = (TmfDataRequest<?>) other;
- return (request.fDataType == fDataType) &&
- (request.fIndex == fIndex) &&
- (request.fNbRequested == fNbRequested);
- }
- return false;
- }
-
- @Override
- public String toString() {
- return "[TmfDataRequest(" + fRequestId + "," + fDataType.getSimpleName()
- + "," + fIndex + "," + fNbRequested + "," + fBlockSize + ")]";
- }
-
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.stream;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.trace.TmfTrace;
+
+/**
+ * <b><u>AbstractTmfEventStream</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public abstract class AbstractTmfEventStream implements ITmfEventStream {
+
+ // ========================================================================
+ // Constants
+ // ========================================================================
+
+ // The default number of events to cache
+ public static final int DEFAULT_CACHE_SIZE = 1000;
+
+ // ========================================================================
+ // Attributes
+ // ========================================================================
+
+ // The stream name
+ private final String fName;
+
+ // The stream parser
+ private final ITmfEventParser fParser;
+
+ // The cache size
+ private final int fCacheSize;
+
+ // The set of event stream checkpoints (for random access)
+ private Vector<TmfStreamCheckpoint> fCheckpoints = new Vector<TmfStreamCheckpoint>();
+
+ // The number of events collected
+ private int fNbEvents = 0;
+
+ // The time span of the event stream
+ private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
+
+ // The listeners
+ private Set<TmfTrace> fListeners = new HashSet<TmfTrace>();
+
+ // ========================================================================
+ // Constructors
+ // ========================================================================
+
+ /**
+ * @param filename
+ * @param parser
+ * @param cacheSize
+ * @throws FileNotFoundException
+ */
+ protected AbstractTmfEventStream(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
+ fName = filename;
+ fParser = parser;
+ fCacheSize = cacheSize;
+ }
+
+ /**
+ * @param filename
+ * @param parser
+ * @throws FileNotFoundException
+ */
+ protected AbstractTmfEventStream(String filename, ITmfEventParser parser) throws FileNotFoundException {
+ this(filename, parser, DEFAULT_CACHE_SIZE);
+ }
+
+ // ========================================================================
+ // Accessors
+ // ========================================================================
+
+ /**
+ * @return
+ */
+ public int getCacheSize() {
+ return fCacheSize;
+ }
+
+ /**
+ * @return
+ */
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * @return
+ */
+ public synchronized int getNbEvents() {
+ return fNbEvents;
+ }
+
+ /**
+ * @return
+ */
+ public synchronized TmfTimeRange getTimeRange() {
+ return fTimeRange;
+ }
+
+ // ========================================================================
+ // Operators
+ // ========================================================================
+
+ public StreamContext seekEvent(TmfTimestamp timestamp) {
+
+ // First, find the right checkpoint
+ int index = Collections.binarySearch(fCheckpoints, new TmfStreamCheckpoint(timestamp, 0));
+
+ // In the very likely event that the checkpoint was not found, bsearch
+ // returns its negated would-be location (not an offset...). From that
+ // index, we can then position the stream and get the event.
+ if (index < 0) {
+ index = Math.max(0, -(index + 2));
+ }
+
+ // Position the stream at the checkpoint
+ Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(location);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+
+ // And get the event
+ TmfEvent event = getNextEvent(nextEventContext);
+ while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
+ currentEventContext.location = nextEventContext.location;
+ event = getNextEvent(nextEventContext);
+ }
+
+ return currentEventContext;
+ }
+
+ public StreamContext seekEvent(int position) {
+
+ // Position the stream at the previous checkpoint
+ int index = position / fCacheSize;
+ Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(location);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+
+ // And locate the event (if it exists)
+ int current = index * fCacheSize;
+ TmfEvent event = getNextEvent(nextEventContext);
+ while (event != null && current < position) {
+ currentEventContext.location = nextEventContext.location;
+ event = getNextEvent(nextEventContext);
+ current++;
+ }
+
+ return currentEventContext;
+ }
+
+ public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp) {
+
+ // Position the stream and update the context object
+ StreamContext ctx = seekEvent(timestamp);
+ context.location = ctx.location;
+
+ return getNextEvent(context);
+ }
+
+ public TmfEvent getEvent(StreamContext context, int position) {
+
+ // Position the stream and update the context object
+ StreamContext ctx = seekEvent(position);
+ context.location = ctx.location;
+
+ return getNextEvent(context);
+ }
+
+ public synchronized TmfEvent getNextEvent(StreamContext context) {
+ try {
+ seekLocation(context.location);
+ TmfEvent event = fParser.getNextEvent(this);
+ context.location = getCurrentLocation();
+ return event;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public synchronized void addListener(TmfTrace listener) {
+ fListeners.add(listener);
+ }
+
+ public synchronized void removeListener(TmfTrace listener) {
+ fListeners.remove(listener);
+ }
+
+ private synchronized void notifyListeners() {
+ for (TmfTrace listener : fListeners) {
+ listener.handleEvent(new TmfStreamUpdateEvent(this));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#indexStream()
+ */
+ public void indexStream(boolean waitForCompletion) {
+ IndexingJob job = new IndexingJob(fName);
+ job.schedule();
+ if (waitForCompletion) {
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private class IndexingJob extends Job {
+
+ public IndexingJob(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+
+ int nbEvents = 0;
+ TmfTimestamp startTime = new TmfTimestamp();
+ TmfTimestamp lastTime = new TmfTimestamp();
+
+ monitor.beginTask("Indexing " + fName, IProgressMonitor.UNKNOWN);
+
+ try {
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(null);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+ TmfEvent event = getNextEvent(nextEventContext);
+ if (event != null) {
+ startTime = event.getTimestamp();
+ lastTime = event.getTimestamp();
+ }
+
+ while (event != null) {
+ lastTime = event.getTimestamp();
+ if ((nbEvents++ % fCacheSize) == 0) {
+ TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(lastTime, currentEventContext.location);
+ synchronized(this) {
+ fCheckpoints.add(bookmark);
+ fNbEvents = nbEvents;
+ fTimeRange = new TmfTimeRange(startTime, lastTime);
+ }
+ notifyListeners();
+ monitor.worked(1);
+ // Check monitor *after* fCheckpoints has been updated
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ }
+
+ currentEventContext.location = nextEventContext.location;
+ event = getNextEvent(nextEventContext);
+ }
+ }
+ finally {
+ synchronized(this) {
+ fNbEvents = nbEvents;
+ fTimeRange = new TmfTimeRange(startTime, lastTime);
+ }
+ notifyListeners();
+ monitor.done();
+ }
+
+ return Status.OK_STATUS;
+ }
+ }
+
+ public void indexStream(final String filename) {
+
+// ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
+// try {
+// dialog.run(true, true, new IRunnableWithProgress() {
+// @Override
+// public void run(IProgressMonitor monitor)
+// throws InvocationTargetException, InterruptedException {
+// monitor.beginTask("Indexing " + filename,
+// IProgressMonitor.UNKNOWN);
+//
+// try {
+// seekLocation(null);
+// TmfTimestamp startTime = new TmfTimestamp();
+// TmfTimestamp lastTime = new TmfTimestamp();
+// Object location = getCurrentLocation();
+//
+// TmfEvent event = getNextEvent();
+// if (event != null) {
+// startTime = event.getTimestamp();
+// while (event != null) {
+// lastTime = event.getTimestamp();
+// if ((fNbEvents++ % fCacheSize) == 0) {
+// if (monitor.isCanceled()) {
+// throw new CancellationException();
+// }
+// TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(
+// lastTime, location);
+// fCheckpoints.add(bookmark);
+// monitor.worked(1);
+// }
+// location = getCurrentLocation();
+// event = getNextEvent();
+// }
+// fTimeRange = new TmfTimeRange(startTime, lastTime);
+// }
+// seekLocation(null);
+// } catch (IOException e) {
+// } finally {
+// monitor.done();
+// }
+// }
+//
+// });
+// } catch (InvocationTargetException e1) {
+// // TODO Auto-generated catch block
+// e1.printStackTrace();
+// } catch (InterruptedException e1) {
+// // TODO Auto-generated catch block
+// e1.printStackTrace();
+// }
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.stream;
+
+import java.io.IOException;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+
+/**
+ * <b><u>ITmfEventParser</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public interface ITmfEventParser {
+
+ /**
+ * @return
+ * @throws IOException
+ */
+ public TmfEvent getNextEvent(ITmfEventStream stream) throws IOException;
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.stream;
+
+import java.util.Map;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.trace.TmfTrace;
+
+/**
+ * <b><u>ITmfEventStream</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public interface ITmfEventStream {
+
+ public class StreamContext {
+ Object location;
+ public StreamContext(Object loc) {
+ location = loc;
+ }
+ }
+
+ public int getNbEvents();
+
+ public TmfTimeRange getTimeRange();
+
+ public Map<String, Object> getAttributes();
+
+ /**
+ * Positions the stream at the first event with timestamp.
+ *
+ * @param timestamp
+ * @return a context object for subsequent reads
+ */
+ public StreamContext seekEvent(TmfTimestamp timestamp);
+
+ /**
+ * Positions the stream on the event at the wanted position.
+ *
+ * @param index
+ * @return a context object for subsequent reads
+ */
+ public StreamContext seekEvent(int index);
+
+ /**
+ * Reads and the next event on the stream and updates the context.
+ * If there is no event left, return null.
+ *
+ * @return the next event in the stream
+ */
+ public TmfEvent getNextEvent(StreamContext context);
+
+ public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp);
+ public TmfEvent getEvent(StreamContext context, int index);
+
+ /**
+ * Parse the stream and creates the checkpoint structure.
+ * Normally performed once at the creation of the event stream.
+ */
+ public void indexStream(boolean waitForCompletion);
+
+ public Object getCurrentLocation();
+ public StreamContext seekLocation(Object location);
+
+ public void addListener(TmfTrace tmfEventLog);
+ public void removeListener(TmfTrace tmfEventLog);
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.stream;
+
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+
+/**
+ * <b><u>TmfStreamCheckpoint</u></b>
+ * <p>
+ * This class maps an event timestamp with a trace location.
+ */
+public class TmfStreamCheckpoint implements Comparable<TmfStreamCheckpoint> {
+
+ // ========================================================================
+ // Attributes
+ // ========================================================================
+
+ private final TmfTimestamp fTimestamp;
+ private final Object fLocation;
+
+ // ========================================================================
+ // Constructors
+ // ========================================================================
+
+ /**
+ * @param ts
+ * @param location
+ */
+ public TmfStreamCheckpoint(TmfTimestamp ts, Object location) {
+ fTimestamp = ts;
+ fLocation = location;
+ }
+
+ // ========================================================================
+ // Accessors
+ // ========================================================================
+
+ /**
+ * @return the checkpoint event timestamp
+ */
+ public TmfTimestamp getTimestamp() {
+ return fTimestamp;
+ }
+
+ /**
+ * @return the checkpoint event stream location
+ */
+ public Object getLocation() {
+ return fLocation;
+ }
+
+ // ========================================================================
+ // Operators
+ // ========================================================================
+
+ public int compareTo(TmfStreamCheckpoint other) {
+ return fTimestamp.compareTo(other.fTimestamp, false);
+ }
+
+}
--- /dev/null
+/**
+ *
+ */
+package org.eclipse.linuxtools.tmf.stream;
+
+import org.eclipse.linuxtools.tmf.trace.ITmfTraceEvent;
+
+/**
+ * @author francois
+ *
+ */
+public class TmfStreamUpdateEvent implements ITmfTraceEvent {
+
+ private final ITmfEventStream fEventStream;
+
+ public TmfStreamUpdateEvent(ITmfEventStream stream) {
+ fEventStream = stream;
+ }
+
+ public ITmfEventStream getEventStream() {
+ return fEventStream;
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+/**
+ * <b><u>ITmfEvent</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public interface ITmfTraceEvent {
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+/**
+ * <b><u>ITmfEventListener</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public interface ITmfTraceEventListener {
+
+ public void handleEvent(ITmfTraceEvent event);
+}
/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.linuxtools.tmf.trace;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import java.util.Vector;
-import org.eclipse.linuxtools.tmf.component.TmfEventProvider;
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.request.ITmfEventRequest;
+import org.eclipse.linuxtools.tmf.request.ITmfRequestHandler;
+import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
+import org.eclipse.linuxtools.tmf.stream.TmfStreamUpdateEvent;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventStream.StreamContext;
/**
- * <b><u>TmfTrace</u></b>
+ * <b><u>TmfEventLog</u></b>
* <p>
- * Abstract implementation of ITmfTrace. It should be sufficient to extend this
- * class and provide implementation for <code>getCurrentLocation()</code> and
- * <code>seekLocation()</code>, as well as a proper parser, to have a working
- * concrete implementation.
+ * TmfEventLog represents a time-ordered set of events tied to a single event
+ * stream. It keeps track of the global information about the event log:
+ * <ul>
+ * <li> the epoch, a reference timestamp for the whole log (t0)
+ * <li> the span of the log i.e. the timestamps range
+ * <li> the total number of events
+ * </ul>
+ * As an ITmfRequestHandler, it provides an implementation of process()
+ * which handles event requests.
* <p>
- * Note: The notion of event rank is still under heavy discussion. Although
- * used by the Events View and probably useful in the general case, there
- * is no easy way to implement it for LTTng (actually a strong case is being
- * made that this is useless).
- * <p>
- * That it is not supported by LTTng does by no mean indicate that it is not
- * useful for (just about) every other tracing tool. Therefore, this class
- * provides a minimal (and partial) implementation of rank. However, the current
- * implementation should not be relied on in the general case.
- *
- * TODO: Add support for live streaming (notifications, incremental indexing, ...)
+ * TODO: Handle concurrent and possibly overlapping requests in a way that
+ * optimizes the stream access and event parsing.
*/
-public abstract class TmfTrace<T extends TmfEvent> extends TmfEventProvider<T> implements ITmfTrace, Cloneable {
-
- // ------------------------------------------------------------------------
- // Constants
- // ------------------------------------------------------------------------
-
- // The default number of events to cache
- // TODO: Make the DEFAULT_CACHE_SIZE a preference
- public static final int DEFAULT_CACHE_SIZE = 1000;
+public class TmfTrace implements ITmfRequestHandler<TmfEvent> {
- // ------------------------------------------------------------------------
+ // ========================================================================
// Attributes
- // ------------------------------------------------------------------------
-
- // The trace path
- private final String fPath;
-
- // The cache page size AND checkpoints interval
- protected int fIndexPageSize;
-
- // The set of event stream checkpoints (for random access)
- protected Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
-
- // The number of events collected
- protected long fNbEvents = 0;
+ // ========================================================================
- // The time span of the event stream
- private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
+ private final String fId;
+ private final ITmfEventStream fStream;
+ private final TmfTimestamp fEpoch;
+
+ // The listeners
+ private Set<ITmfTraceEventListener> fListeners = new HashSet<ITmfTraceEventListener>();
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
+ // ========================================================================
+ // Constructors/Destructors
+ // ========================================================================
- /**
- * @param path
- * @throws FileNotFoundException
- */
- protected TmfTrace(String name, Class<T> type, String path) throws FileNotFoundException {
- this(name, type, path, DEFAULT_CACHE_SIZE);
+ public TmfTrace(String id, ITmfEventStream stream) {
+ this(id, stream, TmfTimestamp.BigBang);
}
- /**
- * @param path
- * @param cacheSize
- * @throws FileNotFoundException
- */
- protected TmfTrace(String name, Class<T> type, String path, int cacheSize) throws FileNotFoundException {
- super(name, type);
- int sep = path.lastIndexOf(File.separator);
- String simpleName = (sep >= 0) ? path.substring(sep + 1) : path;
- setName(simpleName);
- fPath = path;
- fIndexPageSize = (cacheSize > 0) ? cacheSize : DEFAULT_CACHE_SIZE;
-
- try {
- fClone = clone();
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
+ public TmfTrace(String id, ITmfEventStream stream, TmfTimestamp epoch) {
+ assert stream != null;
+ fId = id;
+ fStream = stream;
+ fEpoch = epoch;
+ fStream.addListener(this);
}
- /* (non-Javadoc)
- * @see java.lang.Object#clone()
- */
- @SuppressWarnings("unchecked")
- @Override
- public TmfTrace<T> clone() throws CloneNotSupportedException {
- TmfTrace<T> clone = (TmfTrace<T>) super.clone();
- clone.fCheckpoints = (Vector<TmfCheckpoint>) fCheckpoints.clone();
- clone.fTimeRange = new TmfTimeRange(fTimeRange);
- return clone;
+ public void dispose() {
+ fStream.removeListener(this);
}
- // ------------------------------------------------------------------------
+ // ========================================================================
// Accessors
- // ------------------------------------------------------------------------
+ // ========================================================================
- /**
- * @return the trace path
- */
- public String getPath() {
- return fPath;
+ public String getId() {
+ return fId;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getNbEvents()
- */
- public long getNbEvents() {
- return fNbEvents;
+ public ITmfEventStream getStream() {
+ return fStream;
}
- /**
- * @return the size of the cache
- */
- public int getCacheSize() {
- return fIndexPageSize;
+ public TmfTimestamp getEpoch() {
+ return fEpoch;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getTimeRange()
- */
public TmfTimeRange getTimeRange() {
- return fTimeRange;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStartTime()
- */
- public TmfTimestamp getStartTime() {
- return fTimeRange.getStartTime();
+ return fStream.getTimeRange();
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getEndTime()
- */
- public TmfTimestamp getEndTime() {
- return fTimeRange.getEndTime();
+ public int getNbEvents() {
+ return fStream.getNbEvents();
}
- @SuppressWarnings("unchecked")
- public Vector<TmfCheckpoint> getCheckpoints() {
- return (Vector<TmfCheckpoint>) fCheckpoints.clone();
- }
-
- // ------------------------------------------------------------------------
+ // ========================================================================
// Operators
- // ------------------------------------------------------------------------
-
- protected void setTimeRange(TmfTimeRange range) {
- fTimeRange = range;
- }
+ // ========================================================================
- protected void setStartTime(TmfTimestamp startTime) {
- fTimeRange = new TmfTimeRange(startTime, fTimeRange.getEndTime());
- }
-
- protected void setEndTime(TmfTimestamp endTime) {
- fTimeRange = new TmfTimeRange(fTimeRange.getStartTime(), endTime);
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfDataRequest, boolean)
+ */
+ public void processRequest(TmfDataRequest<TmfEvent> request, boolean waitForCompletion) {
+ if (request.getRange() != null) {
+ serviceEventRequestByTimestamp(request);
+ } else {
+ serviceEventRequestByIndex(request);
+ }
+ if (waitForCompletion) {
+ request.waitForCompletion();
+ }
}
- // ------------------------------------------------------------------------
- // TmfProvider
- // ------------------------------------------------------------------------
-
- @Override
- public ITmfContext armRequest(ITmfDataRequest<T> request) {
- if (request instanceof ITmfEventRequest<?>) {
- return seekEvent(((ITmfEventRequest<T>) request).getRange().getStartTime());
- }
- return seekEvent(request.getIndex());
+ public void addListener(ITmfTraceEventListener listener) {
+ fListeners.add(listener);
}
- /**
- * Return the next piece of data based on the context supplied. The context
- * would typically be updated for the subsequent read.
- *
- * @param context
- * @return
- */
- @SuppressWarnings("unchecked")
- @Override
- public T getNext(ITmfContext context) {
- if (context instanceof TmfContext) {
- return (T) getNextEvent((TmfContext) context);
- }
- return null;
+ public void removeListener(ITmfTraceEventListener listener) {
+ fListeners.remove(listener);
}
- // ------------------------------------------------------------------------
- // ITmfTrace
- // ------------------------------------------------------------------------
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.event.TmfTimestamp)
- */
- public TmfContext seekEvent(TmfTimestamp timestamp) {
-
- if (timestamp == null) {
- timestamp = TmfTimestamp.BigBang;
+ public void handleEvent(TmfStreamUpdateEvent event) {
+ for (ITmfTraceEventListener listener : fListeners) {
+ listener.handleEvent(new TmfTraceUpdateEvent(this));
}
+ }
- // First, find the right checkpoint
- int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
-
- // In the very likely case that the checkpoint was not found, bsearch
- // returns its negated would-be location (not an offset...). From that
- // index, we can then position the stream and get the event.
- if (index < 0) {
- index = Math.max(0, -(index + 2));
- }
+ // ========================================================================
+ // Helper functions
+ // ========================================================================
- // Position the stream at the checkpoint
- ITmfLocation<?> location;
- synchronized (fCheckpoints) {
- if (fCheckpoints.size() > 0) {
- if (index >= fCheckpoints.size()) {
- index = fCheckpoints.size() - 1;
- }
- location = fCheckpoints.elementAt(index).getLocation();
- }
- else {
- location = null;
- }
- }
- TmfContext context = seekLocation(location);
- context.setRank(index * fIndexPageSize);
-
- // And locate the event
- TmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype...
- TmfEvent event = getNextEvent(nextEventContext);
- while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
- context.setLocation(nextEventContext.getLocation().clone());
- context.updateRank(1);
- event = getNextEvent(nextEventContext);
- }
-
- return context;
+ /* (non-Javadoc)
+ *
+ * @param request
+ */
+ private void serviceEventRequestByTimestamp(final TmfDataRequest<TmfEvent> request) {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ TmfTimestamp startTime = request.getRange().getStartTime();
+ TmfTimestamp endTime = request.getRange().getEndTime();
+ int blockSize = request.getBlockize();
+
+ int nbRequestedEvents = request.getNbRequestedItems();
+ if (nbRequestedEvents == -1) {
+ nbRequestedEvents = Integer.MAX_VALUE;
+ }
+
+ Vector<TmfEvent> events = new Vector<TmfEvent>();
+ int nbEvents = 0;
+
+ StreamContext context = new StreamContext(null);
+ TmfEvent event = fStream.getEvent(context, startTime);
+
+ while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null &&
+ event.getTimestamp().compareTo(endTime, false) <= 0 )
+ {
+ events.add(event);
+ if (++nbEvents % blockSize == 0) {
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+ request.handlePartialResult();
+ events.removeAllElements();
+ }
+ // To avoid an unnecessary read passed the last event requested
+ if (nbEvents < nbRequestedEvents)
+ event = fStream.getNextEvent(context);
+ }
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+
+ request.handlePartialResult();
+ request.done();
+ }
+ };
+ thread.start();
}
/* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(int)
+ *
+ * @param request
*/
- public TmfContext seekEvent(long rank) {
-
- // Position the stream at the previous checkpoint
- int index = (int) rank / fIndexPageSize;
- ITmfLocation<?> location;
- synchronized (fCheckpoints) {
- if (fCheckpoints.size() == 0) {
- location = null;
- }
- else {
- if (index >= fCheckpoints.size()) {
- index = fCheckpoints.size() - 1;
- }
- location = fCheckpoints.elementAt(index).getLocation();
- }
- }
-
- TmfContext context = seekLocation(location);
- long pos = index * fIndexPageSize;
- context.setRank(pos);
-
- if (pos < rank) {
- TmfEvent event = getNextEvent(context);
- while (event != null && ++pos < rank) {
- event = getNextEvent(context);
+ private void serviceEventRequestByIndex(final TmfDataRequest<TmfEvent> request) {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ int blockSize = request.getBlockize();
+
+ int nbRequestedEvents = request.getNbRequestedItems();
+ if (nbRequestedEvents == -1) {
+ nbRequestedEvents = Integer.MAX_VALUE;
+ }
+
+ Vector<TmfEvent> events = new Vector<TmfEvent>();
+ int nbEvents = 0;
+
+ StreamContext context = new StreamContext(null);
+ TmfEvent event = fStream.getEvent(context, request.getIndex());
+
+ while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null)
+ {
+ events.add(event);
+ if (++nbEvents % blockSize == 0) {
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+ request.handlePartialResult();
+ events.removeAllElements();
+ }
+ // To avoid an unnecessary read passed the last event requested
+ if (nbEvents < nbRequestedEvents)
+ event = fStream.getNextEvent(context);
+ }
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+
+ request.setData(result);
+ request.handlePartialResult();
+ request.done();
}
- }
-
- return context;
+ };
+ thread.start();
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getNextEvent(org.eclipse.linuxtools.tmf.trace.ITmfTrace.TraceContext)
- */
- public synchronized TmfEvent getNextEvent(TmfContext context) {
- // parseEvent() does not update the context
- TmfEvent event = parseEvent(context);
- if (event != null) {
- context.setLocation(getCurrentLocation());
- updateIndex(context, context.getRank(), event.getTimestamp());
- context.updateRank(1);
- processEvent(event);
- }
- return event;
- }
-
- public synchronized void updateIndex(ITmfContext context, long rank, TmfTimestamp timestamp) {
- // Build the index as we go along
- if (context.isValidRank() && (rank % fIndexPageSize) == 0) {
- // Determine the table position
- long position = rank / fIndexPageSize;
- // Add new entry at proper location (if empty)
- if (fCheckpoints.size() == position) {
- ITmfLocation<?> location = getCurrentLocation().clone();
- fCheckpoints.add(new TmfCheckpoint(timestamp, location));
-// System.out.println(getName() + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + location.toString());
- }
- }
- }
-
- /**
- * Hook for "special" processing by the concrete class
- * (called by getNextEvent())
- *
- * @param event
- */
- protected void processEvent(TmfEvent event) {
- // Do nothing by default
- }
-
- /**
- * To be implemented by the concrete class
- */
- public abstract TmfContext seekLocation(ITmfLocation<?> location);
- public abstract ITmfLocation<?> getCurrentLocation();
- public abstract TmfEvent parseEvent(TmfContext context);
-
- // ------------------------------------------------------------------------
- // toString
- // ------------------------------------------------------------------------
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "[TmfTrace (" + getName() + ")]";
- }
-
}
--- /dev/null
+/**
+ *
+ */
+package org.eclipse.linuxtools.tmf.trace;
+
+
+/**
+ * @author francois
+ *
+ */
+public class TmfTraceSelectedEvent implements ITmfTraceEvent {
+
+ private final TmfTrace fEventLog;
+
+ public TmfTraceSelectedEvent(TmfTrace eventLog) {
+ fEventLog = eventLog;
+ }
+
+ public TmfTrace getEventLog() {
+ return fEventLog;
+ }
+}
--- /dev/null
+/**
+ *
+ */
+package org.eclipse.linuxtools.tmf.trace;
+
+
+/**
+ * @author francois
+ *
+ */
+public class TmfTraceUpdateEvent implements ITmfTraceEvent {
+
+ private final TmfTrace fEventLog;
+
+ public TmfTraceUpdateEvent(TmfTrace eventLog) {
+ fEventLog = eventLog;
+ }
+
+ public TmfTrace getEventLog() {
+ return fEventLog;
+ }
+}