From 28b94d61a5b6ff5474a99df8093e33fe43c70278 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Tue, 8 Dec 2009 04:17:59 +0000 Subject: [PATCH] Monster fix: TMF model update + corresponding LTTng adaptations + JUnits --- .../META-INF/MANIFEST.MF | 6 +- .../linuxtools/lttng/event/AllLttngTests.java | 30 +- .../lttng/event/LttngEventContentTest.java | 45 +- .../lttng/event/LttngEventFieldTest.java | 21 +- .../lttng/event/LttngEventFormatTest.java | 139 ---- .../lttng/event/LttngEventReferenceTest.java | 14 +- .../lttng/event/LttngEventTest.java | 26 +- .../lttng/event/LttngEventTypeTest.java | 27 +- .../lttng/event/LttngTimestampTest.java | 13 +- .../linuxtools/lttng/jni/AllJniTests.java | 29 +- .../linuxtools/lttng/jni/Combinations.java | 18 +- .../linuxtools/lttng/jni/JniEventTest.java | 18 +- .../lttng/jni/JniMarkerFieldTest.java | 15 +- .../linuxtools/lttng/jni/JniMarkerTest.java | 15 +- .../linuxtools/lttng/jni/JniTraceTest.java | 30 +- .../lttng/jni/JniTracefileTest.java | 15 +- .../lttng/state/TestStateManager.java | 28 +- .../lttng/state/handlers/AbsStateUpdate.java | 6 +- .../after/StateAfterUpdateHandlers.java | 2 +- .../before/StateBeforeUpdateHandlers.java | 4 +- .../lttng/trace/LTTngTraceTest.java | 24 +- .../ui/model/trange/TimeRangeComposite.java | 4 +- .../evProcessor/AbsFlowTRangeUpdate.java | 7 +- .../FlowTRangeAfterUpdateHandlers.java | 12 +- .../FlowTRangeBeforeUpdateHandlers.java | 12 +- .../model/FlowProcessContainer.java | 7 +- .../lttng/ui/views/events/EventsView.java | 6 +- .../ResourcesTRangeUpdateFactory.java | 79 ++- .../resources/model/ResourceContainer.java | 2 +- .../AbstractStatsEventHandler.java | 10 +- .../lttng/stubs/LTTngEventParserStub.java | 220 ++++--- .../linuxtools/lttng/event/LttngEvent.java | 84 ++- .../lttng/event/LttngEventContent.java | 237 ++++--- .../lttng/event/LttngEventField.java | 42 +- .../lttng/event/LttngEventFormat.java | 189 ------ .../lttng/event/LttngEventReference.java | 23 +- .../lttng/event/LttngEventSource.java | 63 ++ .../lttng/event/LttngEventType.java | 54 +- .../lttng/event/LttngTimestamp.java | 27 +- .../linuxtools/lttng/jni/JniEvent.java | 104 ++- .../linuxtools/lttng/jni/JniException.java | 2 +- .../linuxtools/lttng/jni/JniMarker.java | 4 +- .../linuxtools/lttng/jni/JniMarkerField.java | 4 +- .../linuxtools/lttng/jni/JniParser.java | 69 +- .../eclipse/linuxtools/lttng/jni/JniTime.java | 47 +- .../linuxtools/lttng/jni/JniTrace.java | 82 ++- .../linuxtools/lttng/jni/JniTracefile.java | 14 +- .../linuxtools/lttng/jni/Jni_C_Common.java | 2 +- .../linuxtools/lttng/jni/Jni_C_Pointer.java | 1 + .../lttng/state/StateDataRequest.java | 5 +- .../linuxtools/lttng/state/StateManager.java | 8 +- .../lttng/state/StateStacksHandler.java | 6 +- .../evProcessor/state/AbsStateProcessing.java | 67 +- .../evProcessor/state/AbsStateUpdate.java | 8 +- .../state/StateUpdateHandlers.java | 31 +- .../state/model/LttngExecutionState.java | 25 +- .../lttng/state/model/LttngProcessState.java | 35 +- .../lttng/state/model/LttngTraceState.java | 29 +- .../linuxtools/lttng/trace/LTTngTrace.java | 246 +++++--- .../META-INF/MANIFEST.MF | 6 +- .../linuxtools/tmf/event/AllEventTests.java | 31 - .../linuxtools/tmf/event/AllTests.java | 24 + .../tmf/event/TmfEventContentTest.java | 182 +++++- .../tmf/event/TmfEventFieldTest.java | 106 ++++ .../tmf/event/TmfEventFormatTest.java | 87 --- .../tmf/event/TmfEventReferenceTest.java | 91 +++ .../tmf/event/TmfEventSourceTest.java | 91 +++ .../linuxtools/tmf/event/TmfEventTest.java | 208 +++--- .../tmf/event/TmfEventTypeTest.java | 121 +++- .../tmf/event/TmfTimeRangeTest.java | 144 +++-- .../tmf/event/TmfTimestampTest.java | 594 +++++++++--------- .../tmf/event/TmfTraceEventTest.java | 137 ++-- .../tmf/request/AllRequestTests.java | 26 - .../linuxtools/tmf/request/AllTests.java | 16 + .../tmf/request/TmfDataRequestTest.java | 259 ++------ .../linuxtools/tmf/trace/AllTests.java | 17 + .../linuxtools/tmf/trace/AllTraceTests.java | 26 - .../tmf/trace/TmfExperimentTest.java | 44 +- .../linuxtools/tmf/trace/TmfTraceTest.java | 78 ++- .../linuxtools/tmf/CreateTestFiles.java | 4 +- .../tmf/event/TmfEventContentStub.java | 22 +- .../tmf/event/TmfEventFormatStub.java | 59 -- .../tmf/request/TmfRequestHandlerStub.java | 2 +- .../tmf/trace/TmfEventParserStub.java | 21 +- .../tmf/ui/views/TmfEventsView.java | 41 +- .../tmf/event/ITmfContentParser.java | 23 - .../linuxtools/tmf/event/TmfEvent.java | 87 ++- .../linuxtools/tmf/event/TmfEventContent.java | 122 ++-- .../linuxtools/tmf/event/TmfEventField.java | 69 +- .../linuxtools/tmf/event/TmfEventFormat.java | 72 --- .../tmf/event/TmfEventReference.java | 27 +- .../linuxtools/tmf/event/TmfEventSource.java | 20 +- .../linuxtools/tmf/event/TmfEventType.java | 98 ++- .../linuxtools/tmf/event/TmfTimeRange.java | 20 +- .../linuxtools/tmf/event/TmfTimestamp.java | 72 +-- .../linuxtools/tmf/event/TmfTraceEvent.java | 55 +- .../tmf/request/TmfDataRequest.java | 82 ++- .../linuxtools/tmf/trace/TmfExperiment.java | 40 +- .../linuxtools/tmf/trace/TmfTrace.java | 2 +- 99 files changed, 2971 insertions(+), 2647 deletions(-) delete mode 100644 org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventFormatTest.java delete mode 100644 org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java create mode 100644 org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java delete mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/AllEventTests.java create mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/AllTests.java create mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventFieldTest.java delete mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventFormatTest.java create mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventReferenceTest.java create mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventSourceTest.java delete mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/AllRequestTests.java create mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/AllTests.java create mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/AllTests.java delete mode 100644 org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/AllTraceTests.java delete mode 100644 org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventFormatStub.java delete mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/ITmfContentParser.java delete mode 100644 org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventFormat.java diff --git a/org.eclipse.linuxtools.lttng.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng.tests/META-INF/MANIFEST.MF index 81cafb16f2..42ef390751 100644 --- a/org.eclipse.linuxtools.lttng.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng.tests/META-INF/MANIFEST.MF @@ -5,6 +5,6 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng.tests Bundle-Version: 0.0.1 Bundle-Vendor: Eclipse Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.junit4;bundle-version="4.5.0", - org.eclipse.linuxtools.lttng;bundle-version="0.0.1", - org.eclipse.linuxtools.tmf;bundle-version="0.0.1" +Require-Bundle: org.eclipse.linuxtools.lttng;bundle-version="0.0.1", + org.eclipse.linuxtools.tmf;bundle-version="0.0.1", + org.junit;bundle-version="3.8.2" diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/AllLttngTests.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/AllLttngTests.java index e45cd78a52..43baa70398 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/AllLttngTests.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/AllLttngTests.java @@ -1,20 +1,20 @@ package org.eclipse.linuxtools.lttng.event; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - LttngTimestampTest.class, - LttngEventFieldTest.class, - LttngEventFormatTest.class, - LttngEventContentTest.class, - LttngEventReferenceTest.class, - LttngEventTypeTest.class, - LttngEventTest.class -}) - -public class AllLttngTests { +import junit.framework.TestCase; +import junit.framework.TestSuite; +public final class AllLttngTests extends TestCase { + public static TestSuite suite() { + TestSuite suite = new TestSuite("Testing JNI"); + + suite.addTestSuite(LttngTimestampTest.class); + suite.addTestSuite(LttngEventFieldTest.class); + suite.addTestSuite(LttngEventContentTest.class); + suite.addTestSuite(LttngEventReferenceTest.class); + suite.addTestSuite(LttngEventTypeTest.class); + suite.addTestSuite(LttngEventTest.class); + + return suite; + } } diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventContentTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventContentTest.java index f66f1ebbbd..d9e204a236 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventContentTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventContentTest.java @@ -1,12 +1,8 @@ package org.eclipse.linuxtools.lttng.event; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.fail; - import org.eclipse.linuxtools.lttng.trace.LTTngTrace; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -20,7 +16,7 @@ import org.junit.Test; public String toString() */ -public class LttngEventContentTest { +public class LttngEventContentTest extends TestCase { private final static boolean skipIndexing=true; private final static boolean waitForCompletion=true; private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; @@ -58,18 +54,17 @@ public class LttngEventContentTest { return tmpEventContent; } - @Test public void testConstructors() { + LttngEvent testEvent = null; LttngEventContent testContent = null; @SuppressWarnings("unused") LttngEventContent testContent2 = null; - LttngEventFormat testFormat = new LttngEventFormat(new String[1]); LttngEventField[] testFields = new LttngEventField[1]; - testFields[0] = new LttngEventField("test", "test"); + testFields[0] = new LttngEventField(testContent2, "test"); // Default construction with good argument try { - testContent = new LttngEventContent(testFormat); + testContent = new LttngEventContent(); } catch( Exception e) { fail("Construction with format failed!"); @@ -77,7 +72,7 @@ public class LttngEventContentTest { // Construction with good parameters try { - testContent = new LttngEventContent(testFormat, "test", testFields); + testContent = new LttngEventContent(testEvent); } catch( Exception e) { fail("Construction with format, content and fields failed!"); @@ -85,7 +80,7 @@ public class LttngEventContentTest { // Copy constructor with correct parameters try { - testContent = new LttngEventContent(testFormat); + testContent = new LttngEventContent(testEvent); testContent2 = new LttngEventContent(testContent); } catch( Exception e) { @@ -95,22 +90,12 @@ public class LttngEventContentTest { } - @Test public void testGetter() { LttngEventContent testContent = null; LTTngTrace tmpStream = null; LttngEvent tmpEvent = null; TmfTraceContext tmpContext = null; - //*** Basic (very bad) interface *** - testContent = prepareToTest(); - // getFieldS() - assertNotSame("getFields() returned null!",null,testContent.getFields().toString()); - // getField(int) - assertEquals("getField(int) returned unexpected result!",firstEventContentFirstField, testContent.getField(0).toString()); - - - //*** Upgraded (better) interface *** // Require an event tmpStream = initializeEventStream(); tmpContext = new TmfTraceContext(null, null, 0); @@ -118,9 +103,9 @@ public class LttngEventContentTest { testContent = prepareToTest(); // getFieldS() - assertNotSame("getFields(event) returned null!",null,testContent.getFields(tmpEvent) ); + assertNotSame("getFields() returned null!",null,testContent.getFields() ); // getField(int) - assertEquals("getField(int, event) returned unexpected result!",firstEventContentFirstField, testContent.getField(0, tmpEvent).toString()); + assertEquals("getField(int) returned unexpected result!",firstEventContentFirstField, testContent.getField(0).toString()); @@ -134,23 +119,13 @@ public class LttngEventContentTest { // Second event past metadata should have more fields tmpEvent = (LttngEvent)tmpStream.parseEvent(tmpContext); - //*** Basic (very bad) interface *** - testContent = (LttngEventContent)tmpEvent.getContent(); // getFieldS() - assertNotSame("getFields() returned null!",null,testContent.getFields().toString()); + assertNotSame("getFields() returned null!",null,testContent.getFields() ); // getField(int) assertEquals("getField(int) returned unexpected result!",secondEventContentSecondField, testContent.getField(1).toString()); - - //*** Upgraded (better) interface *** - // getFieldS() - assertNotSame("getFields(event) returned null!",null,testContent.getFields(tmpEvent) ); - // getField(int) - assertEquals("getField(int, event) returned unexpected result!",secondEventContentSecondField, testContent.getField(1, tmpEvent).toString()); - } - @Test public void testToString() { LttngEventContent tmpContent = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventFieldTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventFieldTest.java index ef8082c71c..a6afa76ac8 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventFieldTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventFieldTest.java @@ -1,12 +1,10 @@ package org.eclipse.linuxtools.lttng.event; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.fail; + import org.eclipse.linuxtools.lttng.trace.LTTngTrace; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -17,7 +15,7 @@ import org.junit.Test; */ -public class LttngEventFieldTest { +public class LttngEventFieldTest extends TestCase { private final static boolean skipIndexing=true; private final static boolean waitForCompletion=true; private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; @@ -53,15 +51,15 @@ public class LttngEventFieldTest { return tmpField; } - @Test public void testConstructors() { + LttngEventContent testContent = null; LttngEventField testField = null; @SuppressWarnings("unused") LttngEventField testField2 = null; // Default construction with good argument try { - testField = new LttngEventField("test", "test"); + testField = new LttngEventField(testContent, "test", "test"); } catch( Exception e) { fail("Default construction failed!"); @@ -69,7 +67,7 @@ public class LttngEventFieldTest { // Copy constructor with correct parameters try { - testField = new LttngEventField("test", "test"); + testField = new LttngEventField(testContent, "test", "test"); testField2 = new LttngEventField(testField); } catch( Exception e) { @@ -78,8 +76,6 @@ public class LttngEventFieldTest { } - - @Test public void testGetter() { // *** To "really" test the field, we will get a real field from LTTngTrace @@ -88,13 +84,12 @@ public class LttngEventFieldTest { LttngEventField testField = (LttngEventField)tmpStream.parseEvent( new TmfTraceContext(null, null, 0) ).getContent().getField(0); assertNotSame("getField is null!",null,testField); - assertEquals("getName() returned unexpected result!",firstEventName, testField.getName().toString()); - assertEquals("getValue() returned unexpected result!",firstEventValue, testField.getValue().toString()); + assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString())); + assertTrue("getValue() returned unexpected result!",firstEventValue.equals(testField.getValue().toString())); } - @Test public void testToString() { LttngEventField tmpField = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventFormatTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventFormatTest.java deleted file mode 100644 index a278acef01..0000000000 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventFormatTest.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.eclipse.linuxtools.lttng.event; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.fail; - -import org.eclipse.linuxtools.lttng.trace.LTTngTrace; -import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; -import org.junit.Test; - -/* - Functions tested here : - public LttngEventFormat() - public String[] getLabels(LttngEvent thisEvent) - public LttngEventField[] parse(LttngEvent thisEvent) - public LttngEventField[] parse(HashMap parsedEvents) - public LttngEventField[] parse(String uselessContent) - - */ - -public class LttngEventFormatTest { - private final static boolean skipIndexing=true; - private final static boolean waitForCompletion=true; - private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; - - private final static long timestampAfterMetadata = 952090116049L; - - private final static String secondEventFirstField = "loglevel"; - private final static String secondEventSecondField = "string"; - //private final static String secondEventThirdField = "ip"; - - private final static String secondEventThirdFieldParsedValue = "ip:0xc04f402c"; - - - private LTTngTrace initializeEventStream() { - LTTngTrace tmpStream = null; - try { - tmpStream = new LTTngTrace(tracepath1, waitForCompletion, skipIndexing); - } - catch (Exception e) { - fail("ERROR : Could not open " + tracepath1 + ". Test failed!" ); - } - - return tmpStream; - } - - - private LttngEventFormat prepareToTest() { - LttngEventFormat tmpEventFormat = null; - - // This trace should be valid - try { - LTTngTrace tmpStream = initializeEventStream(); - tmpEventFormat = (LttngEventFormat)tmpStream.parseEvent( new TmfTraceContext(null, null, 0) ).getContent().getFormat(); - } - catch (Exception e) { - fail("ERROR : Failed to get format!"); - } - - return tmpEventFormat; - } - - @Test - public void testConstructors() { - LttngEventFormat testFormat = null; - @SuppressWarnings("unused") - LttngEventFormat testFormat2 = null; - - - // Default construction with good argument - try { - testFormat = new LttngEventFormat(new String[1]); - } - catch( Exception e) { - fail("Construction failed!"); - } - - // Copy constructor - try { - testFormat = new LttngEventFormat(new String[1]); - testFormat2 = new LttngEventFormat(testFormat); - } - catch( Exception e) { - fail("Copy construction failed!"); - } - - } - - - @Test - public void testGetter() { - LttngEventFormat testFormat = null; - LTTngTrace tmpStream = null; - LttngEvent tmpEvent = null; - TmfTraceContext tmpContext = new TmfTraceContext(null, null, 0); - - //*** Position ourself to the second event to have something interesting to test with *** - - tmpStream = initializeEventStream(); - // Skip first events and seek to events past metadata - tmpContext= tmpStream.seekLocation(new LttngTimestamp(timestampAfterMetadata) ); - // Skip first one - tmpEvent = (LttngEvent)tmpStream.parseEvent(tmpContext); - // Second event should have more fields - tmpEvent = (LttngEvent)tmpStream.parseEvent(tmpContext); - // Get a real format from the event - testFormat = (LttngEventFormat)tmpEvent.getContent().getFormat(); - - // Test getLabels() - assertEquals("Label not as expected!",secondEventFirstField,testFormat.getLabels()[0].toString()); - assertEquals("Label not as expected!",secondEventSecondField,testFormat.getLabels()[1].toString()); - - - // Test different parse() - // parse(event) - assertNotSame("parse() returned null!",null, testFormat.parse(tmpEvent)); - assertEquals("Parsed field not as expected!",secondEventThirdFieldParsedValue,testFormat.parse(tmpEvent)[2].toString()); - - // parse(hashmap) - assertNotSame("parse() returned null!",null, testFormat.parse(tmpEvent.convertEventTmfToJni().parseAllFields())); - assertEquals("Parsed field not as expected!",secondEventThirdFieldParsedValue,testFormat.parse(tmpEvent.convertEventTmfToJni().parseAllFields())[2].toString()); - - - // parse(string) - System.out.println(tmpEvent.getContent().getContent().toString()); - assertNotSame("parse() returned null!",null, testFormat.parse(tmpEvent.getContent().getContent().toString())); - assertEquals("Parsed field not as expected!",secondEventThirdFieldParsedValue,testFormat.parse(tmpEvent.getContent().getContent())[2].toString()); - } - - @Test - public void testToString() { - LttngEventFormat tmpFormat = prepareToTest(); - - // Just make sure toString() does not return null or the java reference - assertNotSame("toString returned null",null, tmpFormat.toString() ); - assertNotSame("toString is not overridded!", tmpFormat.getClass().getName() + '@' + Integer.toHexString(tmpFormat.hashCode()), tmpFormat.toString() ); - } - -} diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventReferenceTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventReferenceTest.java index bdc8118f6e..bf062fc6a6 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventReferenceTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventReferenceTest.java @@ -1,13 +1,8 @@ package org.eclipse.linuxtools.lttng.event; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import org.eclipse.linuxtools.lttng.trace.LTTngTrace; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -18,7 +13,7 @@ import org.junit.Test; public String toString() */ -public class LttngEventReferenceTest { +public class LttngEventReferenceTest extends TestCase { private final static boolean skipIndexing=true; private final static boolean waitForCompletion=true; private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; @@ -53,8 +48,7 @@ public class LttngEventReferenceTest { return tmpEventRef; } - - @Test + public void testConstructors() { LttngEventReference testRef = null; @SuppressWarnings("unused") @@ -79,7 +73,6 @@ public class LttngEventReferenceTest { } - @Test public void testGetter() { LttngEventReference tmpRef = prepareToTest(); @@ -87,7 +80,6 @@ public class LttngEventReferenceTest { assertEquals("Content not what expected!",firstEventReference,tmpRef.getTracepath()); } - @Test public void testToString() { LttngEventReference tmpRef = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventTest.java index db1e2b7145..30a0a4e975 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventTest.java @@ -1,15 +1,10 @@ package org.eclipse.linuxtools.lttng.event; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import org.eclipse.linuxtools.lttng.jni.JniEvent; import org.eclipse.linuxtools.lttng.trace.LTTngTrace; import org.eclipse.linuxtools.tmf.event.TmfEventSource; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -23,7 +18,7 @@ import org.junit.Test; */ -public class LttngEventTest { +public class LttngEventTest extends TestCase { private final static boolean skipIndexing=true; private final static boolean waitForCompletion=true; private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; @@ -52,7 +47,6 @@ public class LttngEventTest { return tmpEvent; } - @Test public void testConstructors() { LTTngTrace testStream1 = null; @@ -61,23 +55,23 @@ public class LttngEventTest { LttngEvent testAnotherEvent = null; LttngTimestamp testTime = null; TmfEventSource testSource = null; - LttngEventFormat testFormat = null; LttngEventType testType = null; LttngEventContent testContent = null; LttngEventReference testReference = null; JniEvent testJniEvent = null; - + String[] testMarkerFields = null; + // This need to work if we want to perform tests try { // In order to test LttngEvent, we need all these constructors/functions to work. // Make sure to run their unit tests first! + testMarkerFields = new String[1]; testStream1 = new LTTngTrace(tracepath1, waitForCompletion, skipIndexing); testEvent = null; testTime = new LttngTimestamp(0L); testSource = new TmfEventSource("test"); - testFormat = new LttngEventFormat(new String[1]); - testType = new LttngEventType("test", 0, "test", testFormat); - testContent = new LttngEventContent(testFormat); + testType = new LttngEventType("test", 0L, "test", testMarkerFields); + testContent = new LttngEventContent(testEvent); testReference = new LttngEventReference("test", "test"); testJniEvent = testStream1.getCurrentJniTrace().findNextEvent(); } @@ -164,8 +158,6 @@ public class LttngEventTest { } - - @Test public void testGetter() { LttngEvent testEvent = prepareToTest(); @@ -177,10 +169,9 @@ public class LttngEventTest { assertEquals("CpuId not what expected!",eventCpu,testEvent.getCpuId()); assertEquals("Marker not what expected!",eventMarker,testEvent.getMarkerName()); assertEquals("Content not what expected!",eventContent,testEvent.getContent().getContent()); - assertTrue("Reference not what expected!",((String)testEvent.getReference().getValue()).contains(eventReference) ); + assertTrue("Reference not what expected!",((String)testEvent.getReference().getReference()).contains(eventReference) ); } - @Test public void testConversion() { JniEvent tmpJniEvent = null; LttngEvent testEvent = null; @@ -199,7 +190,6 @@ public class LttngEventTest { } - @Test public void testToString() { LttngEvent tmpEvent = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventTypeTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventTypeTest.java index af79497f4f..4df2dc0d1c 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventTypeTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngEventTypeTest.java @@ -1,12 +1,8 @@ package org.eclipse.linuxtools.lttng.event; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.fail; - import org.eclipse.linuxtools.lttng.trace.LTTngTrace; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -18,7 +14,7 @@ import org.junit.Test; public String toString() */ -public class LttngEventTypeTest { +public class LttngEventTypeTest extends TestCase { private final static boolean skipIndexing=true; private final static boolean waitForCompletion=true; private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; @@ -54,8 +50,7 @@ public class LttngEventTypeTest { return tmpEventType; } - - @Test + public void testConstructors() { LttngEventType tmpEventType = null; @SuppressWarnings("unused") @@ -63,7 +58,7 @@ public class LttngEventTypeTest { // Default construction with good argument try { - tmpEventType = new LttngEventType("test", 0L, "test", new LttngEventFormat(new String[1])); + tmpEventType = new LttngEventType("test", 0L, "test", new String[1]); } catch( Exception e) { fail("Construction failed!"); @@ -71,7 +66,7 @@ public class LttngEventTypeTest { // Copy constructor try { - tmpEventType = new LttngEventType("test", 0L, "test", new LttngEventFormat(new String[1])); + tmpEventType = new LttngEventType("test", 0L, "test", new String[1]); tmpEventType2 = new LttngEventType(tmpEventType); } catch( Exception e) { @@ -80,18 +75,16 @@ public class LttngEventTypeTest { } - @Test public void testGetter() { LttngEventType tmpEventType = prepareToTest(); - assertEquals("Channel name not what was expected!",firstEventChannel,(String)tmpEventType.getChannelName() ); - assertEquals("Cpu Id not what was expected!",firstEventCpu,tmpEventType.getCpuId() ); - assertEquals("Marker Name not what was expected!",firstEventMarker,(String)tmpEventType.getMarkerName() ); - // Just test the non-nullity of format - assertNotSame("getFormat returned null",null, tmpEventType.getFormat() ); + assertTrue("Channel name not what was expected!",firstEventChannel.equals((String)tmpEventType.getTracefileName()) ); + assertTrue("Cpu Id not what was expected!",firstEventCpu == tmpEventType.getCpuId() ); + assertTrue("Marker Name not what was expected!",firstEventMarker.equals((String)tmpEventType.getMarkerName()) ); + // Just test the non-nullity of labels + assertNotSame("getFormat returned null",null, tmpEventType.getLabels() ); } - @Test public void testToString() { LttngEventType tmpEventType = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngTimestampTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngTimestampTest.java index ff623be540..4ca319e5eb 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngTimestampTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/event/LttngTimestampTest.java @@ -1,12 +1,8 @@ package org.eclipse.linuxtools.lttng.event; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.fail; - import org.eclipse.linuxtools.lttng.trace.LTTngTrace; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -17,7 +13,7 @@ import org.junit.Test; public String toString() */ -public class LttngTimestampTest { +public class LttngTimestampTest extends TestCase { private final static boolean skipIndexing=true; private final static boolean waitForCompletion=true; private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; @@ -53,8 +49,7 @@ public class LttngTimestampTest { return tmpTime; } - - @Test + public void testConstructors() { LttngTimestamp tmpTime = null; @SuppressWarnings("unused") @@ -79,7 +74,6 @@ public class LttngTimestampTest { } - @Test public void testGetter() { LttngTimestamp tmpTime = prepareToTest(); @@ -90,7 +84,6 @@ public class LttngTimestampTest { } - @Test public void testToString() { LttngTimestamp tmpTime = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/AllJniTests.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/AllJniTests.java index 5097653778..a6365913b2 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/AllJniTests.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/AllJniTests.java @@ -1,18 +1,19 @@ package org.eclipse.linuxtools.lttng.jni; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import junit.framework.TestCase; +import junit.framework.TestSuite; -@RunWith(Suite.class) -@Suite.SuiteClasses({ - JniTraceTest.class, - JniTracefileTest.class, - JniEventTest.class, - JniMarkerTest.class, - JniMarkerFieldTest.class -}) - -public class AllJniTests { - -} +public final class AllJniTests extends TestCase { + public static TestSuite suite() { + TestSuite suite = new TestSuite("Testing JNI"); + + suite.addTestSuite(JniTraceTest.class); + suite.addTestSuite(JniTracefileTest.class); + suite.addTestSuite(JniEventTest.class); + suite.addTestSuite(JniMarkerTest.class); + suite.addTestSuite(JniMarkerFieldTest.class); + + return suite; + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/Combinations.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/Combinations.java index cfb7bc7022..c54473d6af 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/Combinations.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/Combinations.java @@ -3,22 +3,20 @@ */ package org.eclipse.linuxtools.lttng.jni; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - +import junit.framework.TestCase; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.junit.Test; - /** * @author alvaro * */ -public class Combinations { +public class Combinations extends TestCase { + private final static boolean printLttDebug = false; + private final static String tracepath="traceset/trace-618339events-1293lost-1cpu"; private final static String eventName = "syscall_state"; @@ -93,14 +91,13 @@ public class Combinations { JniEvent tmpEvent = null; // This trace should be valid try { - tmpEvent = new JniTrace(tracepath).requestEventByName(eventName); + tmpEvent = new JniTrace(tracepath, printLttDebug).requestEventByName(eventName); } catch (JniException e) { } return tmpEvent; } - - @Test + public void testGetSpecEventFields() { JniEvent event = prepareEventToTest(); JniMarker dmarker = event.requestEventMarker(); @@ -111,12 +108,11 @@ public class Combinations { } - @Test public void testEventsLoop() { JniTrace trace = null; JniEvent event = null; try { - trace = new JniTrace(tracepath); + trace = new JniTrace(tracepath, printLttDebug); } catch (JniException e) { e.printStackTrace(); } diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniEventTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniEventTest.java index b9d38dabeb..5cffb479c9 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniEventTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniEventTest.java @@ -30,11 +30,12 @@ package org.eclipse.linuxtools.lttng.jni; -import static org.junit.Assert.*; -import org.junit.Test; +import junit.framework.TestCase; -public class JniEventTest +public class JniEventTest extends TestCase { + private final static boolean printLttDebug = false; + private final static String tracepath="traceset/trace-618339events-1293lost-1cpu"; private final static String eventName="kernel0"; @@ -74,7 +75,7 @@ public class JniEventTest // This trace should be valid try { - tmpEvent = new JniTrace(tracepath).requestEventByName(eventName); + tmpEvent = new JniTrace(tracepath, printLttDebug).requestEventByName(eventName); } catch( JniException e) { } @@ -82,7 +83,6 @@ public class JniEventTest } - @Test public void testEventConstructors() { JniTracefile testTracefile = null; @@ -91,7 +91,7 @@ public class JniEventTest // This trace should be valid and will be used in test try { - testTracefile = new JniTrace(tracepath).requestTracefileByName(eventName); + testTracefile = new JniTrace(tracepath, printLttDebug).requestTracefileByName(eventName); } catch( JniException e) { } @@ -145,7 +145,6 @@ public class JniEventTest } - @Test public void testPrintAndToString() { JniEvent testEvent = prepareEventToTest(); @@ -163,7 +162,6 @@ public class JniEventTest } - @Test public void testEventDisplacement() { int readValue = -1; @@ -222,7 +220,6 @@ public class JniEventTest assertEquals("readNextEvent() event timestamp is incoherent (test #2)",timestampToSeekTest1,testEvent.getEventTime().getTime() ); } - @Test public void testGetSet() { JniEvent testEvent = prepareEventToTest(); @@ -249,7 +246,6 @@ public class JniEventTest assertNotNull("getParentTracefile returned null", testEvent.getParentTracefile() ); } - @Test public void testRequestFunctions() { JniEvent testEvent = prepareEventToTest(); @@ -268,7 +264,6 @@ public class JniEventTest } - @Test public void testParseAllFieldsFunctions() { JniEvent testEvent = prepareEventToTest(); @@ -310,7 +305,6 @@ public class JniEventTest assertNotNull("parseAllFields returned null",testEvent.parseAllFields() ); } - @Test public void testParseFieldByIdFunctions() { JniEvent testEvent = prepareEventToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniMarkerFieldTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniMarkerFieldTest.java index 6220dcb628..971995f029 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniMarkerFieldTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniMarkerFieldTest.java @@ -1,8 +1,7 @@ package org.eclipse.linuxtools.lttng.jni; -import static org.junit.Assert.*; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -16,8 +15,10 @@ import org.junit.Test; public void printMarkerFieldInformation() */ -public class JniMarkerFieldTest +public class JniMarkerFieldTest extends TestCase { + private final static boolean printLttDebug = false; + private final static String tracepath="traceset/trace-618339events-1293lost-1cpu"; private final static String eventName="kernel0"; @@ -29,7 +30,7 @@ public class JniMarkerFieldTest // This trace should be valid // We will read the first 2 event to have something interesting to test on try { - tmpEvent = new JniTrace(tracepath).requestEventByName(eventName); + tmpEvent = new JniTrace(tracepath, printLttDebug).requestEventByName(eventName); tmpEvent.readNextEvent(); tmpEvent.readNextEvent(); @@ -41,8 +42,6 @@ public class JniMarkerFieldTest return tmpMarkerField; } - - @Test public void testEventConstructors() { JniMarker tmpMarker = null; @@ -52,7 +51,7 @@ public class JniMarkerFieldTest // This event should be valid and will be used in test try { - tmpMarker = new JniTrace(tracepath).requestEventByName(eventName).requestEventMarker(); + tmpMarker = new JniTrace(tracepath, printLttDebug).requestEventByName(eventName).requestEventMarker(); } catch( JniException e) { } @@ -86,7 +85,6 @@ public class JniMarkerFieldTest } - @Test public void testGetSet() { JniMarkerField testMarkerField = prepareMarkerFieldToTest(); @@ -97,7 +95,6 @@ public class JniMarkerFieldTest assertNotSame("getMarkerFieldPtr is 0",0,testMarkerField.getMarkerFieldPtr() ); } - @Test public void testPrintAndToString() { JniMarkerField testMarkerField = prepareMarkerFieldToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniMarkerTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniMarkerTest.java index 24f63f6b63..2ab420b2e9 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniMarkerTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniMarkerTest.java @@ -1,8 +1,7 @@ package org.eclipse.linuxtools.lttng.jni; -import static org.junit.Assert.*; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -19,8 +18,10 @@ import org.junit.Test; public void printMarkerInformation() */ -public class JniMarkerTest +public class JniMarkerTest extends TestCase { + private final static boolean printLttDebug = false; + private final static String tracepath="traceset/trace-618339events-1293lost-1cpu"; private final static String eventName="kernel0"; @@ -34,7 +35,7 @@ public class JniMarkerTest // This trace should be valid // We will read the second event to have something interesting to test on try { - tmpEvent = new JniTrace(tracepath).requestEventByName(eventName); + tmpEvent = new JniTrace(tracepath, printLttDebug).requestEventByName(eventName); tmpEvent.readNextEvent(); tmpMarker = tmpEvent.requestEventMarker(); @@ -44,8 +45,6 @@ public class JniMarkerTest return tmpMarker; } - - @Test public void testEventConstructors() { JniEvent tmpEvent = null; @@ -55,7 +54,7 @@ public class JniMarkerTest // This event should be valid and will be used in test try { - tmpEvent = new JniTrace(tracepath).requestEventByName(eventName); + tmpEvent = new JniTrace(tracepath, printLttDebug).requestEventByName(eventName); } catch( JniException e) { } @@ -89,7 +88,6 @@ public class JniMarkerTest } - @Test public void testGetSet() { JniMarker testMarker = prepareMarkerToTest(); @@ -105,7 +103,6 @@ public class JniMarkerTest assertNotSame("getMarkerPtr is 0",0,testMarker.getMarkerPtr() ); } - @Test public void testPrintAndToString() { JniMarker testMarker = prepareMarkerToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniTraceTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniTraceTest.java index bc3b01417e..b557972dc8 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniTraceTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniTraceTest.java @@ -1,12 +1,7 @@ package org.eclipse.linuxtools.lttng.jni; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; - -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -52,8 +47,10 @@ import org.junit.Test; */ -public class JniTraceTest +public class JniTraceTest extends TestCase { + private final static boolean printLttDebug = false; + private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; private final static String tracepath2="traceset/trace-1021events-nolost-1cpu"; private final static String wrongTracePath="/somewhere/that/does/not/exist"; @@ -92,14 +89,13 @@ public class JniTraceTest // This trace should be valid try { - tmpTrace = new JniTrace(tracepath1); + tmpTrace = new JniTrace(tracepath1, printLttDebug); } catch( JniException e) { } return tmpTrace; } - @Test public void testTraceConstructors() { JniTrace testTrace1 = null; @SuppressWarnings("unused") @@ -107,7 +103,7 @@ public class JniTraceTest // Test constructor with argument on a wrong tracepath try { - testTrace1 = new JniTrace(wrongTracePath); + testTrace1 = new JniTrace(wrongTracePath, printLttDebug); fail("Construction with wrong tracepath should fail!"); } catch( JniException e) { @@ -115,7 +111,7 @@ public class JniTraceTest // Test constructor with argument on a correct tracepath try { - testTrace1 = new JniTrace(tracepath1); + testTrace1 = new JniTrace(tracepath1, printLttDebug); } catch( JniException e) { fail("Construction with correct tracepath failed!"); @@ -123,7 +119,7 @@ public class JniTraceTest // Test copy constructor that take a pointer with a good pointer try { - testTrace1 = new JniTrace( new Jni_C_Pointer(0) ); + testTrace1 = new JniTrace( new Jni_C_Pointer(0), printLttDebug); fail("Construction with wrong pointer should fail!"); } catch( JniException e) { @@ -131,8 +127,8 @@ public class JniTraceTest // Test copy constructor that take a pointer with a good pointer try { - testTrace1 = new JniTrace(tracepath1); // This trace should be valid - testTrace2 = new JniTrace( testTrace1.getTracePtr() ); + testTrace1 = new JniTrace(tracepath1, printLttDebug); // This trace should be valid + testTrace2 = new JniTrace( testTrace1.getTracePtr(), printLttDebug); } catch( JniException e) { fail("Construction with correct pointer failed!"); @@ -140,7 +136,6 @@ public class JniTraceTest } - @Test public void testTraceOpenClose() { JniTrace testTrace = prepareTraceToTest(); // This trace should be valid @@ -182,7 +177,6 @@ public class JniTraceTest } } - @Test public void testGetSet() { JniTrace testTrace = prepareTraceToTest(); @@ -210,7 +204,6 @@ public class JniTraceTest } - @Test public void testPrintAndToString() { JniTrace testTrace = prepareTraceToTest(); @@ -227,7 +220,6 @@ public class JniTraceTest assertNotSame("toString returned empty data","",testTrace.toString() ); } - @Test public void testRequestFunctions() { JniTrace testTrace = prepareTraceToTest(); @@ -241,7 +233,6 @@ public class JniTraceTest assertSame("requestEventByName returned content on non existent name",null,testTrace.requestEventByName(wrongTracefileName) ); } - @Test public void testEventDisplacement() { JniEvent testEvent = null; @@ -343,7 +334,6 @@ public class JniTraceTest assertEquals("seekToTime(time) timestamp after seek back is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime()); } - @Test public void testEventDisplacementByTracefile() { JniEvent testEvent = null; diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniTracefileTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniTracefileTest.java index 93366ff067..f7c5890bd6 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniTracefileTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/jni/JniTracefileTest.java @@ -1,8 +1,7 @@ package org.eclipse.linuxtools.lttng.jni; -import static org.junit.Assert.*; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -47,8 +46,10 @@ import org.junit.Test; public void printTracefileInformation() */ -public class JniTracefileTest +public class JniTracefileTest extends TestCase { + private final static boolean printLttDebug = false; + private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; private final static String tracefileName1="kernel0"; @@ -70,7 +71,7 @@ public class JniTracefileTest // This trace should be valid try { - tmpTracefile = new JniTrace(tracepath1).requestTracefileByName(tracefileName1); + tmpTracefile = new JniTrace(tracepath1, printLttDebug).requestTracefileByName(tracefileName1); } catch( JniException e) { } @@ -79,7 +80,6 @@ public class JniTracefileTest } - @Test public void testTracefileConstructors() { JniTrace testTrace = null; JniTracefile testTracefile1 = null; @@ -87,7 +87,7 @@ public class JniTracefileTest // This trace should be valid and will be used in test try { - testTrace = new JniTrace(tracepath1); + testTrace = new JniTrace(tracepath1, printLttDebug); } catch( JniException e) { } @@ -122,7 +122,6 @@ public class JniTracefileTest } - @Test public void testGetSet() { JniTracefile testTracefile = prepareTracefileToTest(); @@ -166,7 +165,6 @@ public class JniTracefileTest } - @Test public void testPrintAndToString() { JniTracefile testTracefile = prepareTracefileToTest(); @@ -184,7 +182,6 @@ public class JniTracefileTest } - @Test public void testEventDisplacement() { int readValue = -1; diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/TestStateManager.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/TestStateManager.java index c5348d9b3e..08cc38836b 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/TestStateManager.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/TestStateManager.java @@ -18,36 +18,14 @@ import org.eclipse.linuxtools.lttng.ActivateDebugging; import org.eclipse.linuxtools.lttng.TraceDebug; import org.eclipse.linuxtools.lttng.trace.LTTngTrace; import org.eclipse.linuxtools.tmf.trace.TmfExperiment; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import junit.framework.TestCase; /** * @author alvaro * */ -public class TestStateManager { - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - ActivateDebugging.activate(); - } - - @After - public void tearDown() throws Exception { - } - - @Test +public class TestStateManager extends TestCase { + public void testSetTraceSelection() { String logName = "traceset/trace1"; diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/AbsStateUpdate.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/AbsStateUpdate.java index 1500fa42a9..1c34ad28f8 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/AbsStateUpdate.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/AbsStateUpdate.java @@ -272,7 +272,7 @@ public abstract class AbsStateUpdate implements IEventProcessing { String expectedFieldName = expectedField.getInName(); for (int i = 0; i < fields.length; i++) { field = (LttngEventField) fields[i]; - fieldname = field.getName(); + fieldname = field.getId(); if (fieldname.equals(expectedFieldName)) { Object fieldObj = field.getValue(); if (fieldObj instanceof Long) { @@ -327,7 +327,7 @@ public abstract class AbsStateUpdate implements IEventProcessing { String expectedFieldName = expectedField.getInName(); for (int i = 0; i < fields.length; i++) { field = (LttngEventField) fields[i]; - fieldname = field.getName(); + fieldname = field.getId(); if (fieldname.equals(expectedFieldName)) { Object fieldObj = field.getValue(); if (fieldObj instanceof String) { @@ -361,7 +361,7 @@ public abstract class AbsStateUpdate implements IEventProcessing { sb.append(" number of fields: " + fields.length + "Fields: "); for (int i = 0; i < fields.length; i++) { field = (LttngEventField) fields[i]; - sb.append(field.getName() + " "); + sb.append(field.getId() + " "); } TraceDebug.debug(sb.toString(), 5); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/after/StateAfterUpdateHandlers.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/after/StateAfterUpdateHandlers.java index a58622cd57..6cb870f21b 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/after/StateAfterUpdateHandlers.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/after/StateAfterUpdateHandlers.java @@ -72,7 +72,7 @@ class StateAfterUpdateHandlers { + ExecutionMode.LTTV_STATE_SYSCALL.getInName()); } - if (stackState.getEntry_LttTime() != trcEvent.getTimestamp()) { + if (stackState.getEntry_LttTime() != trcEvent.getTimestamp().getValue()) { TraceDebug.debug("Unexpected Entry time: " + trcEvent.getTimestamp() + " Expected: " + stackState.getEntry_LttTime()); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/before/StateBeforeUpdateHandlers.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/before/StateBeforeUpdateHandlers.java index 591133cefa..d68d5fb6be 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/before/StateBeforeUpdateHandlers.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/state/handlers/before/StateBeforeUpdateHandlers.java @@ -71,8 +71,8 @@ class StateBeforeUpdateHandlers { exState = new LttngExecutionState(); exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL); exState.setExec_submode(submode); - exState.setEntry_Time(trcEvent.getTimestamp()); - exState.setChange_Time(trcEvent.getTimestamp()); + exState.setEntry_Time(trcEvent.getTimestamp().getValue()); + exState.setChange_Time(trcEvent.getTimestamp().getValue()); exState.setCum_cpu_time(0L); return false; diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/trace/LTTngTraceTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/trace/LTTngTraceTest.java index 023c79bfb8..9c30399507 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/trace/LTTngTraceTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/trace/LTTngTraceTest.java @@ -1,14 +1,9 @@ package org.eclipse.linuxtools.lttng.trace; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import org.eclipse.linuxtools.tmf.event.TmfEvent; import org.eclipse.linuxtools.tmf.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; -import org.junit.Test; +import junit.framework.TestCase; /* Functions tested here : @@ -24,7 +19,7 @@ import org.junit.Test; */ -public class LTTngTraceTest { +public class LTTngTraceTest extends TestCase { private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu"; private final static String wrongTracePath="/somewhere/that/does/not/exist"; @@ -58,8 +53,7 @@ public class LTTngTraceTest { return tmpStream; } - - @Test + public void testTraceConstructors() { @SuppressWarnings("unused") LTTngTrace testStream1 = null; @@ -102,7 +96,6 @@ public class LTTngTraceTest { } } - @Test public void testParseNextEvent() { TmfEvent tmpEvent = null; LTTngTrace testStream1 = prepareStreamToTest(); @@ -119,7 +112,6 @@ public class LTTngTraceTest { assertEquals("tmpEvent has wrong timestamp after second parseEvent()",secondEventTimestamp,(long)tmpEvent.getTimestamp().getValue() ); } - @Test public void testSeekLocation() { TmfEvent tmpEvent = null; TmfTraceContext tmpContext = new TmfTraceContext(null, null, 0); @@ -131,7 +123,7 @@ public class LTTngTraceTest { assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpContext.getLocation()).getValue() ); tmpEvent = testStream1.parseEvent(tmpContext); assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent ); - assertTrue("tmpEvent has wrong reference after first seekLocation()", ((String)tmpEvent.getReference().getValue()).contains(seek1EventReference) ); + assertTrue("tmpEvent has wrong reference after first seekLocation()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) ); // Seek to the last timestamp tmpContext = testStream1.seekLocation(new TmfTimestamp(timestampToSeekLast)); @@ -139,7 +131,7 @@ public class LTTngTraceTest { assertEquals("tmpContext has wrong timestamp after seekLocation() to last",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpContext.getLocation()).getValue() ); tmpEvent = testStream1.parseEvent(tmpContext); assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent ); - assertTrue("tmpEvent has wrong reference after seekLocation() to last",((String)tmpEvent.getReference().getValue()).contains(seekLastEventReference) ); + assertTrue("tmpEvent has wrong reference after seekLocation() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) ); // Seek to the first timestamp (startTime) tmpContext = testStream1.seekLocation(new TmfTimestamp(firstEventTimestamp)); @@ -147,11 +139,10 @@ public class LTTngTraceTest { assertEquals("tmpContext has wrong timestamp after seekLocation() to start",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpContext.getLocation()).getValue() ); tmpEvent = testStream1.parseEvent(tmpContext); assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent ); - assertTrue("tmpEvent has wrong reference after seekLocation() to start",((String)tmpEvent.getReference().getValue()).contains(firstEventReference) ); + assertTrue("tmpEvent has wrong reference after seekLocation() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) ); } - @Test public void testGetter() { TmfEvent tmpEvent = null; LTTngTrace testStream1 = prepareStreamToTest(); @@ -167,10 +158,9 @@ public class LTTngTraceTest { // Test current event assertNotSame("tmpEvent is null after first event",null,tmpEvent ); - assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getValue()).contains(firstEventReference) ); + assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) ); } - @Test public void testToString() { LTTngTrace testStream1 = prepareStreamToTest(); diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java index b9a728632b..7cf42f2cd7 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java @@ -51,9 +51,9 @@ ITmfTimeAnalysisEntry { protected String groupName = ""; protected String className = ""; protected CompositeType contType = CompositeType.UNKNOWN; - protected long next_good_time = -1; + protected Long next_good_time = -1L; /*Time of first event which trigger the creation of this local resource */ - protected long insertionTime = -1; + protected Long insertionTime = -1L; // ======================================================================== // Constructors diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/AbsFlowTRangeUpdate.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/AbsFlowTRangeUpdate.java index f4879b4fdb..cdde5bba81 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/AbsFlowTRangeUpdate.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/AbsFlowTRangeUpdate.java @@ -12,6 +12,7 @@ package org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor; import java.util.Vector; +import org.eclipse.linuxtools.lttng.TraceDebug; import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus; import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing; import org.eclipse.linuxtools.lttng.state.model.LttngProcessState; @@ -45,8 +46,10 @@ public abstract class AbsFlowTRangeUpdate extends AbsTRangeUpdate implements IEv procContainer.getUniqueId(), stateProcess.getName(), traceStartTime, traceEndTime, "", stateProcess.getType() .getInName(), stateProcess.getCpu(), stateProcess - .getInsertion_time().getValue()); - localProcess.setCreationTime(stateProcess.getCreation_time().getValue()); + .getInsertion_time()); + + + localProcess.setCreationTime(stateProcess.getCreation_time()); localProcess.setPid(stateProcess.getPid()); localProcess.setTgid(stateProcess.getTgid()); localProcess.setPpid(stateProcess.getPpid()); diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeAfterUpdateHandlers.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeAfterUpdateHandlers.java index 8ca30915a0..df7e041f8a 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeAfterUpdateHandlers.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeAfterUpdateHandlers.java @@ -60,7 +60,7 @@ class FlowTRangeAfterUpdateHandlers { } //hashed_process_data = processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num); - TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCpu(), traceSt.getTraceId(),process_in.getCreation_time().getValue() ); + TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCpu(), traceSt.getTraceId(),process_in.getCreation_time() ); if ( localProcess == null ) { if ( (pid_in == 0) || (pid_in != process_in.getPpid()) ) { @@ -139,7 +139,7 @@ class FlowTRangeAfterUpdateHandlers { LttngProcessState process_child = lttv_state_find_process(traceSt, trcEvent.getCpuId(), child_pid ); if ( process_child != null ) { - TimeRangeEventProcess localProcess = procContainer.findProcess(process_child.getPid(), process_child.getCpu(), traceSt.getTraceId(), process_child.getCreation_time().getValue() ); + TimeRangeEventProcess localProcess = procContainer.findProcess(process_child.getPid(), process_child.getCpu(), traceSt.getTraceId(), process_child.getCreation_time() ); if ( localProcess == null ) { if ( (child_pid == 0) || (child_pid != process_child.getPpid()) ) { @@ -198,7 +198,7 @@ class FlowTRangeAfterUpdateHandlers { // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){ // hashed_process_data = process_list->current_hash_data[trace_num][cpu]; // } - TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time().getValue()); + TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time()); if ( localProcess == null ) { if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) { @@ -246,7 +246,7 @@ class FlowTRangeAfterUpdateHandlers { if ( process != null ) { - TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time().getValue()); + TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time()); if ( localProcess == null ) { if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) { @@ -302,7 +302,7 @@ class FlowTRangeAfterUpdateHandlers { // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){ // hashed_process_data = process_list->current_hash_data[trace_num][cpu]; // } - TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time().getValue()); + TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time()); if ( localProcess == null ) { if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) { @@ -382,7 +382,7 @@ class FlowTRangeAfterUpdateHandlers { LttngProcessState process_in = lttv_state_find_process(traceSt, trcEvent.getCpuId(), pid_in ); if ( process_in != null ) { - TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCpu(), traceSt.getTraceId(), process_in.getCreation_time().getValue()); + TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCpu(), traceSt.getTraceId(), process_in.getCreation_time()); if (localProcess == null) { if ( (process_in.getPid() == 0) || (process_in.getPid() != process_in.getPpid()) ) { diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java index 20362e3f8a..cad26eee4e 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java @@ -63,7 +63,7 @@ class FlowTRangeBeforeUpdateHandlers { // may change TimeRangeEventProcess localProcess = procContainer .findProcess(stateProcess.getPid(), stateProcess.getCpu(), traceId, stateProcess - .getCreation_time().getValue()); + .getCreation_time()); // Add process to process list if not present if (localProcess == null) { @@ -146,7 +146,7 @@ class FlowTRangeBeforeUpdateHandlers { // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num); TimeRangeEventProcess localProcess = procContainer .findProcess(process.getPid(), process.getCpu(), traceSt - .getTraceId(), process.getCreation_time().getValue()); + .getTraceId(), process.getCreation_time()); // Add process to process list if not present // Replace C Call : @@ -181,7 +181,7 @@ class FlowTRangeBeforeUpdateHandlers { // tfs->cpu, &birth, trace_num); TimeRangeEventProcess localProcess = procContainer .findProcess(process.getPid(), process.getCpu(), traceSt - .getTraceId(), process.getCreation_time().getValue()); + .getTraceId(), process.getCreation_time()); // Add process to process list if not present // Replace C Call : @@ -255,7 +255,7 @@ class FlowTRangeBeforeUpdateHandlers { // process->cpu, &birth,trace_num); TimeRangeEventProcess localProcess = procContainer .findProcess(process.getPid(), process.getCpu(), traceSt - .getTraceId(), process.getCreation_time().getValue()); + .getTraceId(), process.getCreation_time()); // Add process to process list if not present // Replace C Call : @@ -324,7 +324,7 @@ class FlowTRangeBeforeUpdateHandlers { TimeRangeEventProcess localProcess = procContainer .findProcess(process.getPid(), process.getCpu(), traceSt .getTraceId(), process - .getCreation_time().getValue()); + .getCreation_time()); // This is as it was in the C ... ? if (localProcess == null) { @@ -395,7 +395,7 @@ class FlowTRangeBeforeUpdateHandlers { TimeRangeEventProcess localProcess = procContainer .findProcess(process.getPid(), process.getCpu(), traceSt .getTraceId(), process - .getCreation_time().getValue()); + .getCreation_time()); // Add process to process list if not present if (localProcess == null) { diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java index 64be7332b4..65e0f369a0 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java @@ -73,6 +73,7 @@ public class FlowProcessContainer { * @return TimeRangeEventProcess[] */ public TimeRangeEventProcess[] readProcesses() { + // This allow us to return an Array of the correct type of the exact correct dimension, without looping return allProcesses.values().toArray(new TimeRangeEventProcess[allProcesses.size()]); } @@ -138,9 +139,9 @@ public class FlowProcessContainer { * @return TimeRangeEventProcess */ public TimeRangeEventProcess findProcess(Long searchedPid, Long searchedCpuId, String searchedTraceID, Long searchedCreationtime) { - // Get the TimeRangeEventProcess associated to a key we create here + // Get the TimeRangeEventProcess associated to a key we create here TimeRangeEventProcess foundProcess = allProcesses.get( new ProcessKey(searchedPid, searchedCpuId, searchedTraceID, searchedCreationtime) ); - + return foundProcess; } } @@ -251,6 +252,6 @@ class ProcessKey { return (valueRef.getPid().toString() + ":" + valueRef.getCpu().toString() + ":" + valueRef.getTraceID().toString() + ":" + valueRef.getCreationTime().toString()); } - return (pid + ":" + cpuId + ":" + traceId + ":" + creationtime); + return (pid.toString() + ":" + cpuId.toString() + ":" + traceId.toString() + ":" + creationtime.toString()); } } diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/events/EventsView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/events/EventsView.java index 41c21d57af..ae90331ad8 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/events/EventsView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/events/EventsView.java @@ -12,6 +12,8 @@ package org.eclipse.linuxtools.lttng.ui.views.events; +import org.eclipse.linuxtools.lttng.event.LttngEvent; +import org.eclipse.linuxtools.lttng.event.LttngEventContent; import org.eclipse.linuxtools.tmf.event.TmfEvent; import org.eclipse.linuxtools.tmf.ui.views.TmfEventsView; import org.eclipse.swt.SWT; @@ -106,13 +108,15 @@ public class EventsView extends TmfEventsView { @Override protected String[] extractItemFields(TmfEvent event) { String[] fields = new String[0]; + if (event != null) { fields = new String[] { event.getTimestamp().toString(), event.getSource().toString(), event.getType().toString(), event.getReference().toString(), - event.getContent().getContent() }; + ((LttngEventContent)event.getContent()).toString() + }; } return fields; } diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/evProcessor/ResourcesTRangeUpdateFactory.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/evProcessor/ResourcesTRangeUpdateFactory.java index 58098e8381..14b67caa0f 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/evProcessor/ResourcesTRangeUpdateFactory.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/evProcessor/ResourcesTRangeUpdateFactory.java @@ -30,26 +30,26 @@ import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing; * */ public class ResourcesTRangeUpdateFactory extends AbsEventProcessorFactory { - // ======================================================================== - // Data - // ======================================================================= - private final Map eventNametoBeforeProcessor = new HashMap(); - private final Map eventNametoAfterProcessor = new HashMap(); + // ======================================================================== + // Data + // ======================================================================= + private final Map eventNametoBeforeProcessor = new HashMap(); + private final Map eventNametoAfterProcessor = new HashMap(); private ResourcesTRangeFinishUpdateHandler finishProcessor = null; - private static ResourcesTRangeUpdateFactory instance = null; - private ResourcesTRangeBeforeUpdateHandlers instantiateBeforeHandler = new ResourcesTRangeBeforeUpdateHandlers(); - private ResourcesTRangeAfterUpdateHandlers instantiateAfterHandler = new ResourcesTRangeAfterUpdateHandlers(); - - + private static ResourcesTRangeUpdateFactory instance = null; + private ResourcesTRangeBeforeUpdateHandlers instantiateBeforeHandler = new ResourcesTRangeBeforeUpdateHandlers(); + private ResourcesTRangeAfterUpdateHandlers instantiateAfterHandler = new ResourcesTRangeAfterUpdateHandlers(); + private ResourcesTRangeUpdateFactory() { - // Create one instance of each individual event handler and add the instance to the map + // Create one instance of each individual event handler and add the + // instance to the map - // *** BEFORE HOOKS *** + // *** BEFORE HOOKS *** eventNametoBeforeProcessor.put( StateStrings.Events.LTT_EVENT_SCHED_SCHEDULE.getInName(), instantiateBeforeHandler.getBeforeSchedChangeHandler()); - - eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_TRAP_ENTRY + + eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_TRAP_ENTRY .getInName(), instantiateBeforeHandler .getBeforeExecutionModeTrap()); eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_TRAP_EXIT @@ -69,15 +69,15 @@ public class ResourcesTRangeUpdateFactory extends AbsEventProcessorFactory { .put(StateStrings.Events.LTT_EVENT_PAGE_FAULT_NOSEM_EXIT .getInName(), instantiateBeforeHandler .getBeforeExecutionModeTrap()); - - eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_IRQ_ENTRY + + eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_IRQ_ENTRY .getInName(), instantiateBeforeHandler .getBeforeExecutionModeIrq()); eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_IRQ_EXIT .getInName(), instantiateBeforeHandler .getBeforeExecutionModeIrq()); - - eventNametoBeforeProcessor.put( + + eventNametoBeforeProcessor.put( StateStrings.Events.LTT_EVENT_SOFT_IRQ_RAISE.getInName(), instantiateBeforeHandler.getBeforeExecutionModeSoftIrq()); eventNametoBeforeProcessor.put( @@ -86,44 +86,41 @@ public class ResourcesTRangeUpdateFactory extends AbsEventProcessorFactory { eventNametoBeforeProcessor.put( StateStrings.Events.LTT_EVENT_SOFT_IRQ_EXIT.getInName(), instantiateBeforeHandler.getBeforeExecutionModeSoftIrq()); - - eventNametoBeforeProcessor.put( + + eventNametoBeforeProcessor.put( StateStrings.Events.LTT_EVENT_REQUEST_ISSUE.getInName(), instantiateBeforeHandler.getBeforeBdevEvent()); eventNametoBeforeProcessor.put( StateStrings.Events.LTT_EVENT_REQUEST_COMPLETE.getInName(), instantiateBeforeHandler.getBeforeBdevEvent()); - - - - // *** AFTER HOOKS *** + + // *** AFTER HOOKS *** eventNametoAfterProcessor.put( StateStrings.Events.LTT_EVENT_SCHED_SCHEDULE.getInName(), instantiateAfterHandler.getAfterSchedChangeHandler()); finishProcessor = new ResourcesTRangeFinishUpdateHandler(); - } - - - /** + } + + /** * */ public static AbsEventProcessorFactory getInstance() { - if (instance == null) { + if (instance == null) { instance = new ResourcesTRangeUpdateFactory(); - } - return instance; - } - - @Override - public IEventProcessing getAfterProcessor(String eventType) { - return eventNametoAfterProcessor.get(eventType); - } + } + return instance; + } + + @Override + public IEventProcessing getAfterProcessor(String eventType) { + return eventNametoAfterProcessor.get(eventType); + } - @Override - public IEventProcessing getBeforeProcessor(String eventType) { - return eventNametoBeforeProcessor.get(eventType); - } + @Override + public IEventProcessing getBeforeProcessor(String eventType) { + return eventNametoBeforeProcessor.get(eventType); + } @Override public IEventProcessing getfinishProcessor() { diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java index 23082c9207..2f9545d1ab 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java @@ -177,7 +177,7 @@ class ResourceKey { else { if ( ( ((ResourceKey)obj).getResourceId().equals(this.resourceId)) && ( ((ResourceKey)obj).getTraceId().equals(this.traceId)) && - ( ((ResourceKey)obj).getType().equals(this.traceId)) ) + ( ((ResourceKey)obj).getType().equals(this.type)) ) { isSame = true; } diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/statistics/evProcessor/AbstractStatsEventHandler.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/statistics/evProcessor/AbstractStatsEventHandler.java index 613cef3348..57c99b906b 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/statistics/evProcessor/AbstractStatsEventHandler.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/statistics/evProcessor/AbstractStatsEventHandler.java @@ -152,7 +152,7 @@ abstract class AbstractStatsEventHandler implements IEventProcessing { if (process.getState().getProc_status().equals(ProcessStatus.LTTV_STATE_RUN) && !process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) { node.getValue().cpuTime += event.getTimestamp().getValue() - - process.getState().getChange_LttTime().getValue(); + - process.getState().getChange_LttTime(); } } @@ -168,7 +168,7 @@ abstract class AbstractStatsEventHandler implements IEventProcessing { if (!process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) { node.getValue().elapsedTime += event.getTimestamp().getValue() - - process.getState().getEntry_LttTime().getValue(); + - process.getState().getEntry_LttTime(); } } @@ -184,14 +184,14 @@ abstract class AbstractStatsEventHandler implements IEventProcessing { if (!process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) { long cumulativeCpuTime = process.getState().getCum_cpu_time(); - long delta = event.getTimestamp().getValue() - process.getState().getEntry_LttTime().getValue(); + long delta = event.getTimestamp().getValue() - process.getState().getEntry_LttTime(); process.getState().setCum_cpu_time(cumulativeCpuTime + delta); node.getValue().cumulativeCpuTime += process.getState().getCum_cpu_time(); } else if (process.getState().getProc_status().equals(ProcessStatus.LTTV_STATE_RUN) && !process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) { long cumulativeCpuTime = process.getState().getCum_cpu_time(); - long delta = event.getTimestamp().getValue() - process.getState().getChange_LttTime().getValue(); + long delta = event.getTimestamp().getValue() - process.getState().getChange_LttTime(); process.getState().setCum_cpu_time(cumulativeCpuTime + delta); node.getValue().cumulativeCpuTime += process.getState().getCum_cpu_time(); } @@ -209,7 +209,7 @@ abstract class AbstractStatsEventHandler implements IEventProcessing { if (process.getState().getProc_status().equals(ProcessStatus.LTTV_STATE_RUN) && !process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) { long cumulativeCpuTime = process.getState().getCum_cpu_time(); - long delta = event.getTimestamp().getValue() - process.getState().getChange_LttTime().getValue(); + long delta = event.getTimestamp().getValue() - process.getState().getChange_LttTime(); process.getState().setCum_cpu_time(cumulativeCpuTime + delta); } } diff --git a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java index 2b278095cd..6902bbdc12 100644 --- a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java +++ b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java @@ -12,17 +12,9 @@ package org.eclipse.linuxtools.lttng.stubs; -import java.io.EOFException; import java.io.IOException; -import java.io.RandomAccessFile; -import java.util.Vector; 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.trace.ITmfEventParser; import org.eclipse.linuxtools.tmf.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; @@ -34,108 +26,114 @@ import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; */ public class LTTngEventParserStub implements ITmfEventParser { - // ======================================================================== - // Attributes - // ======================================================================== - - private final int NB_FORMATS = 10; - private final TmfEventFormat[] fFormats; - - // ======================================================================== - // Constructors - // ======================================================================== - - public LTTngEventParserStub() { - fFormats = new TmfEventFormat[NB_FORMATS]; - for (int i = 0; i < NB_FORMATS; i++) { - Vector format = new Vector(); - for (int j = 1; j <= i; j++) { - format.add(new String("Fmt-" + i + "-Fld-" + j)); - } - String[] fields = new String[i]; - fFormats[i] = new TmfEventFormat(format.toArray(fields)); - } - } - - // ======================================================================== - // Accessors - // ======================================================================== - - // ======================================================================== - // Operators - // ======================================================================== - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent() - */ - static final String typePrefix = "Type-"; - public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfTraceContext context) throws IOException { - - if (! (eventStream instanceof LTTngTraceStub)) { - return null; - } - - // Highly inefficient... - RandomAccessFile stream = ((LTTngTraceStub) eventStream).getStream(); - String name = eventStream.getName(); - name = name.substring(name.lastIndexOf('/') + 1); - - synchronized(stream) { - long location = 0; - if (context != null) - location = (Long) (context.getLocation()); - stream.seek(location); - - try { - // Read the individual fields - long ts = stream.readLong(); - String source = stream.readUTF(); - String type = stream.readUTF(); - @SuppressWarnings("unused") - int reference = stream.readInt(); - - // Read the event parts - int typeIndex = Integer.parseInt(type.substring(typePrefix.length())); - String[] fields = new String[typeIndex]; - for (int i = 0; i < typeIndex; i++) { - fields[i] = stream.readUTF(); - } - - // Format the content from the individual fields - String content = "["; - if (typeIndex > 0) { - content += fields[0]; - } - for (int i = 1; i < typeIndex; i++) { - content += ", " + fields[i]; - } - content += "]"; - - // Update the context - context.setLocation(stream.getFilePointer()); - context.incrIndex(); - try { - long ts2 = stream.readLong(); - context.setTimestamp(new LTTngTimestampStub(ts2)); - } catch (EOFException e) { - context.setTimestamp(null); - } - - // Create the event - TmfEvent event = new TmfEvent( - new LTTngTimestampStub(ts), - new TmfEventSource(source), - new TmfEventType(type, fFormats[typeIndex]), - new TmfEventContent(content, fFormats[typeIndex]), - new TmfEventReference(name)); - - return event; - - } catch (EOFException e) { - context.setTimestamp(null); - } - } - return null; - } + public TmfEvent parseNextEvent(ITmfTrace stream, TmfTraceContext context) + throws IOException { + // TODO Auto-generated method stub + return null; + } + +// // ======================================================================== +// // Attributes +// // ======================================================================== +// +// private final int NB_FORMATS = 10; +// private final TmfEventFormat[] fFormats; +// +// // ======================================================================== +// // Constructors +// // ======================================================================== +// +// public LTTngEventParserStub() { +// fFormats = new TmfEventFormat[NB_FORMATS]; +// for (int i = 0; i < NB_FORMATS; i++) { +// Vector format = new Vector(); +// for (int j = 1; j <= i; j++) { +// format.add(new String("Fmt-" + i + "-Fld-" + j)); +// } +// String[] fields = new String[i]; +// fFormats[i] = new TmfEventFormat(format.toArray(fields)); +// } +// } +// +// // ======================================================================== +// // Accessors +// // ======================================================================== +// +// // ======================================================================== +// // Operators +// // ======================================================================== +// +// /* (non-Javadoc) +// * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent() +// */ +// static final String typePrefix = "Type-"; +// public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfTraceContext context) throws IOException { +// +// if (! (eventStream instanceof LTTngTraceStub)) { +// return null; +// } +// +// // Highly inefficient... +// RandomAccessFile stream = ((LTTngTraceStub) eventStream).getStream(); +// String name = eventStream.getName(); +// name = name.substring(name.lastIndexOf('/') + 1); +// +// synchronized(stream) { +// long location = 0; +// if (context != null) +// location = (Long) (context.getLocation()); +// stream.seek(location); +// +// try { +// // Read the individual fields +// long ts = stream.readLong(); +// String source = stream.readUTF(); +// String type = stream.readUTF(); +// @SuppressWarnings("unused") +// int reference = stream.readInt(); +// +// // Read the event parts +// int typeIndex = Integer.parseInt(type.substring(typePrefix.length())); +// String[] fields = new String[typeIndex]; +// for (int i = 0; i < typeIndex; i++) { +// fields[i] = stream.readUTF(); +// } +// +// // Format the content from the individual fields +// String content = "["; +// if (typeIndex > 0) { +// content += fields[0]; +// } +// for (int i = 1; i < typeIndex; i++) { +// content += ", " + fields[i]; +// } +// content += "]"; +// +// // Update the context +// context.setLocation(stream.getFilePointer()); +// context.incrIndex(); +// try { +// long ts2 = stream.readLong(); +// context.setTimestamp(new LTTngTimestampStub(ts2)); +// } catch (EOFException e) { +// context.setTimestamp(null); +// } +// +// // Create the event +// TmfEvent event = new TmfEvent( +// new LTTngTimestampStub(ts), +// new TmfEventSource(source), +// new TmfEventType(type, fFormats[typeIndex]), +// new TmfEventContent(content, fFormats[typeIndex]), +// new TmfEventReference(name)); +// +// return event; +// +// } catch (EOFException e) { +// context.setTimestamp(null); +// } +// } +// return null; +// } } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEvent.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEvent.java index a315c635e8..a0f0d4ad4d 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEvent.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEvent.java @@ -3,8 +3,8 @@ package org.eclipse.linuxtools.lttng.event; import org.eclipse.linuxtools.tmf.event.TmfEvent; import org.eclipse.linuxtools.tmf.event.TmfEventSource; import org.eclipse.linuxtools.tmf.event.TmfTimestamp; -import org.eclipse.linuxtools.lttng.jni.JniEvent; import org.eclipse.linuxtools.lttng.LttngException; +import org.eclipse.linuxtools.lttng.jni.JniEvent; /** * LttngEvent

@@ -17,9 +17,9 @@ import org.eclipse.linuxtools.lttng.LttngException; @SuppressWarnings("unused") public class LttngEvent extends TmfEvent { - // Reference to the JNI JniEvent. Should only used INTERNALLY + // Reference to the JNI JniEvent. Should only be used INTERNALLY private JniEvent jniEventReference = null; - + /** * Constructor with parameters.

* @@ -35,16 +35,12 @@ public class LttngEvent extends TmfEvent { * @see org.eclipse.linuxtools.lttng.event.LttngEventType * @see org.eclipse.linuxtools.lttng.event.LttngEventContent * @see org.eclipse.linuxtools.lttng.event.LttngEventReference - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent */ - public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent) throws LttngException { - super(timestamp, source, type, content, reference); - - // Sanity checks - if ( (timestamp == null) || (source == null) || (type == null) || (content == null) || (reference == null) || (lttEvent == null) ) { - throw new LttngException("Event creation with null values is forbidden!"); - } + public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent) { + super(timestamp, source, type, reference); + fContent = content; jniEventReference = lttEvent; } @@ -54,7 +50,7 @@ public class LttngEvent extends TmfEvent { * @param oldEvent Event we want to copy from. * */ - public LttngEvent(LttngEvent oldEvent) throws LttngException { + public LttngEvent(LttngEvent oldEvent) { this( (LttngTimestamp)oldEvent.getTimestamp(), (TmfEventSource)oldEvent.getSource(), (LttngEventType)oldEvent.getType(), @@ -68,48 +64,62 @@ public class LttngEvent extends TmfEvent { /** * Return the channel name of this event.

* - * @return The name of the channel for this event + * @return Channel (tracefile) for this event */ public String getChannelName() { - String returnedValue = ""; + String returnedChannel = ""; - // This should always be true - if ( this.getType() instanceof LttngEventType ) { - returnedValue = ( (LttngEventType)this.getType() ).getChannelName(); - } - return returnedValue; + return ( (LttngEventType)this.getType() ).getTracefileName(); } /** * Cpu id number of this event.

* - * @return The cpu id + * @return Cpu id */ public long getCpuId() { - long returnedValue =-1; - - // This should always be true - if ( this.getType() instanceof LttngEventType ) { - returnedValue = ( (LttngEventType)this.getType() ).getCpuId(); - } - return returnedValue; + return ( (LttngEventType)this.getType() ).getCpuId(); } /** * Marker name of this event.

* - * @return The marker name + * @return Marker name */ public String getMarkerName() { String returnedValue = ""; - // This should always be true - if ( this.getType() instanceof LttngEventType ) { - returnedValue = ( (LttngEventType)this.getType() ).getMarkerName(); - } - return returnedValue; + return ( (LttngEventType)this.getType() ).getMarkerName(); } + + public JniEvent getJniEventReference() { + return jniEventReference; + } + + public void setJniEventReference(JniEvent newJniEventReference) { + this.jniEventReference = newJniEventReference; + } + + @Override + public LttngEventContent getContent() { + return (LttngEventContent)fContent; + } + + public void setContent(LttngEventContent newContent) { + fContent = newContent; + } + + @Override + public LttngEventType getType() { + return (LttngEventType)fType; + } + + public void setType(LttngEventType newType) { + fType = newType; + } + + /** * Convert this event into a Jni JniEvent.

* @@ -118,16 +128,22 @@ public class LttngEvent extends TmfEvent { * * @return The converted JniEvent * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent convertEventTmfToJni() { JniEvent tmpEvent = null; + // ***TODO*** + // Should we remove the check to save some time?? + // We don't want to send away events that are outdated as their informations could be invalid // If the timestamp between the event and the trace are not coherent we will not perform the conversion if ( jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime() == getTimestamp().getValue() ) { tmpEvent = jniEventReference; } + else { + System.out.println("WRONG TIMESTAMP : " + getTimestamp().getValue() + " vs " + jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime()); + } return tmpEvent; } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java index a614cdd3e6..082dc5b6fc 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java @@ -12,8 +12,9 @@ package org.eclipse.linuxtools.lttng.event; +import java.util.HashMap; + import org.eclipse.linuxtools.tmf.event.TmfEventContent; -import org.eclipse.linuxtools.tmf.event.TmfEventField; /** * LttngEventContent

@@ -22,27 +23,41 @@ import org.eclipse.linuxtools.tmf.event.TmfEventField; */ public class LttngEventContent extends TmfEventContent { + // Hash map that contain the (parsed) fields. This is the actual payload of the event. + HashMap fFieldsMap = new HashMap(); + /** - * Constructor with parameters.

+ * Default constructor.

* - * Content will be empty as no parsed content is given. * - * @param thisFormat The LttngEventFormat relative to the JniEvent */ - public LttngEventContent(LttngEventFormat thisFormat) { - super("", thisFormat); + public LttngEventContent() { + super(null, null); } - + /** * Constructor with parameters.

* - * @param thisFormat The LttngEventFormat relative to this JniEvent - * @param thisParsedContent The string content of the JniEvent, already parsed + * @param thisParent Parent event for this content. + * + * @see org.eclipse.linuxtools.lttng.event.LttngEvent + */ + public LttngEventContent(LttngEvent thisParent) { + super(thisParent, null); + } + + /** + * Constructor with parameters, with optional content.

+ * + * @param thisParent Parent event for this content. + * @param thisContent Already parsed content. + * + * @see org.eclipse.linuxtools.lttng.event.LttngEvent */ - public LttngEventContent(LttngEventFormat thisFormat, String thisParsedContent, TmfEventField[] thisFields) { - super(thisParsedContent, thisFormat); + public LttngEventContent(LttngEvent thisParent, HashMap thisContent) { + super(thisParent, null); - setFields(thisFields); + fFieldsMap = thisContent; } /** @@ -51,117 +66,177 @@ public class LttngEventContent extends TmfEventContent { * @param oldContent Content to copy from */ public LttngEventContent(LttngEventContent oldContent) { - this( (LttngEventFormat)oldContent.getFormat(), oldContent.getContent(), oldContent.getFields() ); + this((LttngEvent)oldContent.getEvent(), oldContent.getRawContent() ); + } + + + public LttngEvent getEvent() { + return (LttngEvent)fParentEvent; + } + + public void setEvent(LttngEvent newParent) { + fParentEvent = newParent; + } + + + // *** VERIFY *** + // These are not very useful, are they? + public LttngEventType getType() { + return (LttngEventType)fParentEvent.getType(); +// return (LttngEventType)fEventType; + } + public void setType(LttngEventType newType) { + ((LttngEvent)fParentEvent).setType(newType); +// fEventType = newType; } + + // ***TODO*** + // Find a better way to ensure content is sane!! + public void emptyContent() { + fFieldsMap.clear(); + } + + // ***VERIFY*** + // A bit weird to return the _currently_parsed fields (unlike all like getFields() ) + // Should we keep this? /** - * *DEPRECATED*
Get all fields of the content.

- * - * DO NOT USE!
- * This function will disapears soon! Use getFields(LttngEvent) instead.

+ * Return currently parsed fields in an object array format.

* - * If the content was not parsed, format.parse() will get called.

- * - * @return An array of TmfEventFields + * @return Currently parsed fields. */ @Override - public TmfEventField[] getFields() { - - // Request the field variable from the inherited class - TmfEventField[] fields = super.getFields(); + public Object[] getContent() { + Object[] returnedContent = fFieldsMap.values().toArray( new Object[fFieldsMap.size()] ); - // Field may be null if the content hasn't been parse yet - // If that's the case, call the parsing function - if (fields == null) { - fields = ((LttngEventFormat) this.getFormat()).parse(this.getContent()); - setFields(fields); - } - return fields; + return returnedContent; } - + /** - * *DEPRECATED*
Get a single field of the content, from its id (position).

+ * Return currently parsed fields in the internal hashmap format.

* - * DO NOT USE!
- * This function will disapears soon! Use getFields(LttngEvent) instead.

+ * @return Currently parsed fields. + */ + public HashMap getRawContent() { + return fFieldsMap; + } + +// @SuppressWarnings("unchecked") +// @Override +// public LttngEventField[] getFields() { +// LttngEventField tmpField = null; +// +// // *** TODO *** +// // SLOW! SLOW! SLOW! We should prevent the user to use this!! +// HashMap parsedContent = parseContent(); +// +// String contentKey = null; +// Iterator contentItr = parsedContent.keySet().iterator(); +// while ( contentItr.hasNext() ) { +// contentKey = contentItr.next(); +// +// tmpField = new LttngEventField(this, contentKey, parsedContent.get(contentKey)); +// ((HashMap)fFields).put(contentKey, tmpField); +// } +// +// return fFields.values().toArray(new LttngEventField[fFields.size()]); +// } + + /** + * Parse all fields and return them as an array of LttngFields.

* - * If the content was not parsed, format.parse() will get called.

+ * Note : This function is heavy and should only be called if all fields are really needed. * - * @param id The id of the field we want to obtain. + * @return All fields. * - * @return A single LttngEventField + * @see @see org.eclipse.linuxtools.lttng.event.LttngEventField */ @Override - public LttngEventField getField(int id) { - LttngEventField returnedField = null; + public LttngEventField[] getFields() { + LttngEventField tmpField = null; - if ( (id >= 0) && (id < this.getNbFields()) ) - { - // Call getFields() of this object. Will parse if fields were'nt parse before. - TmfEventField[] allFields = this.getFields(); + LttngEventType tmpType = (LttngEventType)fParentEvent.getType(); + + for ( int pos=0; pos - * - * If the content was not parsed, format.parse(LttngEvent) will get called.

+ * Parse a single field from its given position.

* - * @param thisEvent The event to get the fields from + * @return The parsed field or null. * - * @return An array of TmfEventFields + * @see @see org.eclipse.linuxtools.lttng.event.LttngEventField */ - public TmfEventField[] getFields(LttngEvent thisEvent) { - - // Request the field variable from the inherited class - TmfEventField[] fields = super.getFields(); + @Override + public LttngEventField getField(int position) { + LttngEventField returnedField = null; + String label = fParentEvent.getType().getLabel(position); - // Field may be null if the content hasn't been parse yet - // If that's the case, call the parsing function - if (fields == null) { - fields = ((LttngEventFormat)this.getFormat()).parse(thisEvent); - setFields(fields); + if ( label != null ) { + returnedField = this.getField(label); } - return fields; + + return returnedField; } /** - * Get a single field of the content, from its id (position).

- * - * If the content was not parsed, format.parse(LttngEvent) will get called.

+ * Parse a single field from its given name.

* - * @param thisEvent The event to get the fields from - * @param id The id of the field we want to obtain. + * @return The parsed field or null. * - * @return A single LttngEventField + * @see @see org.eclipse.linuxtools.lttng.event.LttngEventField */ - public LttngEventField getField(int id, LttngEvent thisEvent) { - LttngEventField returnedField = null; + @Override + public LttngEventField getField(String name) { + // *** VERIFY *** + // Should we check if the field exists in LttngType before parsing? + // It could avoid calling parse for non-existent fields but would waste some cpu cycle on check? + LttngEventField returnedField = fFieldsMap.get(name); - if ( (id >= 0) && (id < this.getNbFields()) ) { - // Call getFields() of this object. Will parse if fields were'nt parse before. - TmfEventField[] allFields = this.getFields(thisEvent); + if ( returnedField == null ) { + // *** VERIFY *** + // Should we really make sure we didn't get null before creating/inserting a field? + Object newValue = ((LttngEvent)getEvent()).convertEventTmfToJni().parseFieldByName(name); - if ( allFields != null ) { - returnedField = (LttngEventField)allFields[id]; + if ( newValue!= null ) { + returnedField = new LttngEventField(this, name, newValue); + fFieldsMap.put(name, returnedField ); } } + return returnedField; } - + // *** VERIFY *** + // *** Is this even useful? + @Override + protected void parseContent() { + fFields = getFields(); + } + /** - * toString() method. + * toString() method to print the content * - * @return Attributes of the object concatenated in String + * Note : this function parse all fields and so is very heavy to use. */ @Override - public String toString() { - return getContent().toString(); + public String toString() { + String returnedString = ""; + + LttngEventField[] allFields = getFields(); + + for ( int pos=0; pos < allFields.length; pos++) { + returnedString += allFields[pos].toString() + " "; + } + + return returnedString; + } } \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventField.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventField.java index 7f28dc8be5..31b15bb2e0 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventField.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventField.java @@ -12,6 +12,7 @@ package org.eclipse.linuxtools.lttng.event; +import org.eclipse.linuxtools.tmf.event.TmfEventContent; import org.eclipse.linuxtools.tmf.event.TmfEventField; /** @@ -23,20 +24,26 @@ import org.eclipse.linuxtools.tmf.event.TmfEventField; * mean the fields will have a name and a value. */ public class LttngEventField extends TmfEventField { - private String fieldName = ""; + /** + * Constructor with parameters.

+ * + * @param parent Parent content for this field + * @param id Name (label) of this field + */ + public LttngEventField(TmfEventContent parent, String id) { + super(parent, id, null); + } + /** - * Constructor with parameters.

+ * Constructor with parameters with optional value.

* - * @param name Name of the field - * @param newContent ParsedContent we want to populate the field with. - * - * @see org.eclipse.linuxtools.lttng.jni.JniParser + * @param parent Parent content for this field + * @param id Name (label) of this field + * @param value Parsed value (payload) of this field */ - public LttngEventField(String name, Object newContent) { - super(newContent); - - fieldName = name; + public LttngEventField(TmfEventContent parent, String id, Object value) { + super(parent, id, value); } /** @@ -45,21 +52,12 @@ public class LttngEventField extends TmfEventField { * @param oldField the field to copy from */ public LttngEventField(LttngEventField oldField) { - this(oldField.fieldName, oldField.getValue()); + this(oldField.getParent(), oldField.getId(), oldField.getValue()); } - - public String getName() { - return fieldName; - } - - /** - * toString() method.

- * - * Print both field name and value (i.e. NAME:VALUE ). - */ @Override public String toString() { - return fieldName + ":" + getValue().toString(); + return getId().toString() + ":" + getValue().toString(); } + } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java deleted file mode 100644 index baf13c2746..0000000000 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventFormat.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * 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: - * William Bourque (wbourque@gmail.com) - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.lttng.event; - -import java.util.HashMap; -import java.util.Iterator; - -import org.eclipse.linuxtools.tmf.event.TmfEventFormat; - -/** - * LttngEventFormat

- * - * Lttng specific implementation of the TmfEventFormat.

- */ -public class LttngEventFormat extends TmfEventFormat { - - /** - * Constructor with parameters.

- * - * @param labels The fields labels of the content. - */ - public LttngEventFormat( String[] labels) { - super(labels); - } - - /** - * Copy constructor.

- * - * @param oldFormat The format to copy from - */ - public LttngEventFormat( LttngEventFormat oldFormat ) { - this(oldFormat.getLabels()); - } - - /** - * Parse the given LttngEvent.

- * - * @param thisEvent The LttngEvent to parse - * - * @return An array of LttngEventField that contain the parsed data - */ - public LttngEventField[] parse(LttngEvent thisEvent) { - // Obtain the parsed content from the JNI - HashMap parsedMap = thisEvent.convertEventTmfToJni().parseAllFields(); - LttngEventField[] returnedField = new LttngEventField[parsedMap.size()]; - - String fieldName = null; - int position = 0; - Iterator iterator = parsedMap.keySet().iterator(); - // Loop to create the LttngEventField from the parsedContent - while (iterator.hasNext()) { - fieldName = iterator.next(); - returnedField[position] = new LttngEventField( fieldName, parsedMap.get(fieldName) ); - position++; - } - - return returnedField; - } - - - /** - * *FIXME*
Parse from a HashMap of content.

- * - * This function will hopefully disapears soon!
- * We need to parse WHILE CREATING LttngEvent, so we cannot always use parse(LttngEvent).
- * This function is ugly but should be 100% safe to use.

- * - * @param parsedEvents HashMap of parsed content, as returned by JniParser.parseAllFields() - * - * @return An array of TmfEventFields - */ - public LttngEventField[] parse(HashMap parsedEvents) { - LttngEventField[] returnedField = new LttngEventField[parsedEvents.size()]; - - String fieldName = null; - int position = 0; - Iterator iterator = parsedEvents.keySet().iterator(); - // Loop to create the LttngEventField from the parsedContent in the map - while (iterator.hasNext()) { - fieldName = iterator.next(); - returnedField[position] = new LttngEventField( fieldName, parsedEvents.get(fieldName) ); - position++; - } - return returnedField; - } - - /** - * *DEPRECATED*
Parse from the content string.

- * - * DO NOT USE!
- * This function will disapears soon! Use parse(LttngEvent) instead.
- * It is evil to parse content string directly as we do not control the content.
- * So this would theorically works but it could break at any moment if kernel developpers changes their usual format.

- * - * This is provided because we need to implement this function since we inherit TmfFormat - * - * @param uselessContent Content to parse as String - * - * @return An array of TmfEventFields - */ - public LttngEventField[] parse(String uselessContent) { - - // This function is _under commented_ because you should not use it - // (this imply you shouldn't read it as well). - - // *** Begining of the evil "parse String" function - // - // - 1st : Find the number of ":" in the String. This will be the number of fields in the String. - // Highly unreliable, as we depend on String content that we don't control! - int nbFields = 0; - for ( int pos = 0; pos < uselessContent.length(); pos++ ) { - if ( uselessContent.substring(pos, pos+1).equals(":") ) { - nbFields++; - } - } - - // - 2nd : Create the fields array - LttngEventField[] tmpFields = new LttngEventField[nbFields]; - - // - 3rd : Fill the array - // Content is the NAME:VALUE format with space separators - // - // We search for 3 possible case : - // - Field name - // - Value (AKA payload or parsed content) - // - "Out of range" (EOF found) - // - // - int fieldPosition = 0; - int lastFieldnamePos = 0; - int lastDoubleDottedPos = 0; - int lastSpacePos = 0; - boolean isSearchingFieldname = true; - - String fieldName = ""; - String fieldValue = ""; - - int pos = 0; - while ( (pos < uselessContent.length()) && (fieldPosition length mean EOF - else if ( pos+2 >= uselessContent.length() ) { - fieldName = uselessContent.substring(lastSpacePos+1, lastDoubleDottedPos); - fieldValue = uselessContent.substring(lastDoubleDottedPos+1, pos+1); - - tmpFields[fieldPosition] = new LttngEventField( fieldName, fieldValue ); - fieldPosition++; - } - - pos++; - } - - return tmpFields; - } - -} diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java index 784bc5861c..9ed0652854 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventReference.java @@ -26,8 +26,18 @@ public class LttngEventReference extends TmfEventReference { /** * Constructor with parameters.

* + * @param newTraceName Trace name + */ + public LttngEventReference(String newTraceName) { + super(""); + tracename = newTraceName; + } + + /** + * Constructor with parameters with optional tracefile path.

+ * * @param newTracefilePath Complete tracefile path - * @param newTraceName The Trace name + * @param newTraceName Trace name */ public LttngEventReference(String newTracefilePath, String newTraceName) { super(newTracefilePath); @@ -54,10 +64,19 @@ public class LttngEventReference extends TmfEventReference { this.tracename = tracename; } + public String getValue() { + return (String)fReference; + } + + public void setValue(String newReference) { + fReference = newReference; + } + /** * toString() method.

* - * We return only tracename, as it will be used directly in the eventsView and it gives a better output. + * We return only tracename, as it will be used directly in the eventsView. + * Returning only tracename gives a better output. * * @return tracename as String */ diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java new file mode 100644 index 0000000000..3ba4a2c6ed --- /dev/null +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventSource.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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: + * William Bourque (wbourque@gmail.com) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.lttng.event; + +import org.eclipse.linuxtools.tmf.event.*; + +/** + * LttngEventSource

+ * + * Lttng specific implementation of the TmfEventSource + */ +public class LttngEventSource extends TmfEventSource { + + /** + * Default Constructor.

+ * + */ + public LttngEventSource() { + super(); + } + + /** + * Copy Constructor.

+ * + * @param newSource Source of the event as string. + */ + public LttngEventSource(String newSource) { + super(newSource); + } + + + /** + * Copy Constructor.

+ * + * @param oldSource LttngEventSource to copy from. + */ + public LttngEventSource(LttngEventSource oldSource) { + this( (String)oldSource.getSourceId() ); + } + + + public String getSourceId() { + return (String)fSourceId; + } + + public void setSourceId(String newSource) { + fSourceId = newSource; + } + + public String toString() { + return fSourceId.toString(); + } +} diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventType.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventType.java index 984ad8d3ba..156cd4e8f4 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventType.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventType.java @@ -22,62 +22,66 @@ import org.eclipse.linuxtools.tmf.event.*; * This implementation add some attributes to the basic Tmf object. */ public class LttngEventType extends TmfEventType { - private String channelName = ""; - private long cpuId = 0; - private String markerName = ""; + + private String tracefileName = null; + private Long cpuId = null; + private String markerName = null; /** - * Constructor with parameters.

+ * Default Constructor.

* - * @param thisChannelName Channel name. It is the Tracefile name in LTT - * @param thisCpuId CPU id number from LTT - * @param thisMarkerName JniMarker name. It is the marker_info name in LTT - * @param thisFormat The format relative to the event + */ + public LttngEventType() { + super(); + } + + /** + * Constructor with parameters.

* - * @see org.eclipse.linuxtools.lttng.event.LttngEventFormat + * @param thisTracefileName Tracefile (channel) name in Ltt + * @param thisMarkerName Marker name in LTT + * @param thisMarkerfieldsName MarkerFields related to this marker */ - public LttngEventType(String thisChannelName, long thisCpuId, String thisMarkerName, LttngEventFormat thisFormat) { - super( thisChannelName + "/" + thisCpuId + "/" + thisMarkerName, thisFormat); + public LttngEventType(String thisTracefileName, Long thisCpuId, String thisMarkerName, String[] thisMarkerfieldsName) { + super( thisTracefileName + "/" + thisCpuId + "/" + thisMarkerName, thisMarkerfieldsName); - channelName = thisChannelName; - cpuId = thisCpuId; - markerName = thisMarkerName; + tracefileName = thisTracefileName; + cpuId = thisCpuId; + markerName = thisMarkerName; } /** * Copy constructor.

* * @param oldType Type we want to copy from - * - * @see org.eclipse.linuxtools.lttng.event.LttngEventFormat */ public LttngEventType(LttngEventType oldType) { - this(oldType.channelName, oldType.cpuId, oldType.markerName, (LttngEventFormat)oldType.getFormat()); + this(oldType.tracefileName, oldType.cpuId, oldType.markerName, oldType.getLabels()); } - public String getChannelName() { - return channelName; + public String getTracefileName() { + return tracefileName; } - - public long getCpuId() { + public Long getCpuId() { return cpuId; } - public String getMarkerName() { return markerName; } - /** * toString() method. * - * @return TypeId (channel/cpu/marker) of the object + * @return TypeId (channel/marker) of the object */ @Override public String toString() { - return getTypeId(); + // *** TODO *** + // This is used as-it in the events view, so we won't change its format. + // ...but maybe we should? + return tracefileName + "/" + cpuId.toString() + "/" + markerName; } } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java index 21c2e05e36..df1da9e42a 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java @@ -25,11 +25,19 @@ public class LttngTimestamp extends TmfTimestamp { // Required by Serializable private static final long serialVersionUID = -7016853105162491273L; - + + /** + * Default Constructor.

+ * + */ + public LttngTimestamp() { + super(Long.MIN_VALUE, (byte) -9); + } + /** * Constructor with parameters.

* - * @param newEventTime JniTime as long, unit expected to be nanoseconds + * @param newEventTime Time as long, unit expected to be nanoseconds */ public LttngTimestamp(long newEventTime) { super(newEventTime, (byte) -9); @@ -43,7 +51,16 @@ public class LttngTimestamp extends TmfTimestamp { public LttngTimestamp(TmfTimestamp oldEventTime) { this(oldEventTime.getValue()); } - + + @Override + public long getValue() { + return fValue; + } + + public void setValue(long newValue) { + fValue = newValue; + } + /** * Get the second part in timestamp.

* @@ -65,7 +82,7 @@ public class LttngTimestamp extends TmfTimestamp { public String getNanoSeconds() { return formatNs(fValue); } - + /* * Use the exponent to format the second in the correct format. */ @@ -118,7 +135,7 @@ public class LttngTimestamp extends TmfTimestamp { /** * toString() method. * - * @return Attributes of this object. + * @return timestamp, as string */ @Override public String toString() { diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniEvent.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniEvent.java index aa36ee278d..c9acabe9f9 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniEvent.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniEvent.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; import java.util.HashMap; @@ -47,10 +47,8 @@ public final class JniEvent extends Jni_C_Common implements Comparable // Note that all type have been scaled up as there is no "unsigned" in java // This might be a problem about "unsigned long" as there is no equivalent // in java - private Jni_C_Pointer tracefilePtr = new Jni_C_Pointer();; - private int eventMarkerId = 0; + private Jni_C_Pointer tracefilePtr = new Jni_C_Pointer(); private JniTime eventTime = null; - private long eventDataSize = 0; // These methods need a tracefile pointer, instead of a event pointer private native int ltt_readNextEvent(long tracefilePtr); @@ -68,6 +66,8 @@ public final class JniEvent extends Jni_C_Common implements Comparable @SuppressWarnings("unused") private native long ltt_getTimestamp(long eventPtr); private native int ltt_getEventMarkerId(long eventPtr); + private native long ltt_getNanosencondsTime(long eventPtr); + @SuppressWarnings("unused") private native void ltt_feedEventTime(long eventPtr, JniTime eventTime); private native long ltt_getEventDataSize(long eventPtr); @SuppressWarnings("unused") @@ -107,9 +107,7 @@ public final class JniEvent extends Jni_C_Common implements Comparable eventState = oldEvent.eventState; tracefilePtr = oldEvent.tracefilePtr; - eventMarkerId = oldEvent.eventMarkerId; eventTime = oldEvent.eventTime; - eventDataSize = oldEvent.eventDataSize; } /** @@ -124,9 +122,9 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @exception JniException * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer - * @see org.eclipse.linuxtools.lttng.jni.JniMarker - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniMarker + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile */ public JniEvent(Jni_C_Pointer newEventPtr, HashMap newMarkersMap, JniTracefile newParentTracefile) throws JniException { @@ -147,10 +145,8 @@ public final class JniEvent extends Jni_C_Common implements Comparable // Try to move to the first event // If the event is Out of Range (ERANGE) at the first read, - // this event type will never been usable. + // this event type will never be usable. // In that case, throw JniNoSuchEventException to warn the tracefile. - // - // Position ourself on the first event. eventState = positionToFirstEvent(); if (eventState != EOK) { throw new JniNoSuchEventException("Object not populated, unusable. There is probably no event of that type in the trace. (JniEvent)"); @@ -167,17 +163,16 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return LTT read status, as defined in Jni_C_Common. * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Common */ public int readNextEvent() { // Ask Ltt to read the next event for this particular tracefile - eventState = ltt_readNextEvent(tracefilePtr.getPointer() ); - + eventState = ltt_readNextEvent( tracefilePtr.getPointer() ); // If the event state is sane populate it if (eventState == EOK) { populateEventInformation(); } - + return eventState; } @@ -193,7 +188,7 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return LTT read status, as defined in Jni_C_Common * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Common */ public int seekToTime(JniTime seekTime) { // Ask Ltt to read the next event for this particular tracefile @@ -216,11 +211,11 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return LTT read status, as defined in Jni_C_Common * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Common */ public int seekOrFallBack(JniTime seekTime) { // Save the old time - JniTime oldTime = eventTime; + JniTime oldTime = new JniTime(eventTime); // Call seek to move ahead // Save the state for the return (eventState will be modified if we seek back) @@ -246,7 +241,7 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return LTT read status, as defined in Jni_C_Common * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Common */ public int positionToFirstEvent() { eventState = ltt_positionToFirstEvent(tracefilePtr.getPointer()); @@ -259,10 +254,10 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return Reference to the marker for this tracefile's event or null if none. * - * @see org.eclipse.linuxtools.lttng.jni.JniMarker + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniMarker */ public JniMarker requestEventMarker() { - return markersMap.get(eventMarkerId); + return markersMap.get(getEventMarkerId()); } /** @@ -274,9 +269,9 @@ public final class JniEvent extends Jni_C_Common implements Comparable * @return Bytes array of raw data (contain raw C bytes). */ public byte[] requestEventContent() { - byte dataContent[] = new byte[(int) eventDataSize]; + byte dataContent[] = new byte[(int) getEventDataSize()]; - ltt_getDataContent(thisEventPtr.getPointer(), eventDataSize, dataContent); + ltt_getDataContent(thisEventPtr.getPointer(), getEventDataSize(), dataContent); return dataContent; } @@ -288,7 +283,7 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return Reference to the JniMarker object for this event or null if none. * - * @see org.eclipse.linuxtools.lttng.jni.JniMarker + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniMarker */ public String requestEventSource() { // *** TODO *** @@ -307,6 +302,8 @@ public final class JniEvent extends Jni_C_Common implements Comparable * @param fieldId Position of the field to parse. * * @return Object that contain the parsed payload + * + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniParser */ public Object parseFieldById(int fieldId) { return JniParser.parseField(this, fieldId); @@ -320,6 +317,8 @@ public final class JniEvent extends Jni_C_Common implements Comparable * @param fieldName Position of the field to parse. * * @return Object that contain the parsed payload + * + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniParser */ public Object parseFieldByName(String fieldName) { return JniParser.parseField(this, fieldName); @@ -328,7 +327,9 @@ public final class JniEvent extends Jni_C_Common implements Comparable /** * Method to parse all the event payload.

* - * @return HashMap which is the parsedContent objects and their name as key. + * @return HashMap which is the parsedContent objects and their name as key. + * + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniParser */ public HashMap parseAllFields() { return JniParser.parseAllFields(this); @@ -337,40 +338,32 @@ public final class JniEvent extends Jni_C_Common implements Comparable /* * This function populates the event data with data from LTT * + * NOTE : To get better performance, we copy very few data into memory here + * */ private void populateEventInformation() { - if (thisEventPtr.getPointer() == NULL) { - printlnC("Pointer is NULL, trace closed? (populateEventInformation)"); - } - else { - tracefilePtr = new Jni_C_Pointer( ltt_getTracefilePtr(thisEventPtr.getPointer()) ); - eventMarkerId = ltt_getEventMarkerId(thisEventPtr.getPointer()); - - // Creation of time is a bit different, we need to pass the object - // reference to C - ltt_feedEventTime(thisEventPtr.getPointer(), eventTime); - - eventDataSize = ltt_getEventDataSize(thisEventPtr.getPointer()); - } + // We need to save the time, as it is not a primitive (can't be dynamically called in getter) + eventTime.setTime(ltt_getNanosencondsTime(thisEventPtr.getPointer() )); } - public int getEventMarkerId() { - return eventMarkerId; - } - public JniTime getEventTime() { return eventTime; } + + // *** To get better performance, all getter belows call LTT directly **** + // That way, we can avoid copying data into memory + public int getEventMarkerId() { + return ltt_getEventMarkerId(thisEventPtr.getPointer()); + } public long getEventDataSize() { - return eventDataSize; + return ltt_getEventDataSize(thisEventPtr.getPointer()); } public HashMap getMarkersMap() { return markersMap; } - /** * Pointer to the parent LTTTracefile C structure.
*
@@ -379,10 +372,10 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return The actual (long converted) pointer or NULL. * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer */ public Jni_C_Pointer getTracefilePtr() { - return tracefilePtr; + return new Jni_C_Pointer( ltt_getTracefilePtr(thisEventPtr.getPointer()) ); } /** @@ -393,7 +386,7 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return The actual (long converted) pointer or NULL. * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer */ public Jni_C_Pointer getEventPtr() { return thisEventPtr; @@ -408,7 +401,7 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return The parent tracefile * - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile */ public JniTracefile getParentTracefile() { return parentTracefile; @@ -422,19 +415,20 @@ public final class JniEvent extends Jni_C_Common implements Comparable * * @return -1 if given event happens before, 0 if equal, 1 if passed event happens after. */ - //@Override public int compareTo(JniEvent rightEvent ){ - JniEvent leftEvent = this; + + // Note : this = left hand operand + // By default, we consider the current event to be older. int eventComparaison = -1; // Test against null before performing anything if ( rightEvent != null ) { // Compare the timestamp first - eventComparaison = leftEvent.getEventTime().compareTo( rightEvent.getEventTime() ); + eventComparaison = this.getEventTime().compareTo( rightEvent.getEventTime() ); // If timestamp is equal, compare the parent tracefile ("event type") - if ( (eventComparaison == 0) && ( !leftEvent.parentTracefile.equals(rightEvent.parentTracefile)) ) { + if ( (eventComparaison == 0) && ( !this.parentTracefile.equals(rightEvent.parentTracefile)) ) { eventComparaison = 1; } } @@ -472,11 +466,11 @@ public final class JniEvent extends Jni_C_Common implements Comparable String returnData = ""; returnData += "tracefilePtr : " + tracefilePtr + "\n"; - returnData += "eventMarkerId : " + eventMarkerId + "\n"; + returnData += "eventMarkerId : " + getEventMarkerId() + "\n"; returnData += "eventTime : " + eventTime.getReferenceToString() + "\n"; returnData += " seconds : " + eventTime.getSeconds() + "\n"; returnData += " nanoSeconds : " + eventTime.getNanoSeconds() + "\n"; - returnData += "eventDataSize : " + eventDataSize + "\n"; + returnData += "eventDataSize : " + getEventDataSize() + "\n"; returnData += "markersMap : " + markersMap.keySet() + "\n"; // Hack to avoid ending up with markersMap.toString() return returnData; diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniException.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniException.java index 1bde483810..7f8adf6e0d 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniException.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniException.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; /** * JniException diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniMarker.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniMarker.java index 213b188e66..3990bfc15c 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniMarker.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniMarker.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; import java.util.ArrayList; import java.util.HashMap; @@ -174,7 +174,7 @@ public final class JniMarker extends Jni_C_Common * * @return The actual (long converted) pointer or NULL * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer */ public Jni_C_Pointer getMarkerPtr() { return thisMarkerPtr; diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java index 70e18a733f..de2422f2ab 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniMarkerField.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; /** * JniMarkerField

@@ -117,7 +117,7 @@ public final class JniMarkerField extends Jni_C_Common * * @return The actual (long converted) pointer or NULL * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer */ public Jni_C_Pointer getMarkerFieldPtr() { return thisMarkerFieldPtr; diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniParser.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniParser.java index 3f7e36c1e4..4f1ee63f23 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniParser.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniParser.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; import java.util.HashMap; import java.util.Iterator; @@ -29,7 +29,14 @@ public class JniParser extends Jni_C_Common static { System.loadLibrary("lttvtraceread"); } - + + // *** HACK *** + // We cannot use "Object" directly as java does not support swapping primitive value + // We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions + // Another (ugly) hack would be to pass an array to modify the reference's reference. + // *** + private static ParsedObjectContent parsedData = new ParsedObjectContent(); + /* * Default constructor is forbidden */ @@ -47,7 +54,7 @@ public class JniParser extends Jni_C_Common * * @return An Object that contain the JniEvent payload parsed by the C, or null, if if was impossible to parse (i.e., wrong position) * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent */ static public Object parseField(JniEvent eventToParse, int fieldPosition) { @@ -56,15 +63,10 @@ public class JniParser extends Jni_C_Common return null; } - // *** HACK *** - // We cannot use "Object" directly as java does not support swapping primitive value - // We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions - // Another (ugly) hack would be to pass an array to modify the reference's reference. - // *** - ParsedObjectContent parsedData = new ParsedObjectContent(); + JniMarkerField tmpField = eventToParse.requestEventMarker().getMarkerFieldsArrayList().get(fieldPosition); // Call the parsing function in C. The result will be put in parsedData object - ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), eventToParse.requestEventMarker().getMarkerFieldsArrayList().get(fieldPosition).getMarkerFieldPtr().getPointer() ); + ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), tmpField.getMarkerFieldPtr().getPointer() ); return parsedData.getData(); } @@ -80,7 +82,7 @@ public class JniParser extends Jni_C_Common * * @return An Object that contain the JniEvent payload parsed by the C, or null, if if was impossible to parse (i.e., wrong position) * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent */ static public Object parseField(JniEvent eventToParse, String fieldName) { @@ -91,13 +93,6 @@ public class JniParser extends Jni_C_Common return null; } - // *** HACK *** - // We cannot use "Object" directly as java does not support swapping on primitive value - // We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions - // Another (ugly) hack would be to pass an array to modify the reference's reference. - // *** - ParsedObjectContent parsedData = new ParsedObjectContent(); - ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), tmpField.getMarkerFieldPtr().getPointer() ); return parsedData.getData(); @@ -113,7 +108,7 @@ public class JniParser extends Jni_C_Common * @param eventToParse The jni event we want to parse. * @return An HashMap of Object that contain the is the JniEvent's payload parsed by the C * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent */ static public HashMap parseAllFields(JniEvent eventToParse) { HashMap markerFieldData = eventToParse.requestEventMarker().getMarkerFieldsHashMap(); @@ -134,23 +129,17 @@ public class JniParser extends Jni_C_Common // Or even safer, use HashMap constructor to do so : HashMap parsedDataMap = new HashMap(markerFieldData); - // *** HACK *** - // We cannot use "Object" directly as java does not support swapping on primitive value - // We either need to create a new object type or to use a "non-primitive" type that have "Setter()" functions - // *** - ParsedObjectContent parsedData = new ParsedObjectContent(); - - String newKey = null; - JniMarkerField newValue = null; - Iterator iterator = markerFieldData.keySet().iterator(); - + String newKey = null; + JniMarkerField newMarkerField = null; + Iterator iterator = markerFieldData.keySet().iterator(); + while ( iterator.hasNext() ) { newKey = iterator.next(); - newValue = markerFieldData.get(newKey); + newMarkerField = markerFieldData.get(newKey); // Call the C to parse the data - ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), newValue.getMarkerFieldPtr().getPointer() ); + ltt_getParsedData(parsedData, eventToParse.getEventPtr().getPointer(), newMarkerField.getMarkerFieldPtr().getPointer() ); // Save the result into the HashMap - parsedDataMap.put(newValue.getField(), parsedData.getData() ); + parsedDataMap.put(newMarkerField.getField(), parsedData.getData() ); } return parsedDataMap; @@ -170,7 +159,7 @@ public class JniParser extends Jni_C_Common * @param formatToAdd The format of the raw data */ @SuppressWarnings("unused") - static private void addStringToParsingFromC(Object contentHolder, String fieldName, String stringToAdd) { + static private void addStringToParsingFromC(Object contentHolder, String stringToAdd) { ((ParsedObjectContent)contentHolder).setData( stringToAdd); } @@ -187,7 +176,7 @@ public class JniParser extends Jni_C_Common * @param formatToAdd The format of the raw data */ @SuppressWarnings("unused") - static private void addLongPointerToParsingFromC(Object contentHolder, String fieldName, long pointerToAdd) { + static private void addLongPointerToParsingFromC(Object contentHolder, long pointerToAdd) { ((ParsedObjectContent)contentHolder).setData( new Jni_C_Pointer((long) pointerToAdd)); } @@ -204,7 +193,7 @@ public class JniParser extends Jni_C_Common * @param formatToAdd The format of the raw data */ @SuppressWarnings("unused") - static private void addIntPointerToParsingFromC(Object contentHolder, String fieldName, long pointerToAdd) { + static private void addIntPointerToParsingFromC(Object contentHolder, long pointerToAdd) { ((ParsedObjectContent)contentHolder).setData( new Jni_C_Pointer((int) pointerToAdd)); } @@ -221,7 +210,7 @@ public class JniParser extends Jni_C_Common * @param formatToAdd The format of the raw data */ @SuppressWarnings("unused") - static private void addShortToParsingFromC(Object contentHolder, String fieldName, short shortToAdd) { + static private void addShortToParsingFromC(Object contentHolder, short shortToAdd) { ((ParsedObjectContent)contentHolder).setData( new Short(shortToAdd)); } @@ -238,7 +227,7 @@ public class JniParser extends Jni_C_Common * @param formatToAdd The format of the raw data */ @SuppressWarnings("unused") - static private void addIntegerToParsingFromC(Object contentHolder, String fieldName, int intToAdd) { + static private void addIntegerToParsingFromC(Object contentHolder, int intToAdd) { ((ParsedObjectContent)contentHolder).setData( new Integer(intToAdd)); } @@ -255,7 +244,7 @@ public class JniParser extends Jni_C_Common * @param formatToAdd The format of the raw data */ @SuppressWarnings("unused") - static private void addLongToParsingFromC(Object contentHolder, String fieldName, long longToAdd) { + static private void addLongToParsingFromC(Object contentHolder, long longToAdd) { ((ParsedObjectContent)contentHolder).setData( new Long(longToAdd)); } @@ -272,7 +261,7 @@ public class JniParser extends Jni_C_Common * @param formatToAdd The format of the raw data */ @SuppressWarnings("unused") - static private void addFloatToParsingFromC(Object contentHolder, String fieldName, float floatToAdd) { + static private void addFloatToParsingFromC(Object contentHolder, float floatToAdd) { ((ParsedObjectContent)contentHolder).setData( new Float(floatToAdd)); } @@ -290,7 +279,7 @@ public class JniParser extends Jni_C_Common * @param formatToAdd The format of the raw data */ @SuppressWarnings("unused") - static private void addDoubleToParsingFromC(Object contentHolder, String fieldName, double doubleToAdd) { + static private void addDoubleToParsingFromC(Object contentHolder, double doubleToAdd) { ((ParsedObjectContent)contentHolder).setData( new Double(doubleToAdd)); } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTime.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTime.java index e11acb4791..4559bfb013 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTime.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTime.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; /** * JniTime @@ -95,7 +95,28 @@ public final class JniTime extends Jni_C_Common implements Comparable public long getTime() { return time; } - + + /** + * Changes the current time for this object

+ * + * @param newTime New time to set, in nanoseconds. + */ + public void setTime(long newTime) { + time = newTime; + } + + /* + * Populate this time object + * + * Note: This function is called from C side. + * + * @param newTime The time we want to populate + */ + @SuppressWarnings("unused") + private void setTimeFromC(long newTime) { + time = newTime; + } + /** * Comparaison operator smaller or equal than "<=" .

* @@ -123,31 +144,19 @@ public final class JniTime extends Jni_C_Common implements Comparable * @return int of value -1, 0 or 1, as the pased argument is bigger, equal or smaller than this time */ public int compareTo(JniTime right) { + long leftTime = this.getTime(); + long rightTime = right.getTime(); - JniTime left = this; - - if ( left.getTime() < right.getTime() ) { + if ( leftTime < rightTime ) { return -1; } - else if ( left.getTime() > right.getTime() ) { - return 1; + else if ( leftTime > rightTime ) { + return 1; } else { return 0; } } - - /* - * Populate this time object - * - * Note: This function is called from C side. - * - * @param newTime The time we want to populate - */ - @SuppressWarnings("unused") - private void setTimeFromC(long newTime) { - time = newTime; - } /** * toString() method. diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java index 391a506217..91d35297e4 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; import java.util.HashMap; import java.util.Iterator; @@ -29,7 +29,9 @@ import java.util.PriorityQueue; * */ public class JniTrace extends Jni_C_Common { - + + private final static boolean DEFAULT_LTT_DEBUG = false; + // Internal C pointer of the JniTrace used in LTT private Jni_C_Pointer thisTracePtr = new Jni_C_Pointer(); @@ -61,8 +63,11 @@ public class JniTrace extends Jni_C_Common { // This variable will hold the content of the "last" event we read private JniEvent currentEvent = null; + // Should we print debug in the C library or not? + private boolean printLttDebug = DEFAULT_LTT_DEBUG; + // Open/close native functions - private native long ltt_openTrace(String pathname); + private native long ltt_openTrace(String pathname, boolean printDebug); private native void ltt_closeTrace(long tracePtr); // Native access functions @@ -78,10 +83,10 @@ public class JniTrace extends Jni_C_Common { private native long ltt_getStartFreq(long tracePtr); private native long ltt_getStartTimestampCurrentCounter(long tracePtr); private native long ltt_getStartMonotonic(long tracePtr); - + // Native function to fill out startTime private native void ltt_feedStartTime(long tracePtr, JniTime startTime); - + // Native function to fill out startTimeFromTimestampCurrentCounter private native void ltt_feedStartTimeFromTimestampCurrentCounter(long tracePtr, JniTime startTime); @@ -108,12 +113,14 @@ public class JniTrace extends Jni_C_Common { * This constructor also opens the trace. * * @param newpath The directory of the trace to be opened + * @param newPrintDebug Should the debug information be printed in the LTT C library * * @exception JniException */ - public JniTrace(String newpath) throws JniException { + public JniTrace(String newpath, boolean newPrintDebug) throws JniException { tracepath = newpath; thisTracePtr = new Jni_C_Pointer(); + printLttDebug = newPrintDebug; openTrace(newpath); } @@ -146,19 +153,23 @@ public class JniTrace extends Jni_C_Common { eventsHeap = new PriorityQueue( oldTrace.eventsHeap.size()); eventsHeap = oldTrace.eventsHeap; + + printLttDebug = oldTrace.printLttDebug; } /** * Constructor, using C pointer.

* * @param newPtr The pointer to an already opened LttTrace C structure. + * @param newPrintDebug Should the debug information be printed in the LTT C library * * @exception JniException * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer */ - public JniTrace(Jni_C_Pointer newPtr) throws JniException { + public JniTrace(Jni_C_Pointer newPtr, boolean newPrintDebug) throws JniException { thisTracePtr = newPtr; + printLttDebug = newPrintDebug; // Populate our trace populateTraceInformation(); @@ -205,7 +216,7 @@ public class JniTrace extends Jni_C_Common { } // Call the LTT to open the trace - long newPtr = ltt_openTrace(tracepath); + long newPtr = ltt_openTrace(tracepath, printLttDebug); if (newPtr == NULL) { throw new JniOpenTraceFailedException("Error while opening trace. Is the tracepath correct? (openTrace)"); } @@ -328,7 +339,7 @@ public class JniTrace extends Jni_C_Common { // the tracefile fill itself with LTT data while being constructed try { newTracefile = new JniTracefile( new Jni_C_Pointer(tracefilePtr), this ); - tracefilesMap.put(tracefileName + newTracefile.getCpuNumber(), newTracefile); + tracefilesMap.put( (tracefileName + newTracefile.getCpuNumber()), newTracefile); } catch(JniTracefileWithoutEventException e) { printlnC("JniTracefile " + tracefileName + " has no event (addTracefileFromC). Ignoring."); @@ -337,7 +348,7 @@ public class JniTrace extends Jni_C_Common { printlnC("Failed to add tracefile " + tracefileName + " to tracefilesMap!(addTracefileFromC)\n\tException raised : " + e.toString() ); } } - + /** * Return the top event in the events stack, determined by timestamp, in the trace (all the tracefiles).

* @@ -345,7 +356,7 @@ public class JniTrace extends Jni_C_Common { * * @return The top event in the stack or null if no event is available. * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent findNextEvent() { return eventsHeap.peek(); @@ -356,7 +367,7 @@ public class JniTrace extends Jni_C_Common { * * @return The next event in the trace or null if no event is available. * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent readNextEvent() { // Get the "next" event on the top of the heap but DO NOT remove it @@ -405,8 +416,8 @@ public class JniTrace extends Jni_C_Common { * * @return The next event in the tracefile or null if no event is available. * - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent readNextEvent(JniTracefile targetTracefile) { JniEvent returnedEvent = null; @@ -447,7 +458,7 @@ public class JniTrace extends Jni_C_Common { * * @param seekTime The time where we want to seek to * - * @see org.eclipse.linuxtools.lttng.jni.JniTime + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTime */ public void seekToTime(JniTime seekTime) { @@ -474,15 +485,15 @@ public class JniTrace extends Jni_C_Common { * @param targetTracefile The tracefile object to read from * @param seekTime The time where we want to seek to * - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile - * @see org.eclipse.linuxtools.lttng.jni.JniTime + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTime */ public void seekToTime(JniTime seekTime, JniTracefile targetTracefile) { // Invalidate the current read event currentEvent = null; // Remove from the event related to this tracefile from the event heap, if it exists. - // WARNING : This only safe as long getCurrentEvent() never return "null" in any case. + // WARNING : This is only safe as long getCurrentEvent() never return "null" in any case. eventsHeap.remove(targetTracefile.getCurrentEvent() ); // Perform the actual seek on the tracefile @@ -502,8 +513,8 @@ public class JniTrace extends Jni_C_Common { * * @return The event just after the seeked time or null if none available. * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent - * @see org.eclipse.linuxtools.lttng.jni.JniTime + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTime */ public JniEvent seekAndRead(JniTime seekTime) { JniEvent returnedEvent = null; @@ -527,9 +538,9 @@ public class JniTrace extends Jni_C_Common { * * @return The event just after the seeked time or null if none available. * - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile - * @see org.eclipse.linuxtools.lttng.jni.JniTime - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTime + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent seekAndRead(JniTime seekTime, JniTracefile targetTracefile) { seekToTime(seekTime, targetTracefile); @@ -543,7 +554,7 @@ public class JniTrace extends Jni_C_Common { * * @return The tracefile found or null if none. * - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile */ public JniTracefile requestTracefileByName(String tracefileName) { return tracefilesMap.get(tracefileName); @@ -556,7 +567,7 @@ public class JniTrace extends Jni_C_Common { * * @return Event of the tracefile or null if none found. * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent */ public JniEvent requestEventByName(String tracefileName) { JniEvent returnValue = null; @@ -640,7 +651,7 @@ public class JniTrace extends Jni_C_Common { * * @return Time of the last event read * - * @see org.eclipse.linuxtools.lttng.jni.JniTime + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTime */ public JniTime getCurrentEventTimestamp() { JniTime returnedTime = null; @@ -664,12 +675,23 @@ public class JniTrace extends Jni_C_Common { * * @return The actual (long converted) pointer or NULL. * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer */ public Jni_C_Pointer getTracePtr() { return thisTracePtr; } - + + /** + * Return boolean value saying if the debug is enabled in LTT or not.

+ * + * Note : this need to be set at construction. + * + * @return If the debug is set or not + */ + public boolean isPrintingLttDebug() { + return printLttDebug; + } + /** * Print information for all the tracefiles associated with this trace. * Intended to debug

@@ -677,7 +699,7 @@ public class JniTrace extends Jni_C_Common { * This function will call Ltt to print, so information printed will be the * one from the C structure, not the one populated in java. * - * @see org.eclipse.linuxtools.lttng.jni.JniTracefile + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile */ public void printAllTracefilesInformation() { JniTracefile tracefile = null; diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java index c541e5776d..4ce1b91aec 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/JniTracefile.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; import java.util.HashMap; @@ -161,8 +161,8 @@ public final class JniTracefile extends Jni_C_Common { * * @exception JniException * - * @see org.eclipse.linuxtools.lttng.jni.JniTrace - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTrace + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer */ public JniTracefile(Jni_C_Pointer newPtr, JniTrace newParentTrace) throws JniException { thisTracefilePtr = newPtr; @@ -185,7 +185,7 @@ public final class JniTracefile extends Jni_C_Common { * * @return LTT read status, as defined in Jni_C_Common * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Common */ public int readNextEvent() { return currentEvent.readNextEvent(); @@ -200,7 +200,7 @@ public final class JniTracefile extends Jni_C_Common { * * @return LTT read status, as defined in Jni_C_Common * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Common + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Common */ public int seekToTime(JniTime seekTime) { return currentEvent.seekToTime(seekTime); @@ -382,7 +382,7 @@ public final class JniTracefile extends Jni_C_Common { * * @return The parent trace * - * @see org.eclipse.linuxtools.lttng.jni.JniTrace + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTrace */ public JniTrace getParentTrace() { return parentTrace; @@ -396,7 +396,7 @@ public final class JniTracefile extends Jni_C_Common { * * @return The actual (long converted) pointer or NULL. * - * @see org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer + * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer */ public Jni_C_Pointer getTracefilePtr() { return thisTracefilePtr; diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java index 8803123c5b..23904606db 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Common.java @@ -1,3 +1,4 @@ +package org.eclipse.linuxtools.lttng.jni; /******************************************************************************* * Copyright (c) 2009 Ericsson * @@ -10,7 +11,6 @@ * William Bourque (wbourque@gmail.com) - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.lttng.jni; /** * Jni_C_Common diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Pointer.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Pointer.java index d1c4038846..7cfec13078 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Pointer.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/jni/Jni_C_Pointer.java @@ -1,5 +1,6 @@ package org.eclipse.linuxtools.lttng.jni; + /** * Jni_C_Pointer *

diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateDataRequest.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateDataRequest.java index b4318fb107..62eb5be5bf 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateDataRequest.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateDataRequest.java @@ -49,8 +49,9 @@ public class StateDataRequest extends TmfDataRequest { public StateDataRequest(TmfTimeRange range, long offset, int nbEvents, int maxBlockSize, IStateDataRequestListener listener, StateManager manager) { - - super(range, offset, nbEvents, maxBlockSize); + + super(range, nbEvents, maxBlockSize); + //super(0, nbEvents, maxBlockSize); this.manager = manager; if (listener != null && !listeners.contains(listener)) { listeners.add(listener); diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java index 5cd47bf380..9a0ec870da 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java @@ -44,7 +44,7 @@ import org.eclipse.linuxtools.tmf.trace.TmfTraceCheckpoint; */ public class StateManager extends Observable { - private static final long LTTNG_STATE_SAVE_INTERVAL = 50000L; + private static final long LTTNG_STATE_SAVE_INTERVAL = 5000000L; // These are used in the building of the data request. private static final long DEFAULT_OFFSET = 0L; @@ -308,13 +308,13 @@ public class StateManager extends Observable { || (eventTime.getValue() > logRange.getEndTime().getValue())) { return null; } - + // The GUI can have time limits lower than this log, since GUI can // handle multiple logs if ((eventTime.getValue() < logRange.getStartTime().getValue())) { eventTime = logRange.getStartTime(); } - + // Sort the checkpoints, required before the binary search Collections.sort(timestampCheckpointsList); // Initiate the compare with a checkpoint containing the target time @@ -482,7 +482,7 @@ public class StateManager extends Observable { @Override public void handleData() { TmfEvent[] result = getData(); - + evt[0] = (result.length > 0) ? result[0] : null; // Dispatch information for Event processing stateIn.processEvent(evt[0]); diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateStacksHandler.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateStacksHandler.java index 354f3a76b9..5001dc8ca7 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateStacksHandler.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateStacksHandler.java @@ -17,6 +17,8 @@ import java.util.Vector; import org.eclipse.linuxtools.lttng.TraceDebug; import org.eclipse.linuxtools.lttng.event.LttngEvent; +import org.eclipse.linuxtools.lttng.event.LttngEventContent; +import org.eclipse.linuxtools.lttng.event.LttngEventField; import org.eclipse.linuxtools.lttng.jni.JniTrace; import org.eclipse.linuxtools.lttng.state.evProcessor.AbsEventProcessorFactory; import org.eclipse.linuxtools.lttng.state.evProcessor.EventProcessorProxy; @@ -81,9 +83,9 @@ public class StateStacksHandler { } LttngEvent trcEvent = (LttngEvent) tmfEvent; - TmfEventField[] fields = trcEvent.getContent().getFields(); +// LttngEventField[] fields = ((LttngEventContent)trcEvent.getContent()).getFields(); - if (fields != null) { + if (trcEvent != null) { String inEventName = trcEvent.getMarkerName(); // String inChannel = trcEvent.getChannelName(); // TraceDebug.debug("Event: " + inEventName); diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateProcessing.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateProcessing.java index b6cb14ecf4..8d23f4d1ae 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateProcessing.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateProcessing.java @@ -30,9 +30,30 @@ public abstract class AbsStateProcessing { * @param expectedNumFields * @return */ - protected Long getAFieldLong(LttngEvent trcEvent, LttngTraceState traceSt, - Fields expectedField) { + protected Long getAFieldLong(LttngEvent trcEvent, LttngTraceState traceSt, Fields expectedField) { Long fieldVal = null; + + String fieldname = expectedField.getInName(); + LttngEventField field = ((LttngEventContent) trcEvent.getContent()).getField(fieldname); + +// if ( field == null ) { +// System.out.println("****************** JOIE : " + fieldname); +// System.out.println("***************** CONTENT : " + ((LttngEventContent) trcEvent.getContent()).toString()); +// } +// else { + Object fieldObj = field.getValue(); + if ( (fieldObj instanceof Long) || (fieldObj instanceof Integer) ) { + // Expected numeric value found + fieldVal = (Long) field.getValue(); + } + else { + if (TraceDebug.isDEBUG()) { + TraceDebug.debug("Unexpected field Type. Expected: Long, Received: "+ fieldObj.getClass().getSimpleName()); + } + } +// } + + /* // TmfEventField[] fields = trcEvent.getContent().getFields(); TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent()) .getFields(trcEvent); @@ -69,12 +90,13 @@ public abstract class AbsStateProcessing { } } } + */ - if (fieldVal == null) { - if (TraceDebug.isDEBUG()) { - sendNoFieldFoundMsg(fields, expectedFieldName); - } - } +// if (fieldVal == null) { +// if (TraceDebug.isDEBUG()) { +// sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname); +// } +// } return fieldVal; } @@ -90,6 +112,22 @@ public abstract class AbsStateProcessing { protected String getAFieldString(LttngEvent trcEvent, LttngTraceState traceSt, Fields expectedField) { String fieldVal = null; + + String fieldname = expectedField.getInName(); + LttngEventField field = ((LttngEventContent) trcEvent.getContent()).getField(fieldname); + + Object fieldObj = field.getValue(); + if (fieldObj instanceof String) { + // Expected numeric value found + fieldVal = (String) field.getValue(); + } + else { + if (TraceDebug.isDEBUG()) { + TraceDebug.debug("Unexpected field Type. Expected: String, Received: "+ fieldObj.getClass().getSimpleName()); + } + } + + /* // TmfEventField[] fields = trcEvent.getContent().getFields(); TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent()) .getFields(trcEvent); @@ -123,12 +161,13 @@ public abstract class AbsStateProcessing { } } } - - if (fieldVal == null) { - if (TraceDebug.isDEBUG()) { - sendNoFieldFoundMsg(fields, expectedFieldName); - } - } + */ + +// if (fieldVal == null) { +// if (TraceDebug.isDEBUG()) { +// sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname); +// } +// } return fieldVal; } @@ -157,7 +196,7 @@ public abstract class AbsStateProcessing { sb.append(" number of fields: " + fields.length + "Fields: "); for (int i = 0; i < fields.length; i++) { field = (LttngEventField) fields[i]; - sb.append(field.getName() + " "); + sb.append(field.getId() + " "); } TraceDebug.debug(sb.toString(), 5); diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateUpdate.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateUpdate.java index f2a6340325..bf82ff2e75 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateUpdate.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateUpdate.java @@ -45,8 +45,8 @@ public abstract class AbsStateUpdate extends AbsStateProcessing implements LttngExecutionState exe_state = new LttngExecutionState(); exe_state.setExec_mode(execMode); exe_state.setExec_submode(submode); - exe_state.setEntry_Time(eventTime); - exe_state.setChange_Time(eventTime); + exe_state.setEntry_Time(eventTime.getValue()); + exe_state.setChange_Time(eventTime.getValue()); exe_state.setCum_cpu_time(0L); exe_state.setProc_status(process.getState().getProc_status()); process.pushToExecutionStack(exe_state); @@ -68,7 +68,7 @@ public abstract class AbsStateUpdate extends AbsStateProcessing implements //The process state is updated within the pop method process.popFromExecutionStack(); - process.getState().setChange_Time(eventTime); + process.getState().setChange_Time(eventTime.getValue()); } protected void irq_push_mode(LttngIRQState irqst, IRQMode state) { @@ -217,7 +217,7 @@ public abstract class AbsStateUpdate extends AbsStateProcessing implements Long cpu, Long pid, Long tgid, String name, final TmfTimestamp timestamp) { LttngProcessState process; - process = new LttngProcessState(cpu, pid, tgid, name, timestamp, traceSt.getTraceId()); + process = new LttngProcessState(cpu, pid, tgid, name, timestamp.getValue(), traceSt.getTraceId()); traceSt.addProcessState(process); return process; } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/StateUpdateHandlers.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/StateUpdateHandlers.java index f5297cfb9d..48292b86b6 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/StateUpdateHandlers.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/StateUpdateHandlers.java @@ -902,16 +902,16 @@ class StateUpdateHandlers { process.getState().setProc_status( ProcessStatus.LTTV_STATE_WAIT); process.getState().setChange_Time( - trcEvent.getTimestamp()); + trcEvent.getTimestamp().getValue()); process.getState().setEntry_Time( - trcEvent.getTimestamp()); + trcEvent.getTimestamp().getValue()); } } else { if (process.getState().getProc_status() == ProcessStatus.LTTV_STATE_EXIT) { process.getState().setProc_status( ProcessStatus.LTTV_STATE_ZOMBIE); process.getState().setChange_Time( - trcEvent.getTimestamp()); + trcEvent.getTimestamp().getValue()); } else { if ((state_out != null) && (state_out.longValue() == 0L)) { @@ -923,7 +923,7 @@ class StateUpdateHandlers { } process.getState().setChange_Time( - trcEvent.getTimestamp()); + trcEvent.getTimestamp().getValue()); } if ((state_out != null) @@ -937,7 +937,7 @@ class StateUpdateHandlers { process.getState().setProc_status( ProcessStatus.LTTV_STATE_DEAD); process.getState().setChange_Time( - trcEvent.getTimestamp()); + trcEvent.getTimestamp().getValue()); } } } @@ -948,7 +948,7 @@ class StateUpdateHandlers { traceSt.getRunning_process().put(cpu, process); process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN); - process.getState().setChange_Time(eventTime); + process.getState().setChange_Time(eventTime.getValue()); process.setCpu(cpu); // process->state->s = LTTV_STATE_RUN; // if(process->usertrace) @@ -1073,7 +1073,7 @@ class StateUpdateHandlers { if (child_process == null) { child_process = create_process(traceSt, cpu, child_pid, child_tgid, timeStamp); - child_process.setPpid(process.getPid(), timeStamp); + child_process.setPpid(process.getPid(), timeStamp.getValue()); } else { /* * The process has already been created : due to time @@ -1452,8 +1452,8 @@ class StateUpdateHandlers { es .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE .getInName()); - es.setEntry_Time(timestamp); - es.setChange_Time(timestamp); + es.setEntry_Time(timestamp.getValue()); + es.setChange_Time(timestamp.getValue()); es.setCum_cpu_time(0L); if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) { es.setProc_status(ProcessStatus.LTTV_STATE_WAIT); @@ -1466,8 +1466,8 @@ class StateUpdateHandlers { es .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE .getInName()); - es.setEntry_Time(timestamp); - es.setChange_Time(timestamp); + es.setEntry_Time(timestamp.getValue()); + es.setChange_Time(timestamp.getValue()); es.setCum_cpu_time(0L); if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) { es.setProc_status(ProcessStatus.LTTV_STATE_RUN); @@ -1494,8 +1494,8 @@ class StateUpdateHandlers { es .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE .getInName()); - es.setEntry_Time(timestamp); - es.setChange_Time(timestamp); + es.setEntry_Time(timestamp.getValue()); + es.setChange_Time(timestamp.getValue()); es.setCum_cpu_time(0L); es.setProc_status(ProcessStatus.LTTV_STATE_WAIT); @@ -1534,13 +1534,14 @@ class StateUpdateHandlers { Long tgid; String command; Long cpu = trcEvent.getCpuId(); + LttngProcessState process = traceSt.getRunning_process().get( cpu); LttngProcessState parent_process; String type; // String mode, submode, status; LttngExecutionState es; - + /* PID */ pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID); @@ -1607,7 +1608,7 @@ class StateUpdateHandlers { process = create_process(traceSt, cpu, pid, tgid, command, eventTime); if (parent_process != null) { - process.setPpid(parent_process.getPid(), eventTime); + process.setPpid(parent_process.getPid(), eventTime.getValue()); } /* Keep the stack bottom : a running user mode */ diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngExecutionState.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngExecutionState.java index ee0b094181..4a19227466 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngExecutionState.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngExecutionState.java @@ -12,7 +12,6 @@ package org.eclipse.linuxtools.lttng.state.model; import org.eclipse.linuxtools.lttng.state.StateStrings; -import org.eclipse.linuxtools.tmf.event.TmfTimestamp; /** * LttngExecutionState @@ -23,8 +22,8 @@ public class LttngExecutionState implements Cloneable { // ======================================================================== // Data // ======================================================================= - private TmfTimestamp entry_LttTime = null; - private TmfTimestamp change_LttTime = null; + private Long entry_LttTime = null; + private Long change_LttTime = null; private Long cum_cpu_time_Timens = null; private StateStrings.ProcessStatus proc_status = StateStrings.ProcessStatus.LTTV_STATE_UNNAMED; @@ -48,16 +47,8 @@ public class LttngExecutionState implements Cloneable { // ProcessStatus and ExecutionMode are enum, and so shouldn't be a problem to use their reference newState.proc_status = this.proc_status; newState.exec_mode = this.exec_mode; - - // No clonable implemented in TMF, we will use copy constructor - // NOTE : we GOT to check for null to avoid crashing on null pointer here! - if ( this.entry_LttTime != null ) { - newState.entry_LttTime = new TmfTimestamp(this.entry_LttTime); - } - - if ( this.change_LttTime != null ) { - newState.change_LttTime = new TmfTimestamp(this.change_LttTime); - } + newState.entry_LttTime = this.entry_LttTime; + newState.change_LttTime = this.change_LttTime; } catch ( CloneNotSupportedException e ) { System.out.println("Cloning failed with : " + e.getMessage() ); @@ -72,7 +63,7 @@ public class LttngExecutionState implements Cloneable { /** * @return the entry_LttTime */ - public TmfTimestamp getEntry_LttTime() { + public Long getEntry_LttTime() { return entry_LttTime; } @@ -80,14 +71,14 @@ public class LttngExecutionState implements Cloneable { * @param entryLttTime * the entry_LttTime to set */ - public void setEntry_Time(TmfTimestamp entryLttTime) { + public void setEntry_Time(Long entryLttTime) { entry_LttTime = entryLttTime; } /** * @return the change_LttTime */ - public TmfTimestamp getChange_LttTime() { + public Long getChange_LttTime() { return change_LttTime; } @@ -95,7 +86,7 @@ public class LttngExecutionState implements Cloneable { * @param changeLttTime * the change_LttTime to set */ - public void setChange_Time(TmfTimestamp changeLttTime) { + public void setChange_Time(Long changeLttTime) { change_LttTime = changeLttTime; } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngProcessState.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngProcessState.java index d0a556ee85..63451594de 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngProcessState.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngProcessState.java @@ -18,7 +18,6 @@ import org.eclipse.linuxtools.lttng.state.StateStrings; import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionMode; import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionSubMode; import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus; -import org.eclipse.linuxtools.tmf.event.TmfTimestamp; /** * LttngProcessState @@ -34,12 +33,12 @@ public class LttngProcessState implements Cloneable { private Long pid = null; private Long tgid = null; private String name = null; - private TmfTimestamp creation_time = null; + private Long creation_time = null; private String brand = null; private StateStrings.ProcessType type = null; private Long current_function = null; private Long ppid = null; - private TmfTimestamp insertion_time = null; + private Long insertion_time = null; private String pid_time = null; private Long free_events = null; private LttngExecutionState state = null; // top of stack @@ -53,7 +52,7 @@ public class LttngProcessState implements Cloneable { // ======================================================================== // Constructor // ======================================================================= - public LttngProcessState(TmfTimestamp startTime) { + public LttngProcessState(Long startTime, String traceId) { this.cpu = 0L; this.pid = 0L; this.tgid = 0L; @@ -64,7 +63,7 @@ public class LttngProcessState implements Cloneable { } public LttngProcessState(Long cpu, Long pid, Long tgid, - String name, TmfTimestamp startTime, String traceId) { + String name, Long startTime, String traceId) { this.cpu = cpu; this.pid = pid; this.tgid = tgid; @@ -82,9 +81,7 @@ public class LttngProcessState implements Cloneable { this.type = StateStrings.ProcessType.LTTV_STATE_USER_THREAD; this.current_function = 0L; this.ppid = 0L; - // creation time defined when parent pid is known - // calling the setCreation_time method adjust the pid_time string - setCreation_time(new TmfTimestamp()); + this.creation_time = 0L; this.free_events = 0L; // Initialise stack @@ -138,16 +135,8 @@ public class LttngProcessState implements Cloneable { newState.userTrace = this.userTrace; newState.target_pid = this.target_pid; newState.trace_id = this.trace_id; - - // No clonable implemented in TMF, we will use copy constructor - // NOTE : we GOT to check for null to avoid crashing on null pointer here! - if ( this.creation_time != null ) { - newState.creation_time = new TmfTimestamp(this.creation_time); - } - - if ( this.creation_time != null ) { - newState.insertion_time = new TmfTimestamp(this.insertion_time); - } + newState.creation_time = this.creation_time; + newState.insertion_time = this.insertion_time; // Call clone on our own object is safe as Long it implements Clonable newState.state = (LttngExecutionState)this.state.clone(); @@ -242,7 +231,7 @@ public class LttngProcessState implements Cloneable { * @param ppid * the ppid to set */ - public void setPpid(Long ppid, TmfTimestamp creationTime) { + public void setPpid(Long ppid, Long creationTime) { if (ppid != null) { this.ppid = ppid; } @@ -255,7 +244,7 @@ public class LttngProcessState implements Cloneable { /** * @return the creation_time */ - public TmfTimestamp getCreation_time() { + public Long getCreation_time() { return creation_time; } @@ -263,7 +252,7 @@ public class LttngProcessState implements Cloneable { * @param creationTime * the creation_time to set */ - public void setCreation_time(TmfTimestamp creationTime) { + public void setCreation_time(Long creationTime) { if ( (creationTime != null) && (pid != null) ) { creation_time = creationTime; StringBuilder sb = new StringBuilder(this.pid.toString() + "-" @@ -275,7 +264,7 @@ public class LttngProcessState implements Cloneable { /** * @return the insertion_time */ - public TmfTimestamp getInsertion_time() { + public Long getInsertion_time() { return insertion_time; } @@ -283,7 +272,7 @@ public class LttngProcessState implements Cloneable { * @param insertionTime * the insertion_time to set */ - public void setInsertion_time(TmfTimestamp insertionTime) { + public void setInsertion_time(Long insertionTime) { insertion_time = insertionTime; } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngTraceState.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngTraceState.java index ca2cece640..4d0ff321e5 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngTraceState.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngTraceState.java @@ -23,7 +23,6 @@ import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionSubMode; import org.eclipse.linuxtools.lttng.state.StateStrings.IRQMode; import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus; import org.eclipse.linuxtools.tmf.event.TmfTimeRange; -import org.eclipse.linuxtools.tmf.event.TmfTimestamp; /** * LttngTraceState @@ -41,7 +40,7 @@ public class LttngTraceState implements Cloneable { private Long save_interval = null; - private TmfTimestamp max_time_state_recomputed_in_seek = null; + private Long max_time_state_recomputed_in_seek = null; private boolean has_precomputed_states = false; private HashMap processes = new HashMap(); @@ -121,14 +120,7 @@ public class LttngTraceState implements Cloneable { // Basic value only need to be assigned while cloning newState.has_precomputed_states = this.has_precomputed_states; newState.nb_events = this.nb_events; - - // No clonable implemented in TMF, we will use copy constructor - // NOTE : we GOT to check for null to avoid crashing on null pointer - // here! - if (this.max_time_state_recomputed_in_seek != null) { - newState.max_time_state_recomputed_in_seek = new TmfTimestamp( - this.max_time_state_recomputed_in_seek); - } + newState.max_time_state_recomputed_in_seek = this.max_time_state_recomputed_in_seek; // Clone should work correctly for all stack object that contain // basic java object (String, Long, etc...) @@ -228,7 +220,7 @@ public class LttngTraceState implements Cloneable { traceId = inputDataRef.getTraceId(); // max time - setMax_time_state_recomputed_in_seek(new TmfTimestamp()); + max_time_state_recomputed_in_seek = 0L; // reset cpu_states cpu_states.clear(); @@ -260,13 +252,7 @@ public class LttngTraceState implements Cloneable { // bdev states bdev_states.clear(); - - // JniTrace State - init_state(numCpus); - - } - - public void init_state(int numCpus) { + processes.clear(); nb_events = 0; @@ -274,8 +260,7 @@ public class LttngTraceState implements Cloneable { /* Put the per cpu running_process to beginning state : process 0. */ for (Long i = 0L; i < numCpus; i++) { - LttngProcessState process = new LttngProcessState(timeWin - .getStartTime()); + LttngProcessState process = new LttngProcessState(timeWin.getStartTime().getValue(), traceId ); /* * We are not sure is it's a kernel thread or normal thread, put the @@ -353,12 +338,12 @@ public class LttngTraceState implements Cloneable { return inputDataRef; } - public TmfTimestamp getMax_time_state_recomputed_in_seek() { + public Long getMax_time_state_recomputed_in_seek() { return max_time_state_recomputed_in_seek; } public void setMax_time_state_recomputed_in_seek( - TmfTimestamp maxTimeStateRecomputedInSeek) { + Long maxTimeStateRecomputedInSeek) { max_time_state_recomputed_in_seek = maxTimeStateRecomputedInSeek; } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java index 583e8f7aeb..1a9031e2f6 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java @@ -12,19 +12,22 @@ package org.eclipse.linuxtools.lttng.trace; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + import org.eclipse.linuxtools.lttng.LttngException; import org.eclipse.linuxtools.lttng.event.LttngEvent; import org.eclipse.linuxtools.lttng.event.LttngEventContent; -import org.eclipse.linuxtools.lttng.event.LttngEventField; -import org.eclipse.linuxtools.lttng.event.LttngEventFormat; import org.eclipse.linuxtools.lttng.event.LttngEventReference; +import org.eclipse.linuxtools.lttng.event.LttngEventSource; import org.eclipse.linuxtools.lttng.event.LttngEventType; import org.eclipse.linuxtools.lttng.event.LttngTimestamp; import org.eclipse.linuxtools.lttng.jni.JniEvent; +import org.eclipse.linuxtools.lttng.jni.JniMarker; import org.eclipse.linuxtools.lttng.jni.JniTime; import org.eclipse.linuxtools.lttng.jni.JniTrace; -import org.eclipse.linuxtools.tmf.event.TmfEvent; -import org.eclipse.linuxtools.tmf.event.TmfEventSource; +import org.eclipse.linuxtools.lttng.jni.JniTracefile; import org.eclipse.linuxtools.tmf.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.trace.TmfTrace; @@ -46,24 +49,35 @@ class LTTngTraceException extends LttngException { * (seeking, reading and parsing) through the JNI component. */ public class LTTngTrace extends TmfTrace { - - private final static boolean IS_PARSING_NEEDED_DEFAULT = true; - private final static int CHECKPOINT_PAGE_SIZE = 1000; - - // Reference to the current LttngEvent - private LttngEvent currentLttngEvent = null; + private final static boolean SHOW_LTT_DEBUG_DEFAULT = false; + private final static boolean IS_PARSING_NEEDED_DEFAULT = false; + private final static int CHECKPOINT_PAGE_SIZE = 1; // Reference to our JNI trace private JniTrace currentJniTrace = null; + // *** HACK *** + // To save time, we will declare all component of the LttngEvent during the construction of the trace + // Then, while reading the trace, we will just SET the values instead of declaring new object + LttngTimestamp eventTimestamp = null; + LttngEventSource eventSource = null; + LttngEventType eventType = null; + LttngEventContent eventContent = null; + LttngEventReference eventReference = null; + // The actual event + LttngEvent currentLttngEvent = null; + + // Hashmap of the possible types of events (Tracefile/CPU/Marker in the JNI) + HashMap traceTypes = null; + // This vector will be used to quickly find a marker name from a position + Vector traceTypeNames = null; + /** * Default Constructor.

* * @param path Path to a directory that contain an LTTng trace. * * @exception Exception (most likely LTTngTraceException or FileNotFoundException) - * - * @see org.eclipse.linuxtools.lttng.jni.JniTrace */ public LTTngTrace(String path) throws Exception { // Call with "wait for completion" true and "skip indexing" false @@ -77,11 +91,9 @@ public class LTTngTrace extends TmfTrace { * @param waitForCompletion Should we wait for indexign to complete before moving on. * * @exception Exception (most likely LTTngTraceException or FileNotFoundException) - * - * @see org.eclipse.linuxtools.lttng.jni.JniTrace */ public LTTngTrace(String path, boolean waitForCompletion) throws Exception { - // Call with "skip indexing" false + // Call with "skip indexing" false this(path, waitForCompletion, false); } @@ -94,19 +106,39 @@ public class LTTngTrace extends TmfTrace { * * @exception Exception (most likely LTTngTraceException or FileNotFoundException) * - * @see org.eclipse.linuxtools.lttng.jni.JniTrace */ public LTTngTrace(String path, boolean waitForCompletion, boolean bypassIndexing) throws Exception { super(path, CHECKPOINT_PAGE_SIZE, true); try { - currentJniTrace = new JniTrace(path); + currentJniTrace = new JniTrace(path, SHOW_LTT_DEBUG_DEFAULT); } catch (Exception e) { throw new LTTngTraceException(e.getMessage()); } - TmfTimestamp startTime = new LttngTimestamp(currentJniTrace.getStartTimeFromTimestampCurrentCounter().getTime()); + + // Set the start time of the trace + LttngTimestamp startTime = new LttngTimestamp(currentJniTrace.getStartTimeFromTimestampCurrentCounter().getTime()); setTimeRange(new TmfTimeRange(startTime, startTime)); + // Export all the event types from the JNI side + traceTypes = new HashMap(); + traceTypeNames = new Vector(); + initialiseEventTypes(currentJniTrace); + + // *** VERIFY *** + // Verify that all those "default constructor" are safe to use + eventTimestamp = new LttngTimestamp(); + eventSource = new LttngEventSource(); + eventType = new LttngEventType(); + eventContent = new LttngEventContent(currentLttngEvent); + eventReference = new LttngEventReference(this.getName()); + + // Create the skeleton event + currentLttngEvent = new LttngEvent(eventTimestamp, eventSource, eventType, eventContent, eventReference, null); + + // Set the currentEvent to the eventContent + eventContent.setEvent(currentLttngEvent); + // Bypass indexing if asked if ( bypassIndexing == false ) { indexStream(); @@ -125,19 +157,70 @@ public class LTTngTrace extends TmfTrace { throw new Exception("Copy constructor should never be use with a LTTngTrace!"); } + /* + * Fill out the HashMap with "Type" (Tracefile/Marker) + * + * This should be called at construction once the trace is open + */ + private void initialiseEventTypes(JniTrace trace) { + // Work variables + LttngEventType tmpType = null; + String[] markerFieldsLabels = null; + + String newTracefileKey = null; + Integer newMarkerKey = null; + + JniTracefile newTracefile = null; + JniMarker newMarker = null; + + // First, obtain an iterator on TRACEFILES of owned by the TRACE + Iterator tracefileItr = trace.getTracefilesMap().keySet().iterator(); + while ( tracefileItr.hasNext() ) { + newTracefileKey = tracefileItr.next(); + newTracefile = trace.getTracefilesMap().get(newTracefileKey); + + // From the TRACEFILE read, obtain its MARKER + Iterator markerItr = newTracefile.getTracefileMarkersMap().keySet().iterator(); + while ( markerItr.hasNext() ) { + newMarkerKey = markerItr.next(); + newMarker = newTracefile.getTracefileMarkersMap().get(newMarkerKey); + + // From the MARKER we can obtain the MARKERFIELDS keys (i.e. labels) + markerFieldsLabels = newMarker.getMarkerFieldsHashMap().keySet().toArray( new String[newMarker.getMarkerFieldsHashMap().size()] ); + tmpType = new LttngEventType(newTracefile.getTracefileName(), newTracefile.getCpuNumber(), newMarker.getName(), markerFieldsLabels ); + + // Add the type to the map/vector + addEventTypeToMap(tmpType); + } + } + } + + /* + * Add a new type to the HashMap + * + * As the hashmap use a key format that is a bit dangerous to use, we should always add using this function. + */ + private void addEventTypeToMap(LttngEventType newEventType) { + String newTypeKey = EventTypeKey.getEventTypeKey(newEventType); + + this.traceTypes.put(newTypeKey, newEventType); + this.traceTypeNames.add(newTypeKey); + } + /** - * Parse the next event in the trace.

+ * Return the next event in the trace.

* * @param context The actual context of the trace * - * @return The parsed event, or null if none available + * @return The next event, or null if none available * - * @see org.eclipse.linuxtools.lttng.jni.JniTrace + * @see org.eclipse.linuxtools.lttng.event.LttngEvent */ @Override - public TmfEvent parseEvent(TmfTraceContext context) { + public LttngEvent parseEvent(TmfTraceContext context) { JniEvent jniEvent; LttngTimestamp timestamp = null; + LttngEvent returnedEvent = null; synchronized (currentJniTrace) { // Seek to the context's location @@ -145,7 +228,12 @@ public class LTTngTrace extends TmfTrace { // Read an event from the JNI and convert it into a LttngEvent jniEvent = currentJniTrace.readNextEvent(); - currentLttngEvent = (jniEvent != null) ? convertJniEventToTmf(jniEvent, true) : null; + + //currentLttngEvent = (jniEvent != null) ? convertJniEventToTmf(jniEvent, true) : null; + if ( jniEvent != null ) { + currentLttngEvent = convertJniEventToTmf(jniEvent); + returnedEvent = currentLttngEvent; + } // Save timestamp timestamp = (LttngTimestamp) getCurrentLocation(); @@ -153,8 +241,8 @@ public class LTTngTrace extends TmfTrace { context.setLocation(timestamp); context.setTimestamp(timestamp); context.incrIndex(); - - return currentLttngEvent; + + return returnedEvent; } /** @@ -165,66 +253,58 @@ public class LTTngTrace extends TmfTrace { * * @param newEvent The JniEvent to convert into LttngEvent * - * @return The converted event + * @return The converted LttngEvent * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.event.LttngEvent */ public LttngEvent convertJniEventToTmf(JniEvent newEvent) { - LttngEvent event = null; - if (newEvent != null) - event = convertJniEventToTmf(newEvent, IS_PARSING_NEEDED_DEFAULT); - return event; + currentLttngEvent = convertJniEventToTmf(newEvent, IS_PARSING_NEEDED_DEFAULT); + + return currentLttngEvent; } /** - * Method tp convert a JniEvent into a LttngEvent + * Method to convert a JniEvent into a LttngEvent * * @param jniEvent The JniEvent to convert into LttngEvent * @param isParsingNeeded A boolean value telling if the event should be parsed or not. * - * @return The converted event + * @return The converted LttngEvent * - * @see org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent + * @see org.eclipse.linuxtools.lttng.event.LttngEvent */ public LttngEvent convertJniEventToTmf(JniEvent jniEvent, boolean isParsingNeeded) { - - // *** FIXME *** - // Format seems weird to me... we need to revisit Format/Fields/Content to find a better ways - // - // Generate fields - String[] labels = new String[jniEvent.requestEventMarker().getMarkerFieldsHashMap().size()]; - labels = jniEvent.requestEventMarker().getMarkerFieldsHashMap().keySet().toArray( labels ); - - // We need a format for content and fields - LttngEventFormat eventFormat = new LttngEventFormat(labels); - String content = ""; - LttngEventField[] fields = null; - - if (isParsingNeeded == true) { - fields = eventFormat.parse(jniEvent.parseAllFields()); - for (int y = 0; y < fields.length; y++) { - content += fields[y].toString() + " "; - } - } + // *** HACK *** + // To save time here, we only set value instead of allocating new object + // This give an HUGE performance improvement + // all allocation done in the LttngTrace constructor - LttngEvent event = null; - try { - event = new LttngEvent( - new LttngTimestamp(jniEvent.getEventTime().getTime()), - new TmfEventSource(jniEvent.requestEventSource() ), - new LttngEventType(jniEvent.getParentTracefile().getTracefileName(), - jniEvent.getParentTracefile().getCpuNumber(), - jniEvent.requestEventMarker().getName(), - eventFormat), - new LttngEventContent(eventFormat, content, fields), - new LttngEventReference(jniEvent.getParentTracefile().getTracefilePath(), this.getName()), - jniEvent); - } - catch (LttngException e) { - System.out.println("ERROR : Event creation returned :" + e.getMessage() ); + eventTimestamp.setValue(jniEvent.getEventTime().getTime()); + eventSource.setSourceId(jniEvent.requestEventSource()); + + eventType = traceTypes.get( EventTypeKey.getEventTypeKey(jniEvent) ); + + eventReference.setValue(jniEvent.getParentTracefile().getTracefilePath()); + eventReference.setTracepath(this.getName()); + +// eventContent.setEvent(currentLttngEvent); +// eventContent.setType(eventType); + eventContent.emptyContent(); + +// currentLttngEvent.setContent(eventContent); + currentLttngEvent.setType(eventType); + // Save the jni reference + currentLttngEvent.setJniEventReference(jniEvent); + + // Parse now if was asked + // Warning : THIS IS SLOW + if (isParsingNeeded == true ) { + eventContent.getFields(); } - return event; + return currentLttngEvent; } /** @@ -294,7 +374,7 @@ public class LTTngTrace extends TmfTrace { * * @return Reference to the current LttngTrace * - * @see org.eclipse.linuxtools.lttng.jni.JniTrace + * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniTrace */ public JniTrace getCurrentJniTrace() { return currentJniTrace; @@ -323,5 +403,29 @@ public class LTTngTrace extends TmfTrace { return returnedData; } +} + +/* + * EventTypeKey inner class + * + * This class is used to make the process of generating the HashMap key more transparent and so less error prone to use + * + */ +class EventTypeKey { + //*** WARNING *** + // These two getEventTypeKey() functions should ALWAYS construct the key the same ways! + // Otherwise, every type search will fail! + + static public String getEventTypeKey(LttngEventType newEventType) { + String key = newEventType.getTracefileName() + "/" + newEventType.getCpuId().toString() + "/" + newEventType.getMarkerName(); + + return key; + } -} \ No newline at end of file + static public String getEventTypeKey(JniEvent newEvent) { + String key = newEvent.getParentTracefile().getTracefileName() + "/" + newEvent.getParentTracefile().getCpuNumber() + "/" + newEvent.requestEventMarker().getName(); + + return key; + } + +} diff --git a/org.eclipse.linuxtools.tmf.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.tests/META-INF/MANIFEST.MF index ff905a6e93..703cff9331 100644 --- a/org.eclipse.linuxtools.tmf.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.tests/META-INF/MANIFEST.MF @@ -1,9 +1,9 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Test +Bundle-Name: TMF Unit Test Suite Bundle-SymbolicName: org.eclipse.linuxtools.tmf.tests -Bundle-Version: 0.0.1 +Bundle-Version: 0.1.0.qualifier Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-Vendor: Eclipse -Require-Bundle: org.junit4;bundle-version="4.5.0", +Require-Bundle: org.junit;bundle-version="3.8.2", org.eclipse.linuxtools.tmf;bundle-version="0.0.1" diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/AllEventTests.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/AllEventTests.java deleted file mode 100644 index 373579f168..0000000000 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/AllEventTests.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * 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.event; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - TmfTimestampTest.class, - TmfTimeRangeTest.class, - TmfEventTypeTest.class, - TmfEventFormatTest.class, - TmfEventContentTest.class, - TmfEventTest.class, - TmfTraceEventTest.class -}) - -public class AllEventTests { - -} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/AllTests.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/AllTests.java new file mode 100644 index 0000000000..307d3d9373 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/AllTests.java @@ -0,0 +1,24 @@ +package org.eclipse.linuxtools.tmf.event; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite(AllTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(TmfEventFieldTest.class); + suite.addTestSuite(TmfEventContentTest.class); + suite.addTestSuite(TmfEventTypeTest.class); + suite.addTestSuite(TmfEventSourceTest.class); + suite.addTestSuite(TmfTraceEventTest.class); + suite.addTestSuite(TmfEventReferenceTest.class); + suite.addTestSuite(TmfTimestampTest.class); + suite.addTestSuite(TmfTimeRangeTest.class); + suite.addTestSuite(TmfEventTest.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java index 4e36cd7137..60ffe558ff 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java @@ -12,49 +12,181 @@ package org.eclipse.linuxtools.tmf.event; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import junit.framework.TestCase; /** * TmfEventContentTest *

- * JUnit test suite for the TmfEventContent class. + * TODO: Implement me. Please. */ -public class TmfEventContentTest { +public class TmfEventContentTest extends TestCase { + + private final TmfTimestamp fTimestamp; + private final TmfEventSource fEventSource; + private final TmfEventType fEventType; + private final TmfEventTypeStub fEventTypeStub; + private final TmfEventReference fReference; + private final TmfEvent fEvent; + private final TmfEvent fEventStub; + + private final Object fRawContent = new String("Some content"); + + private final TmfEventContent fBasicContent; + private final TmfEventContentStub fStubContent; + + /** + * @param name + */ + public TmfEventContentTest(String name) { + super(name); + fTimestamp = new TmfTimestamp(); + fEventSource = new TmfEventSource(); + fEventType = new TmfEventType(); + fEventTypeStub = new TmfEventTypeStub(); + fReference = new TmfEventReference(); + + fEvent = new TmfEvent(fTimestamp, fEventSource, fEventType, fReference); + fBasicContent = new TmfEventContent(fEvent, fRawContent); + + fEventStub = new TmfEvent(fTimestamp, fEventSource, fEventTypeStub, fReference); + fStubContent = new TmfEventContentStub(fEventStub, fRawContent); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } // ======================================================================== // Constructors // ======================================================================== - @Test public void testTmfEventContent() { - TmfEventContent content = new TmfEventContent("Some content", new TmfEventFormat()); - assertEquals("getFormat", 1, content.getFormat().getLabels().length); - assertEquals("getLabels", "Content", content.getFormat().getLabels()[0]); - assertEquals("getContent", "Some content", content.getContent()); + assertSame("getLabels", fEvent, fBasicContent.getEvent()); + assertSame("getType", fEventType, fBasicContent.getType()); + assertSame("getContent", fRawContent, fBasicContent.getContent()); + } + + public void testTmfEventContentCopy() { + TmfEventContent content = new TmfEventContent(fBasicContent); + assertSame("getLabels", fEvent, content.getEvent()); + assertSame("getType", fEventType, content.getType()); + assertSame("getContent", fRawContent, content.getContent()); + } + + public void testCloneShallowCopy() { + TmfEventContent content = fBasicContent.clone(); + assertSame("getLabels", fEvent, content.getEvent()); + assertSame("getType", fEventType, content.getType()); + assertSame("getContent", fRawContent, content.getContent()); + } + + public void testCloneDeepCopy() { + TmfEventContent content = fStubContent.clone(); + assertSame ("getEvent", fEventStub, content.getEvent()); + assertSame ("getType", fEventTypeStub, content.getType()); + assertNotSame("getContent", fRawContent, content.getContent()); + assertEquals ("getContent", fRawContent, content.getContent()); + } + + // ======================================================================== + // Basic content parsing + // ======================================================================== + + public void testGetFields() { + Object[] fields = fBasicContent.getFields(); + assertEquals("getFields", 1, fields.length); + assertEquals("getFields", fRawContent, fields[0].toString()); + } + + public void testGetFieldFromId() { + Object field; + try { + field = fBasicContent.getField("Content"); + assertEquals("getField", fRawContent, field.toString()); + } catch (TmfNoSuchFieldException e) { + fail("Field not found"); + } + } + + public void testGetFieldFromIdFailed() { + try { + fBasicContent.getField("Dummy"); + fail("Found an inexisting field..."); + } catch (TmfNoSuchFieldException e) { + // Success + } + } + + public void testGetFieldFromPos() { + Object field = fBasicContent.getField(0); + assertEquals("getField", fRawContent, field.toString()); } // ======================================================================== - // getField + // Standard content parsing // ======================================================================== - @Test - public void testBasicGetField() { - TmfEventContent content = new TmfEventContent("Some content", new TmfEventFormat()); - assertEquals("getField", 1, content.getFields().length); - assertEquals("getField", "Some content", content.getField(0).toString()); + public void testGetFields2() { + Object[] fields = fStubContent.getFields(); + assertEquals("getFields", 5, fields.length); } - @Test - public void testExtendedGetField() { - TmfEventContent content = new TmfEventContent("", new TmfEventFormatStub()); - assertEquals("getField", 5, content.getFields().length); - assertEquals("getField", "1", content.getField(0).toString()); - assertEquals("getField", "-10", content.getField(1).toString()); - assertEquals("getField", "true", content.getField(2).toString()); - assertEquals("getField", "some string", content.getField(3).toString()); - assertEquals("getField", "[TmfTimestamp:1,2,3]", content.getField(4).toString()); + public void testGetFieldFromId2() { + Object field; + try { + field = fStubContent.getField("Field1"); + assertEquals("getField", new Integer(1), field); + + field = fStubContent.getField("Field2"); + assertEquals("getField", new Integer(-10), field); + + field = fStubContent.getField("Field3"); + assertEquals("getField", new Boolean(true), field); + + field = fStubContent.getField("Field4"); + assertEquals("getField", new String("some string"), field); + + field = fStubContent.getField("Field5"); + assertEquals("getField", new TmfTimestamp(1, (byte) 2, 3), field); + + } catch (TmfNoSuchFieldException e) { + fail("Field not found"); + } + } + + public void testGetFieldFromPos2() { + TmfEventContentStub content = new TmfEventContentStub(fEvent, fRawContent); + + Object field = content.getField(0); + assertEquals("getField", new Integer(1), field); + + field = content.getField(1); + assertEquals("getField", new Integer(-10), field); + + field = content.getField(2); + assertEquals("getField", new Boolean(true), field); + + field = content.getField(3); + assertEquals("getField", new String("some string"), field); + + field = content.getField(4); + assertEquals("getField", new TmfTimestamp(1, (byte) 2, 3), field); + } + + // ======================================================================== + // Operators + // ======================================================================== + + public void testToString() { + String expected = "[TmfEventContent(" + fRawContent + ",)]"; + TmfEventContent content = new TmfEventContent(fEvent, fRawContent); + assertEquals("toString", expected, content.toString()); } } diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventFieldTest.java new file mode 100644 index 0000000000..a94facace1 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventFieldTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * 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.event; + +import junit.framework.TestCase; + +/** + * TmfEventFieldTest + *

+ * TODO: Implement me. Please. + */ +public class TmfEventFieldTest extends TestCase { + + private final TmfEventContent fContent; + private final String fFieldId = "Field"; + private final Object fValue1 = new String("Value"); + private final Object fValue2 = new Integer(10); + + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfEventFieldTest(String name) { + super(name); + TmfTimestamp fTimestamp = new TmfTimestamp(); + TmfEventSource fEventSource = new TmfEventSource(); + TmfEventType fEventType = new TmfEventTypeStub(); + TmfEventReference fReference = new TmfEventReference(); + TmfEvent fEvent = new TmfEvent(fTimestamp, fEventSource, fEventType, fReference); + + fContent = new TmfEventContent(fEvent, "Some content"); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ======================================================================== + // Constructors + // ======================================================================== + + public void testTmfEventField() { + TmfEventField field = new TmfEventField(fContent, fFieldId, fValue1); + assertSame("getParent", fContent, field.getParent()); + assertSame("getId", fFieldId, field.getId()); + assertSame("getValue", fValue1, field.getValue()); + } + + public void testTmfEventFieldCopy() { + TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1); + TmfEventField field = new TmfEventField(original); + assertSame("getParent", fContent, field.getParent()); + assertSame("getId", fFieldId, field.getId()); + assertSame("getValue", fValue1, field.getValue()); + } + + public void testCloneShallowCopy() { + TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1); + TmfEventField field = original.clone(); + assertSame("getParent", fContent, field.getParent()); + assertSame("getId", fFieldId, field.getId()); + assertSame("getValue", fValue1, field.getValue()); + } + +// public void testCloneDeepCopy() { +// TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1); +// TmfEventField field = original.clone(); +// assertNotSame("getParent", fContent, field.getParent()); +// assertNotSame("getId", fFieldId, field.getId()); +// assertNotSame("getValue", fValue1, field.getValue()); +// assertEquals ("getParent", fContent, field.getParent()); +// assertEquals ("getId", fFieldId, field.getId()); +// assertEquals ("getValue", fValue1, field.getValue()); +// } + + // ======================================================================== + // Operators + // ======================================================================== + + public void testToString() { + String expected1 = "[TmfEventField(" + fFieldId + ":" + fValue1.toString() + ")]"; + TmfEventField field = new TmfEventField(fContent, fFieldId, fValue1); + assertEquals("toString", expected1, field.toString()); + + String expected2 = "[TmfEventField(" + fFieldId + ":" + fValue2.toString() + ")]"; + field = new TmfEventField(fContent, fFieldId, fValue2); + assertEquals("toString", expected2, field.toString()); + } + +} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventFormatTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventFormatTest.java deleted file mode 100644 index 6c89085774..0000000000 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventFormatTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * 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.event; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * TmfEventFormatTest - *

- * JUnit test suite for the TmfEventFormat class. - */ -public class TmfEventFormatTest { - - // ======================================================================== - // Constructors - // ======================================================================== - - @Test - public void testBasicTmfEventFormat() { - TmfEventFormat format = new TmfEventFormat(); - assertEquals("getLabels", 1, format.getLabels().length); - assertEquals("getValue", "Content", format.getLabels()[0]); - } - - @Test - public void testEmptyConstructor() { - TmfEventFormat format = new TmfEventFormat(new String[] {}); - assertEquals("getLabels", 0, format.getLabels().length); - } - - @Test - public void testNormalConstructor() { - TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2", "field3" }); - assertEquals("getLabels", 3, format.getLabels().length); - assertEquals("getLabels", "field1", format.getLabels()[0]); - assertEquals("getLabels", "field2", format.getLabels()[1]); - assertEquals("getLabels", "field3", format.getLabels()[2]); - } - - @Test - public void testExtendedConstructor() { - TmfEventFormatStub format = new TmfEventFormatStub(); - assertEquals("getLabels", 5, format.getLabels().length); - assertEquals("getLabels", "Field1", format.getLabels()[0]); - assertEquals("getLabels", "Field2", format.getLabels()[1]); - assertEquals("getLabels", "Field3", format.getLabels()[2]); - assertEquals("getLabels", "Field4", format.getLabels()[3]); - assertEquals("getLabels", "Field5", format.getLabels()[4]); - } - - // ======================================================================== - // parse - // ======================================================================== - - @Test - public void testBasicParse() { - TmfEventFormat format = new TmfEventFormat(); - TmfEventField[] content = format.parse(new TmfTimestamp()); - assertEquals("length", 1, content.length); - assertEquals("getValue", "[TmfTimestamp:0,0,0]", content[0].toString()); - } - - @Test - public void testExtendedParse() { - TmfEventFormatStub format = new TmfEventFormatStub(); - TmfEventField[] content = format.parse(new TmfTimestamp()); - assertEquals("length", 5, content.length); - assertEquals("getValue", "1", content[0].toString()); - assertEquals("getValue", "-10", content[1].toString()); - assertEquals("getValue", "true", content[2].toString()); - assertEquals("getValue", "some string", content[3].toString()); - assertEquals("getValue", "[TmfTimestamp:1,2,3]", content[4].toString()); - } - -} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventReferenceTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventReferenceTest.java new file mode 100644 index 0000000000..875f73f91f --- /dev/null +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventReferenceTest.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * 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.event; + +import junit.framework.TestCase; + +/** + * TmfEventReferenceTest + *

+ * TODO: Implement me. Please. + */ +public class TmfEventReferenceTest extends TestCase { + + private final Object fReference = new String("Some reference"); + + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfEventReferenceTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ======================================================================== + // Constructors + // ======================================================================== + + public void testTmfEventReferenceDefault() { + TmfEventReference reference = new TmfEventReference(); + assertEquals("getReference", null, reference.getReference()); + } + + public void testTmfEventReference() { + TmfEventReference reference = new TmfEventReference(fReference); + assertSame("getReference", fReference, reference.getReference()); + } + + public void testTmfEventReferenceCopy() { + TmfEventReference original = new TmfEventReference(fReference); + TmfEventReference reference = new TmfEventReference(original); + assertSame("getReference", fReference, reference.getReference()); + } + + public void testCloneShallowCopy() { + TmfEventReference original = new TmfEventReference(fReference); + TmfEventReference reference = original.clone(); + assertSame("getReference", fReference, reference.getReference()); + } + +// public void testCloneDeepCopy() { +// TmfEventReference original = new TmfEventReference(fReference); +// TmfEventReference reference = original.clone(); +// assertNotSame("getReference", fReference, reference.getReference()); +// assertEquals ("getReference", fReference, reference.getReference()); +// } + + // ======================================================================== + // Operators + // ======================================================================== + + public void testToString() { + String expected1 = "[TmfEventReference(" + "null" + ")]"; + TmfEventReference reference1 = new TmfEventReference(); + assertEquals("toString", expected1, reference1.toString()); + + String expected2 = "[TmfEventReference(" + fReference.toString() + ")]"; + TmfEventReference reference2 = new TmfEventReference(fReference); + assertEquals("toString", expected2, reference2.toString()); + } + +} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventSourceTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventSourceTest.java new file mode 100644 index 0000000000..d3de8de78c --- /dev/null +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventSourceTest.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * 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.event; + +import junit.framework.TestCase; + +/** + * TmfEventSourceTest + *

+ * TODO: Implement me. Please. + */ +public class TmfEventSourceTest extends TestCase { + + private final Object fSource = new String("Some source"); + + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfEventSourceTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ======================================================================== + // Constructors + // ======================================================================== + + public void testTmfEventSourceDefault() { + TmfEventSource source = new TmfEventSource(); + assertEquals("getSourceId", null, source.getSourceId()); + } + + public void testTmfEventSource() { + TmfEventSource source = new TmfEventSource(fSource); + assertSame("getSourceId", fSource, source.getSourceId()); + } + + public void testTmfEventSourceCopy() { + TmfEventSource original = new TmfEventSource(fSource); + TmfEventSource source = new TmfEventSource(original); + assertSame("getSourceId", fSource, source.getSourceId()); + } + + public void testCloneShallowCopy() { + TmfEventSource original = new TmfEventSource(fSource); + TmfEventSource source = original.clone(); + assertSame("getSourceId", fSource, source.getSourceId()); + } + +// public void testCloneDeepCopy() { +// TmfEventSource original = new TmfEventSource(fSource); +// TmfEventSource source = original.clone(); +// assertNotSame("getSourceId", fSource, source.getSourceId()); +// assertEquals ("getSourceId", fSource, source.getSourceId()); +// } + + // ======================================================================== + // Operators + // ======================================================================== + + public void testToString() { + String expected1 = "[TmfEventSource(" + "null" + ")]"; + TmfEventSource source1 = new TmfEventSource(); + assertEquals("toString", expected1, source1.toString()); + + String expected2 = "[TmfEventSource(" + fSource.toString() + ")]"; + TmfEventSource source2 = new TmfEventSource(fSource); + assertEquals("toString", expected2, source2.toString()); + } + +} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java index c6e880ff5f..133746b9b5 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java @@ -12,108 +12,120 @@ package org.eclipse.linuxtools.tmf.event; -import static org.junit.Assert.*; - -import org.junit.Test; +import junit.framework.TestCase; /** * TmfEventTest *

- * JUNit test suite for the TmfEvent class. + * TODO: Implement me. Please. */ -public class TmfEventTest { - - // ======================================================================== - // Constructor - // ======================================================================== - - @Test - public void testTmfEvent() { - TmfTimestamp timestamp = new TmfTimestamp(12345, (byte) 2, 5); - TmfEventSource source = new TmfEventSource("Source"); - TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2" }); - TmfEventType type = new TmfEventType("Type", format); - TmfEventContent content = new TmfEventContent("Some content", format); - TmfEventReference reference = new TmfEventReference("Reference"); - - // Create the event - TmfEvent event = new TmfEvent(timestamp, source, type, content, reference); - - // Check the event timestamp - TmfTimestamp ts = event.getTimestamp(); - assertEquals("getValue", 12345, ts.getValue()); - assertEquals("getscale", 2, ts.getScale()); - assertEquals("getPrecision", 5, ts.getPrecision()); - - // Check the original event timestamp - ts = event.getOriginalTimestamp(); - assertEquals("getValue", 12345, ts.getValue()); - assertEquals("getscale", 2, ts.getScale()); - assertEquals("getPrecision", 5, ts.getPrecision()); - - // Check the event source - TmfEventSource src = event.getSource(); - assertEquals("getValue", "Source", src.getSourceId()); - - // Check the event type - TmfEventType tp = event.getType(); - assertEquals("getValue", "Type", tp.getTypeId()); - assertEquals("getFormat", "field1", tp.getFormat().getLabels()[0]); - assertEquals("getFormat", "field2", tp.getFormat().getLabels()[1]); - - // Check the event content - TmfEventContent cnt = event.getContent(); - assertEquals("getField", 1, cnt.getFields().length); - assertEquals("getField", "Some content", cnt.getField(0).toString()); - - // Check the event reference - TmfEventReference ref = event.getReference(); - assertEquals("getValue", "Reference", ref.getValue()); - } - - @Test - public void testTmfEvent2() { - TmfTimestamp original = new TmfTimestamp(12345, (byte) 2, 5); - TmfTimestamp effective = new TmfTimestamp(12350, (byte) 2, 5); - TmfEventSource source = new TmfEventSource("Source"); - TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2" }); - TmfEventType type = new TmfEventType("Type", format); - TmfEventContent content = new TmfEventContent("Some content", format); - TmfEventReference reference = new TmfEventReference("Reference"); - - // Create the event - TmfEvent event = new TmfEvent(original, effective, source, type, content, reference); - - // Check the event timestamp - TmfTimestamp ts = event.getTimestamp(); - assertEquals("getValue", 12350, ts.getValue()); - assertEquals("getscale", 2, ts.getScale()); - assertEquals("getPrecision", 5, ts.getPrecision()); - - // Check the original event timestamp - ts = event.getOriginalTimestamp(); - assertEquals("getValue", 12345, ts.getValue()); - assertEquals("getscale", 2, ts.getScale()); - assertEquals("getPrecision", 5, ts.getPrecision()); - - // Check the event source - TmfEventSource src = event.getSource(); - assertEquals("getValue", "Source", src.getSourceId()); - - // Check the event type - TmfEventType tp = event.getType(); - assertEquals("getValue", "Type", tp.getTypeId()); - assertEquals("getFormat", "field1", tp.getFormat().getLabels()[0]); - assertEquals("getFormat", "field2", tp.getFormat().getLabels()[1]); - - // Check the event content - TmfEventContent cnt = event.getContent(); - assertEquals("getField", 1, cnt.getFields().length); - assertEquals("getField", "Some content", cnt.getField(0).toString()); - - // Check the event reference - TmfEventReference ref = event.getReference(); - assertEquals("getValue", "Reference", ref.getValue()); - } +public class TmfEventTest extends TestCase { + + private final String fTypeId = "Some type"; + private final String fLabel0 = "label1"; + private final String fLabel1 = "label2"; + private final String[] fLabels = new String[] { fLabel0, fLabel1 }; + + private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5); + private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2, 5); + private final TmfEventSource fSource = new TmfEventSource("Source"); + private final TmfEventType fType = new TmfEventType(fTypeId, fLabels); + private final TmfEventReference fReference = new TmfEventReference("Some reference"); + + private final TmfEvent fEvent1; + private final TmfEvent fEvent2; + + private final TmfEventContent fContent1; + private final TmfEventContent fContent2; + + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfEventTest(String name) { + super(name); + + fEvent1 = new TmfEvent(fTimestamp1, fSource, fType, fReference); + fContent1 = new TmfEventContent(fEvent1, "Some content"); + fEvent1.setContent(fContent1); + + fEvent2 = new TmfEvent(fTimestamp1, fTimestamp2, fSource, fType, fReference); + fContent2 = new TmfEventContent(fEvent2, "Some other content"); + fEvent2.setContent(fContent2); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ======================================================================== + // Constructors + // ======================================================================== + + public void testTmfEvent() { + assertEquals("getTimestamp", fTimestamp1, fEvent1.getTimestamp()); + assertEquals("getOriginalTimestamp", fTimestamp1, fEvent1.getOriginalTimestamp()); + assertEquals("getSource", fSource, fEvent1.getSource()); + assertEquals("getType", fType, fEvent1.getType()); + assertEquals("getContent", fContent1, fEvent1.getContent()); + assertEquals("getReference", fReference, fEvent1.getReference()); + } + + public void testTmfEvent2() { + assertEquals("getTimestamp", fTimestamp2, fEvent2.getTimestamp()); + assertEquals("getOriginalTimestamp", fTimestamp1, fEvent2.getOriginalTimestamp()); + assertEquals("getSource", fSource, fEvent2.getSource()); + assertEquals("getType", fType, fEvent2.getType()); + assertEquals("getContent", fContent2, fEvent2.getContent()); + assertEquals("getReference", fReference, fEvent2.getReference()); + } + + public void testTmfEventCopy() { + TmfEvent event = new TmfEvent(fEvent1); + assertEquals("getTimestamp", fTimestamp1, event.getTimestamp()); + assertEquals("getOriginalTimestamp", fTimestamp1, event.getOriginalTimestamp()); + assertEquals("getSource", fSource, event.getSource()); + assertEquals("getType", fType, event.getType()); + assertEquals("getContent", fContent1, event.getContent()); + assertEquals("getReference", fReference, event.getReference()); + } + +// public void testTmfEventCloneShallowCopy() { +// TmfEvent event = fEvent1.clone(); +// assertEquals("getTimestamp", fTimestamp1, event.getTimestamp()); +// assertEquals("getOriginalTimestamp", fTimestamp1, event.getOriginalTimestamp()); +// assertEquals("getSource", fSource, event.getSource()); +// assertEquals("getType", fType, event.getType()); +// assertEquals("getContent", fContent1, event.getContent()); +// assertEquals("getReference", fReference, event.getReference()); +// } + +// public void testTmfEventCloneDeepCopy() { +// TmfEvent event = fEvent1.clone(); +// assertEquals("getTimestamp", fTimestamp1, event.getTimestamp()); +// assertEquals("getOriginalTimestamp", fTimestamp1, event.getOriginalTimestamp()); +// assertEquals("getSource", fSource, event.getSource()); +// assertEquals("getType", fType, event.getType()); +// assertEquals("getContent", fContent1, event.getContent()); +// assertEquals("getReference", fReference, event.getReference()); +// } + + // ======================================================================== + // Operators + // ======================================================================== + +// public void testToString() { +// String expected1 = "[TmfEventType:" + TmfEventType.DEFAULT_TYPE_ID + "]"; +// assertEquals("toString", expected1, fEvent1.toString()); +// +// String expected2 = "[TmfEventType:" + fTypeId + "]"; +// assertEquals("toString", expected2, fEvent2.toString()); +// } } diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventTypeTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventTypeTest.java index e90a9fa1e3..2683dcc4d5 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventTypeTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfEventTypeTest.java @@ -12,34 +12,109 @@ package org.eclipse.linuxtools.tmf.event; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import junit.framework.TestCase; /** * TmfEventTypeTest *

* JUnit test suite for the TmfEventType class. */ -public class TmfEventTypeTest { - - // ======================================================================== - // Constructor - // ======================================================================== - - @Test - public void testEmptyConstructor() { - TmfEventType type = new TmfEventType("", null); - assertEquals("getValue", "", type.getTypeId()); - assertEquals("getFormat", null, type.getFormat()); - } - - @Test - public void testNormalConstructor() { - TmfEventType type = new TmfEventType("Type", new TmfEventFormat(new String[] { "field1", "field2" })); - assertEquals("getValue", "Type", type.getTypeId()); - assertEquals("getFormat", "field1", type.getFormat().getLabels()[0]); - assertEquals("getFormat", "field2", type.getFormat().getLabels()[1]); - } +public class TmfEventTypeTest extends TestCase { + + private final String fTypeId = "Some type"; + private final String fLabel0 = "label1"; + private final String fLabel1 = "label2"; + private final String[] fLabels = new String[] { fLabel0, fLabel1 }; + + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfEventTypeTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ======================================================================== + // Constructors + // ======================================================================== + + public void testTmfEventTypeDefault() { + TmfEventType type = new TmfEventType(); + try { + assertEquals("getTypeId", TmfEventType.DEFAULT_TYPE_ID, type.getTypeId()); + assertEquals("getNbFields", 1, type.getNbFields()); + assertEquals("getFieldIndex", 0, type.getFieldIndex(TmfEventType.DEFAULT_LABELS[0])); + assertEquals("getLabels", TmfEventType.DEFAULT_LABELS, type.getLabels()); + assertEquals("getLabel", TmfEventType.DEFAULT_LABELS[0], type.getLabel(0)); + } catch (TmfNoSuchFieldException e) { + fail("getFieldIndex: no such field"); + } + } + + public void testTmfEventType() { + TmfEventType type = new TmfEventType(fTypeId, fLabels); + try { + assertEquals("getTypeId", fTypeId, type.getTypeId()); + assertEquals("getNbFields", fLabels.length, type.getNbFields()); + assertEquals("getFieldIndex", 0, type.getFieldIndex(fLabel0)); + assertEquals("getFieldIndex", 1, type.getFieldIndex(fLabel1)); + assertEquals("getLabels", fLabels, type.getLabels()); + assertEquals("getLabel", fLabel0, type.getLabel(0)); + assertEquals("getLabel", fLabel1, type.getLabel(1)); + } catch (TmfNoSuchFieldException e) { + fail("getFieldIndex: no such field"); + } + + try { + assertEquals("getFieldIndex", 0, type.getFieldIndex("Dummy")); + fail("getFieldIndex: inexistant field"); + } catch (TmfNoSuchFieldException e) { + // Success + } + } + + public void testTmfEventTypeCopy() { + TmfEventType original = new TmfEventType(fTypeId, fLabels); + TmfEventType type = new TmfEventType(original); + assertEquals("getTypeId", fTypeId, type.getTypeId()); + assertEquals("getNbFields", fLabels.length, type.getNbFields()); + assertEquals("getLabels", fLabels, type.getLabels()); + } + + public void testCloneShallowCopy() { + TmfEventType original = new TmfEventType(fTypeId, fLabels); + TmfEventType type = original.clone(); + assertEquals("getTypeId", fTypeId, type.getTypeId()); + assertEquals("getNbFields", fLabels.length, type.getNbFields()); + assertEquals("getLabels", fLabels, type.getLabels()); + } + +// public void testCloneDeepCopy() { +// fail("Not yet implemented"); +// } + + // ======================================================================== + // Operators + // ======================================================================== + + public void testToString() { + String expected1 = "[TmfEventType:" + TmfEventType.DEFAULT_TYPE_ID + "]"; + TmfEventType type1 = new TmfEventType(); + assertEquals("toString", expected1, type1.toString()); + + String expected2 = "[TmfEventType:" + fTypeId + "]"; + TmfEventType type2 = new TmfEventType(fTypeId, fLabels); + assertEquals("toString", expected2, type2.toString()); + } } diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTimeRangeTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTimeRangeTest.java index a2f752444c..1d93fd5859 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTimeRangeTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTimeRangeTest.java @@ -12,71 +12,93 @@ package org.eclipse.linuxtools.tmf.event; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; - -import org.junit.Test; +import junit.framework.TestCase; /** * TmfTimeRangeTest *

- * JUnit test suite for the TmfTimeRange class. + * TODO: Implement me. Please. */ -public class TmfTimeRangeTest { - - // ======================================================================== - // Constructors - // ======================================================================== - - @Test - public void testConstructor() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp(12345); - TmfTimestamp ts2 = new TmfTimestamp(12350); - TmfTimeRange range = new TmfTimeRange(ts1, ts2); - assertEquals("startTime", ts1, range.getStartTime()); - assertEquals("endTime", ts2, range.getEndTime()); - } - - @Test - public void testOpenRange1() throws Exception { - TmfTimestamp ts2 = new TmfTimestamp(12350); - TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, ts2); - assertEquals("startTime", TmfTimestamp.BigBang, range.getStartTime()); - assertEquals("endTime", ts2, range.getEndTime()); - } - - @Test - public void testOpenRange2() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp(12345); - TmfTimeRange range = new TmfTimeRange(ts1, TmfTimestamp.BigCrunch); - assertEquals("startTime", ts1, range.getStartTime()); - assertEquals("endTime", TmfTimestamp.BigCrunch, range.getEndTime()); - } - - @Test - public void testOpenRange3() throws Exception { - TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - assertEquals("startTime", TmfTimestamp.BigBang, range.getStartTime()); - assertEquals("endTime", TmfTimestamp.BigCrunch, range.getEndTime()); - } - - // ======================================================================== - // Constructors - // ======================================================================== - - @Test - public void testContains() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp(12345); - TmfTimestamp ts2 = new TmfTimestamp(12350); - TmfTimeRange range = new TmfTimeRange(ts1, ts2); - - assertTrue("contains (lower bound)", range.contains(new TmfTimestamp(12345))); - assertTrue("contains (higher bound)", range.contains(new TmfTimestamp(12350))); - assertTrue("contains (within bounds)", range.contains(new TmfTimestamp(12346))); - - assertFalse("contains (low value)", range.contains(new TmfTimestamp(12340))); - assertFalse("contains (high value)", range.contains(new TmfTimestamp(12351))); - } +public class TmfTimeRangeTest extends TestCase { + + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfTimeRangeTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ======================================================================== + // Constructors + // ======================================================================== + + public void testConstructor() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(12345); + TmfTimestamp ts2 = new TmfTimestamp(12350); + TmfTimeRange range = new TmfTimeRange(ts1, ts2); + assertEquals("startTime", ts1, range.getStartTime()); + assertEquals("endTime", ts2, range.getEndTime()); + } + + public void testOpenRange1() throws Exception { + TmfTimestamp ts2 = new TmfTimestamp(12350); + TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, ts2); + assertEquals("startTime", TmfTimestamp.BigBang, range.getStartTime()); + assertEquals("endTime", ts2, range.getEndTime()); + } + + public void testOpenRange2() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(12345); + TmfTimeRange range = new TmfTimeRange(ts1, TmfTimestamp.BigCrunch); + assertEquals("startTime", ts1, range.getStartTime()); + assertEquals("endTime", TmfTimestamp.BigCrunch, range.getEndTime()); + } + + public void testOpenRange3() throws Exception { + TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); + assertEquals("startTime", TmfTimestamp.BigBang, range.getStartTime()); + assertEquals("endTime", TmfTimestamp.BigCrunch, range.getEndTime()); + } + + // ======================================================================== + // contains + // ======================================================================== + + public void testContains() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(12345); + TmfTimestamp ts2 = new TmfTimestamp(12350); + TmfTimeRange range = new TmfTimeRange(ts1, ts2); + + assertTrue("contains (lower bound)", range.contains(new TmfTimestamp(12345))); + assertTrue("contains (higher bound)", range.contains(new TmfTimestamp(12350))); + assertTrue("contains (within bounds)", range.contains(new TmfTimestamp(12346))); + + assertFalse("contains (low value)", range.contains(new TmfTimestamp(12340))); + assertFalse("contains (high value)", range.contains(new TmfTimestamp(12351))); + } + + // ======================================================================== + // toString + // ======================================================================== + + public void testToString() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(12345); + TmfTimestamp ts2 = new TmfTimestamp(12350); + TmfTimeRange range = new TmfTimeRange(ts1, ts2); + String expected = "[TmfTimeRange(" + ts1.toString() + ":" + ts2.toString() + ")]"; + assertEquals("toString", expected, range.toString()); + } + } diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTimestampTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTimestampTest.java index 833e10efa8..66d5e95e7c 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTimestampTest.java @@ -12,308 +12,306 @@ package org.eclipse.linuxtools.tmf.event; -import static org.junit.Assert.*; - -import org.junit.Test; +import junit.framework.TestCase; /** * TmfTimestampTest *

- * JUnit test suite for the TmfTimestamp class. + * TODO: Implement me. Please. */ -public class TmfTimestampTest { - - // ======================================================================== - // Constructors - // ======================================================================== - - @Test - public void testDefaultConstructor() throws Exception { - TmfTimestamp ts = new TmfTimestamp(); - assertEquals("getValue", 0, ts.getValue()); - assertEquals("getscale", 0, ts.getScale()); - assertEquals("getPrecision", 0, ts.getPrecision()); - } - - @Test - public void testSimpleConstructor() throws Exception { - TmfTimestamp ts = new TmfTimestamp(12345); - assertEquals("getValue", 12345, ts.getValue()); - assertEquals("getscale", 0, ts.getScale()); - assertEquals("getPrecision", 0, ts.getPrecision()); - } - - @Test - public void testSimpleConstructor2() throws Exception { - TmfTimestamp ts = new TmfTimestamp(12345, (byte) -1); - assertEquals("getValue", 12345, ts.getValue()); - assertEquals("getscale", -1, ts.getScale()); - assertEquals("getPrecision", 0, ts.getPrecision()); - } - - @Test - public void testFullConstructor() throws Exception { - TmfTimestamp ts = new TmfTimestamp(12345, (byte) 2, 5); - assertEquals("getValue", 12345, ts.getValue()); - assertEquals("getscale", 2, ts.getScale()); - assertEquals("getPrecision", 5, ts.getPrecision()); - } - - @Test - public void testCopyConstructor() throws Exception { - TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) 2, 5); - TmfTimestamp ts = new TmfTimestamp(ts0); - assertEquals("getValue", 12345, ts.getValue()); - assertEquals("getscale", 2, ts.getScale()); - assertEquals("getPrecision", 5, ts.getPrecision()); - } - - // ======================================================================== - // BigBang, BigCrunch - // ======================================================================== - - @Test - public void testCopyConstructorBigBang() throws Exception { - TmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BigBang); - assertEquals("getValue", TmfTimestamp.BigBang.getValue(), ts.getValue()); - assertEquals("getscale", TmfTimestamp.BigBang.getScale(), ts.getScale()); - assertEquals("getPrecision", TmfTimestamp.BigBang.getPrecision(), ts.getPrecision()); - } - - @Test - public void testCopyConstructorBigCrunch() throws Exception { - TmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BigCrunch); - assertEquals("getValue", TmfTimestamp.BigCrunch.getValue(), ts.getValue()); - assertEquals("getscale", TmfTimestamp.BigCrunch.getScale(), ts.getScale()); - assertEquals("getPrecision", TmfTimestamp.BigCrunch.getPrecision(), ts.getPrecision()); - } - - // ======================================================================== - // toString - // ======================================================================== - - @Test - public void testToString() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp(); - TmfTimestamp ts2 = new TmfTimestamp(1234, (byte) 2); - TmfTimestamp ts3 = new TmfTimestamp(1234, (byte) 2, 1); - TmfTimestamp ts4 = new TmfTimestamp(-1234, (byte) -1, 4); - - assertEquals("toString", "[TmfTimestamp:0,0,0]", ts1.toString()); - assertEquals("toString", "[TmfTimestamp:1234,2,0]", ts2.toString()); - assertEquals("toString", "[TmfTimestamp:1234,2,1]", ts3.toString()); - assertEquals("toString", "[TmfTimestamp:-1234,-1,4]", ts4.toString()); - } - - // ======================================================================== - // synchronize - // ======================================================================== - - @Test - public void testSynchronizeOffset() throws Exception { - TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 1); - TmfTimestamp ts = new TmfTimestamp(); - - ts = ts0.synchronize(0, (byte) 0); - assertEquals("getValue", 1234, ts.getValue()); - assertEquals("getscale", 0, ts.getScale()); - assertEquals("getPrecision", 1, ts.getPrecision()); - - ts = ts0.synchronize(10, (byte) 0); - assertEquals("getValue", 1244, ts.getValue()); - assertEquals("getscale", 0, ts.getScale()); - assertEquals("getPrecision", 1, ts.getPrecision()); - - ts = ts0.synchronize(-10, (byte) 0); - assertEquals("getValue", 1224, ts.getValue()); - assertEquals("getscale", 0, ts.getScale()); - assertEquals("getPrecision", 1, ts.getPrecision()); - } - - @Test - public void testSynchronizeScale() throws Exception { - TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 12); - TmfTimestamp ts = new TmfTimestamp(); - - ts = ts0.synchronize(0, (byte) 0); - assertEquals("getValue", 1234, ts.getValue()); - assertEquals("getscale", 0, ts.getScale()); - assertEquals("getPrecision", 12, ts.getPrecision()); - - ts = ts0.synchronize(0, (byte) 1); - assertEquals("getValue", 123, ts.getValue()); - assertEquals("getscale", 1, ts.getScale()); - assertEquals("getPrecision", 1, ts.getPrecision()); - - ts = ts0.synchronize(0, (byte) 2); - assertEquals("getValue", 12, ts.getValue()); - assertEquals("getscale", 2, ts.getScale()); - assertEquals("getPrecision", 0, ts.getPrecision()); - - ts = ts0.synchronize(0, (byte) 4); - assertEquals("getValue", 0, ts.getValue()); - assertEquals("getscale", 4, ts.getScale()); - assertEquals("getPrecision", 0, ts.getPrecision()); - - ts = ts0.synchronize(0, (byte) -2); - assertEquals("getValue", 123400, ts.getValue()); - assertEquals("getscale", -2, ts.getScale()); - assertEquals("getPrecision", 1200, ts.getPrecision()); - } - - @Test - public void testSynchronizeOffsetAndScale() throws Exception { - TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 12); - TmfTimestamp ts = new TmfTimestamp(); - - ts = ts0.synchronize(10, (byte) 1); - assertEquals("getValue", 133, ts.getValue()); - assertEquals("getscale", 1, ts.getScale()); - assertEquals("getPrecision", 1, ts.getPrecision()); - - ts = ts0.synchronize(-10, (byte) -1); - assertEquals("getValue", 12330, ts.getValue()); - assertEquals("getscale", -1, ts.getScale()); - assertEquals("getPrecision", 120, ts.getPrecision()); - } - - // ======================================================================== - // getAdjustment - // ======================================================================== - - @Test - public void testGetAdjustmentSameScale() throws Exception { - TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) -2); - TmfTimestamp ts = new TmfTimestamp(10000, (byte) -2); - - long delta = ts.getAdjustment(ts0); - assertEquals("delta", 2345, delta); - } - - @Test - public void testGetAdjustmentDifferentScale() throws Exception { - TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) -2); - TmfTimestamp ts = new TmfTimestamp( 1, (byte) 2); - - long delta = ts.getAdjustment(ts0); - assertEquals("delta", 2345, delta); - - delta = ts0.getAdjustment(ts); - assertEquals("delta", 0, delta); - } - - // ======================================================================== - // CompareTo - // ======================================================================== - - @Test - public void testCompareToSameScale() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp( 900, (byte) 0, 50); - TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50); - TmfTimestamp ts3 = new TmfTimestamp(1100, (byte) 0, 50); - TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) 0, 75); - - assertTrue(ts1.compareTo(ts1, false) == 0); - - assertTrue(ts1.compareTo(ts2, false) < 0); - assertTrue(ts1.compareTo(ts3, false) < 0); - assertTrue(ts1.compareTo(ts4, false) < 0); - - assertTrue(ts2.compareTo(ts1, false) > 0); - assertTrue(ts2.compareTo(ts3, false) < 0); - assertTrue(ts2.compareTo(ts4, false) == 0); - - assertTrue(ts3.compareTo(ts1, false) > 0); - assertTrue(ts3.compareTo(ts2, false) > 0); - assertTrue(ts3.compareTo(ts4, false) > 0); - } - - @Test - public void testCompareToDifferentScale() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp(9000, (byte) -1, 50); - TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50); - TmfTimestamp ts3 = new TmfTimestamp( 110, (byte) 1, 50); - TmfTimestamp ts4 = new TmfTimestamp( 1, (byte) 3, 75); - - assertTrue(ts1.compareTo(ts1, false) == 0); - - assertTrue(ts1.compareTo(ts2, false) < 0); - assertTrue(ts1.compareTo(ts3, false) < 0); - assertTrue(ts1.compareTo(ts4, false) < 0); - - assertTrue(ts2.compareTo(ts1, false) > 0); - assertTrue(ts2.compareTo(ts3, false) < 0); - assertTrue(ts2.compareTo(ts4, false) == 0); - - assertTrue(ts3.compareTo(ts1, false) > 0); - assertTrue(ts3.compareTo(ts2, false) > 0); - assertTrue(ts3.compareTo(ts4, false) > 0); - } - - @Test - public void testCompareToWithinPrecision() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp( 900, (byte) 0, 50); - TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50); - TmfTimestamp ts3 = new TmfTimestamp(1100, (byte) 0, 50); - TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) 0, 75); - - assertTrue(ts1.compareTo(ts1, true) == 0); - - assertTrue(ts1.compareTo(ts2, true) == 0); - assertTrue(ts1.compareTo(ts3, true) < 0); - assertTrue(ts1.compareTo(ts4, true) == 0); - - assertTrue(ts2.compareTo(ts1, true) == 0); - assertTrue(ts2.compareTo(ts3, true) == 0); - assertTrue(ts2.compareTo(ts4, true) == 0); - - assertTrue(ts3.compareTo(ts1, true) > 0); - assertTrue(ts3.compareTo(ts2, true) == 0); - assertTrue(ts3.compareTo(ts4, true) == 0); - } - - @Test - public void testCompareToLargeScale() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp( -1, (byte) 100); - TmfTimestamp ts2 = new TmfTimestamp(-1000, (byte) -100); - TmfTimestamp ts3 = new TmfTimestamp( 1, (byte) 100); - TmfTimestamp ts4 = new TmfTimestamp( 1000, (byte) -100); - - assertTrue(ts1.compareTo(ts2, false) < 0); - assertTrue(ts1.compareTo(ts3, false) < 0); - assertTrue(ts1.compareTo(ts4, false) < 0); - - assertTrue(ts2.compareTo(ts1, false) > 0); - assertTrue(ts2.compareTo(ts3, false) < 0); - assertTrue(ts2.compareTo(ts4, false) < 0); - - assertTrue(ts3.compareTo(ts1, false) > 0); - assertTrue(ts3.compareTo(ts2, false) > 0); - assertTrue(ts3.compareTo(ts4, false) > 0); - - assertTrue(ts4.compareTo(ts1, false) > 0); - assertTrue(ts4.compareTo(ts2, false) > 0); - assertTrue(ts4.compareTo(ts3, false) < 0); - } - - @Test - public void testCompareToBigGuys() throws Exception { - TmfTimestamp ts1 = new TmfTimestamp(-1, Byte.MAX_VALUE); - TmfTimestamp ts2 = new TmfTimestamp(-1, Byte.MIN_VALUE); - TmfTimestamp ts3 = new TmfTimestamp( 1, Byte.MAX_VALUE); - TmfTimestamp ts4 = new TmfTimestamp( 1, Byte.MIN_VALUE); - - assertTrue(ts1.compareTo(TmfTimestamp.BigBang, false) > 0); - assertTrue(ts1.compareTo(TmfTimestamp.BigCrunch, false) < 0); - - assertTrue(ts2.compareTo(TmfTimestamp.BigBang, false) > 0); - assertTrue(ts2.compareTo(TmfTimestamp.BigCrunch, false) < 0); - - assertTrue(ts3.compareTo(TmfTimestamp.BigBang, false) > 0); - assertTrue(ts3.compareTo(TmfTimestamp.BigCrunch, false) < 0); - - assertTrue(ts4.compareTo(TmfTimestamp.BigBang, false) > 0); - assertTrue(ts4.compareTo(TmfTimestamp.BigCrunch, false) < 0); - } +public class TmfTimestampTest extends TestCase { + + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfTimestampTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ======================================================================== + // Constructors + // ======================================================================== + + public void testDefaultConstructor() throws Exception { + TmfTimestamp ts = new TmfTimestamp(); + assertEquals("getValue", 0, ts.getValue()); + assertEquals("getscale", 0, ts.getScale()); + assertEquals("getPrecision", 0, ts.getPrecision()); + } + + public void testSimpleConstructor() throws Exception { + TmfTimestamp ts = new TmfTimestamp(12345); + assertEquals("getValue", 12345, ts.getValue()); + assertEquals("getscale", 0, ts.getScale()); + assertEquals("getPrecision", 0, ts.getPrecision()); + } + + public void testSimpleConstructor2() throws Exception { + TmfTimestamp ts = new TmfTimestamp(12345, (byte) -1); + assertEquals("getValue", 12345, ts.getValue()); + assertEquals("getscale", -1, ts.getScale()); + assertEquals("getPrecision", 0, ts.getPrecision()); + } + + public void testFullConstructor() throws Exception { + TmfTimestamp ts = new TmfTimestamp(12345, (byte) 2, 5); + assertEquals("getValue", 12345, ts.getValue()); + assertEquals("getscale", 2, ts.getScale()); + assertEquals("getPrecision", 5, ts.getPrecision()); + } + + public void testCopyConstructor() throws Exception { + TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) 2, 5); + TmfTimestamp ts = new TmfTimestamp(ts0); + assertEquals("getValue", 12345, ts.getValue()); + assertEquals("getscale", 2, ts.getScale()); + assertEquals("getPrecision", 5, ts.getPrecision()); + } + + // ======================================================================== + // BigBang, BigCrunch + // ======================================================================== + + public void testCopyConstructorBigBang() throws Exception { + TmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BigBang); + assertEquals("getValue", TmfTimestamp.BigBang.getValue(), ts.getValue()); + assertEquals("getscale", TmfTimestamp.BigBang.getScale(), ts.getScale()); + assertEquals("getPrecision", TmfTimestamp.BigBang.getPrecision(), ts.getPrecision()); + } + + public void testCopyConstructorBigCrunch() throws Exception { + TmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BigCrunch); + assertEquals("getValue", TmfTimestamp.BigCrunch.getValue(), ts.getValue()); + assertEquals("getscale", TmfTimestamp.BigCrunch.getScale(), ts.getScale()); + assertEquals("getPrecision", TmfTimestamp.BigCrunch.getPrecision(), ts.getPrecision()); + } + + // ======================================================================== + // toString + // ======================================================================== + + public void testToString() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(); + TmfTimestamp ts2 = new TmfTimestamp(1234, (byte) 2); + TmfTimestamp ts3 = new TmfTimestamp(1234, (byte) 2, 1); + TmfTimestamp ts4 = new TmfTimestamp(-1234, (byte) -1, 4); + + assertEquals("toString", "[TmfTimestamp(0,0,0)]", ts1.toString()); + assertEquals("toString", "[TmfTimestamp(1234,2,0)]", ts2.toString()); + assertEquals("toString", "[TmfTimestamp(1234,2,1)]", ts3.toString()); + assertEquals("toString", "[TmfTimestamp(-1234,-1,4)]", ts4.toString()); + } + + // ======================================================================== + // synchronize + // ======================================================================== + + public void testSynchronizeOffset() throws Exception { + TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 1); + TmfTimestamp ts = new TmfTimestamp(); + + ts = ts0.synchronize(0, (byte) 0); + assertEquals("getValue", 1234, ts.getValue()); + assertEquals("getscale", 0, ts.getScale()); + assertEquals("getPrecision", 1, ts.getPrecision()); + + ts = ts0.synchronize(10, (byte) 0); + assertEquals("getValue", 1244, ts.getValue()); + assertEquals("getscale", 0, ts.getScale()); + assertEquals("getPrecision", 1, ts.getPrecision()); + + ts = ts0.synchronize(-10, (byte) 0); + assertEquals("getValue", 1224, ts.getValue()); + assertEquals("getscale", 0, ts.getScale()); + assertEquals("getPrecision", 1, ts.getPrecision()); + } + + public void testSynchronizeScale() throws Exception { + TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 12); + TmfTimestamp ts = new TmfTimestamp(); + + ts = ts0.synchronize(0, (byte) 0); + assertEquals("getValue", 1234, ts.getValue()); + assertEquals("getscale", 0, ts.getScale()); + assertEquals("getPrecision", 12, ts.getPrecision()); + + ts = ts0.synchronize(0, (byte) 1); + assertEquals("getValue", 123, ts.getValue()); + assertEquals("getscale", 1, ts.getScale()); + assertEquals("getPrecision", 1, ts.getPrecision()); + + ts = ts0.synchronize(0, (byte) 2); + assertEquals("getValue", 12, ts.getValue()); + assertEquals("getscale", 2, ts.getScale()); + assertEquals("getPrecision", 0, ts.getPrecision()); + + ts = ts0.synchronize(0, (byte) 4); + assertEquals("getValue", 0, ts.getValue()); + assertEquals("getscale", 4, ts.getScale()); + assertEquals("getPrecision", 0, ts.getPrecision()); + + ts = ts0.synchronize(0, (byte) -2); + assertEquals("getValue", 123400, ts.getValue()); + assertEquals("getscale", -2, ts.getScale()); + assertEquals("getPrecision", 1200, ts.getPrecision()); + } + + public void testSynchronizeOffsetAndScale() throws Exception { + TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 12); + TmfTimestamp ts = new TmfTimestamp(); + + ts = ts0.synchronize(10, (byte) 1); + assertEquals("getValue", 133, ts.getValue()); + assertEquals("getscale", 1, ts.getScale()); + assertEquals("getPrecision", 1, ts.getPrecision()); + + ts = ts0.synchronize(-10, (byte) -1); + assertEquals("getValue", 12330, ts.getValue()); + assertEquals("getscale", -1, ts.getScale()); + assertEquals("getPrecision", 120, ts.getPrecision()); + } + + // ======================================================================== + // getAdjustment + // ======================================================================== + + public void testGetAdjustmentSameScale() throws Exception { + TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) -2); + TmfTimestamp ts = new TmfTimestamp(10000, (byte) -2); + + long delta = ts.getAdjustment(ts0); + assertEquals("delta", 2345, delta); + } + + public void testGetAdjustmentDifferentScale() throws Exception { + TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) -2); + TmfTimestamp ts = new TmfTimestamp(1, (byte) 2); + + long delta = ts.getAdjustment(ts0); + assertEquals("delta", 2345, delta); + + delta = ts0.getAdjustment(ts); + assertEquals("delta", 0, delta); + } + + // ======================================================================== + // CompareTo + // ======================================================================== + + public void testCompareToSameScale() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(900, (byte) 0, 50); + TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50); + TmfTimestamp ts3 = new TmfTimestamp(1100, (byte) 0, 50); + TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) 0, 75); + + assertTrue(ts1.compareTo(ts1, false) == 0); + + assertTrue(ts1.compareTo(ts2, false) < 0); + assertTrue(ts1.compareTo(ts3, false) < 0); + assertTrue(ts1.compareTo(ts4, false) < 0); + + assertTrue(ts2.compareTo(ts1, false) > 0); + assertTrue(ts2.compareTo(ts3, false) < 0); + assertTrue(ts2.compareTo(ts4, false) == 0); + + assertTrue(ts3.compareTo(ts1, false) > 0); + assertTrue(ts3.compareTo(ts2, false) > 0); + assertTrue(ts3.compareTo(ts4, false) > 0); + } + + public void testCompareToDifferentScale() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(9000, (byte) -1, 50); + TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50); + TmfTimestamp ts3 = new TmfTimestamp(110, (byte) 1, 50); + TmfTimestamp ts4 = new TmfTimestamp(1, (byte) 3, 75); + + assertTrue(ts1.compareTo(ts1, false) == 0); + + assertTrue(ts1.compareTo(ts2, false) < 0); + assertTrue(ts1.compareTo(ts3, false) < 0); + assertTrue(ts1.compareTo(ts4, false) < 0); + + assertTrue(ts2.compareTo(ts1, false) > 0); + assertTrue(ts2.compareTo(ts3, false) < 0); + assertTrue(ts2.compareTo(ts4, false) == 0); + + assertTrue(ts3.compareTo(ts1, false) > 0); + assertTrue(ts3.compareTo(ts2, false) > 0); + assertTrue(ts3.compareTo(ts4, false) > 0); + } + + public void testCompareToWithinPrecision() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(900, (byte) 0, 50); + TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50); + TmfTimestamp ts3 = new TmfTimestamp(1100, (byte) 0, 50); + TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) 0, 75); + + assertTrue(ts1.compareTo(ts1, true) == 0); + + assertTrue(ts1.compareTo(ts2, true) == 0); + assertTrue(ts1.compareTo(ts3, true) < 0); + assertTrue(ts1.compareTo(ts4, true) == 0); + + assertTrue(ts2.compareTo(ts1, true) == 0); + assertTrue(ts2.compareTo(ts3, true) == 0); + assertTrue(ts2.compareTo(ts4, true) == 0); + + assertTrue(ts3.compareTo(ts1, true) > 0); + assertTrue(ts3.compareTo(ts2, true) == 0); + assertTrue(ts3.compareTo(ts4, true) == 0); + } + + public void testCompareToLargeScale() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(-1, (byte) 100); + TmfTimestamp ts2 = new TmfTimestamp(-1000, (byte) -100); + TmfTimestamp ts3 = new TmfTimestamp(1, (byte) 100); + TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) -100); + + assertTrue(ts1.compareTo(ts2, false) < 0); + assertTrue(ts1.compareTo(ts3, false) < 0); + assertTrue(ts1.compareTo(ts4, false) < 0); + + assertTrue(ts2.compareTo(ts1, false) > 0); + assertTrue(ts2.compareTo(ts3, false) < 0); + assertTrue(ts2.compareTo(ts4, false) < 0); + + assertTrue(ts3.compareTo(ts1, false) > 0); + assertTrue(ts3.compareTo(ts2, false) > 0); + assertTrue(ts3.compareTo(ts4, false) > 0); + + assertTrue(ts4.compareTo(ts1, false) > 0); + assertTrue(ts4.compareTo(ts2, false) > 0); + assertTrue(ts4.compareTo(ts3, false) < 0); + } + + public void testCompareToBigGuys() throws Exception { + TmfTimestamp ts1 = new TmfTimestamp(-1, Byte.MAX_VALUE); + TmfTimestamp ts2 = new TmfTimestamp(-1, Byte.MIN_VALUE); + TmfTimestamp ts3 = new TmfTimestamp(1, Byte.MAX_VALUE); + TmfTimestamp ts4 = new TmfTimestamp(1, Byte.MIN_VALUE); + + assertTrue(ts1.compareTo(TmfTimestamp.BigBang, false) > 0); + assertTrue(ts1.compareTo(TmfTimestamp.BigCrunch, false) < 0); + + assertTrue(ts2.compareTo(TmfTimestamp.BigBang, false) > 0); + assertTrue(ts2.compareTo(TmfTimestamp.BigCrunch, false) < 0); + + assertTrue(ts3.compareTo(TmfTimestamp.BigBang, false) > 0); + assertTrue(ts3.compareTo(TmfTimestamp.BigCrunch, false) < 0); + + assertTrue(ts4.compareTo(TmfTimestamp.BigBang, false) > 0); + assertTrue(ts4.compareTo(TmfTimestamp.BigCrunch, false) < 0); + } } diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTraceEventTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTraceEventTest.java index dee1fba659..3d48563bc4 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTraceEventTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/event/TmfTraceEventTest.java @@ -12,63 +12,102 @@ package org.eclipse.linuxtools.tmf.event; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import junit.framework.TestCase; /** * TmfTraceEventTest *

- * JUnit test suite for the TmfTraceEvent class. + * TODO: Implement me. Please. */ -public class TmfTraceEventTest { +public class TmfTraceEventTest extends TestCase { + + private final String fTypeId = "Some type"; + private final String fLabel0 = "label1"; + private final String fLabel1 = "label2"; + private final String[] fLabels = new String[] { fLabel0, fLabel1 }; + + private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5); + private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2, 5); + private final TmfEventSource fSource = new TmfEventSource("Source"); + private final TmfEventType fType = new TmfEventType(fTypeId, fLabels); + private final TmfEventReference fReference = new TmfEventReference("Some reference"); + + private final TmfTraceEvent fEvent1; + private final TmfTraceEvent fEvent2; + + private final TmfEventContent fContent1; + private final TmfEventContent fContent2; + + private final String fPath = "/some/path/"; + private final String fFile = "filename"; + private final int fLine = 10; + + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfTraceEventTest(String name) { + super(name); + + fEvent1 = new TmfTraceEvent(fTimestamp1, fSource, fType, fReference, fPath, fFile, fLine); + fContent1 = new TmfEventContent(fEvent1, "Some content"); + fEvent1.setContent(fContent1); - // ======================================================================== - // Constructor - // ======================================================================== + fEvent2 = new TmfTraceEvent(fTimestamp1, fTimestamp2, fSource, fType, fReference, fPath, fFile, fLine); + fContent2 = new TmfEventContent(fEvent2, "Some other content"); + fEvent2.setContent(fContent2); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ======================================================================== + // Constructors + // ======================================================================== - @Test public void testTmfTraceEvent() throws Exception { - TmfTimestamp timestamp = new TmfTimestamp(12345, (byte) 2, 5); - TmfEventSource source = new TmfEventSource("Source"); - TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2" }); - TmfEventType type = new TmfEventType("Type", format); - TmfEventContent content = new TmfEventContent("Some content", format); - TmfEventReference reference = new TmfEventReference("Reference"); - - // Create the trace event - TmfTraceEvent event = - new TmfTraceEvent(timestamp, source, type, content, reference, "path", "filename", 10); - - // Check the event timestamp - TmfTimestamp evTS = event.getTimestamp(); - assertEquals("getValue", 12345, evTS.getValue()); - assertEquals("getscale", 2, evTS.getScale()); - assertEquals("getPrecision", 5, evTS.getPrecision()); - - // Check the event source - TmfEventSource evSrc = event.getSource(); - assertEquals("getValue", "Source", evSrc.getSourceId()); - - // Check the event type - TmfEventType evType = event.getType(); - assertEquals("getValue", "Type", evType.getTypeId()); - assertEquals("getFormat", "field1", evType.getFormat().getLabels()[0]); - assertEquals("getFormat", "field2", evType.getFormat().getLabels()[1]); - - // Check the event content - TmfEventContent evContent = event.getContent(); - assertEquals("getField", 1, evContent.getFields().length); - assertEquals("getField", "Some content", evContent.getField(0).toString()); - - // Check the event reference - TmfEventReference evRef = event.getReference(); - assertEquals("getValue", "Reference", evRef.getValue()); - - // Check the event file reference - assertEquals("getPath", "path", event.getSourcePath()); - assertEquals("getFile", "filename", event.getFileName()); - assertEquals("getLineNumber", 10, event.getLineNumber()); + assertEquals("getTimestamp", fTimestamp1, fEvent1.getTimestamp()); + assertEquals("getOriginalTimestamp", fTimestamp1, fEvent1.getOriginalTimestamp()); + assertEquals("getSource", fSource, fEvent1.getSource()); + assertEquals("getType", fType, fEvent1.getType()); + assertEquals("getContent", fContent1, fEvent1.getContent()); + assertEquals("getReference", fReference, fEvent1.getReference()); + assertEquals("getSourcePath", fPath, fEvent1.getSourcePath()); + assertEquals("getFileName", fFile, fEvent1.getFileName()); + assertEquals("getLineNumber", fLine, fEvent1.getLineNumber()); + } + + public void testTmfTraceEvent2() throws Exception { + assertEquals("getTimestamp", fTimestamp2, fEvent2.getTimestamp()); + assertEquals("getOriginalTimestamp", fTimestamp1, fEvent2.getOriginalTimestamp()); + assertEquals("getSource", fSource, fEvent2.getSource()); + assertEquals("getType", fType, fEvent2.getType()); + assertEquals("getContent", fContent2, fEvent2.getContent()); + assertEquals("getReference", fReference, fEvent2.getReference()); + assertEquals("getSourcePath", fPath, fEvent2.getSourcePath()); + assertEquals("getFileName", fFile, fEvent2.getFileName()); + assertEquals("getLineNumber", fLine, fEvent2.getLineNumber()); + } + + public void testTmfTraceEventCopy() throws Exception { + TmfTraceEvent event = new TmfTraceEvent(fEvent2); + assertEquals("getTimestamp", fTimestamp2, event.getTimestamp()); + assertEquals("getOriginalTimestamp", fTimestamp1, event.getOriginalTimestamp()); + assertEquals("getSource", fSource, event.getSource()); + assertEquals("getType", fType, event.getType()); + assertEquals("getContent", fContent2, event.getContent()); + assertEquals("getReference", fReference, event.getReference()); + assertEquals("getSourcePath", fPath, event.getSourcePath()); + assertEquals("getFileName", fFile, event.getFileName()); + assertEquals("getLineNumber", fLine, event.getLineNumber()); } } + diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/AllRequestTests.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/AllRequestTests.java deleted file mode 100644 index 1769cd114d..0000000000 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/AllRequestTests.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * 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 { - -} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/AllTests.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/AllTests.java new file mode 100644 index 0000000000..c8980857e0 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/AllTests.java @@ -0,0 +1,16 @@ +package org.eclipse.linuxtools.tmf.request; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite(AllTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(TmfDataRequestTest.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/TmfDataRequestTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/TmfDataRequestTest.java index bbdcdc40b7..eb11231d09 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/TmfDataRequestTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/TmfDataRequestTest.java @@ -12,239 +12,90 @@ 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 junit.framework.TestCase; 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; /** * TmfDataRequestTest *

* TODO: Implement me. Please. */ -public class TmfDataRequestTest { +public class TmfDataRequestTest extends TestCase { - private static ITmfRequestHandler fProcessor = null; + // ======================================================================== + // Housekeeping + // ======================================================================== - @BeforeClass - public static void setUpBeforeClass() throws Exception { - fProcessor = new TmfRequestHandlerStub(); - } + public TmfDataRequestTest(String name) { + super(name); + } - // ======================================================================== - // Constructor - // ======================================================================== + @Override + protected void setUp() throws Exception { + super.setUp(); + } - @Test - public void testConstructorForRange() throws Exception { - TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - TmfDataRequest request = new TmfDataRequest(range, 0, -1, 1); + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } - assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime()); - assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime()); - assertEquals("Offset", 0, request.getOffset()); - assertEquals("NbRequestedEvents", -1, request.getNbRequestedItems()); - } + // ======================================================================== + // Constructors + // ======================================================================== - @Test - public void testConstructorForNbEvents() throws Exception { - TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - TmfDataRequest request = new TmfDataRequest(range, 0, 10, 1); + public void testTmfDataRequestIndexNbEvents() { + TmfDataRequest request = new TmfDataRequest(10, 100); - assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime()); - assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime()); - assertEquals("Offset", 0, request.getOffset()); - assertEquals("NbRequestedEvents", 10, request.getNbRequestedItems()); - } + assertEquals("getRange", null, request.getRange()); + assertEquals("getIndex", 10, request.getIndex()); + assertEquals("getNbRequestedEvents", 100, request.getNbRequestedEvents()); + assertEquals("getBlockize", TmfDataRequest.DEFAULT_BLOCK_SIZE, request.getBlockize()); + } - @Test - public void testConstructorWithOffset() throws Exception { - TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - TmfDataRequest request = new TmfDataRequest(range, 5, 10, 1); + public void testTmfDataRequestIndexNbEventsBlocksize() { + TmfDataRequest request = new TmfDataRequest(10, 100, 200); - assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime()); - assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime()); - assertEquals("Offset", 5, request.getOffset()); - assertEquals("NbRequestedEvents", 10, request.getNbRequestedItems()); - } + assertEquals("getRange", null, request.getRange()); + assertEquals("getIndex", 10, request.getIndex()); + assertEquals("getNbRequestedEvents", 100, request.getNbRequestedEvents()); + assertEquals("getBlockize", 200, request.getBlockize()); + } - @Test - public void testConstructorWithNegativeOffset() throws Exception { + public void testTmfDataRequestTimeRange() { TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - TmfDataRequest request = new TmfDataRequest(range, -5, 10, 1); + TmfDataRequest request = new TmfDataRequest(range); 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 requestedEvents = new Vector(); + assertEquals("getIndex", 0, request.getIndex()); + assertEquals("getNbRequestedEvents", -1, request.getNbRequestedEvents()); + assertEquals("getBlockize", TmfDataRequest.DEFAULT_BLOCK_SIZE, request.getBlockize()); + } + public void testTmfDataRequestTimeRangeNbEvents() { TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, NB_EVENTS, BLOCK_SIZE) { - @Override - public void handleData() { - 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 requestedEvents = new Vector(); - int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS; + TmfDataRequest request = new TmfDataRequest(range, 10); - TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, NB_EVENTS, BLOCK_SIZE) { - @Override - public void handleData() { - 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 requestedEvents = new Vector(); - int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS; - - TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, OFFSET, NB_EVENTS, BLOCK_SIZE) { - @Override - public void handleData() { - 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 requestedEvents = new Vector(); - int nbExpectedEvents = TmfRequestHandlerStub.MAX_GENERATED_EVENTS; + assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime()); + assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime()); + assertEquals("getIndex", 0, request.getIndex()); + assertEquals("getNbRequestedEvents", 10, request.getNbRequestedEvents()); + assertEquals("getBlockize", TmfDataRequest.DEFAULT_BLOCK_SIZE, request.getBlockize()); + } + public void testTmfDataRequestTimeRangeNbEventsBlockSize() { TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, OFFSET, NB_EVENTS, BLOCK_SIZE) { - @Override - public void handleData() { - 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 requestedEvents = new Vector(); + TmfDataRequest request = new TmfDataRequest(range, 10, 100); - TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, NB_EVENTS, BLOCK_SIZE) { - @Override - public void handleData() { - 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()); - } + assertEquals("StartTime", TmfTimestamp.BigBang, request.getRange().getStartTime()); + assertEquals("EndTime", TmfTimestamp.BigCrunch, request.getRange().getEndTime()); + assertEquals("getIndex", 0, request.getIndex()); + assertEquals("getNbRequestedEvents", 10, request.getNbRequestedEvents()); + assertEquals("getBlockize", 100, request.getBlockize()); + } } diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/AllTests.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/AllTests.java new file mode 100644 index 0000000000..dc87e232bb --- /dev/null +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/AllTests.java @@ -0,0 +1,17 @@ +package org.eclipse.linuxtools.tmf.trace; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite(AllTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(TmfTraceTest.class); + suite.addTestSuite(TmfExperimentTest.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/AllTraceTests.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/AllTraceTests.java deleted file mode 100644 index f7bfe968a2..0000000000 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/AllTraceTests.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * 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, - TmfExperimentTest.class -}) - -public class AllTraceTests { - -} diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfExperimentTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfExperimentTest.java index cbb5ca18b2..0c3f89918e 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfExperimentTest.java @@ -12,10 +12,6 @@ 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; @@ -23,15 +19,15 @@ 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.junit.BeforeClass; -import org.junit.Test; + +import junit.framework.TestCase; /** - * TmfEventLogTest + * TmfExperimentTest *

* TODO: Implement me. Please. */ -public class TmfExperimentTest { +public class TmfExperimentTest extends TestCase { private static final String DIRECTORY = "testfiles"; private static final String TEST_STREAM = "M-Test-10K"; @@ -43,8 +39,12 @@ public class TmfExperimentTest { private static ITmfTrace fStream; private static TmfExperiment fExperiment; - @BeforeClass - public static void setUpBeforeClass() throws Exception { + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfExperimentTest(String name) throws Exception { + super(name); String directory = new File(".").getCanonicalPath() + File.separator + DIRECTORY; testfile = directory + File.separator + TEST_STREAM; @@ -52,11 +52,20 @@ public class TmfExperimentTest { fExperiment = new TmfExperiment(EXPERIMENT, new ITmfTrace[] { fStream }, true); } + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + // ======================================================================== // Constructor // ======================================================================== - @Test public void testBasicTmfTrace() { assertEquals("GetId", EXPERIMENT, fExperiment.getExperimentId()); assertEquals("GetEpoch", TmfTimestamp.BigBang, fExperiment.getEpoch()); @@ -71,14 +80,13 @@ public class TmfExperimentTest { // processRequest // ======================================================================== - @Test public void testProcessRequestForNbEvents() throws Exception { final int blockSize = 100; final int nbEvents = 1000; final Vector requestedEvents = new Vector(); TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, nbEvents, blockSize) { + final TmfDataRequest request = new TmfDataRequest(range, nbEvents, blockSize) { @Override public void handleData() { TmfEvent[] events = getData(); @@ -100,14 +108,13 @@ public class TmfExperimentTest { } } - @Test public void testProcessRequestForNbEvents2() throws Exception { final int blockSize = 2 * NB_EVENTS; final int nbEvents = 1000; final Vector requestedEvents = new Vector(); TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, nbEvents, blockSize) { + final TmfDataRequest request = new TmfDataRequest(range, nbEvents, blockSize) { @Override public void handleData() { TmfEvent[] events = getData(); @@ -129,7 +136,6 @@ public class TmfExperimentTest { } } - @Test public void testProcessRequestForAllEvents() throws Exception { final int nbEvents = -1; final int blockSize = 1; @@ -137,7 +143,7 @@ public class TmfExperimentTest { int nbExpectedEvents = fExperiment.getNbEvents(); TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, nbEvents, blockSize) { + final TmfDataRequest request = new TmfDataRequest(range, nbEvents, blockSize) { @Override public void handleData() { TmfEvent[] events = getData(); @@ -163,14 +169,13 @@ public class TmfExperimentTest { // cancel // ======================================================================== - @Test public void testCancel() throws Exception { final int nbEvents = NB_EVENTS; final int blockSize = fDefaultBlockSize; final Vector requestedEvents = new Vector(); TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, nbEvents, blockSize) { + final TmfDataRequest request = new TmfDataRequest(range, nbEvents, blockSize) { @Override public void handleData() { TmfEvent[] events = getData(); @@ -187,5 +192,4 @@ public class TmfExperimentTest { assertTrue("isCompleted", request.isCompleted()); assertTrue("isCancelled", request.isCancelled()); } - } diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java index 421c6b6152..b1f20f46b5 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java @@ -12,10 +12,6 @@ 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; @@ -23,15 +19,15 @@ 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.junit.BeforeClass; -import org.junit.Test; + +import junit.framework.TestCase; /** - * TmfEventStreamTest + * TmfTraceTest *

* TODO: Implement me. Please. */ -public class TmfTraceTest { +public class TmfTraceTest extends TestCase { private static final String DIRECTORY = "testfiles"; private static final String TEST_STREAM = "M-Test-10K"; @@ -41,43 +37,51 @@ public class TmfTraceTest { private static byte SCALE = (byte) -3; - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { + // ======================================================================== + // Housekeeping + // ======================================================================== + + public TmfTraceTest(String name) throws Exception { + super(name); String directory = new File(".").getCanonicalPath() + File.separator + DIRECTORY; testfile = directory + File.separator + TEST_STREAM; fTrace = new TmfTraceStub(testfile, 500, true); - } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } // ======================================================================== - // Constructor + // Constructors // ======================================================================== - @Test - public void testDefaultConstructor() throws Exception { + public void testTmfTraceDefault() throws Exception { TmfTraceStub trace = new TmfTraceStub(testfile, true); assertEquals("getCacheSize", TmfTraceStub.DEFAULT_CACHE_SIZE, trace.getCacheSize()); - assertEquals("getTraceSize", NB_EVENTS, trace.getNbEvents()); - assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); - assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); + assertEquals("getTraceSize", 0, trace.getNbEvents()); + assertEquals("getRange-start", 0, trace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", 0, trace.getTimeRange().getEndTime().getValue()); } - @Test - public void testNormalConstructor() throws Exception { - assertEquals("getCacheSize", 500, fTrace.getCacheSize()); - assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents()); - assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); - assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); + public void testTmfTrace() throws Exception { + assertEquals("getCacheSize", 500, fTrace.getCacheSize()); + assertEquals("getTraceSize", 0, fTrace.getNbEvents()); + assertEquals("getRange-start", 0, fTrace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", 0, fTrace.getTimeRange().getEndTime().getValue()); } // ======================================================================== // seek // ======================================================================== - @Test public void testSeekOnCacheBoundary() throws Exception { TmfTraceContext context = fTrace.seekLocation(null); @@ -94,7 +98,6 @@ public class TmfTraceTest { assertEquals("Event timestamp", 4000, event.getTimestamp().getValue()); } - @Test public void testSeekNotOnCacheBoundary() throws Exception { TmfTraceContext context = fTrace.seekLocation(null); @@ -111,7 +114,6 @@ public class TmfTraceTest { assertEquals("Event timestamp", 4499, event.getTimestamp().getValue()); } - @Test public void testSeekForEventOutOfBounds() throws Exception { TmfTraceContext context = fTrace.seekLocation(null); @@ -130,7 +132,6 @@ public class TmfTraceTest { // getNextEvent // ======================================================================== - @Test public void testGetNextEvent() throws Exception { TmfTraceContext context = fTrace.seekLocation(null); @@ -149,14 +150,13 @@ public class TmfTraceTest { // processRequest // ======================================================================== - @Test public void testProcessRequestForNbEvents() throws Exception { final int BLOCK_SIZE = 100; final int NB_EVENTS = 1000; final Vector requestedEvents = new Vector(); TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, NB_EVENTS, BLOCK_SIZE) { + final TmfDataRequest request = new TmfDataRequest(range, NB_EVENTS, BLOCK_SIZE) { @Override public void handleData() { TmfEvent[] events = getData(); @@ -178,15 +178,13 @@ public class TmfTraceTest { } } - @Test public void testProcessRequestForAllEvents() throws Exception { - final int NB_EVENTS = -1; final int BLOCK_SIZE = 1; final Vector requestedEvents = new Vector(); - long nbExpectedEvents = fTrace.getNbEvents(); + long nbExpectedEvents = NB_EVENTS; TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, NB_EVENTS, BLOCK_SIZE) { + final TmfDataRequest request = new TmfDataRequest(range, NB_EVENTS, BLOCK_SIZE) { @Override public void handleData() { TmfEvent[] events = getData(); @@ -197,13 +195,13 @@ public class TmfTraceTest { }; fTrace.processRequest(request, true); - assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size()); + 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 < nbExpectedEvents; i++) { + for (int i = 0; i < NB_EVENTS; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); } } @@ -212,12 +210,11 @@ public class TmfTraceTest { // cancel // ======================================================================== - @Test public void testCancel() throws Exception { final Vector requestedEvents = new Vector(); TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); - final TmfDataRequest request = new TmfDataRequest(range, 0, NB_EVENTS, NB_EVENTS) { + final TmfDataRequest request = new TmfDataRequest(range, NB_EVENTS, NB_EVENTS) { @Override public void handleData() { TmfEvent[] events = getData(); @@ -234,5 +231,4 @@ public class TmfTraceTest { assertTrue("isCompleted", request.isCompleted()); assertTrue("isCancelled", request.isCancelled()); } - } diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/CreateTestFiles.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/CreateTestFiles.java index 9e91fc6f42..db6ea3a09b 100644 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/CreateTestFiles.java +++ b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/CreateTestFiles.java @@ -39,8 +39,8 @@ public class CreateTestFiles { // ======================================================================== private static final String DIRECTORY = "testfiles"; - 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 String FILE_NAMES[] = { "Test-10", "Test-1K", "Test-10K", "Test-100K" }; + private static final int FILE_SIZES[] = { 10 , 1000 , 10000 , 100000 }; private static final int NB_SOURCES = 15; private static final int NB_TYPES = 7; diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java index 91dc38af1c..b56485bbc6 100644 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java +++ b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java @@ -45,15 +45,15 @@ public class TmfEventContentStub extends TmfEventContent { return content; } -// @Override -// public String toString() { -// Object[] fields = getFields(); -// StringBuilder result = new StringBuilder("[TmfEventContent("); -// for (int i = 0; i < fields.length; i++) { -// if (i > 0) result.append(","); -// result.append(fields[i]); -// } -// result.append(")]"); -// return result.toString(); -// } + @Override + public String toString() { + Object[] fields = getFields(); + String result = "[TmfEventContentStub("; + for (int i = 0; i < fields.length; i++) { + result += fields[i].toString() + ","; + } + result += ")]"; + + return result; + } } diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventFormatStub.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventFormatStub.java deleted file mode 100644 index e144343ac2..0000000000 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventFormatStub.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * 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.event; - -/** - * TmfEventFormatStub - *

- * TODO: Implement me. Please. - */ -public class TmfEventFormatStub extends TmfEventFormat { - - // ======================================================================== - // Attributes - // ======================================================================== - - // ======================================================================== - // Constructors - // ======================================================================== - - public TmfEventFormatStub() { - super(new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" }); - } - - // ======================================================================== - // Accessors - // ======================================================================== - - // ======================================================================== - // Operators - // ======================================================================== - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.event.TmfEventFormat#parse(java.lang.Object) - */ - @Override - public TmfEventField[] parse(Object content) { - TmfEventField field1 = new TmfEventField(1); - TmfEventField field2 = new TmfEventField(-10); - TmfEventField field3 = new TmfEventField(true); - TmfEventField field4 = new TmfEventField("some string"); - TmfEventField field5 = new TmfEventField(new TmfTimestamp(1, (byte) 2, 3)); - return new TmfEventField[] { field1, field2, field3, field4, field5 }; - } - - // ======================================================================== - // Helper functions - // ======================================================================== - -} diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java index 281c93fa49..2d56c1fae9 100644 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java +++ b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java @@ -54,7 +54,7 @@ public class TmfRequestHandlerStub implements ITmfRequestHandler { TmfTimestamp endTime = request.getRange().getEndTime(); int blockSize = request.getBlockize(); - int nbRequestedEvents = request.getNbRequestedItems(); + int nbRequestedEvents = request.getNbRequestedEvents(); if (nbRequestedEvents <= 0) { nbRequestedEvents = MAX_GENERATED_EVENTS; } diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java index 1b739ca466..0196766d3f 100644 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java +++ b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java @@ -19,7 +19,6 @@ import java.util.Vector; 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; @@ -36,22 +35,22 @@ public class TmfEventParserStub implements ITmfEventParser { // Attributes // ======================================================================== - private final int NB_FORMATS = 10; - private final TmfEventFormat[] fFormats; + private final int NB_TYPES = 10; + private final TmfEventType[] fTypes; // ======================================================================== // Constructors // ======================================================================== public TmfEventParserStub() { - fFormats = new TmfEventFormat[NB_FORMATS]; - for (int i = 0; i < NB_FORMATS; i++) { + fTypes = new TmfEventType[NB_TYPES]; + for (int i = 0; i < NB_TYPES; i++) { Vector format = new Vector(); for (int j = 1; j <= i; j++) { format.add(new String("Fmt-" + i + "-Fld-" + j)); } String[] fields = new String[i]; - fFormats[i] = new TmfEventFormat(format.toArray(fields)); + fTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields)); } } @@ -59,9 +58,6 @@ public class TmfEventParserStub implements ITmfEventParser { // Operators // ======================================================================== - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent() - */ static final String typePrefix = "Type-"; public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfTraceContext context) throws IOException { @@ -108,10 +104,11 @@ public class TmfEventParserStub implements ITmfEventParser { TmfEvent event = new TmfEvent( new TmfTimestamp(ts, (byte) -3, 0), // millisecs new TmfEventSource(source), - new TmfEventType(type, fFormats[typeIndex]), - new TmfEventContent(content, fFormats[typeIndex]), + fTypes[typeIndex], new TmfEventReference(name)); - return event; + TmfEventContent cnt = new TmfEventContent(event, content); + event.setContent(cnt); + return event; } catch (EOFException e) { } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java index 6767043666..62ba8f598a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java @@ -141,17 +141,36 @@ public class TmfEventsView extends TmfView { item.setText(extractItemFields(cache[index - cacheStartIndex])); return; } - TmfDataRequest request = new TmfDataRequest(index, 0, CACHE_SIZE) { + + // *** TODO *** + // This is broken! + // + // This one fails to return any result : + // TmfDataRequest request = new TmfDataRequest(fExperiment.getTimeRange(), index, 1) { + // All these will return THE SAME RESULT! + // TmfDataRequest request = new TmfDataRequest(index, 1) { + // TmfDataRequest request = new TmfDataRequest(index+10, 1) { + // TmfDataRequest request = new TmfDataRequest(null, 1) { + // + // THIS IS ONLY A TEMPORARY FIX! + + TmfDataRequest request = new TmfDataRequest(index, 1) { @Override public void handleData() { - // No need to synchronize because the request is synchronous - cache = getData(); - cacheStartIndex = index; - cacheEndIndex = index + cache.length; + TmfEvent[] tmpEvent = getData(); + if ( (tmpEvent != null) && (tmpEvent.length > 0) ) { + cache = tmpEvent; + } +// cacheStartIndex = index; +// cacheEndIndex = index + cache.length; } }; fExperiment.processRequest(request, true); - item.setText(extractItemFields(cache[0])); + + if (cache[0] != null) { + item.setText(extractItemFields(cache[0])); + } + } }); @@ -166,7 +185,7 @@ public class TmfEventsView extends TmfView { } // Events cache - temporary stuff - private final int CACHE_SIZE = 100; + private final int CACHE_SIZE = 1; private TmfEvent[] cache; private int cacheStartIndex = 0; private int cacheEndIndex = 0; @@ -214,8 +233,8 @@ public class TmfEventsView extends TmfView { new Long(event.getTimestamp().getValue()).toString(), event.getSource().getSourceId().toString(), event.getType().getTypeId().toString(), - event.getReference().getValue().toString(), - event.getContent().getContent() + event.getReference().getReference().toString(), + event.getContent().toString() }; } return fields; @@ -249,7 +268,7 @@ public class TmfEventsView extends TmfView { // Perform the updates on the UI thread fTable.getDisplay().asyncExec(new Runnable() { public void run() { - // TODO: Potentially long operation. Add some feedback for the user +// // TODO: Potentially long operation. Add some feedback for the user fTable.setSelection(0); fTable.clearAll(); fTable.setItemCount(fExperiment.getNbEvents()); @@ -292,4 +311,4 @@ public class TmfEventsView extends TmfView { } } -} \ No newline at end of file +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/ITmfContentParser.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/ITmfContentParser.java deleted file mode 100644 index 0128da4b9d..0000000000 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/ITmfContentParser.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * 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.event; - -/** - * ITmfContentParser - *

- * Event content parser. - */ -public interface ITmfContentParser { - - public TmfEventField[] parse(Object content); -} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEvent.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEvent.java index 51143ee220..934d42e642 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEvent.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEvent.java @@ -25,61 +25,76 @@ package org.eclipse.linuxtools.tmf.event; * For convenience, a free-form reference field is also provided. It could be * used as e.g. a location marker in the event stream to distinguish between * otherwise identical events. + * + * Notice that for performance reasons TmfEvent is NOT immutable. If a copy + * of the event is needed, use clone(). */ -public class TmfEvent extends TmfData { +public class TmfEvent extends TmfData implements Cloneable { // ======================================================================== // Attributes // ======================================================================== - private final TmfTimestamp fEffectiveTimestamp; - private final TmfTimestamp fOriginalTimestamp; - private final TmfEventSource fSource; - private final TmfEventType fType; - private final TmfEventContent fContent; - private final TmfEventReference fReference; + protected TmfTimestamp fEffectiveTimestamp; + protected TmfTimestamp fOriginalTimestamp; + protected TmfEventSource fSource; + protected TmfEventType fType; + protected TmfEventReference fReference; - // ======================================================================== + // Content requires a reference to the parent event so it is initialized + // using setContent() + protected TmfEventContent fContent; + + // ======================================================================== // Constructors // ======================================================================== /** - * @param timestamp + * @param originalTS + * @param effectiveTS * @param source * @param type - * @param content * @param reference */ - public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS, TmfEventSource source, - TmfEventType type, TmfEventContent content, TmfEventReference reference) + public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS, + TmfEventSource source, TmfEventType type, TmfEventReference reference) { - fOriginalTimestamp = originalTS; + fOriginalTimestamp = originalTS; fEffectiveTimestamp = effectiveTS; - fSource = source; - fType = type; - fContent = content; - fReference = reference; + fSource = source; + fType = type; + fReference = reference; } /** * @param timestamp * @param source * @param type - * @param content * @param reference */ public TmfEvent(TmfTimestamp timestamp, TmfEventSource source, - TmfEventType type, TmfEventContent content, TmfEventReference reference) + TmfEventType type, TmfEventReference reference) { - this(timestamp, timestamp, source, type, content, reference); + this(timestamp, timestamp, source, type, reference); } /** + * Copy constructor (shallow) + * + * @param other */ - public TmfEvent(TmfEvent other) - { - this(other.fOriginalTimestamp, other.fEffectiveTimestamp, other.fSource, - other.fType, other.fContent, other.fReference); + public TmfEvent(TmfEvent other) { + assert(other != null); + fOriginalTimestamp = other.fOriginalTimestamp; + fEffectiveTimestamp = other.fEffectiveTimestamp; + fSource = other.fSource; + fType = other.fType; + fContent = other.fContent; + fReference = other.fReference; + } + + @SuppressWarnings("unused") + private TmfEvent() { } // ======================================================================== @@ -114,6 +129,13 @@ public class TmfEvent extends TmfData { return fType; } + /** + * @return + */ + public void setContent(TmfEventContent content) { + fContent = content; + } + /** * @return */ @@ -128,6 +150,23 @@ public class TmfEvent extends TmfData { return fReference; } + // ======================================================================== + // Operators + // ======================================================================== + + @Override + public TmfEvent clone() { + TmfEvent event = new TmfEvent( + fOriginalTimestamp.clone(), + fEffectiveTimestamp.clone(), + fSource.clone(), + fType.clone(), + fReference.clone()); + TmfEventContent content = fContent.clone(); + event.setContent(content); + return event; + } + // TODO: Design a proper format... @Override public String toString() { diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java index 2bfc446aa2..1a97c6cb52 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java @@ -12,68 +12,83 @@ package org.eclipse.linuxtools.tmf.event; + /** * TmfEventContent *

* The event content. */ -public class TmfEventContent { +public class TmfEventContent implements Cloneable { // ======================================================================== // Attributes // ======================================================================== - private final TmfEventFormat fFormat; - private final String fContent; - private final int fNbFields; - private TmfEventField[] fFields = null; + protected TmfEvent fParentEvent = null; + protected Object fRawContent = null; + protected Object[] fFields = null; // ======================================================================== // Constructors // ======================================================================== /** + * @param parent * @param content - * @param format */ - public TmfEventContent(Object content, TmfEventFormat format) { - fFormat = format; - fContent = content.toString(); - fNbFields = fFormat.getLabels().length; + public TmfEventContent(TmfEvent parent, Object content) { + fParentEvent = parent; + fRawContent = content; } + /** + * @param other + */ + public TmfEventContent(TmfEventContent other) { + assert(other != null); + fParentEvent = other.fParentEvent; + fRawContent = other.fRawContent; + fFields = other.fFields; + } + + @SuppressWarnings("unused") + private TmfEventContent() { + } + // ======================================================================== // Accessors // ======================================================================== /** - * @return + * @return the parent (containing) event */ - public String getContent() { - return fContent; + public TmfEvent getEvent() { + return fParentEvent; } /** - * @return + * @return the event type */ - public TmfEventFormat getFormat() { - return fFormat; + public TmfEventType getType() { + return fParentEvent.getType(); } - /** - * @return - */ - public int getNbFields() { - return fNbFields; - } + /** + * @return the raw content + */ + public Object getContent() { + return fRawContent; + } /** - * @return + * Returns the list of fields in the same order as TmfEventType.getLabels() + * + * @return the ordered set of fields (optional fields might be null) */ - public TmfEventField[] getFields() { - if (fFields == null) { - fFields = fFormat.parse(fContent); - } + public Object[] getFields() { + if (fFields == null) { + parseContent(); + } return fFields; } @@ -81,19 +96,56 @@ public class TmfEventContent { * @param id * @return */ - public TmfEventField getField(int id) { - assert id >= 0 && id < fNbFields; - if (fFields == null) { - fFields = fFormat.parse(fContent); - } - return fFields[id]; + public Object getField(String id) throws TmfNoSuchFieldException { + if (fFields == null) { + parseContent(); + } + return fFields[getType().getFieldIndex(id)]; } /** + * @param n * @return */ - public void setFields(TmfEventField[] fields) { - fFields = fields; + public Object getField(int n) { + if (fFields == null) { + parseContent(); + } + if (n >= 0 && n < fFields.length) + return fFields[n]; + return null; + } + + // ======================================================================== + // Operators + // ======================================================================== + + /** + * Should be overridden (all fields are null by default) + */ + protected void parseContent() { + fFields = new Object[1]; + fFields[0] = fRawContent; } + + /** + * Clone: shallow copy by default; override for deep copy. + */ + @Override + public TmfEventContent clone() { + return new TmfEventContent(this); + } + + @Override + public String toString() { + Object[] fields = getFields(); + String result = "[TmfEventContent("; + for (int i = 0; i < fields.length; i++) { + result += fields[i].toString() + ","; + } + result += ")]"; + + return result; + } } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventField.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventField.java index 085311eab0..9cbd789af3 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventField.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventField.java @@ -16,30 +16,69 @@ package org.eclipse.linuxtools.tmf.event; * TmfEventField *

* A basic event field. + * + * TODO: Add support for field hierarchy. */ -public class TmfEventField { +public class TmfEventField implements Cloneable { // ======================================================================== // Attributes // ======================================================================== - private final Object fValue; + private final TmfEventContent fParent; + private final String fFieldId; + private Object fValue; // ======================================================================== // Constructors // ======================================================================== /** + * @param parent + * @param id * @param value */ - public TmfEventField(Object value) { - fValue = value; + public TmfEventField(TmfEventContent parent, String id, Object value) { + fParent = parent; + fFieldId = id; + fValue = value; + } + + /** + * @param other + */ + public TmfEventField(TmfEventField other) { + assert(other != null); + fParent = other.fParent; + fFieldId = other.fFieldId; + fValue = other.fValue; + } + + @SuppressWarnings("unused") + private TmfEventField() { + fParent = null; + fFieldId = null; + fValue = null; } // ======================================================================== // Accessors // ======================================================================== + /** + * @return + */ + public TmfEventContent getParent() { + return fParent; + } + + /** + * @return + */ + public String getId() { + return fFieldId; + } + /** * @return */ @@ -47,16 +86,28 @@ public class TmfEventField { return fValue; } + /** + * @param value + */ + protected void setValue(Object value) { + fValue = value; + } + // ======================================================================== // Operators // ======================================================================== - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ + /** + * Clone: shallow copy by default; override for deep copy. + */ + @Override + public TmfEventField clone() { + return new TmfEventField(this); + } + @Override public String toString() { - return fValue.toString(); + return "[TmfEventField(" + fFieldId + ":" + fValue.toString() + ")]"; } -} +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventFormat.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventFormat.java deleted file mode 100644 index 6d26b20666..0000000000 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventFormat.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * 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.event; - -/** - * TmfEventFormat - *

- * The basic event content format. - */ -public class TmfEventFormat implements ITmfContentParser { - - // ======================================================================== - // Attributes - // ======================================================================== - - private final String[] fLabels; - - // ======================================================================== - // Constructors - // ======================================================================== - - /** - * - */ - public TmfEventFormat() { - this(new String[] { "Content" }); - } - - /** - * @param labels - */ - public TmfEventFormat(String[] labels) { - fLabels = labels; - } - - // ======================================================================== - // Accessors - // ======================================================================== - - /** - * @return - */ - public String[] getLabels() { - return fLabels; - } - - // ======================================================================== - // Operators - // ======================================================================== - - /** - * The default content parser: returns a single field containing the whole - * content. - * - * @param content - * @return - */ - public TmfEventField[] parse(Object content) { - return new TmfEventField[] { new TmfEventField(content.toString()) }; - } - -} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventReference.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventReference.java index e06cccc465..40a2debec8 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventReference.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventReference.java @@ -17,18 +17,25 @@ package org.eclipse.linuxtools.tmf.event; *

* An application-defined event reference. */ -public class TmfEventReference { +public class TmfEventReference implements Cloneable { // ======================================================================== // Attributes // ======================================================================== - private final Object fReference; + protected Object fReference; // ======================================================================== // Constructors // ======================================================================== + /** + * + */ + public TmfEventReference() { + this(null); + } + /** * @param reference */ @@ -36,6 +43,13 @@ public class TmfEventReference { fReference = reference; } + /** + * @param other + */ + public TmfEventReference(TmfEventReference other) { + this((other != null) ? other.fReference : null); + } + // ======================================================================== // Accessors // ======================================================================== @@ -43,7 +57,7 @@ public class TmfEventReference { /** * @return */ - public Object getValue() { + public Object getReference() { return fReference; } @@ -51,9 +65,14 @@ public class TmfEventReference { // Operators // ======================================================================== + @Override + public TmfEventReference clone() { + return new TmfEventReference(this); + } + @Override public String toString() { - return fReference.toString(); + return "[TmfEventReference(" + ((fReference != null) ? fReference.toString() : "null") + ")]"; } } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventSource.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventSource.java index d827477fbd..4d6cb2437b 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventSource.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventSource.java @@ -17,13 +17,13 @@ package org.eclipse.linuxtools.tmf.event; *

* The event source. */ -public class TmfEventSource { +public class TmfEventSource implements Cloneable { // ======================================================================== // Attributes // ======================================================================== - private final Object fSourceId; + protected Object fSourceId; // ======================================================================== // Constructors @@ -43,6 +43,13 @@ public class TmfEventSource { fSourceId = sourceId; } + /** + * @param other + */ + public TmfEventSource(TmfEventSource other) { + this((other != null) ? other.fSourceId : null); + } + // ======================================================================== // Accessors // ======================================================================== @@ -58,9 +65,14 @@ public class TmfEventSource { // Operators // ======================================================================== - @Override + @Override + public TmfEventSource clone() { + return new TmfEventSource(this); + } + + @Override public String toString() { - return fSourceId.toString(); + return "[TmfEventSource(" + ((fSourceId != null) ? fSourceId.toString() : "null") + ")]"; } } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventType.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventType.java index 56a50d103e..467910c76a 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventType.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventType.java @@ -12,31 +12,68 @@ package org.eclipse.linuxtools.tmf.event; +import java.util.HashMap; +import java.util.Map; + /** * TmfEventType *

* The event type. */ -public class TmfEventType { +public class TmfEventType implements Cloneable { + // ======================================================================== + // Constants + // ======================================================================== + + public static final String DEFAULT_TYPE_ID = "TMF Default Type"; + public static final String[] DEFAULT_LABELS = new String[] { "Content" }; + // ======================================================================== // Attributes // ======================================================================== - private final String fTypeId; - private final TmfEventFormat fFormat; + private final String fTypeId; + private final String[] fFieldLabels; + private final int fNbFields; + private final Map fFieldMap; - // ======================================================================== + // ======================================================================== // Constructors // ======================================================================== + /** + * + */ + public TmfEventType() { + this(DEFAULT_TYPE_ID, DEFAULT_LABELS); + } + /** * @param type * @param format */ - public TmfEventType(String typeID, TmfEventFormat format) { - fTypeId = typeID; - fFormat = format; + public TmfEventType(String typeId, String[] labels) { + assert(typeId != null); + assert(labels != null); + fTypeId = typeId; + fFieldLabels = labels; + fNbFields = fFieldLabels.length; + fFieldMap = new HashMap(); + for (int i = 0; i < fNbFields; i++) { + fFieldMap.put(fFieldLabels[i], i); + } + } + + /** + * @param other + */ + public TmfEventType(TmfEventType other) { + assert(other != null); + fTypeId = other.fTypeId; + fFieldLabels = other.fFieldLabels; + fNbFields = other.fNbFields; + fFieldMap = other.fFieldMap; } // ======================================================================== @@ -50,20 +87,51 @@ public class TmfEventType { return fTypeId; } - /** - * @return - */ - public TmfEventFormat getFormat() { - return fFormat; - } + /** + * @return + */ + public int getNbFields() { + return fNbFields; + } + + /** + * @return + */ + public int getFieldIndex(String id) throws TmfNoSuchFieldException { + Integer index = fFieldMap.get(id); + if (index == null) + throw(new TmfNoSuchFieldException(id)); + return index; + } + + /** + * @return + */ + public String[] getLabels() { + return fFieldLabels; + } + + /** + * @return + */ + public String getLabel(int i) { + if (i >= 0 && i < fNbFields) + return fFieldLabels[i]; + return null; + } // ======================================================================== // Operators // ======================================================================== + @Override + public TmfEventType clone() { + return new TmfEventType(this); + } + @Override public String toString() { - return fTypeId.toString(); + return "[TmfEventType:" + fTypeId + "]"; } -} +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java index 67365a58d2..5f90f796ba 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java @@ -36,6 +36,15 @@ public class TmfTimeRange { // Constructors // ======================================================================== + /** + * + */ + @SuppressWarnings("unused") + private TmfTimeRange() { + fStartTime = null; + fEndTime = null; + } + /** * @param startTime * @param endTime @@ -44,6 +53,15 @@ public class TmfTimeRange { fStartTime = startTime; fEndTime = endTime; } + + /** + * @param other + */ + public TmfTimeRange(TmfTimeRange other) { + assert(other != null); + fStartTime = other.fStartTime; + fEndTime = other.fEndTime; + } // ======================================================================== // Accessors @@ -83,7 +101,7 @@ public class TmfTimeRange { */ @Override public String toString() { - return "[TmfTimeRange (" + fStartTime.toString() + ":" + fEndTime.toString() + ")]"; + return "[TmfTimeRange(" + fStartTime.toString() + ":" + fEndTime.toString() + ")]"; } } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java index 228399cc35..cefc7a5714 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java @@ -12,7 +12,6 @@ package org.eclipse.linuxtools.tmf.event; -import java.io.Serializable; /** * TmfTimestamp @@ -27,29 +26,25 @@ import java.io.Serializable; *

  • a precision to indicate the error on the value (useful for comparing * timestamps in different scales). Default: 0. * - * To allow synchronization of timestamps from different reference clocks, there - * is a possibility to "adjust" the timestamp both by changing its scale (traces - * of different scale) and by adding an offset to its value (clock drift between - * traces). + * To allow synchronization of timestamps from different reference clocks, + * there is a possibility to "adjust" the timestamp both by changing its scale + * (traces of different scale) and by adding an offset to its value (clock + * drift between traces). *

    - * Note that the adjusted timestamp value could be negative e.g. for events that - * occurred before t0 of the reference clock. - * + * Notice that the adjusted timestamp value could be negative e.g. for events + * that occurred before t0 wrt the reference clock. + *

    + * Finally, notice that timestamps are immutable. */ -public class TmfTimestamp implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3196421507276821609L; +public class TmfTimestamp implements Cloneable { // ======================================================================== // Attributes // ======================================================================== - protected final long fValue; // The timestamp value - protected final byte fScale; // The time scale - protected final long fPrecision; // The value precision (tolerance) + protected long fValue; // The timestamp value + protected byte fScale; // The time scale + protected long fPrecision; // The value precision (tolerance) // ======================================================================== // Constants @@ -64,21 +59,21 @@ public class TmfTimestamp implements Serializable { // ======================================================================== /** - * Default constructor. + * Default constructor */ public TmfTimestamp() { this(0, (byte) 0, 0); } /** - * Simple constructor. + * Simple constructor with value only */ public TmfTimestamp(long value) { this(value, (byte) 0, 0); } /** - * Simple constructor with default error value + * Simple constructor with value and scale * * @param value * @param scale @@ -88,7 +83,7 @@ public class TmfTimestamp implements Serializable { } /** - * Constructor with measurement error. + * Constructor with value, scale and precision * * @param value * @param scale @@ -101,12 +96,15 @@ public class TmfTimestamp implements Serializable { } /** - * Copy constructor. + * Copy constructor * * @param other */ public TmfTimestamp(TmfTimestamp other) { - this(other.fValue, other.fScale, other.fPrecision); + assert(other != null); + fValue = other.fValue; + fScale = other.fScale; + fPrecision = other.fPrecision; } // ======================================================================== @@ -114,21 +112,21 @@ public class TmfTimestamp implements Serializable { // ======================================================================== /** - * @return The timestamp value + * @return the timestamp value */ public long getValue() { return fValue; } /** - * @return The timestamp scale + * @return the timestamp scale */ public byte getScale() { return fScale; } /** - * @return The timestamp value precision + * @return the timestamp value precision */ public long getPrecision() { return fPrecision; @@ -196,7 +194,7 @@ public class TmfTimestamp implements Serializable { * * @param reference * - the reference timestamp to synchronize with - * @return The adjustment term in the reference time scale + * @return the adjustment term in the reference time scale * @throws TmfNumericalException */ public long getAdjustment(TmfTimestamp reference) throws ArithmeticException { @@ -211,8 +209,9 @@ public class TmfTimestamp implements Serializable { * - the other timestamp * @param withinPrecision * - indicates if precision is to be take into consideration - * @return

  • -1: this timestamp is lower
  • 0: timestamps are equal - * (within precision if requested)
  • 1: this timestamp is higher + * @return -1: this timestamp is lower + * 0: timestamps are equal (within precision if requested) + * 1: this timestamp is higher * @throws TmfNumericalException */ public int compareTo(final TmfTimestamp other, boolean withinPrecision) { @@ -254,11 +253,11 @@ public class TmfTimestamp implements Serializable { } } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ + @Override + public TmfTimestamp clone() { + return new TmfTimestamp(this); + } + @Override public boolean equals(Object other) { if (other instanceof TmfTimestamp) @@ -266,12 +265,9 @@ public class TmfTimestamp implements Serializable { return super.equals(other); } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override public String toString() { - return "[TmfTimestamp:" + fValue + "," + fScale + "," + fPrecision + "]"; + return "[TmfTimestamp(" + fValue + "," + fScale + "," + fPrecision + ")]"; } } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTraceEvent.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTraceEvent.java index 90e4ef9569..f030752f89 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTraceEvent.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTraceEvent.java @@ -30,50 +30,61 @@ public class TmfTraceEvent extends TmfEvent { private final String fSourcePath; private final String fFileName; - private final int fLineNumber; + private final int fLineNumber; // ======================================================================== // Constructors // ======================================================================== /** - * The constructor. - * - * @param timestamp + * @param originalTS + * @param effectiveTS * @param source * @param type * @param content * @param reference + * @param path + * @param file + * @param line */ public TmfTraceEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS, TmfEventSource source, - TmfEventType type, TmfEventContent content, TmfEventReference reference, - String path, String file, int line) + TmfEventType type, TmfEventReference reference, String path, String file, int line) { - super(originalTS, effectiveTS, source, type,content, reference); + super(originalTS, effectiveTS, source, type, reference); fSourcePath = path; - fFileName = file; + fFileName = file; fLineNumber = line; } /** - * The constructor. - * * @param timestamp * @param source * @param type * @param content * @param reference + * @param path + * @param file + * @param line */ public TmfTraceEvent(TmfTimestamp timestamp, TmfEventSource source, TmfEventType type, - TmfEventContent content, TmfEventReference reference, - String path, String file, int line) + TmfEventReference reference, String path, String file, int line) { - super(timestamp, source, type,content, reference); + super(timestamp, source, type, reference); fSourcePath = path; - fFileName = file; + fFileName = file; fLineNumber = line; } + /** + * @param other + */ + public TmfTraceEvent(TmfTraceEvent other) { + super(other); + fSourcePath = other.fSourcePath; + fFileName = other.fFileName; + fLineNumber = other.fLineNumber; + } + // ======================================================================== // Accessors // ======================================================================== @@ -99,4 +110,20 @@ public class TmfTraceEvent extends TmfEvent { return fLineNumber; } + // ======================================================================== + // Operators + // ======================================================================== + + // TODO: Deep copy + @Override + public TmfTraceEvent clone() { + return new TmfTraceEvent(this); + } + + // TODO: Proper format + @Override + public String toString() { + return null; + } + } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/request/TmfDataRequest.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/request/TmfDataRequest.java index 08c328587d..7ad4083dcd 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/request/TmfDataRequest.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/request/TmfDataRequest.java @@ -23,7 +23,7 @@ import org.eclipse.linuxtools.tmf.event.TmfTimeRange; * continuous streaming. *

    * The request is processed asynchronously by an ITmfRequestProcessor and, - * as blocks of data become available, the callback handlePartialData() is + * as blocks of data become available, the callback handleData() 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 @@ -83,10 +83,9 @@ public class TmfDataRequest { // Attributes // ======================================================================== - 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 fIndex; // The index (order) of the requested event + private final TmfTimeRange fRange; // The requested events time range + private final int fNbRequestedEvents; // The number of events to read (-1 == all in the range) private final int fBlockSize; // The maximum number of events per chunk private int fNbEvents; // The number of events read so far @@ -105,49 +104,62 @@ public class TmfDataRequest { * @param index * @param nbEvents */ - public TmfDataRequest(int index, long offset, int nbEvents) { - this(null, index, offset, nbEvents, DEFAULT_BLOCK_SIZE); + public TmfDataRequest(int index, int nbEvents) { + this(null, index, nbEvents, DEFAULT_BLOCK_SIZE); } + public TmfDataRequest(int index, int nbEvents, int blockSize) { + this(null, index, nbEvents, blockSize); + } + /** * @param range - * @param offset - * @param nbEvents */ - public TmfDataRequest(TmfTimeRange range, long offset, int nbEvents) { - this(range, 0, offset, nbEvents, DEFAULT_BLOCK_SIZE); + public TmfDataRequest(TmfTimeRange range) { + this(range, 0, ALL_EVENTS, DEFAULT_BLOCK_SIZE); } /** * @param range - * @param offset - * @param nbItems - * @param maxBlockSize Size of the largest blocks expected + * @param nbEvents + */ + public TmfDataRequest(TmfTimeRange range, int nbEvents) { + this(range, 0, nbEvents, DEFAULT_BLOCK_SIZE); + } + /** + * @param range + * @param nbEvents + * @param blockSize Size of the largest blocks expected */ - public TmfDataRequest(TmfTimeRange range, long offset, int nbEvents, int maxBlockSize) { - this(range, 0, offset, nbEvents, maxBlockSize); + public TmfDataRequest(TmfTimeRange range, int nbEvents, int blockSize) { + this(range, 0, nbEvents, blockSize); } /** * @param range * @param index - * @param offset - * @param nbItems - * @param maxBlockSize Size of the largest blocks expected + * @param nbEvents + * @param blockSize Size of the largest blocks expected */ - public TmfDataRequest(TmfTimeRange range, int index, long offset, int nbEvents, int maxBlockSize) { - fRange = range; - fIndex = index; - fOffset = offset; - fNbRequestedItems = nbEvents; - fBlockSize = maxBlockSize; - fNbEvents = 0; + private TmfDataRequest(TmfTimeRange range, int index, int nbEvents, int blockSize) { + fIndex = index; + fRange = range; + fNbRequestedEvents = nbEvents; + fBlockSize = blockSize; + fNbEvents = 0; } // ======================================================================== // Accessors // ======================================================================== + /** + * @return the index + */ + public int getIndex() { + return fIndex; + } + /** * @return the requested time range */ @@ -155,25 +167,11 @@ public class TmfDataRequest { return fRange; } - /** - * @return the index - */ - public int getIndex() { - return fIndex; - } - - /** - * @return the offset - */ - public long getOffset() { - return fOffset; - } - /** * @return the number of requested events (-1 = all) */ - public int getNbRequestedItems() { - return fNbRequestedItems; + public int getNbRequestedEvents() { + return fNbRequestedEvents; } /** diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java index e046703065..ddd0bcabd0 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java @@ -275,7 +275,7 @@ public class TmfExperiment extends TmfComponent implements ITmfRequestHandler