From ce2388e0117a0d5a1bc3392fe90e45a50e8e9a34 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Mon, 16 Apr 2012 15:41:56 -0400 Subject: [PATCH] Merge master in TmfTraceModel --- .../.gitignore | 1 + .../ctf/core/tests/AllCtfCoreTests.java | 13 +- .../linuxtools/ctf/core/tests/TestParams.java | 16 +- .../core/tests/event/CTFEventFieldTest.java | 2 +- .../ctf/core/tests/event/TestAll.java | 6 +- .../ctf/core/tests/headless/ReadTrace.java | 175 ++++++++++++++ .../ctf/core/tests/io/BitBufferIntTest.java | 2 +- .../ctf/core/tests/io/BitBufferTest.java | 2 +- .../core/tests/trace/CTFTraceReaderTest.java | 49 +++- .../ctf/core/tests/trace/CTFTraceTest.java | 8 +- .../StreamInputPacketIndexEntryTest.java | 26 +-- .../trace/StreamInputPacketIndexTest.java | 30 +-- .../trace/StreamInputPacketReaderTest.java | 192 ---------------- .../StreamInputReaderComparatorTest.java | 6 +- .../tests/trace/StreamInputReaderTest.java | 29 +-- ...eamInputReaderTimestampComparatorTest.java | 6 +- .../ctf/core/tests/trace/StreamInputTest.java | 6 +- .../ctf/core/tests/trace/StreamTest.java | 6 +- .../core/tests/types/ArrayDefinitionTest.java | 177 +++++++++----- .../ctf/core/tests/types/DefinitionTest.java | 2 +- .../core/tests/types/EnumDefinitionTest.java | 2 +- .../tests/types/EventDeclarationTest.java | 4 +- .../tests/types/IntegerDefinitionTest.java | 2 +- .../tests/types/SequenceDeclarationTest.java | 5 +- .../tests/types/SequenceDefinitionTest.java | 2 +- .../tests/types/StringDefinitionTest.java | 2 +- .../tests/types/StructDefinitionTest.java | 15 +- .../META-INF/MANIFEST.MF | 3 - .../ctf/core/event/EventDeclaration.java | 2 +- .../ctf/core/event/types/ArrayDefinition.java | 2 +- .../ctf/core/event/types/Definition.java | 2 +- .../ctf/core/event/types/EnumDefinition.java | 2 +- .../core/event/types/IntegerDefinition.java | 2 +- .../core/event/types/SequenceDefinition.java | 8 +- .../core/event/types/StringDefinition.java | 2 +- .../core/event/types/StructDefinition.java | 2 +- .../core/event/types/VariantDefinition.java | 2 +- .../linuxtools/ctf/core/trace/CTFTrace.java | 14 +- .../ctf/core/trace/CTFTraceReader.java | 135 ++++++++++- .../linuxtools/ctf/core/trace/Metadata.java | 4 +- .../trace/StreamInputPacketIndexEntry.java | 97 -------- .../core/trace/StreamInputPacketReader.java | 16 +- .../ctf/core/trace/StreamInputReader.java | 85 ++++++- .../ctf/core/event/io/BitBuffer.java | 2 +- .../core/event/metadata/DeclarationScope.java | 4 +- .../ctf/core/event/metadata/IOStructGen.java | 6 +- .../metadata/exceptions/ParseException.java | 2 +- .../{ => internal}/ctf/core/trace/Stream.java | 5 +- .../ctf/core/trace/StreamInput.java | 74 +++--- .../core/trace/StreamInputPacketIndex.java | 77 ++++++- .../trace/StreamInputPacketIndexEntry.java | 216 ++++++++++++++++++ .../trace/StreamInputReaderComparator.java | 5 +- .../StreamInputReaderTimestampComparator.java | 5 +- org.eclipse.linuxtools.lttng.ui/plugin.xml | 8 + .../lttng/ui/views/events/EventsTable.java | 7 +- .../.classpath | 1 + .../META-INF/MANIFEST.MF | 3 +- .../tests/ctfadaptor/headless/Benchmark.java | 107 +++++++++ .../ctfadaptor/headless/RequestBenchmark.java | 135 +++++++++++ .../linuxtools/internal/tmf/core/Tracer.java | 6 +- .../tmf/core/ctfadaptor/CtfIterator.java | 69 +++--- .../tmf/core/ctfadaptor/CtfLocation.java | 2 +- .../tmf/core/ctfadaptor/CtfTmfContent.java | 29 +++ .../tmf/core/ctfadaptor/CtfTmfEvent.java | 44 ++-- .../tmf/core/ctfadaptor/CtfTmfEventField.java | 13 +- .../tmf/core/ctfadaptor/CtfTmfEventType.java | 18 ++ .../tmf/core/ctfadaptor/CtfTmfTimestamp.java | 84 +++++++ .../tmf/core/ctfadaptor/CtfTmfTrace.java | 74 +++--- .../tmf/core/experiment/TmfExperiment.java | 157 ++++++------- .../core/experiment/TmfExperimentContext.java | 60 +++-- .../tmf/core/filter/model/TmfFilterNode.java | 15 +- .../core/filter/model/TmfFilterTreeNode.java | 16 +- .../META-INF/MANIFEST.MF | 1 + .../plugin.properties | 1 + org.eclipse.linuxtools.tmf.ui/plugin.xml | 9 + .../ui/parsers/custom/CustomEventsTable.java | 19 +- .../handlers/OpenExperimentHandler.java | 22 +- .../ui/project/handlers/OpenTraceHandler.java | 25 +- .../tmf/ui/editors/EventsViewEditor.java | 21 +- .../tmf/ui/editors/TmfEventsEditor.java | 33 +-- .../tmf/ui/project/model/TmfTraceElement.java | 22 +- .../tmf/ui/viewers/events/TmfEventsCache.java | 92 ++++---- .../tmf/ui/viewers/events/TmfEventsTable.java | 99 ++++---- .../views/environment/TmfEnvironmentView.java | 126 ++++++++++ 84 files changed, 1969 insertions(+), 909 deletions(-) create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java delete mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java delete mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/event/io/BitBuffer.java (99%) rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/event/metadata/DeclarationScope.java (98%) rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/event/metadata/IOStructGen.java (99%) rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/event/metadata/exceptions/ParseException.java (92%) rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/trace/Stream.java (96%) rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/trace/StreamInput.java (80%) rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/trace/StreamInputPacketIndex.java (62%) create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndexEntry.java rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/trace/StreamInputReaderComparator.java (93%) rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{ => internal}/ctf/core/trace/StreamInputReaderTimestampComparator.java (94%) create mode 100644 org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java create mode 100644 org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContent.java create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventType.java create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/environment/TmfEnvironmentView.java diff --git a/org.eclipse.linuxtools.ctf.core.tests/.gitignore b/org.eclipse.linuxtools.ctf.core.tests/.gitignore index 8d94ef8deb..a381466d18 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/.gitignore +++ b/org.eclipse.linuxtools.ctf.core.tests/.gitignore @@ -3,3 +3,4 @@ bin javaCompiler...args build.xml target +Tests/traces diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java index 6f01e38fd3..66f8400926 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java @@ -14,12 +14,11 @@ import org.junit.runners.Suite; */ @RunWith(Suite.class) @Suite.SuiteClasses({ CtfCorePluginTest.class, - org.eclipse.linuxtools.ctf.core.tests.io.TestAll.class, - org.eclipse.linuxtools.ctf.core.tests.types.TestAll.class, - org.eclipse.linuxtools.ctf.core.tests.trace.TestAll.class, - org.eclipse.linuxtools.ctf.core.tests.trace.UtilsTest.class, - org.eclipse.linuxtools.ctf.core.tests.event.TestAll.class, - + org.eclipse.linuxtools.ctf.core.tests.io.TestAll.class, + org.eclipse.linuxtools.ctf.core.tests.types.TestAll.class, + org.eclipse.linuxtools.ctf.core.tests.trace.TestAll.class, + org.eclipse.linuxtools.ctf.core.tests.trace.UtilsTest.class, + // org.eclipse.linuxtools.ctf.core.tests.event.TestAll.class, }) public class AllCtfCoreTests { @@ -29,7 +28,7 @@ public class AllCtfCoreTests { * @param args * the command line arguments */ - public static void main(String[] args) { + public static void main(final String[] args) { // try { // ProfileMe.prof_s(); // } catch (Exception e) { diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java index cf3dbc61e4..92524979fb 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java @@ -7,24 +7,24 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; /** * Here are the definitions common to all the CTF parser tests. - * + * * @author alexmont * */ public abstract class TestParams { - + /* Path to test traces */ - private static final String testTracePath1 = "Tests/traces/trace20m"; //$NON-NLS-1$ + private static final String testTracePath1 = "Tests/traces/trace20m1"; //$NON-NLS-1$ private static CTFTrace testTrace1 = null; private static CTFTrace testTraceFromFile1 = null; - + private static final File emptyFile = new File(""); //$NON-NLS-1$ private static CTFTrace emptyTrace = null; - + public static File getEmptyFile() { return emptyFile; } - + public static CTFTrace getEmptyTrace() { if (emptyTrace == null) { try { @@ -32,11 +32,11 @@ public abstract class TestParams { } catch (CTFReaderException e) { /* We know this trace should exist */ throw new RuntimeException(e); - } + } } return emptyTrace; } - + public static CTFTrace createTrace() throws CTFReaderException { if (testTrace1 == null) { testTrace1 = new CTFTrace(testTracePath1); diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java index 47a4d8609c..7b5e2da1c1 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java @@ -6,7 +6,6 @@ import static org.junit.Assert.assertNotNull; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; @@ -20,6 +19,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java index 814ce63456..1a3d40e541 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java @@ -13,7 +13,9 @@ import org.junit.runners.Suite; * @version $Revision: 1.0 $ */ @RunWith(Suite.class) -@Suite.SuiteClasses({ }) +@Suite.SuiteClasses({ + org.eclipse.linuxtools.ctf.core.tests.event.CTFEventFieldTest.class, +}) public class TestAll { /** @@ -22,7 +24,7 @@ public class TestAll { * @param args * the command line arguments */ - public static void main(String[] args) { + public static void main(final String[] args) { JUnitCore.runClasses(new Class[] { TestAll.class }); } } diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java new file mode 100644 index 0000000000..d54a02ba49 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2012 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: + * Matthew Khouzam - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.tests.headless; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Vector; + +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; + +public class ReadTrace { + + /** + * @param args + */ + @SuppressWarnings("nls") + public static void main(String[] args) { + final String TRACE_PATH = "Tests/traces/trace20m1"; + + // Change this to enable text output + final boolean USE_TEXT = false; + + final int LOOP_COUNT = 1; + + // Work variables + Long nbEvent = 0L; + Vector benchs = new Vector(); + CTFTrace trace = null; + long start, stop; + for (int loops = 0; loops < LOOP_COUNT; loops++) { + try { + nbEvent = 0L; + trace = new CTFTrace(TRACE_PATH); + } catch (CTFReaderException e) { + // do nothing + } + long prev = -1; + start = System.nanoTime(); + if (USE_TEXT) { + System.out.println("Event, " + " Time, " + " type, " + " CPU "); + } + if (trace != null) { + CTFTraceReader traceReader = new CTFTraceReader(trace); + + start = System.nanoTime(); + + while (traceReader.hasMoreEvents()) { + EventDefinition ed = traceReader.getCurrentEventDef(); + nbEvent++; + if (prev == traceReader.getIndex()) { + System.out.println("Error on events " + prev); + } + prev = traceReader.getIndex(); + if (USE_TEXT) { + String output = formatDate(ed.timestamp + + trace.getOffset()); + System.out.println(traceReader.getIndex() + ", " + + output + ", " + ed.getDeclaration().getName() + + ", " + ed.getCPU()); + } + + traceReader.advance(); + } + } + stop = System.nanoTime(); + System.out.print('.'); + double time = (stop - start) / (double) nbEvent; + benchs.add(time); + } + System.out.println(""); + double avg = 0; + for (Double val : benchs) { + avg += val; + } + avg /= benchs.size(); + System.out.println("Time to read " + nbEvent + " events = " + avg + + " events/ns"); + for (Double val : benchs) { + System.out.print(val); + System.out.print(", "); + } + try { + testSeekIndex(trace); + } catch (CTFReaderException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + try { + testSeekIndex(trace); + } catch (CTFReaderException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + /** + * @return + */ + private static long getTimestamp(CTFTraceReader fixture) { + if (fixture.getCurrentEventDef() != null) { + return fixture.getCurrentEventDef().timestamp; + } + return Long.MIN_VALUE; + } + + public static void testSeekIndex(CTFTrace trace) throws CTFReaderException { + CTFTraceReader fixture = new CTFTraceReader(trace); + long rank = 300000L; + long timeRank = 4281275394331L; + long nearEnd = 4287422858132L; + long seekTime_0; + long seekIndex_0 = 0; + long seekNext_300000 = 0; + long seekIndex_300000 = 0; + long seekTime_300000 = 0; + String cr = "\n"; //$NON-NLS-1$ + fixture.seek(0); + for (int i = 0; i < 100; i++) { + fixture.advance(); + } + + fixture.seek(nearEnd); + /* + * we need to read the trace before seeking + */ + fixture.seek(0); + seekTime_0 = getTimestamp(fixture); + for (int i = 0; i < rank; i++) { + fixture.advance(); + } + seekNext_300000 = getTimestamp(fixture); + fixture.seek(timeRank); + seekTime_300000 = getTimestamp(fixture); + fixture.seekIndex(0); + seekIndex_0 = getTimestamp(fixture); + + fixture.seekIndex(rank); + seekIndex_300000 = getTimestamp(fixture); + System.out.print(cr); + System.out.println("seek(0) " + seekTime_0 + cr + //$NON-NLS-1$ + "seekIndex(0) " + seekIndex_0 + cr + //$NON-NLS-1$ + "Next(300000) " + seekNext_300000 + cr + //$NON-NLS-1$ + "seek(time(300000)) " + seekTime_300000 + cr + //$NON-NLS-1$ + "seekIndex(300000) " + seekIndex_300000 //$NON-NLS-1$ + ); + } + + /** + * @param timestamp + * the timestamp in UTC to convert to nanoseconds. + * @return formatted string. + */ + private static String formatDate(long timestamp) { + Date d = new Date(timestamp / 1000000); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$ + String output = df.format(d) + (timestamp % 1000000000); + return output; + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java index aedef19959..79b4bc2fc7 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java @@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java index 84d01067ab..a8edb89e7b 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertNotNull; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java index 5c8b9282c1..1e7f7b6b49 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java @@ -1,5 +1,6 @@ package org.eclipse.linuxtools.ctf.core.tests.trace; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -36,7 +37,7 @@ public class CTFTraceReaderTest { /** * Perform pre-test initialization. - * @throws CTFReaderException + * @throws CTFReaderException */ @Before public void setUp() throws CTFReaderException { @@ -54,7 +55,7 @@ public class CTFTraceReaderTest { /** * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good * trace. - * @throws CTFReaderException + * @throws CTFReaderException */ @Test public void testOpen_existing() throws CTFReaderException { @@ -141,7 +142,7 @@ public class CTFTraceReaderTest { * * Both trace reader are different objects, so they shouldn't "equals" each * other. - * @throws CTFReaderException + * @throws CTFReaderException */ @Test public void testEquals() throws CTFReaderException { @@ -198,9 +199,10 @@ public class CTFTraceReaderTest { @Test public void testGoToLastEvent() throws CTFReaderException { fixture.goToLastEvent(); - long ts1 = fixture.getCurrentEventDef().timestamp; + long ts1 = getTimestamp(); long ts2 = fixture.getEndTime(); - assertTrue(ts1 == ts2); + // the end time can be later than the last event. + assertTrue(ts1 <= ts2); } /** @@ -279,4 +281,41 @@ public class CTFTraceReaderTest { boolean result = fixture.seek(timestamp); assertTrue(result); } + + + /** + * Run the boolean seek(long) method test. + * @throws CTFReaderException + */ + @Test + public void testSeekIndex() throws CTFReaderException { + long rank = 30000L; + long first, second = 0, third , fourth; + /* + * we need to read the trace before seeking + */ + first = getTimestamp(); + for( int i = 0 ; i < 60000; i++ ) + { + if( i == rank) { + second = getTimestamp(); + } + fixture.advance(); + } + boolean result= fixture.seekIndex(0); + third = getTimestamp(); + boolean result2 = fixture.seekIndex(rank); + fourth = getTimestamp(); + assertTrue(result); + assertTrue(result2); + assertEquals( first , third); + assertEquals( second , fourth); + } + + /** + * @return + */ + private long getTimestamp() { + return fixture.getCurrentEventDef().timestamp; + } } diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java index 58358e6cbc..39537d09a7 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java @@ -12,13 +12,13 @@ import java.util.Map; import java.util.UUID; import org.eclipse.linuxtools.ctf.core.event.CTFClock; -import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; -import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -99,7 +99,7 @@ public class CTFTraceTest { * Run the void addStream(Stream) method test. * * @throws ParseException - * @throws CTFReaderException + * @throws CTFReaderException */ @Test public void testAddStream() throws ParseException, CTFReaderException { @@ -313,7 +313,7 @@ public class CTFTraceTest { @Test public void testGetClock_1() { CTFClock result = fixture.getClock(); - assertNull(result); + assertNotNull(result); } /** diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java index c661d262b9..52493974c1 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java @@ -3,7 +3,7 @@ package org.eclipse.linuxtools.ctf.core.tests.trace; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndexEntry; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -11,7 +11,7 @@ import org.junit.Test; /** * The class StreamInputPacketIndexEntryTest contains tests for the * class {@link StreamInputPacketIndexEntry}. - * + * * @author ematkho * @version $Revision: 1.0 $ */ @@ -21,7 +21,7 @@ public class StreamInputPacketIndexEntryTest { /** * Launch the test. - * + * * @param args * the command line arguments */ @@ -50,9 +50,9 @@ public class StreamInputPacketIndexEntryTest { */ @Test public void testStreamInputPacketIndexEntry_1() { - String expectedResult = "PacketIndexEntry [offset=1, " + //$NON-NLS-1$ + String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1, " + //$NON-NLS-1$ "timestampBegin=0, timestampEnd=0, " + //$NON-NLS-1$ - "dataOffset=0, packetSize=0, contentSize=0]"; //$NON-NLS-1$ + "indexBegin=9223372036854775807, indexEnd=9223372036854775807]"; //$NON-NLS-1$ assertNotNull(fixture); assertEquals(expectedResult, fixture.toString()); @@ -63,15 +63,15 @@ public class StreamInputPacketIndexEntryTest { */ @Test public void testToString() { - String expectedResult = "PacketIndexEntry [offset=1, " + //$NON-NLS-1$ - "timestampBegin=1, timestampEnd=1, " + //$NON-NLS-1$ - "dataOffset=1, packetSize=1, contentSize=1]"; //$NON-NLS-1$ + String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1,"+ //$NON-NLS-1$ + " timestampBegin=1, timestampEnd=1, indexBegin=9223372036854775807,"+ //$NON-NLS-1$ + " indexEnd=9223372036854775807]"; //$NON-NLS-1$ - fixture.contentSizeBits = 1; - fixture.dataOffsetBits = 1; - fixture.timestampEnd = 1L; - fixture.packetSizeBits = 1; - fixture.timestampBegin = 1L; + fixture.setContentSizeBits(1); + fixture.setDataOffsetBits(1); + fixture.setTimestampEnd(1L); + fixture.setPacketSizeBits(1); + fixture.setTimestampBegin(1L); assertEquals(expectedResult, fixture.toString()); } diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java index e0e3ad1ef8..0992c7e2f5 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java @@ -7,8 +7,8 @@ import java.util.Collection; import java.util.ListIterator; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndex; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndexEntry; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -16,7 +16,7 @@ import org.junit.Test; /** * The class StreamInputPacketIndexTest contains tests for the * class {@link StreamInputPacketIndex}. - * + * * @author ematkho * @version $Revision: 1.0 $ */ @@ -27,7 +27,7 @@ public class StreamInputPacketIndexTest { /** * Launch the test. - * + * * @param args * the command line arguments */ @@ -37,7 +37,7 @@ public class StreamInputPacketIndexTest { /** * Perform pre-test initialization. - * + * * @throws CTFReaderException */ @Before @@ -66,40 +66,40 @@ public class StreamInputPacketIndexTest { /** * Run the void addEntry(StreamInputPacketIndexEntry) method test, by * specifying only 1 parameter to the entry. - * + * * @throws CTFReaderException */ @Test public void testAddEntry_1param() throws CTFReaderException { - entry.packetSizeBits = 0; + entry.setPacketSizeBits(0); fixture.addEntry(entry); } /** * Run the void addEntry(StreamInputPacketIndexEntry) method test by * specifying 2 parameters to the entry. - * + * * @throws CTFReaderException */ @Test public void testAddEntry_2params() throws CTFReaderException { - entry.packetSizeBits = 1; - entry.contentSizeBits = 0; + entry.setPacketSizeBits(1); + entry.setContentSizeBits(0); fixture.addEntry(entry); } /** * Run the void addEntry(StreamInputPacketIndexEntry) method test, by * specifying all 4 parameters to the entry. - * + * * @throws CTFReaderException */ @Test public void testAddEntry_4params() throws CTFReaderException { - entry.timestampBegin = 1L; - entry.packetSizeBits = 1; - entry.contentSizeBits = 1; - entry.timestampEnd = 1L; + entry.setTimestampBegin(1L); + entry.setPacketSizeBits(1); + entry.setContentSizeBits(1); + entry.setTimestampEnd(1L); fixture.addEntry(entry); } diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java deleted file mode 100644 index b113ffe963..0000000000 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java +++ /dev/null @@ -1,192 +0,0 @@ -package org.eclipse.linuxtools.ctf.core.tests.trace; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.nio.channels.FileChannel; - -import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.Definition; -import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.ctf.core.tests.TestParams; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.ctf.core.trace.Stream; -import org.eclipse.linuxtools.ctf.core.trace.StreamInput; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndexEntry; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketReader; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; -import org.junit.*; - -/** - * The class StreamInputPacketReaderTest contains tests for the - * class {@link StreamInputPacketReader}. - * - * @author ematkho - * @version $Revision: 1.0 $ - */ -public class StreamInputPacketReaderTest { - - private StreamInputPacketReader fixture; - - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(StreamInputPacketReaderTest.class); - } - - /** - * Perform pre-test initialization. - * - * @throws CTFReaderException - */ - @Before - public void setUp() throws CTFReaderException { - // FIXME The test is broken here. "FileChannel" can't be null because we - // need it further in. Heck this whole thing shouldn't be public in the - // first place, perhaps fixing that is the best way to go. - fixture = new StreamInputPacketReader(new StreamInputReader( - new StreamInput(new Stream(TestParams.createTrace()), - (FileChannel) null, TestParams.getEmptyFile()))); - } - - /** - * Perform post-test clean-up. - */ - @After - public void tearDown() { - // Add additional tear down code here - } - - /** - * Run the StreamInputPacketReader(StreamInputReader) constructor test. - * - * @throws CTFReaderException - */ - @Test - public void testStreamInputPacketReader() throws CTFReaderException { - StreamInputReader streamInputReader; - StreamInputPacketReader result; - - streamInputReader = new StreamInputReader(new StreamInput(new Stream( - TestParams.createTrace()), (FileChannel) null, - TestParams.getEmptyFile())); - - result = new StreamInputPacketReader(streamInputReader); - - assertNotNull(result); - } - - /** - * Run the int getCPU() method test. - */ - @Test - public void testGetCPU() { - int result = fixture.getCPU(); - assertEquals(0, result); - } - - /** - * Run the StreamInputPacketIndexEntry getCurrentPacket() method test. - */ - @Test - public void testGetCurrentPacket() { - StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(1L); - fixture.setCurrentPacket(sipie); - StreamInputPacketIndexEntry result = fixture.getCurrentPacket(); - assertNotNull(result); - } - - /** - * Run the String getPath() method test. - */ - @Test - public void testGetPath() { - String result = fixture.getPath(); - assertNotNull(result); - } - - /** - * Run the StructDefinition getStreamPacketContextDef() method test. - */ - @Test - public void testGetStreamPacketContextDef() { - fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); - StructDefinition result = fixture.getStreamPacketContextDef(); - assertNotNull(result); - } - - /** - * Run the boolean hasMoreEvents() method test. - */ - @Test - public void testHasMoreEvents() { - fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); - boolean result = fixture.hasMoreEvents(); - assertTrue(result); - } - - /** - * Run the Definition lookupDefinition(String) method test. - */ - @Test - public void testLookupDefinition() { - fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); - String lookupPath = ""; //$NON-NLS-1$ - Definition result = fixture.lookupDefinition(lookupPath); - assertNotNull(result); - } - - /** - * Run the EventDefinition readNextEvent() method test. - * - * @throws CTFReaderException - */ - @Test - public void testReadNextEvent() throws CTFReaderException { - fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); - EventDefinition result = fixture.readNextEvent(); - assertNotNull(result); - } - - /** - * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. - */ - @Test - public void testSetCurrentPacket() { - fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); - StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry( - 1L); - currentPacket.packetSizeBits = 1; - fixture.setCurrentPacket(currentPacket); - } - - /** - * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. - */ - @Test - public void testSetCurrentPacket_2() throws Exception { - fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); - StreamInputPacketIndexEntry currentPacket = null; - fixture.setCurrentPacket(currentPacket); - - } - - /** - * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. - */ - @Test - public void testSetCurrentPacket_3() { - fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); - StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry( - 1L); - currentPacket.timestampBegin = 1L; - currentPacket.packetSizeBits = 1; - - fixture.setCurrentPacket(currentPacket); - } -} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java index 5c4e278920..2b03b3825f 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java @@ -8,10 +8,10 @@ import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.ctf.core.trace.Stream; -import org.eclipse.linuxtools.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputReaderComparator; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderComparator; import org.junit.*; /** diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java index d9a6573877..f10138f576 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java @@ -13,9 +13,9 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; -import org.eclipse.linuxtools.ctf.core.trace.Stream; -import org.eclipse.linuxtools.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -23,7 +23,7 @@ import org.junit.Test; /** * The class StreamInputReaderTest contains tests for the class * {@link StreamInputReader}. - * + * * @author ematkho * @version $Revision: 1.0 $ */ @@ -33,7 +33,7 @@ public class StreamInputReaderTest { /** * Launch the test. - * + * * @param args * the command line arguments */ @@ -43,8 +43,8 @@ public class StreamInputReaderTest { /** * Perform pre-test initialization. - * - * @throws CTFReaderException + * + * @throws CTFReaderException */ @Before public void setUp() throws CTFReaderException { @@ -92,7 +92,7 @@ public class StreamInputReaderTest { /** * Run the StreamInputReader(StreamInput) constructor test, with an invalid * trace. - * + * * @throws CTFReaderException */ @Test(expected = CTFReaderException.class) @@ -140,18 +140,9 @@ public class StreamInputReaderTest { assertEquals(1, result); } - /** - * Run the StreamInput getStreamInput() method test. - */ - @Test - public void testGetStreamInput() { - StreamInput result = fixture.getStreamInput(); - assertNotNull(result); - } - /** * Run the void goToLastEvent() method test. - * + * * @throws CTFReaderException */ @Test @@ -180,8 +171,8 @@ public class StreamInputReaderTest { /** * Run the seek test. Seek by passing an EventDefinition to which we've * given the timestamp we want. - * - * @throws CTFReaderException + * + * @throws CTFReaderException */ @Test public void testSeek_eventDefinition() throws CTFReaderException { diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java index 1d3a3ca73e..33ab674893 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java @@ -7,10 +7,10 @@ import java.nio.channels.FileChannel; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.ctf.core.trace.Stream; -import org.eclipse.linuxtools.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputReaderTimestampComparator; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator; import org.junit.*; /** diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java index 4a71dc3ac8..40963a9498 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java @@ -10,9 +10,9 @@ import java.nio.channels.FileChannel; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.ctf.core.trace.Stream; -import org.eclipse.linuxtools.ctf.core.trace.StreamInput; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndex; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java index cf660c8f9f..c6b6740613 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java @@ -8,13 +8,13 @@ import java.util.HashMap; import java.util.Set; import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; -import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; -import org.eclipse.linuxtools.ctf.core.trace.Stream; -import org.eclipse.linuxtools.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java index adb35a2d41..3bdf3f9c08 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java @@ -7,22 +7,20 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; -import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -37,7 +35,9 @@ import org.junit.Test; public class ArrayDefinitionTest { private CTFTrace trace; - private ArrayDefinition fixture; + private ArrayDefinition charArrayFixture; + private ArrayDefinition stringArrayFixture; + private ArrayDefinition longArrayFixture; /** * Launch the test. @@ -54,34 +54,70 @@ public class ArrayDefinitionTest { * * structDef shouldn't be null after parsing the CTFTraceReader object, so * we can ignore the warning. - * - * @throws CTFReaderException + * + * @throws CTFReaderException */ @Before public void setUp() throws CTFReaderException { this.trace = TestParams.createTrace(); - CTFTraceReader tr = new CTFTraceReader(this.trace); - String name = ""; //$NON-NLS-1$ - StructDefinition structDef = null; - boolean foundArray = false; - - while (tr.hasMoreEvents() && !foundArray) { - tr.advance(); - EventDefinition ed = tr.getCurrentEventDef(); - for (String key : ed.fields.getDefinitions().keySet()) { - structDef = ed.fields; - Definition d = structDef.lookupDefinition(key); - if (d instanceof ArrayDefinition) { - foundArray = true; - name = key; - break; - } - } - } - fixture = structDef.lookupArray(name); + charArrayFixture = createCharArray(); + stringArrayFixture = createStringArray(); + longArrayFixture = createLongArray(); } + private ArrayDefinition createLongArray() { + IntegerDeclaration decl = new IntegerDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none"); //$NON-NLS-1$ + IntegerDefinition[] defs = createIntDefs(10, 32); + ArrayDefinition temp = setUpDeclaration(decl, defs); + return temp; + } + + private ArrayDefinition createCharArray() { + IntegerDeclaration decl = new IntegerDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none"); //$NON-NLS-1$ + IntegerDefinition[] defs = createIntDefs(4,8); + ArrayDefinition temp = setUpDeclaration(decl, defs); + return temp; + } + + + /** + * @return + */ + private ArrayDefinition createStringArray() { + StringDeclaration strDecl = new StringDeclaration(); + StringDefinition[] defs = createDefs(); + ArrayDefinition temp = setUpDeclaration(strDecl, defs); + return temp; + } + /** + * @param decl + * @param defs + * @return + */ + private ArrayDefinition setUpDeclaration(IDeclaration decl, + Definition[] defs) { + ArrayDeclaration ad = new ArrayDeclaration(0, decl); + ArrayDefinition temp = new ArrayDefinition(ad , this.trace , "Testx"); //$NON-NLS-1$ + temp.setDefinitions(defs); + return temp; + } + /** + * @param size + * @param bits + * @return + */ + private IntegerDefinition[] createIntDefs(int size, int bits) { + IntegerDefinition[] defs = new IntegerDefinition[size]; + for (int i = 0; i < size; i++) { + + String content = "test" + i; //$NON-NLS-1$ + defs[i] = new IntegerDefinition(new IntegerDeclaration(bits, false, + 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content), null, content); + defs[i].setValue(i); + } + return defs; + } /** * Perform post-test clean-up. */ @@ -109,7 +145,7 @@ public class ArrayDefinitionTest { */ @Test public void testArrayDefinition_baseDeclaration() { - ArrayDeclaration declaration = fixture.getDeclaration(); + ArrayDeclaration declaration = charArrayFixture.getDeclaration(); String fieldName = ""; //$NON-NLS-1$ ArrayDefinition result = new ArrayDefinition(declaration, this.trace, @@ -140,8 +176,8 @@ public class ArrayDefinitionTest { */ @Test public void testGetDeclaration() { - fixture.setDefinitions(new Definition[] {}); - ArrayDeclaration result = fixture.getDeclaration(); + charArrayFixture.setDefinitions(new Definition[] {}); + ArrayDeclaration result = charArrayFixture.getDeclaration(); assertNotNull(result); } @@ -152,7 +188,7 @@ public class ArrayDefinitionTest { @Test public void testGetElem_noDefs() { int i = 0; - Definition result = fixture.getElem(i); + Definition result = charArrayFixture.getElem(i); assertNotNull(result); } @@ -163,10 +199,10 @@ public class ArrayDefinitionTest { @Test public void testGetElem_withDefs() { Definition defs[] = createDefs(); - fixture.setDefinitions(defs); + charArrayFixture.setDefinitions(defs); int j = 1; - Definition result = fixture.getElem(j); + Definition result = charArrayFixture.getElem(j); assertNotNull(result); } @@ -176,14 +212,14 @@ public class ArrayDefinitionTest { */ @Test public void testIsString_ownDefs() { - StringDefinition[] defs = createDefs(); - fixture.setDefinitions(defs); - boolean result = fixture.isString(); + boolean result = stringArrayFixture.isString(); assertFalse(result); } + + /** * Run the boolean isString() method test. */ @@ -196,14 +232,8 @@ public class ArrayDefinitionTest { "Testx"); //$NON-NLS-1$ int size = 4; - IntegerDefinition[] defs = new IntegerDefinition[size]; - for (int i = 0; i < size; i++) { - - String content = "test" + i; //$NON-NLS-1$ - defs[i] = new IntegerDefinition(new IntegerDeclaration(8, false, - 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content), null, content); - defs[i].setValue(i); - } + int bits = 8; + IntegerDefinition[] defs = createIntDefs(size, bits); ownFixture.setDefinitions(defs); boolean result = ownFixture.isString(); @@ -211,17 +241,28 @@ public class ArrayDefinitionTest { assertTrue(result); } + + /** * Run the boolean isString() method test. */ @Test public void testIsString_emptyDef() { - fixture.setDefinitions(new Definition[] {}); - boolean result = fixture.isString(); + charArrayFixture.setDefinitions(new Definition[] {}); + boolean result = charArrayFixture.isString(); - assertFalse(result); + assertTrue(result); } + /** + * Run the boolean isString() method test. + */ + @Test + public void testIsString_emptyDefStrDecl() { + ArrayDefinition ownFixture = createStringArray(); + boolean result = ownFixture.isString(); + assertFalse(result); + } /** * Run the void read(BitBuffer) method test. */ @@ -229,7 +270,7 @@ public class ArrayDefinitionTest { public void testRead_noDefs() { BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128)); - fixture.read(input); + charArrayFixture.read(input); } /** @@ -237,34 +278,52 @@ public class ArrayDefinitionTest { */ @Test public void testRead_withDefs() { - fixture.setDefinitions(new Definition[] {}); + charArrayFixture.setDefinitions(new Definition[] {}); BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); - fixture.read(input); + charArrayFixture.read(input); } /** * Run the String toString() method test. */ @Test - public void testToString_base() { - String result = fixture.toString(); - + public void testToString_char() { + String result = charArrayFixture.toString(); + assertNotNull(result); + } + /** + * Run the String toString() method test. + */ + @Test + public void testToString_long() { + String result = longArrayFixture.toString(); assertNotNull(result); } + /** + * Run the String toString() method test. + */ + @Test + public void testToString_string() { + String result = stringArrayFixture.toString(); + assertNotNull(result); + } /** * Run the String toString() method test. */ @Test public void testToString_withDefs() { - int size = 2; - StringDefinition[] defs = new StringDefinition[size]; - for (int i = 0; i < size; i++) { - defs[i] = new StringDefinition(null, null, ("test" + i)); //$NON-NLS-1$ - } - fixture.setDefinitions(defs); - String result = fixture.toString(); + String result = charArrayFixture.toString(); + + assertNotNull(result); + } + /** + * Run the String toString() method test. + */ + @Test + public void testToStringStringArray() { + String result = stringArrayFixture.toString(); assertNotNull(result); } diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java index 56af49da16..7e172082f9 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java @@ -2,9 +2,9 @@ package org.eclipse.linuxtools.ctf.core.tests.types; import static org.junit.Assert.assertNotNull; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java index 9fdb60e057..15c827c1db 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java @@ -7,11 +7,11 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java index f129c9a9e7..2c796beca2 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java @@ -15,9 +15,9 @@ import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; -import org.eclipse.linuxtools.ctf.core.trace.Stream; -import org.eclipse.linuxtools.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java index a06be0ca63..1d6a8eb83f 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java @@ -6,7 +6,6 @@ import static org.junit.Assert.assertNotNull; import java.nio.ByteOrder; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; @@ -17,6 +16,7 @@ import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java index 5e312b6fd0..56c17d53fd 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java @@ -28,6 +28,7 @@ public class SequenceDeclarationTest { private SequenceDeclaration fixture; + static final String fieldName = "LengthName"; //$NON-NLS-1$ /** * Launch the test. * @@ -40,7 +41,7 @@ public class SequenceDeclarationTest { @Before public void setUp() { - fixture = new SequenceDeclaration("", new StringDeclaration()); //$NON-NLS-1$ + fixture = new SequenceDeclaration(fieldName, new StringDeclaration()); } @After @@ -71,7 +72,7 @@ public class SequenceDeclarationTest { public void testCreateDefinition() { IntegerDeclaration id = new IntegerDeclaration(8, false, 8, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null); - String fieldName = "LengthName"; //$NON-NLS-1$ + StructDeclaration structDec = new StructDeclaration(0); structDec.addField(fieldName, id); StructDefinition structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$ diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java index 0ca0e13703..11745a81f1 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java @@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteOrder; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; @@ -15,6 +14,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java index a80df32b72..fbfd03b3e1 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java @@ -3,7 +3,6 @@ package org.eclipse.linuxtools.ctf.core.tests.types; import static org.junit.Assert.assertNotNull; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; @@ -13,6 +12,7 @@ import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java index 0d4bce83f3..2ab82a0285 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java @@ -7,7 +7,6 @@ import java.nio.ByteBuffer; import java.util.HashMap; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; @@ -21,7 +20,7 @@ import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; - +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -29,7 +28,7 @@ import org.junit.Test; /** * The class StructDefinitionTest contains tests for the class * {@link StructDefinition}. - * + * * @author ematkho * @version $Revision: 1.0 $ */ @@ -41,7 +40,7 @@ public class StructDefinitionTest { /** * Launch the test. - * + * * @param args * the command line arguments */ @@ -51,8 +50,8 @@ public class StructDefinitionTest { /** * Perform pre-test initialization. - * - * @throws CTFReaderException + * + * @throws CTFReaderException */ @Before public void setUp() throws CTFReaderException { @@ -104,7 +103,7 @@ public class StructDefinitionTest { */ @Test public void testLookupDefinition() { - String lookupPath = "id"; //$NON-NLS-1$ + String lookupPath = "args"; //$NON-NLS-1$ Definition result = fixture.lookupDefinition(lookupPath); assertNotNull(result); @@ -127,7 +126,7 @@ public class StructDefinitionTest { */ @Test public void testLookupInteger_1() { - String name = "id"; //$NON-NLS-1$ + String name = "_args"; //$NON-NLS-1$ IntegerDefinition result = fixture.lookupInteger(name); assertNotNull(result); diff --git a/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF index 1bd574c12a..64b5eb13b5 100644 --- a/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF @@ -12,8 +12,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0", org.antlr.runtime;bundle-version="3.2.0", org.eclipse.linuxtools.ctf.parser;bundle-version="0.1.0" Export-Package: org.eclipse.linuxtools.ctf.core.event, - org.eclipse.linuxtools.ctf.core.event.io, - org.eclipse.linuxtools.ctf.core.event.metadata, - org.eclipse.linuxtools.ctf.core.event.metadata.exceptions, org.eclipse.linuxtools.ctf.core.event.types, org.eclipse.linuxtools.ctf.core.trace diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java index c6e06f8d5c..1650ed1a08 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java @@ -13,8 +13,8 @@ package org.eclipse.linuxtools.ctf.core.event; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.ctf.core.trace.Stream; import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; /** * EventDeclaration diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java index 8c7e67a0f8..da5cef3475 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java @@ -12,7 +12,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * ArrayDefinition diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java index 4d4d28ba3d..52ea6ef366 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java @@ -12,7 +12,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * Definition diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java index aef0446728..e7824197d7 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java @@ -12,7 +12,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * EnumDefinition diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java index 9c594ebc15..6ac0d93d9f 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java @@ -12,7 +12,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * IntegerDefinition diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java index 9a7a1bd029..1abe32784e 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java @@ -12,8 +12,8 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * SequenceDefinition @@ -37,17 +37,17 @@ public class SequenceDefinition extends Definition { IDefinitionScope definitionScope, String fieldName) throws CTFReaderException { super(definitionScope, fieldName); Definition lenDef = null; - + this.declaration = declaration; if (definitionScope != null) { lenDef = definitionScope.lookupDefinition(declaration.getLengthName()); } - if (lenDef == null) { + if (lenDef == null) { throw new CTFReaderException("Sequence length field not found"); //$NON-NLS-1$ } - + if (!(lenDef instanceof IntegerDefinition)) { throw new CTFReaderException("Sequence length field not integer"); //$NON-NLS-1$ } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java index 17506a9ec6..8a4eb8733a 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java @@ -12,7 +12,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * StringDefinition diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java index 5ca77b2c20..e29a6d0d68 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java @@ -15,7 +15,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; import java.util.HashMap; import java.util.ListIterator; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * StructDefinition diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java index 135ff682d0..55011eae9f 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java @@ -15,7 +15,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; import java.util.HashMap; import java.util.Map; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * VariantDefinition diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java index fefbc593c4..08732817a7 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java @@ -28,8 +28,6 @@ import java.util.Set; import java.util.UUID; import org.eclipse.linuxtools.ctf.core.event.CTFClock; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; @@ -37,6 +35,10 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.internal.ctf.core.Activator; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; /** * CTFTrace @@ -632,4 +634,12 @@ public class CTFTrace implements IDefinitionScope { return null; } + public long getOffset() { + if(getClock() == null ) + { + return 0; + } + return (Long) getClock().getProperty("offset"); //$NON-NLS-1$ + } + } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java index df1a5d1e47..fda56132c2 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java @@ -19,6 +19,11 @@ import java.util.Vector; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.internal.ctf.core.Activator; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator; + /** * Reads the events of a trace. */ @@ -59,6 +64,13 @@ public class CTFTraceReader { */ private long endTime; + /** + * Current event index + */ + private long index; + + private final long startIndex[]; + // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ @@ -88,6 +100,11 @@ public class CTFTraceReader { */ this.startTime = prio.peek().getCurrentEvent().timestamp; this.endTime = this.startTime; + this.index = 0; + startIndex = new long[prio.size()]; + for (int i = 0; i < prio.size(); i++) { + startIndex[i] = 0; + } } /** @@ -115,6 +132,13 @@ public class CTFTraceReader { return this.startTime; } + /** + * @return the index + */ + public long getIndex() { + return index; + } + // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ @@ -193,7 +217,7 @@ public class CTFTraceReader { * of the trace. */ public EventDefinition getCurrentEventDef() { - StreamInputReader top = this.prio.peek(); + StreamInputReader top = getTopStream(); return (top != null) ? top.getCurrentEvent() : null; } @@ -204,6 +228,9 @@ public class CTFTraceReader { * @return True if an event was read. */ public boolean advance() { + /* + * Index the + */ /* * Remove the reader from the top of the priority queue. */ @@ -215,7 +242,21 @@ public class CTFTraceReader { if (top == null) { return false; } - + /* + * index if needed + */ + if (hasMoreEvents()) { + StreamInputPacketReader packetReader = top.getPacketReader(); + boolean packetHasMoreEvents = packetReader.hasMoreEvents(); + StreamInputPacketIndexEntry currentPacket = packetReader + .getCurrentPacket(); + if (!packetHasMoreEvents) { + int n = this.streamInputReaders.indexOf(top); + currentPacket.setIndexBegin(startIndex[n]); + currentPacket.setIndexEnd(index); + startIndex[n] = index + 1; + } + } /* * Read the next event of this reader. */ @@ -227,13 +268,18 @@ public class CTFTraceReader { final long topEnd = top.getCurrentEvent().timestamp; this.endTime = Math.max(topEnd, this.endTime); this.eventCountPerTraceFile[top.getName()]++; + /* + * increment the index + */ + index++; } + boolean hasMoreEvents = hasMoreEvents(); /* * If there is no reader in the queue, it means the trace reader reached * the end of the trace. */ - return hasMoreEvents(); + return hasMoreEvents; } /** @@ -243,7 +289,6 @@ public class CTFTraceReader { */ public void goToLastEvent() throws CTFReaderException { - this.seek(0); for (StreamInputReader streamInputReader : this.streamInputReaders) { /* * Seek the trace reader. @@ -251,7 +296,7 @@ public class CTFTraceReader { streamInputReader.goToLastEvent(); } int count = prio.size(); - for (int i = 0; i < (count); i++) { + for (int i = 0; i < (count-1); i++) { advance(); } } @@ -272,24 +317,93 @@ public class CTFTraceReader { * Remove all the trace readers from the priority queue */ this.prio.clear(); - + index = 0; + long offset = 0; for (StreamInputReader streamInputReader : this.streamInputReaders) { /* * Seek the trace reader. */ - streamInputReader.seek(timestamp); + offset += streamInputReader.seek(timestamp); + + /* + * Add it to the priority queue if there is a current event. + */ + + } + for (StreamInputReader streamInputReader : this.streamInputReaders) { + if (streamInputReader.getCurrentEvent() != null) { + this.prio.add(streamInputReader); + index = Math.max(index, streamInputReader.getPacketReader() + .getCurrentPacket().getIndexBegin() + + offset); + } + } + return hasMoreEvents(); + } + + public boolean seekIndex(long index) { + this.prio.clear(); + + long tempIndex = Long.MIN_VALUE; + long tempTimestamp = Long.MIN_VALUE; + try { + for (StreamInputReader streamInputReader : this.streamInputReaders) { + /* + * Seek the trace reader. + */ + final long streamIndex = streamInputReader.seekIndex(index); + tempIndex = Math.max(tempIndex, streamIndex); + tempTimestamp = Math.max(tempTimestamp, + streamInputReader.getCurrentEvent().timestamp); + } + } catch (CTFReaderException e) { + /* + * Important, if it failed, it's because it's not yet indexed, so we + * have to manually advance to the right value. + */ + for (StreamInputReader streamInputReader : this.streamInputReaders) { + /* + * Seek the trace reader. + */ + streamInputReader.seek(0); + } + tempIndex = 0; + } + for (StreamInputReader streamInputReader : this.streamInputReaders) { /* * Add it to the priority queue if there is a current event. */ + if (streamInputReader.getCurrentEvent() != null) { this.prio.add(streamInputReader); } } + if (tempIndex == Long.MAX_VALUE) { + tempIndex = 0; + } + long pos = tempIndex; + if (index > tempIndex) { + /* + * advance for offset + */ + while ((prio.peek().getCurrentEvent().timestamp < tempTimestamp) + && hasMoreEvents()) { + this.advance(); + } + for (pos = tempIndex; (pos < index) && hasMoreEvents(); pos++) { + this.advance(); + } + } + this.index = pos; return hasMoreEvents(); } + public StreamInputReader getTopStream() { + return this.prio.peek(); + } + /** * Does the trace have more events? * @@ -328,8 +442,7 @@ public class CTFTraceReader { int len = (width * this.eventCountPerTraceFile[se.getName()]) / numEvents; - StringBuilder sb = new StringBuilder( - se.getStreamInput().getFilename() + "\t["); //$NON-NLS-1$ + StringBuilder sb = new StringBuilder(se.getFilename() + "\t["); //$NON-NLS-1$ for (int i = 0; i < len; i++) { sb.append('+'); @@ -355,8 +468,8 @@ public class CTFTraceReader { result = (prime * result) + (int) (endTime ^ (endTime >>> 32)); result = (prime * result) + (int) (startTime ^ (startTime >>> 32)); result = (prime * result) - + ((streamInputReaders == null) ? 0 - : streamInputReaders.hashCode()); + + ((streamInputReaders == null) ? 0 : streamInputReaders + .hashCode()); result = (prime * result) + ((trace == null) ? 0 : trace.hashCode()); return result; } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java index 749bf393ba..10172d09e0 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java @@ -29,11 +29,11 @@ import org.antlr.runtime.ANTLRReaderStream; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; import org.antlr.runtime.tree.CommonTree; -import org.eclipse.linuxtools.ctf.core.event.metadata.IOStructGen; -import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; import org.eclipse.linuxtools.ctf.parser.CTFLexer; import org.eclipse.linuxtools.ctf.parser.CTFParser; import org.eclipse.linuxtools.ctf.parser.CTFParser.parse_return; +import org.eclipse.linuxtools.internal.ctf.core.event.metadata.IOStructGen; +import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; /** * Metadata diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java deleted file mode 100644 index 167d8ffe15..0000000000 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others - * - * 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: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -/** - * StreamInputPacketIndexEntry - *

- * Represents an entry in the index of event packets. - */ -public class StreamInputPacketIndexEntry { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** - * Offset of the packet in the file, in bytes - */ - public long offsetBytes; - - /** - * Offset of the data in the packet, in bits - */ - public int dataOffsetBits = 0; - - /** - * Packet size, in bits - */ - public int packetSizeBits = 0; - - /** - * Content size, in bits - */ - public int contentSizeBits = 0; - - /** - * Begin timestamp - */ - public long timestampBegin = 0; - - /** - * End timestamp - */ - public long timestampEnd = 0; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructs an index entry. - * - * @param offset - * The offset of the packet in the file, in bytes. - */ - - public StreamInputPacketIndexEntry(long offset) { - this.offsetBytes = offset; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * Returns whether the packet includes (inclusively) the given timestamp in - * the begin-end timestamp range. - * - * @param ts - * The timestamp to check. - * @return True if the packet includes the timestamp. - */ - boolean includes(long ts) { - return (ts >= timestampBegin) && (ts <= timestampEnd); - } - - @Override - public String toString() { - /* Only for debugging, shouldn't be externalized */ - return "PacketIndexEntry [offset=" + offsetBytes + ", timestampBegin=" //$NON-NLS-1$ //$NON-NLS-2$ - + Long.toHexString(timestampBegin) + ',' + " timestampEnd=" //$NON-NLS-1$ - + Long.toHexString(timestampEnd) + ", dataOffset=" //$NON-NLS-1$ - + dataOffsetBits + ", packetSize=" + packetSizeBits //$NON-NLS-1$ - + ", contentSize=" + contentSizeBits + ']'; //$NON-NLS-1$ - } - -} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java index 210b4827be..53e410605e 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java @@ -19,7 +19,6 @@ import java.util.HashMap; import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; @@ -27,13 +26,16 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; /** * StreamInputPacketReader *

* Reads the events of a packet of a trace file. */ -public class StreamInputPacketReader implements IDefinitionScope { +class StreamInputPacketReader implements IDefinitionScope { // ------------------------------------------------------------------------ // Constants @@ -108,7 +110,7 @@ public class StreamInputPacketReader implements IDefinitionScope { /* * Set the BitBuffer's byte order. */ - getBitBuffer().setByteOrder(streamInputReader.getStreamInput().getStream().getTrace().getByteOrder()); + getBitBuffer().setByteOrder(streamInputReader.getByteOrder()); /* * Create definitions needed to read the events. @@ -224,8 +226,8 @@ public class StreamInputPacketReader implements IDefinitionScope { MappedByteBuffer bb = null; try { bb = getStreamInputReader().getStreamInput().getFileChannel().map( - MapMode.READ_ONLY, this.currentPacket.offsetBytes, - (this.currentPacket.packetSizeBits + 7) / 8); + MapMode.READ_ONLY, this.currentPacket.getOffsetBytes(), + (this.currentPacket.getPacketSizeBits() + 7) / 8); } catch (IOException e) { /* * The streamInputReader object is already allocated, so this @@ -258,7 +260,7 @@ public class StreamInputPacketReader implements IDefinitionScope { * Use the timestamp begin of the packet as the reference for the * timestamp reconstitution. */ - lastTimestamp = currentPacket.timestampBegin; + lastTimestamp = currentPacket.getTimestampBegin(); } else { getBitBuffer().setByteBuffer(null); @@ -273,7 +275,7 @@ public class StreamInputPacketReader implements IDefinitionScope { */ public boolean hasMoreEvents() { if (currentPacket != null) { - return getBitBuffer().position() < currentPacket.contentSizeBits; + return getBitBuffer().position() < currentPacket.getContentSizeBits(); } return false; } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java index 25a3b2b2d6..7c4bf08676 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java @@ -12,10 +12,13 @@ package org.eclipse.linuxtools.ctf.core.trace; +import java.nio.ByteOrder; import java.util.ListIterator; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; /** * StreamInputReader @@ -88,8 +91,8 @@ public class StreamInputReader { return this.packetReader.getStreamPacketContextDef(); } - public StreamInput getStreamInput() { - return this.streamInput; + public ByteOrder getByteOrder() { + return streamInput.getStream().getTrace().getByteOrder(); } public int getName() { @@ -104,6 +107,17 @@ public class StreamInputReader { return this.packetReader.getCPU(); } + public String getFilename() { + return streamInput.getFilename(); + } + + /* + * for internal use only + */ + StreamInput getStreamInput() { + return streamInput; + } + // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ @@ -140,8 +154,9 @@ public class StreamInputReader { * Change the current packet of the packet reader to the next one. */ private void goToNextPacket() { - if (this.packetIndexIt.hasNext()) { - this.packetReader.setCurrentPacket(this.packetIndexIt.next()); + if (getPacketIndexIt().hasNext()) { + StreamInputPacketIndexEntry nextPacket = getPacketIndexIt().next(); + this.packetReader.setCurrentPacket(nextPacket); } else { this.packetReader.setCurrentPacket(null); } @@ -154,7 +169,8 @@ public class StreamInputReader { * @param timestamp * The timestamp to seek to. */ - public void seek(long timestamp) { + public long seek(long timestamp) { + long offset = 0; /* * Search in the index for the packet to search in. */ @@ -175,19 +191,62 @@ public class StreamInputReader { while (!done && (this.getCurrentEvent().timestamp < timestamp)) { readNextEvent(); done = (this.getCurrentEvent() == null); + offset++; } + return offset; + } + + public long seekIndex(long index) throws CTFReaderException { + /* + * Search in the index for the packet to search in. + */ + this.packetIndexIt = this.streamInput.getIndex().searchIndex(index); + /* + * Switch to this packet. + */ + goToNextPacket(); + /* + * Read the first packet + */ + readNextEvent(); + /* + * get the current index + */ + if (this.packetReader.getCurrentPacket() == null) { + throw new CTFReaderException( + "Current packet null in index seek, did you index your trace yet?"); + } + return this.packetReader.getCurrentPacket().getIndexBegin(); + } public void goToLastEvent() throws CTFReaderException { /* * Search in the index for the packet to search in. */ - this.packetIndexIt = this.streamInput.getIndex().search(Long.MAX_VALUE); + int len = this.streamInput.getIndex().getEntries().size(); + int back = 0; + long desired_timestamp = -1; + do { + back++; + StreamInputPacketIndexEntry entry = this.streamInput.getIndex() + .getEntries().get(len - back); + desired_timestamp = entry.getTimestampBegin() + 1; + seek(desired_timestamp); + + } while (!this.packetReader.hasMoreEvents()); /* * Go until the end of that packet */ + + int packet_size = 0; while (this.packetReader.hasMoreEvents()) { this.packetReader.readNextEvent(); + packet_size++; + } + seek(desired_timestamp); + for (int i = 0; i < (packet_size - 1); i++) { + this.packetReader.readNextEvent(); } } @@ -195,4 +254,18 @@ public class StreamInputReader { this.currentEvent = currentEvent; } + /** + * @return the packetIndexIt + */ + private ListIterator getPacketIndexIt() { + return packetIndexIt; + } + + /** + * @return the packetReader + */ + public StreamInputPacketReader getPacketReader() { + return packetReader; + } + } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/io/BitBuffer.java similarity index 99% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/io/BitBuffer.java index 64dc466dce..04e54908b3 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/io/BitBuffer.java @@ -10,7 +10,7 @@ * Contributors: Francis Giraldeau - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.event.io; +package org.eclipse.linuxtools.internal.ctf.core.event.io; import java.nio.BufferOverflowException; import java.nio.ByteBuffer; diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java similarity index 98% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java index 57e887ecde..82ed90b630 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java @@ -10,15 +10,15 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.event.metadata; +package org.eclipse.linuxtools.internal.ctf.core.event.metadata; import java.util.HashMap; -import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; +import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; /** * DeclarationScope diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/IOStructGen.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java similarity index 99% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/IOStructGen.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java index 519f44d601..40588ebf36 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/IOStructGen.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java @@ -10,7 +10,7 @@ * Contributors: Francis Giraldeau - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.event.metadata; +package org.eclipse.linuxtools.internal.ctf.core.event.metadata; import java.io.FileNotFoundException; import java.io.IOException; @@ -25,7 +25,6 @@ import java.util.UUID; import org.antlr.runtime.tree.CommonTree; import org.eclipse.linuxtools.ctf.core.event.CTFClock; import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; -import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration; @@ -36,9 +35,10 @@ import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; -import org.eclipse.linuxtools.ctf.core.trace.Stream; import org.eclipse.linuxtools.ctf.parser.CTFParser; import org.eclipse.linuxtools.internal.ctf.core.Activator; +import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; /* * Asserts throughout this class denote the assumptions we can make because of diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/ParseException.java similarity index 92% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/ParseException.java index f4eb8a4502..48055d96aa 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/ParseException.java @@ -10,7 +10,7 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.event.metadata.exceptions; +package org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions; /** * ParseException diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java similarity index 96% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java index 473eeaa044..9a83d84f63 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java @@ -10,15 +10,16 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.trace; +package org.eclipse.linuxtools.internal.ctf.core.trace; import java.util.HashMap; import java.util.HashSet; import java.util.Set; import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; -import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; /** * Stream diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java similarity index 80% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java index 236b6ad312..931b5d332a 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java @@ -10,7 +10,7 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.trace; +package org.eclipse.linuxtools.internal.ctf.core.trace; import java.io.File; import java.io.IOException; @@ -19,12 +19,14 @@ import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; import java.util.UUID; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.Utils; +import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * StreamInput @@ -116,6 +118,7 @@ public class StreamInput implements IDefinitionScope { // Operations // ------------------------------------------------------------------------ + @SuppressWarnings("unused") @Override public Definition lookupDefinition(String lookupPath) { /* TODO: lookup in different dynamic scopes is not supported yet. */ @@ -171,13 +174,13 @@ public class StreamInput implements IDefinitionScope { * Create the definitions we need to read the packet headers + contexts */ if (getStream().getTrace().getPacketHeader() != null) { - tracePacketHeaderDef = getStream().getTrace().getPacketHeader().createDefinition( - this, "trace.packet.header"); //$NON-NLS-1$ + tracePacketHeaderDef = getStream().getTrace().getPacketHeader() + .createDefinition(this, "trace.packet.header"); //$NON-NLS-1$ } if (getStream().getPacketContextDecl() != null) { - streamPacketContextDef = getStream().getPacketContextDecl().createDefinition( - this, "stream.packet.context"); //$NON-NLS-1$ + streamPacketContextDef = getStream().getPacketContextDecl() + .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$ } /* @@ -219,7 +222,8 @@ public class StreamInput implements IDefinitionScope { /* * Check the CTF magic number */ - IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef.lookupDefinition("magic"); //$NON-NLS-1$ + IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef + .lookupDefinition("magic"); //$NON-NLS-1$ if (magicDef != null) { int magic = (int) magicDef.getValue(); if (magic != Utils.CTF_MAGIC) { @@ -232,12 +236,14 @@ public class StreamInput implements IDefinitionScope { /* * Check the trace UUID */ - ArrayDefinition uuidDef = (ArrayDefinition) tracePacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$ + ArrayDefinition uuidDef = (ArrayDefinition) tracePacketHeaderDef + .lookupDefinition("uuid"); //$NON-NLS-1$ if (uuidDef != null) { byte[] uuidArray = new byte[16]; for (int i = 0; i < 16; i++) { - IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getElem(i); + IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef + .getElem(i); uuidArray[i] = (byte) uuidByteDef.getValue(); } @@ -251,7 +257,8 @@ public class StreamInput implements IDefinitionScope { /* * Check that the stream id did not change */ - IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$ + IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef + .lookupDefinition("stream_id"); //$NON-NLS-1$ if (streamIDDef != null) { long streamID = streamIDDef.getValue(); @@ -271,41 +278,51 @@ public class StreamInput implements IDefinitionScope { /* * Read the content size in bits */ - IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("content_size"); //$NON-NLS-1$ + IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef + .lookupDefinition("content_size"); //$NON-NLS-1$ if (contentSizeDef != null) { - packetIndex.contentSizeBits = (int) contentSizeDef.getValue(); + packetIndex.setContentSizeBits((int) contentSizeDef + .getValue()); } else { - packetIndex.contentSizeBits = (int) (fileSizeBytes * 8); + packetIndex.setContentSizeBits((int) (fileSizeBytes * 8)); } /* * Read the packet size in bits */ - IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("packet_size"); //$NON-NLS-1$ + IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef + .lookupDefinition("packet_size"); //$NON-NLS-1$ if (packetSizeDef != null) { - packetIndex.packetSizeBits = (int) packetSizeDef.getValue(); + packetIndex.setPacketSizeBits((int) packetSizeDef + .getValue()); } else { - if (packetIndex.contentSizeBits != 0) { - packetIndex.packetSizeBits = packetIndex.contentSizeBits; + if (packetIndex.getContentSizeBits() != 0) { + packetIndex.setPacketSizeBits(packetIndex + .getContentSizeBits()); } else { - packetIndex.packetSizeBits = (int) (fileSizeBytes * 8); + packetIndex + .setPacketSizeBits((int) (fileSizeBytes * 8)); } } /* * Read the begin timestamp */ - IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("timestamp_begin"); //$NON-NLS-1$ + IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef + .lookupDefinition("timestamp_begin"); //$NON-NLS-1$ if (timestampBeginDef != null) { - packetIndex.timestampBegin = timestampBeginDef.getValue(); + packetIndex.setTimestampBegin( timestampBeginDef.getValue()); } /* * Read the end timestamp */ - IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("timestamp_end"); //$NON-NLS-1$ + IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef + .lookupDefinition("timestamp_end"); //$NON-NLS-1$ if (timestampEndDef != null) { - setTimestampEnd(packetIndex.timestampEnd = timestampEndDef.getValue()); + packetIndex.setTimestampEnd(timestampEndDef + .getValue()); + setTimestampEnd(packetIndex.getTimestampEnd()); } } else { /* @@ -313,16 +330,16 @@ public class StreamInput implements IDefinitionScope { * size from the file size (assume that there is only one packet * and no padding) */ - packetIndex.contentSizeBits = (int) (fileSizeBytes * 8); - packetIndex.packetSizeBits = (int) (fileSizeBytes * 8); + packetIndex.setContentSizeBits( (int) (fileSizeBytes * 8)); + packetIndex.setPacketSizeBits( (int) (fileSizeBytes * 8)); } /* Basic validation */ - if (packetIndex.contentSizeBits > packetIndex.packetSizeBits) { + if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) { throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$ } - if (packetIndex.packetSizeBits > ((fileSizeBytes - packetIndex.offsetBytes) * 8)) { + if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex.getOffsetBytes()) * 8)) { throw new CTFReaderException( "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$ } @@ -330,7 +347,7 @@ public class StreamInput implements IDefinitionScope { /* * Offset in the file, in bits */ - packetIndex.dataOffsetBits = bitBuffer.position(); + packetIndex.setDataOffsetBits( bitBuffer.position()); /* * Add the packet index entry to the index @@ -340,9 +357,10 @@ public class StreamInput implements IDefinitionScope { /* * Update the counting packet offset */ - packetOffsetBytes += (packetIndex.packetSizeBits + 7) / 8; + packetOffsetBytes += (packetIndex.getPacketSizeBits() + 7) / 8; } + index.getEntries().get(0).setIndexBegin(0L); } } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java similarity index 62% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java index eae9dc4776..80723ea1be 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java @@ -10,12 +10,13 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.trace; +package org.eclipse.linuxtools.internal.ctf.core.trace; -import java.util.Collection; import java.util.ListIterator; import java.util.Vector; +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; + /** * StreamInputPacketIndex *

@@ -37,7 +38,7 @@ public class StreamInputPacketIndex { // Getters/Setters/Predicates // ------------------------------------------------------------------------ - public Collection getEntries() { + public Vector getEntries() { return this.entries; } @@ -62,16 +63,16 @@ public class StreamInputPacketIndex { */ public void addEntry(StreamInputPacketIndexEntry entry) throws CTFReaderException { - assert (entry.packetSizeBits != 0); - assert (entry.contentSizeBits != 0); + assert (entry.getContentSizeBits() != 0); + assert (entry.getContentSizeBits() != 0); - if (entry.timestampBegin > entry.timestampEnd) { + if (entry.getTimestampBegin() > entry.getTimestampEnd()) { throw new CTFReaderException( "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$ } if (!this.entries.isEmpty()) { - if (entry.timestampBegin < this.entries.lastElement().timestampBegin) { + if (entry.getTimestampBegin() < this.entries.lastElement().getTimestampBegin()) { throw new CTFReaderException( "Packets begin timestamp decreasing"); //$NON-NLS-1$ } @@ -122,13 +123,13 @@ public class StreamInputPacketIndex { break; } - if (timestamp < guessEntry.timestampBegin) { + if (timestamp < guessEntry.getTimestampBegin()) { /* * If the timestamp if before the begin timestamp, we know that * the packet to return is before the guess. */ max = guessI - 1; - } else if (timestamp >= guessEntry.timestampBegin) { + } else if (timestamp >= guessEntry.getTimestampBegin()) { /* * If the timestamp is after the begin timestamp, we know that * the packet to return is after the guess or is the guess. @@ -139,5 +140,63 @@ public class StreamInputPacketIndex { return this.entries.listIterator(guessI); } + /** + * Given a rank, this methods returns the first PacketIndexEntry that + * could include the rank, that is the last packet with a begin + * rank smaller than the given rank. + * + * @param index + * The rank to look for. + * @return The StreamInputPacketEntry that corresponds to the packet that + * includes the given timestamp. + */ + public ListIterator searchIndex(final long index) { + /* + * Start with min and max covering all the elements. + */ + int max = this.entries.size() - 1; + int min = 0; + int guessI; + StreamInputPacketIndexEntry guessEntry = null; + + if (index < 0) { + throw new IllegalArgumentException("rank is negative"); //$NON-NLS-1$ + } + + for (;;) { + /* + * Guess in the middle of min and max. The +1 is so that in case + * (min + 1 == max), we choose the packet at the subscript "max" + * instead of the one at "min". Otherwise, it would give an infinite + * loop. + */ + guessI = (max + min + 1) / 2; + guessEntry = this.entries.get(guessI); + + /* + * If we reached the point where we focus on a single packet, our + * search is done. + */ + if (min == max) { + break; + } + + if (index < guessEntry.getIndexBegin()) { + /* + * If the timestamp if before the begin timestamp, we know that + * the packet to return is before the guess. + */ + max = guessI - 1; + } else if (index >= guessEntry.getIndexBegin()) { + /* + * If the timestamp is after the begin timestamp, we know that + * the packet to return is after the guess or is the guess. + */ + min = guessI; + } + } + + return this.entries.listIterator(guessI); + } } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndexEntry.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndexEntry.java new file mode 100644 index 0000000000..f9968451ae --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndexEntry.java @@ -0,0 +1,216 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * 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: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.ctf.core.trace; + +/** + * StreamInputPacketIndexEntry + *

+ * Represents an entry in the index of event packets. + */ +public class StreamInputPacketIndexEntry { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + + + /** + * Offset of the packet in the file, in bytes + */ + final private long offsetBytes; + + /** + * Offset of the data in the packet, in bits + */ + private int dataOffsetBits = 0; + + /** + * Packet size, in bits + */ + private int packetSizeBits = 0; + + /** + * Content size, in bits + */ + private int contentSizeBits = 0; + + /** + * Begin timestamp + */ + private long timestampBegin = 0; + + /** + * End timestamp + */ + private long timestampEnd = 0; + + + private long indexBegin = Long.MAX_VALUE; + + private long indexEnd = Long.MAX_VALUE; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructs an index entry. + * + * @param offset + * The offset of the packet in the file, in bytes. + */ + + public StreamInputPacketIndexEntry(long offset) { + this.offsetBytes = offset; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Returns whether the packet includes (inclusively) the given timestamp in + * the begin-end timestamp range. + * + * @param ts + * The timestamp to check. + * @return True if the packet includes the timestamp. + */ + boolean includes(long ts) { + return (ts >= timestampBegin) && (ts <= timestampEnd); + } + + boolean includesIndex(long index){ + return (index >= indexBegin) && (index <= indexEnd); + } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "StreamInputPacketIndexEntry [offsetBytes=" + offsetBytes //$NON-NLS-1$ + + ", timestampBegin=" + timestampBegin + ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$ + + timestampEnd + ", indexBegin=" + indexBegin + ", indexEnd=" //$NON-NLS-1$ //$NON-NLS-2$ + + indexEnd + "]"; //$NON-NLS-1$ + } + + // ------------------------------------------------------------------------ + // Getters and Setters + // ------------------------------------------------------------------------ + + /** + * @return the offsetBytes + */ + public long getOffsetBytes() { + return offsetBytes; + } + + /** + * @return the dataOffsetBits + */ + public int getDataOffsetBits() { + return dataOffsetBits; + } + + /** + * @param dataOffsetBits the dataOffsetBits to set + */ + public void setDataOffsetBits(int dataOffsetBits) { + this.dataOffsetBits = dataOffsetBits; + } + + /** + * @return the packetSizeBits + */ + public int getPacketSizeBits() { + return packetSizeBits; + } + + /** + * @param packetSizeBits the packetSizeBits to set + */ + public void setPacketSizeBits(int packetSizeBits) { + this.packetSizeBits = packetSizeBits; + } + + /** + * @return the contentSizeBits + */ + public int getContentSizeBits() { + return contentSizeBits; + } + + /** + * @param contentSizeBits the contentSizeBits to set + */ + public void setContentSizeBits(int contentSizeBits) { + this.contentSizeBits = contentSizeBits; + } + + /** + * @return the timestampBegin + */ + public long getTimestampBegin() { + return timestampBegin; + } + + /** + * @param timestampBegin the timestampBegin to set + */ + public void setTimestampBegin(long timestampBegin) { + this.timestampBegin = timestampBegin; + } + + /** + * @return the timestampEnd + */ + public long getTimestampEnd() { + return timestampEnd; + } + + /** + * @param timestampEnd the timestampEnd to set + */ + public void setTimestampEnd(long timestampEnd) { + this.timestampEnd = timestampEnd; + } + + /** + * @return the indexBegin + */ + public long getIndexBegin() { + return indexBegin; + } + + /** + * @param indexBegin the indexBegin to set + */ + public void setIndexBegin(long indexBegin) { + this.indexBegin = indexBegin; + } + + /** + * @return the indexEnd + */ + public long getIndexEnd() { + return indexEnd; + } + + /** + * @param indexEnd the indexEnd to set + */ + public void setIndexEnd(long indexEnd) { + this.indexEnd = indexEnd; + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderComparator.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderComparator.java similarity index 93% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderComparator.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderComparator.java index 1b81e0d402..105e96de5f 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderComparator.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderComparator.java @@ -10,11 +10,14 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.trace; +package org.eclipse.linuxtools.internal.ctf.core.trace; import java.io.Serializable; import java.util.Comparator; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; + + /** * StreamInputReaderComparator *

diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java similarity index 94% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java index 0971758fdc..7bc12e79b8 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java @@ -10,11 +10,14 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.trace; +package org.eclipse.linuxtools.internal.ctf.core.trace; import java.io.Serializable; import java.util.Comparator; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; + + /** * StreamInputReaderTimestampComparator *

diff --git a/org.eclipse.linuxtools.lttng.ui/plugin.xml b/org.eclipse.linuxtools.lttng.ui/plugin.xml index 88dd6d8b60..55cbd7dfc1 100644 --- a/org.eclipse.linuxtools.lttng.ui/plugin.xml +++ b/org.eclipse.linuxtools.lttng.ui/plugin.xml @@ -433,6 +433,14 @@ class="org.eclipse.linuxtools.internal.lttng.ui.views.events.EventsTable"> + + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/events/EventsTable.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/events/EventsTable.java index 8952ba7996..abdcb4772b 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/events/EventsTable.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/views/events/EventsTable.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2009, 2010, 2011 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 * Francois Chouinard - Aligned columns with domain terminology @@ -15,7 +15,6 @@ package org.eclipse.linuxtools.internal.lttng.ui.views.events; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; -import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; import org.eclipse.linuxtools.tmf.ui.widgets.ColumnData; @@ -64,7 +63,7 @@ public class EventsTable extends TmfEventsTable { * @return */ @Override - protected ITmfEventField[] extractItemFields(TmfEvent event) { + protected ITmfEventField[] extractItemFields(ITmfEvent event) { ITmfEventField[] fields = new TmfEventField[0]; if (event != null) { fields = new TmfEventField[] { diff --git a/org.eclipse.linuxtools.tmf.core.tests/.classpath b/org.eclipse.linuxtools.tmf.core.tests/.classpath index 2a987e2854..a2dcfc3c80 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/.classpath +++ b/org.eclipse.linuxtools.tmf.core.tests/.classpath @@ -4,5 +4,6 @@ + diff --git a/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF index 31c3c81636..f09ae57717 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF @@ -11,5 +11,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Require-Bundle: org.junit;bundle-version="3.8.2", org.eclipse.core.runtime;bundle-version="3.7.0", org.eclipse.core.resources;bundle-version="3.7.100", - org.eclipse.linuxtools.tmf.core;bundle-version="0.4.0" + org.eclipse.linuxtools.tmf.core;bundle-version="0.4.0", + org.eclipse.linuxtools.ctf.core;bundle-version="0.1.0" Export-Package: org.eclipse.linuxtools.tmf.tests.stubs.trace;x-friends:="org.eclipse.linuxtools.tmf.ui.tests" diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java new file mode 100644 index 0000000000..f6daa8473f --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2012 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: + * Matthew Khouzam - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Vector; + +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; + +public class Benchmark { + + /** + * @param args + */ + @SuppressWarnings("nls") + public static void main(String[] args) { + final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m1"; + final int NUM_LOOPS = 100; + + // Change this to enable text output + final boolean USE_TEXT = false; + + try { + System.in.read(); + } catch (IOException e1) { + e1.printStackTrace(); + } + // Work variables + Long nbEvent = 0L; + Vector benchs = new Vector(); + CtfTmfTrace trace = null; + long start, stop; + for (int loops = 0; loops < NUM_LOOPS; loops++) { + nbEvent = 0L; + trace = new CtfTmfTrace(); + try { + trace.initTrace("Test", TRACE_PATH, CtfTmfEvent.class); + } catch (FileNotFoundException e) { + loops = NUM_LOOPS +1; + break; + } + + start = System.nanoTime(); + if (nbEvent != -1) { + CtfIterator traceReader = (CtfIterator) trace.seekEvent(0); + + start = System.nanoTime(); + CtfTmfEvent current = traceReader.getCurrentEvent(); + while (current != null) { + nbEvent++; + if (USE_TEXT) { + String output = formatDate(current.getTimestampValue()); + System.out.println("Event " + traceReader.getRank() + " Time " + + output + " type " + current.getSource() + + " on CPU " + current.getCPU()); + } + traceReader.advance(); + current = traceReader.getCurrentEvent(); + } + } + stop = System.nanoTime(); + System.out.print('.'); + double time = (stop - start) / (double) nbEvent; + benchs.add(time); + } + System.out.println(""); + double avg = 0; + for (Double val : benchs) { + avg += val; + } + avg /= benchs.size(); + System.out.println("Time to read = " + avg + " events/ns"); + for (Double val : benchs) { + System.out.print(val); + System.out.print(", "); + } + + } + + /** + * @param timestamp + * the timestamp in UTC to convert to nanoseconds. + * @return formatted string. + */ + private static String formatDate(long timestamp) { + Date d = new Date(timestamp / 1000000); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$ + String output = df.format(d) + (timestamp % 1000000000); + return output; + } + +} diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java new file mode 100644 index 0000000000..7ebfd0bae8 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * 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.tmf.core.tests.ctfadaptor.headless; + +import java.util.Vector; + +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; +import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; +import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; + +@SuppressWarnings("nls") +public class RequestBenchmark extends TmfEventRequest { + + @SuppressWarnings("unchecked") + public RequestBenchmark(Class dataType, + TmfTimeRange range, int nbRequested) { + super((Class) dataType, range, nbRequested, 1); + } + + // Path of the trace + public static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m1"; + + // *** Change this to run several time over the same trace + public static final int NB_OF_PASS = 100; + + // *** Change this to true to parse all the events in the trace + // Otherwise, events are just read + public final boolean PARSE_EVENTS = true; + + // Work variables + public static int nbEvent = 0; + public static int nbPassDone = 0; + public static TmfExperiment fExperiment = null; + public static Vector benchs = new Vector(); + + public static void main(String[] args) { + + try { + // OUr experiment will contains ONE trace + @SuppressWarnings("unchecked") + ITmfTrace[] traces = new ITmfTrace[1]; + traces[0] = new CtfTmfTrace(); + traces[0].initTrace("CtfTrace", TRACE_PATH, CtfTmfEvent.class); + // Create our new experiment + fExperiment = new TmfExperiment(CtfTmfEvent.class, + "Headless", traces); + + // Create a new time range from -infinity to +infinity + // That way, we will get "everything" in the trace + CtfTmfTimestamp ts1 = new CtfTmfTimestamp(Long.MIN_VALUE, + (CtfTmfTrace) traces[0]); + CtfTmfTimestamp ts2 = new CtfTmfTimestamp(Long.MAX_VALUE, + (CtfTmfTrace) traces[0]); + TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2); + + // We will issue a request for each "pass". + // TMF will then process them synchonously + RequestBenchmark request = null; + for (int x = 0; x < NB_OF_PASS; x++) { + request = new RequestBenchmark(CtfTmfEvent.class, tmpRange, + Integer.MAX_VALUE); + fExperiment.sendRequest(request); + nbPassDone++; + } + prev = System.nanoTime(); + } catch (NullPointerException e) { + // Silently dismiss Null pointer exception + // The only way to "finish" the threads in TMF is by crashing them + // with null + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Override + public void handleData(CtfTmfEvent event) { + super.handleData(event); + nbEvent++; + + } + + static long prev; + static long done = 0; + @Override + public void handleCompleted() { + long next = System.nanoTime(); + double val = next - prev; + int nbEvent2 = nbEvent; + val /= nbEvent2; + + nbEvent = 0; + prev = next; + benchs.add(val); + if (benchs.size() == NB_OF_PASS) { + try { + System.out.println("Nb events : " + nbEvent2); + + for (double value : benchs) { + System.out.print(value + ", "); + } + fExperiment.sendRequest(null); + + } catch (Exception e) { + } + } + } + + @Override + public void handleSuccess() { + } + + @Override + public void handleFailure() { + } + + @Override + public void handleCancel() { + } + +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/Tracer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/Tracer.java index 8d1404d193..3262e502f7 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/Tracer.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/Tracer.java @@ -3,6 +3,7 @@ package org.eclipse.linuxtools.internal.tmf.core; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; +import java.io.OutputStreamWriter; import org.eclipse.core.runtime.Platform; import org.eclipse.linuxtools.tmf.core.component.ITmfComponent; @@ -27,7 +28,7 @@ public class Tracer { static Boolean EVENT = Boolean.FALSE; private static String LOGNAME = "trace.log"; - private static BufferedWriter fTraceLog = null; + private static BufferedWriter fTraceLog = new BufferedWriter(new OutputStreamWriter(System.out)); private static BufferedWriter openLogFile(String filename) { BufferedWriter outfile = null; @@ -93,8 +94,9 @@ public class Tracer { } public static void stop() { - if (fTraceLog == null) + if (fTraceLog == null) { return; + } try { fTraceLog.close(); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java index 8b56ceb34a..de1458b986 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java @@ -6,7 +6,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; public class CtfIterator extends CTFTraceReader implements ITmfContext, - Comparable { +Comparable { private final CtfTmfTrace ctfTmfTrace; @@ -19,7 +19,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, * * @param trace */ - public CtfIterator(CtfTmfTrace trace) { + public CtfIterator(final CtfTmfTrace trace) { super(trace.getCTFTrace()); this.ctfTmfTrace = trace; @@ -28,14 +28,13 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, this.curRank = 0; } - public CtfIterator(CtfTmfTrace trace, long timestampValue, long rank) { + public CtfIterator(final CtfTmfTrace trace, final long timestampValue, final long rank) { super(trace.getCTFTrace()); this.ctfTmfTrace = trace; - this.curLocation = (new CtfLocation( - this.getCurrentEvent().getTimestampValue())); - if (this.getCurrentEvent().getTimestampValue() != timestampValue) { + this.curLocation = (new CtfLocation(this.getCurrentEvent() + .getTimestampValue())); + if (this.getCurrentEvent().getTimestampValue() != timestampValue) this.seek(timestampValue); - } this.curRank = rank; } @@ -45,36 +44,43 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, } public CtfTmfEvent getCurrentEvent() { - StreamInputReader top = super.prio.peek(); - if (top != null) { - return new CtfTmfEvent(top.getCurrentEvent(), top, ctfTmfTrace); - } + final StreamInputReader top = super.prio.peek(); + if (top != null) + return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(), ctfTmfTrace); return null; } @Override - public boolean seek(long timestamp) { + public boolean seek(final long timestamp) { boolean ret = false; - ret = super.seek(timestamp); + final long offsetTimestamp = timestamp - this.getCtfTmfTrace().getCTFTrace().getOffset(); + if( offsetTimestamp < 0 ) + ret = super.seek(timestamp); + else + ret = super.seek(offsetTimestamp); - if (ret) { + if (ret) + curLocation.setLocation(getCurrentEvent().getTimestampValue()); + return ret; + } + + public boolean seekRank(final long rank) { + boolean ret = false; + ret = super.seekIndex(rank); + + if (ret) curLocation.setLocation(getCurrentEvent().getTimestampValue()); - } return ret; } @Override public long getRank() { - final CtfTmfEvent current = getCurrentEvent(); - if (current != null) { - return getCurrentEvent().getRank(); - } - return 0; + return super.getIndex(); } @Override - public void setRank(long rank) { - // FIXME NYI + public void setRank(final long rank) { + seekRank(rank); } /* @@ -85,8 +91,8 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, @Override public CtfIterator clone() { CtfIterator clone = null; - clone = new CtfIterator(ctfTmfTrace, - this.getCurrentEvent().getTimestampValue(), curRank); + clone = new CtfIterator(ctfTmfTrace, this.getCurrentEvent() + .getTimestampValue(), curRank); return clone; } @@ -97,9 +103,10 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, } @Override - public void setLocation(ITmfLocation location) { + public void setLocation(final ITmfLocation location) { // FIXME alex: isn't there a cleaner way than a cast here? this.curLocation = (CtfLocation) location; + seek(((CtfLocation)location).getLocation()); } @Override @@ -107,6 +114,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, return curLocation; } + @SuppressWarnings("unused") @Override public void increaseRank() { curRank++; @@ -114,7 +122,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, @Override public boolean hasValidRank() { - return true; + return (getRank() > -1); } @Override @@ -123,13 +131,12 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, } @Override - public int compareTo(CtfIterator o) { - if (this.getRank() < o.getRank()) { + public int compareTo(final CtfIterator o) { + if (this.getRank() < o.getRank()) return -1; - } else if (this.getRank() > o.getRank()) { + else if (this.getRank() > o.getRank()) return 1; - } return 0; } -} \ No newline at end of file +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java index a44610d35f..e935ebdc71 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java @@ -8,7 +8,7 @@ public class CtfLocation implements ITmfLocation { public CtfLocation(Long location) { setLocation(location); } - + public CtfLocation(ITmfTimestamp timestamp) { setLocation(timestamp.getValue()); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContent.java new file mode 100644 index 0000000000..00531972e6 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContent.java @@ -0,0 +1,29 @@ +package org.eclipse.linuxtools.tmf.core.ctfadaptor; + +import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; +import org.eclipse.linuxtools.tmf.core.event.TmfEventField; + +public class CtfTmfContent extends TmfEventField { + + public CtfTmfContent(String name, ITmfEventField[] fields) { + super(name, fields); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder retVal = new StringBuilder(); + for( ITmfEventField field : getFields()) { + retVal.append(field.getName()); + retVal.append(':'); + retVal.append(field.getValue()); + retVal.append(' '); + retVal.append('\t'); + } + return retVal.toString(); + } +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java index 85ee867e79..1500c504ae 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java @@ -19,13 +19,10 @@ import java.util.Map.Entry; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; -import org.eclipse.linuxtools.tmf.core.event.TmfEventField; -import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; /** * CTFEvent @@ -41,6 +38,7 @@ public final class CtfTmfEvent implements ITmfEvent { private static final String NO_STREAM = "No stream"; //$NON-NLS-1$ private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$ + private static final String CONTEXT_ID = "Ctf Event"; //$NON-NLS-1$ // ------------------------------------------------------------------------ // Attributes @@ -53,7 +51,7 @@ public final class CtfTmfEvent implements ITmfEvent { private final String eventName; private final String fileName; - private final TmfEventField fContent; + private final CtfTmfContent fContent; // ------------------------------------------------------------------------ // Constructors @@ -66,7 +64,7 @@ public final class CtfTmfEvent implements ITmfEvent { * @param eventDef * @param top */ - public CtfTmfEvent(EventDefinition eventDef, StreamInputReader top, + public CtfTmfEvent(EventDefinition eventDef, String fileName, CtfTmfTrace originTrace) { this.fTrace = originTrace; @@ -81,17 +79,15 @@ public final class CtfTmfEvent implements ITmfEvent { } /* Read the base event info */ - // FIXME restore once the CTF parser with clocks gets merged - //Long offset = originTrace.getCTFTrace().getOffset(); - Long offset = 0L; + Long offset = originTrace.getCTFTrace().getOffset(); this.timestamp = eventDef.timestamp + offset; this.sourceCPU = eventDef.getCPU(); this.typeId = eventDef.getDeclaration().getId(); this.eventName = eventDef.getDeclaration().getName(); - this.fileName = top.getStreamInput().getFilename(); + this.fileName = fileName; /* Read the fields */ - this.fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, + this.fContent = new CtfTmfContent(ITmfEventField.ROOT_FIELD_ID, parseFields(eventDef)); } @@ -143,14 +139,14 @@ public final class CtfTmfEvent implements ITmfEvent { this.fileName = other.fileName; /* Copy the fields over */ - this.fContent = other.fContent.clone(); + this.fContent = (CtfTmfContent) other.fContent.clone(); } /** * Inner constructor to create "null" events. Don't use this directly, use * CTFEvent.getNullEvent(); */ - private CtfTmfEvent() { + public CtfTmfEvent() { this.fTrace = null; this.timestamp = -1; this.sourceCPU = -1; @@ -243,21 +239,28 @@ public final class CtfTmfEvent implements ITmfEvent { @Override public ITmfTimestamp getTimestamp() { if (fTimestamp == null) { - fTimestamp = new TmfTimestamp(timestamp); + fTimestamp = new CtfTmfTimestamp(timestamp, fTrace); } return fTimestamp; } + String fSource = null; @Override public String getSource() { - // TODO Returns eventName for now - return eventName; + // TODO Returns CPU for now + if(fSource == null) { + fSource= Integer.toString(getCPU()); + } + return fSource; } + private CtfTmfEventType type = null; @Override public ITmfEventType getType() { - // TODO Auto-generated method stub - return null; + if(type == null){ + type = new CtfTmfEventType(CONTEXT_ID, eventName, fContent); + } + return type; } @Override @@ -265,10 +268,13 @@ public final class CtfTmfEvent implements ITmfEvent { return fContent; } + String fReference = null; @Override public String getReference() { - // TODO Auto-generated method stub - return null; + if( fReference == null){ + fReference = getChannelName(); + } + return fReference; } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java index 20234a1fde..c7b71e02ba 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java @@ -138,7 +138,7 @@ public abstract class CtfTmfEventField implements ITmfEventField { /** * Return the int representing this field's value type - * + * * @return the field type */ public abstract int getFieldType(); @@ -146,7 +146,7 @@ public abstract class CtfTmfEventField implements ITmfEventField { /** * Return this field's value. You can cast it to the correct type depending * on what getFieldType says. - * + * * @return the field value */ @Override @@ -155,7 +155,7 @@ public abstract class CtfTmfEventField implements ITmfEventField { /** * Other methods defined by ITmfEventField, but not used here: the CTF * fields do not have sub-fields (yet!) - * + * * @return the field names */ @Override @@ -163,6 +163,7 @@ public abstract class CtfTmfEventField implements ITmfEventField { return null; } + @SuppressWarnings("unused") @Override public String getFieldName(int index) { return null; @@ -173,11 +174,13 @@ public abstract class CtfTmfEventField implements ITmfEventField { return null; } + @SuppressWarnings("unused") @Override public ITmfEventField getField(String fieldName) { return null; } + @SuppressWarnings("unused") @Override public ITmfEventField getField(int index) { return null; @@ -212,7 +215,7 @@ final class CTFIntegerField extends CtfTmfEventField { /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ @Override @@ -245,7 +248,7 @@ final class CTFStringField extends CtfTmfEventField { /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventType.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventType.java new file mode 100644 index 0000000000..612abc056c --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventType.java @@ -0,0 +1,18 @@ +package org.eclipse.linuxtools.tmf.core.ctfadaptor; + +import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; +import org.eclipse.linuxtools.tmf.core.event.TmfEventType; + +public class CtfTmfEventType extends TmfEventType { + + public CtfTmfEventType(String contextId, String eventName, + ITmfEventField content) { + super(contextId, eventName, content); + } + + @Override + public String toString() + { + return this.getName(); + } +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java new file mode 100644 index 0000000000..c9193943bd --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java @@ -0,0 +1,84 @@ +package org.eclipse.linuxtools.tmf.core.ctfadaptor; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; + +public class CtfTmfTimestamp extends TmfTimestamp implements ITmfTimestamp { + + final private CtfTmfTrace fTrace; + + public CtfTmfTimestamp(long timestamp, CtfTmfTrace trace) { + fTrace = trace; + fValue = timestamp; + fScale = (byte) -9; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = (prime * result) + ((fTrace == null) ? 0 : fTrace.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof CtfTmfTimestamp)) { + return false; + } + CtfTmfTimestamp other = (CtfTmfTimestamp) obj; + if (fTrace == null) { + if (other.fTrace != null) { + return false; + } + } else if (!fTrace.equals(other.fTrace)) { + return false; + } + return true; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + final long timestamp = fValue; + final Date d = new Date(timestamp / 1000000); + final DateFormat df = new SimpleDateFormat("HH:mm:ss."); //$NON-NLS-1$ + final long nanos = (timestamp % 1000000000); + StringBuilder output = new StringBuilder(); + output.append(df.format(d)); + output.append(String.format("%09d", nanos)); //$NON-NLS-1$ + return output.toString(); + } + + public String toFullDateString(){ + final long timestamp = fValue; + final Date d = new Date(timestamp / 1000000); + final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$ + final long nanos = (timestamp % 1000000000); + StringBuilder output = new StringBuilder(); + output.append(df.format(d)); + output.append(String.format("%09d", nanos)); //$NON-NLS-1$ + return output.toString(); + } + +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java index 65e7998435..a4c7616eaf 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java @@ -1,7 +1,6 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor; import java.io.FileNotFoundException; -import java.util.Vector; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -18,7 +17,6 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; -import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; public class CtfTmfTrace extends TmfEventProvider implements ITmfTrace { @@ -27,10 +25,6 @@ public class CtfTmfTrace extends TmfEventProvider implements // Constants // ------------------------------------------------------------------------ - // The default number of events to cache - // TODO: Make the DEFAULT_CACHE_SIZE a preference - public static final int DEFAULT_INDEX_PAGE_SIZE = 50000; - // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ @@ -38,12 +32,6 @@ public class CtfTmfTrace extends TmfEventProvider implements // the Ctf Trace private CTFTrace fTrace; - // The cache page size AND checkpoints interval - protected int fIndexPageSize = DEFAULT_INDEX_PAGE_SIZE; - - // The set of event stream checkpoints (for random access) - private Vector fCheckpoints = new Vector(); - // The number of events collected protected long fNbEvents = 0; @@ -69,6 +57,7 @@ public class CtfTmfTrace extends TmfEventProvider implements super(); } + @SuppressWarnings("unused") @Override public void initTrace(String name, String path, Class eventType) throws FileNotFoundException { @@ -80,7 +69,6 @@ public class CtfTmfTrace extends TmfEventProvider implements * was not found or was not recognized as a CTF trace. Throw into * the new type of exception expected by the rest of TMF. */ - System.err.println("Cannot find file " + path); //$NON-NLS-1$ throw new FileNotFoundException(e.getMessage()); } this.iterator = new CtfIterator(this, 0, 0); @@ -95,8 +83,10 @@ public class CtfTmfTrace extends TmfEventProvider implements // this.fEndTime.clone())); } + @SuppressWarnings("unused") @Override public void indexTrace(boolean waitForCompletion) { + // do nothing } @Override @@ -109,6 +99,7 @@ public class CtfTmfTrace extends TmfEventProvider implements TmfSignalManager.dispatchSignal(signal); } + @SuppressWarnings("unused") @Override public boolean validate(IProject project, String path) { try { @@ -124,7 +115,6 @@ public class CtfTmfTrace extends TmfEventProvider implements public CtfTmfTrace clone() throws CloneNotSupportedException { CtfTmfTrace clone = null; clone = (CtfTmfTrace) super.clone(); - clone.setfCheckpoints(this.fCheckpoints); clone.fStartTime = this.fStartTime.clone(); clone.fEndTime = this.fEndTime.clone(); clone.fTrace = this.fTrace; @@ -135,6 +125,21 @@ public class CtfTmfTrace extends TmfEventProvider implements // Accessors // ------------------------------------------------------------------------ + public int getNbEnvVars() { + return this.fTrace.getEnvironment().size(); + } + + + public String[] getEnvNames() { + String[] s = new String[getNbEnvVars()]; + return this.fTrace.getEnvironment().keySet().toArray(s); + } + + public String getEnvValue(String key) { + return this.fTrace.getEnvironment().get(key); + } + + /** * @return the trace path */ @@ -155,7 +160,7 @@ public class CtfTmfTrace extends TmfEventProvider implements @Override public int getIndexPageSize() { - return this.fIndexPageSize; + return 50000; // not true, but it works } @Override @@ -213,10 +218,14 @@ public class CtfTmfTrace extends TmfEventProvider implements @Override public ITmfContext armRequest(ITmfDataRequest request) { if ((request instanceof ITmfEventRequest) - && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime()) + && !TmfTimestamp.BIG_BANG + .equals(((ITmfEventRequest) request) + .getRange().getStartTime()) && (request.getIndex() == 0)) { - ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime()); - ((ITmfEventRequest) request).setStartIndex((int) context.getRank()); + ITmfContext context = seekEvent(((ITmfEventRequest) request) + .getRange().getStartTime()); + ((ITmfEventRequest) request) + .setStartIndex((int) context.getRank()); return context; } return seekEvent(request.getIndex()); @@ -225,13 +234,14 @@ public class CtfTmfTrace extends TmfEventProvider implements /** * The trace reader keeps its own iterator: the "context" parameter here * will be ignored. - * + * * If you wish to specify a new context, instantiate a new CtfIterator and * seek() it to where you want, and use that to read events. - * + * * FIXME merge with getNextEvent below once they both use the same parameter * type. */ + @SuppressWarnings("unused") @Override public CtfTmfEvent getNext(ITmfContext context) { iterator.advance(); @@ -244,13 +254,21 @@ public class CtfTmfTrace extends TmfEventProvider implements @Override public ITmfContext seekLocation(ITmfLocation location) { - iterator.setLocation(location); + CtfLocation currentLocation = (CtfLocation) location; + if (currentLocation == null) { + currentLocation = new CtfLocation(0L); + } + iterator.setLocation(currentLocation); return iterator; } @Override public double getLocationRatio(ITmfLocation location) { - return 0; + CtfLocation curLocation = (CtfLocation) location; + iterator.seek(curLocation.getLocation()); + return ((double) iterator.getCurrentEvent().getTimestampValue() - iterator + .getStartTime()) + / (iterator.getEndTime() - iterator.getStartTime()); } @Override @@ -282,25 +300,19 @@ public class CtfTmfTrace extends TmfEventProvider implements return iterator; } + @SuppressWarnings("unused") @Override public CtfTmfEvent getNextEvent(ITmfContext context) { iterator.advance(); return iterator.getCurrentEvent(); } + @SuppressWarnings("unused") @Override public CtfTmfEvent parseEvent(ITmfContext context) { return iterator.getCurrentEvent(); } - public Vector getfCheckpoints() { - return this.fCheckpoints; - } - - public void setfCheckpoints(Vector fCheckpoints) { - this.fCheckpoints = fCheckpoints; - } - @Override public IResource getResource() { return this.fResource; @@ -315,4 +327,6 @@ public class CtfTmfTrace extends TmfEventProvider implements return fTrace; } + + } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java index bbaa8fe085..14a40e197b 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2009, 2010 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 *******************************************************************************/ @@ -286,26 +286,22 @@ public class TmfExperiment extends TmfEventProvider impl // ------------------------------------------------------------------------ @Override public ITmfContext armRequest(final ITmfDataRequest request) { -// Tracer.trace("Ctx: Arming request - start"); - ITmfTimestamp timestamp = (request instanceof ITmfEventRequest) ? ((ITmfEventRequest) request).getRange() - .getStartTime() - : null; - + // Tracer.trace("Ctx: Arming request - start"); + ITmfTimestamp timestamp = (request instanceof ITmfEventRequest) ? ((ITmfEventRequest) request).getRange().getStartTime() : null; if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0) timestamp = null; // use request index - TmfExperimentContext context = null; if (timestamp != null) { // seek by timestamp context = seekEvent(timestamp); ((ITmfEventRequest) request).setStartIndex((int) context.getRank()); } else // Seek by rank - if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex()) - // We are already at the right context -> no need to seek - context = fExperimentContext; - else - context = seekEvent(request.getIndex()); -// Tracer.trace("Ctx: Arming request - done"); + if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex()) + // We are already at the right context -> no need to seek + context = fExperimentContext; + else + context = seekEvent(request.getIndex()); + // Tracer.trace("Ctx: Arming request - done"); return context; } @@ -334,12 +330,11 @@ public class TmfExperiment extends TmfEventProvider impl // Instantiate the location final TmfExperimentLocation expLocation = (location == null) ? new TmfExperimentLocation(new TmfLocationArray( - new ITmfLocation[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location - .clone(); + new ITmfLocation[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location.clone(); // Create and populate the context's traces contexts - final TmfExperimentContext context = new TmfExperimentContext(fTraces, new TmfContext[fTraces.length]); -// Tracer.trace("Ctx: SeekLocation - start"); + final TmfExperimentContext context = new TmfExperimentContext(fTraces, new ITmfContext[fTraces.length]); + // Tracer.trace("Ctx: SeekLocation - start"); long rank = 0; for (int i = 0; i < fTraces.length; i++) { @@ -357,11 +352,11 @@ public class TmfExperiment extends TmfEventProvider impl * The (TmfContext) cast should be safe since we created 'context' * ourselves higher up. */ - expLocation.getLocation().locations[i] = ((TmfContext) context.getContexts()[i]).getLocation().clone(); + expLocation.getLocation().locations[i] = context.getContexts()[i].getLocation().clone(); context.getEvents()[i] = fTraces[i].getNextEvent(context.getContexts()[i]); } -// Tracer.trace("Ctx: SeekLocation - done"); + // Tracer.trace("Ctx: SeekLocation - done"); // Finalize context context.setLocation(expLocation); @@ -375,15 +370,12 @@ public class TmfExperiment extends TmfEventProvider impl /* * (non-Javadoc) - * - * @see - * org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools - * .tmf.event.TmfTimestamp) + * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp) */ @Override public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) { -// Tracer.trace("Ctx: seekEvent(TS) - start"); + // Tracer.trace("Ctx: seekEvent(TS) - start"); if (timestamp == null) timestamp = TmfTimestamp.BIG_BANG; @@ -413,7 +405,7 @@ public class TmfExperiment extends TmfEventProvider impl // And locate the event ITmfEvent event = parseEvent(context); - while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { + while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) { getNextEvent(context); event = parseEvent(context); } @@ -428,13 +420,13 @@ public class TmfExperiment extends TmfEventProvider impl /* * (non-Javadoc) - * + * * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long) */ @Override public synchronized TmfExperimentContext seekEvent(final long rank) { -// Tracer.trace("Ctx: seekEvent(rank) - start"); + // Tracer.trace("Ctx: seekEvent(rank) - start"); // Position the stream at the previous checkpoint int index = (int) rank / fIndexPageSize; @@ -455,7 +447,7 @@ public class TmfExperiment extends TmfEventProvider impl // And locate the event ITmfEvent event = parseEvent(context); long pos = context.getRank(); - while (event != null && pos++ < rank) { + while ((event != null) && (pos++ < rank)) { getNextEvent(context); event = parseEvent(context); } @@ -488,22 +480,22 @@ public class TmfExperiment extends TmfEventProvider impl return null; } -// private void dumpContext(TmfExperimentContext context, boolean isBefore) { + // private void dumpContext(TmfExperimentContext context, boolean isBefore) { -// TmfContext context0 = context.getContexts()[0]; -// TmfEvent event0 = context.getEvents()[0]; -// TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation(); -// long rank0 = context.getRank(); -// int trace = context.getLastTrace(); -// -// StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A ")); -// -// result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] "); -// result.append("[Evt: " + event0.getTimestamp().toString() + "] "); -// result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] "); -// result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]"); -// Tracer.trace(result.toString()); -// } + // TmfContext context0 = context.getContexts()[0]; + // TmfEvent event0 = context.getEvents()[0]; + // TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation(); + // long rank0 = context.getRank(); + // int trace = context.getLastTrace(); + // + // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A ")); + // + // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] "); + // result.append("[Evt: " + event0.getTimestamp().toString() + "] "); + // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] "); + // result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]"); + // Tracer.trace(result.toString()); + // } /** * Scan the next events from all traces and return the next one in @@ -525,7 +517,7 @@ public class TmfExperiment extends TmfEventProvider impl final TmfExperimentContext expContext = (TmfExperimentContext) context; -// dumpContext(expContext, true); + // dumpContext(expContext, true); // If an event was consumed previously, get the next one from that trace final int lastTrace = expContext.getLastTrace(); @@ -564,10 +556,10 @@ public class TmfExperiment extends TmfEventProvider impl final ITmfContext traceContext = expContext.getContexts()[trace]; final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation(); -// expLocation.getLocation()[trace] = traceContext.getLocation().clone(); + // expLocation.getLocation()[trace] = traceContext.getLocation().clone(); expLocation.getLocation().locations[trace] = traceContext.getLocation().clone(); -// updateIndex(expContext, timestamp); + // updateIndex(expContext, timestamp); expLocation.getRanks()[trace] = traceContext.getRank(); expContext.setLastTrace(trace); @@ -576,11 +568,11 @@ public class TmfExperiment extends TmfEventProvider impl fExperimentContext = expContext; } -// if (event != null) { -// Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString()); -// dumpContext(expContext, false); -// Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString()); -// } + // if (event != null) { + // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString()); + // dumpContext(expContext, false); + // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString()); + // } return event; } @@ -595,18 +587,14 @@ public class TmfExperiment extends TmfEventProvider impl if (fCheckpoints.size() == position) { final ITmfLocation location = context.getLocation().clone(); fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location)); -// System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " -// + location.toString()); + // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + // + location.toString()); } } } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools - * .tmf.trace.TmfContext) + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext) */ @Override public ITmfEvent parseEvent(final ITmfContext context) { @@ -653,7 +641,7 @@ public class TmfExperiment extends TmfEventProvider impl /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ @Override @@ -761,16 +749,16 @@ public class TmfExperiment extends TmfEventProvider impl private Integer fEndSynchReference; -// private static BufferedWriter fEventLog = null; -// private static BufferedWriter openLogFile(String filename) { -// BufferedWriter outfile = null; -// try { -// outfile = new BufferedWriter(new FileWriter(filename)); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// return outfile; -// } + // private static BufferedWriter fEventLog = null; + // private static BufferedWriter openLogFile(String filename) { + // BufferedWriter outfile = null; + // try { + // outfile = new BufferedWriter(new FileWriter(filename)); + // } catch (IOException e) { + // e.printStackTrace(); + // } + // return outfile; + // } protected boolean isIndexingBusy() { synchronized (fCheckpoints) { @@ -809,15 +797,15 @@ public class TmfExperiment extends TmfEventProvider impl }; job.schedule(); -// fEventLog = openLogFile("TraceEvent.log"); -// System.out.println(System.currentTimeMillis() + ": Experiment indexing started"); + // fEventLog = openLogFile("TraceEvent.log"); + // System.out.println(System.currentTimeMillis() + ": Experiment indexing started"); final ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, timeRange, index, TmfDataRequest.ALL_DATA, fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA - // FOREGROUND + // FOREGROUND -// long indexingStart = System.nanoTime(); + // long indexingStart = System.nanoTime(); ITmfTimestamp startTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getStartTime(); ITmfTimestamp lastTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getEndTime(); @@ -843,7 +831,7 @@ public class TmfExperiment extends TmfEventProvider impl @Override public void handleSuccess() { -// long indexingEnd = System.nanoTime(); + // long indexingEnd = System.nanoTime(); // if the end time is a real value then it is the streaming safe // time stamp @@ -852,13 +840,13 @@ public class TmfExperiment extends TmfEventProvider impl if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH) lastTime = getRange().getEndTime(); updateExperiment(); -// System.out.println(System.currentTimeMillis() + ": Experiment indexing completed"); + // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed"); -// long average = (indexingEnd - indexingStart) / fNbEvents; -// System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" -// + (indexingEnd * 1.0 - indexingStart) / 1000000000); -// System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "." -// + (average % 1000) + " us/evt)"); + // long average = (indexingEnd - indexingStart) / fNbEvents; + // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" + // + (indexingEnd * 1.0 - indexingStart) / 1000000000); + // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "." + // + (average % 1000) + " us/evt)"); super.handleSuccess(); } @@ -880,8 +868,8 @@ public class TmfExperiment extends TmfEventProvider impl if (startTime != null) fTimeRange = new TmfTimeRange(startTime, lastTime.clone()); if (nbRead != 0) { -// updateTimeRange(); -// updateNbEvents(); + // updateTimeRange(); + // updateNbEvents(); fNbEvents = initialNbEvents + nbRead; notifyListeners(); } @@ -922,7 +910,6 @@ public class TmfExperiment extends TmfEventProvider impl fEndSynchReference = null; initializeStreamingMonitor(); } - } @TmfSignalHandler diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java index 20809ec3e8..8670897ee5 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2009, 2010 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 *******************************************************************************/ @@ -24,9 +24,16 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; * The experiment keeps track of the next event from each of its traces so it * can pick the next one in chronological order. *

+<<<<<<< HEAD * This implies that the "next" event from each trace has already been read and * that we at least know its timestamp. This doesn't imply that a full parse of * the event content was performed (read: LTTng works like this). +======= + * This implies that the "next" event from each trace has already been + * read and that we at least know its timestamp. This doesn't imply that a + * full parse of the event content was performed (read: LTTng works like + * this). +>>>>>>> refs/heads/master *

* The last trace refers to the trace from which the last event was "consumed" * at the experiment level. @@ -45,7 +52,7 @@ public class TmfExperimentContext extends TmfContext { private ITmfTrace[] fTraces = new ITmfTrace[0]; private final ITmfContext[] fContexts; - private final ITmfEvent[] fEvents; + private ITmfEvent[] fEvents; private int lastTraceRead; // ------------------------------------------------------------------------ @@ -73,25 +80,42 @@ public class TmfExperimentContext extends TmfContext { lastTraceRead = NO_TRACE; } + public TmfExperimentContext(final TmfExperimentContext other) { + this(other.fTraces, other.cloneContexts()); + fEvents = other.fEvents; + if (other.getLocation() != null) + setLocation(other.getLocation().clone()); + setRank(other.getRank()); + setLastTrace(other.lastTraceRead); + } + public TmfExperimentContext(final ITmfTrace[] traces) { this(traces, new TmfContext[traces.length]); } -// public TmfExperimentContext(TmfExperimentContext other) { -// this(other.fTraces, other.cloneContexts()); -// fEvents = other.fEvents; -// if (other.getLocation() != null) -// setLocation(other.getLocation().clone()); -// setRank(other.getRank()); -// setLastTrace(other.lastTraceRead); -// } - -// private ITmfContext[] cloneContexts() { -// ITmfContext[] contexts = new TmfContext[fContexts.length]; -// for (int i = 0; i < fContexts.length; i++) -// contexts[i] = fContexts[i].clone(); -// return contexts; -// } + private ITmfContext[] cloneContexts() { + final ITmfContext[] contexts = new ITmfContext[fContexts.length]; + for (int i = 0; i < fContexts.length; i++) + contexts[i] = fContexts[i].clone(); + return contexts; + } + + + // public TmfExperimentContext(TmfExperimentContext other) { + // this(other.fTraces, other.cloneContexts()); + // fEvents = other.fEvents; + // if (other.getLocation() != null) + // setLocation(other.getLocation().clone()); + // setRank(other.getRank()); + // setLastTrace(other.lastTraceRead); + // } + + // private ITmfContext[] cloneContexts() { + // ITmfContext[] contexts = new TmfContext[fContexts.length]; + // for (int i = 0; i < fContexts.length; i++) + // contexts[i] = fContexts[i].clone(); + // return contexts; + // } // ------------------------------------------------------------------------ // Accessors diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java index a3dc3a1a9e..3aac38af92 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2010 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: * Patrick Tasse - Initial API and implementation *******************************************************************************/ @@ -19,12 +19,12 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; public class TmfFilterNode extends TmfFilterTreeNode { - + public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$ public static final String NAME_ATTR = "name"; //$NON-NLS-1$ - + String fFilterName; - + public TmfFilterNode(String filterName) { super(null); fFilterName = filterName; @@ -63,9 +63,8 @@ public class TmfFilterNode extends TmfFilterTreeNode { public List getValidChildren() { if (getChildrenCount() == 0) { return super.getValidChildren(); - } else { - return new ArrayList(0); // only one child allowed } + return new ArrayList(0); // only one child allowed } @Override @@ -77,7 +76,7 @@ public class TmfFilterNode extends TmfFilterTreeNode { for (int i = 0; i < getChildrenCount(); i++) { ITmfFilterTreeNode node = getChildren()[i]; buf.append(node.toString()); - if (i < getChildrenCount() - 1) { + if (i < (getChildrenCount() - 1)) { buf.append(" and "); //$NON-NLS-1$ } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java index 52c5bb85de..9c6536bd55 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2010 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: * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation * Patrick Tasse - Refactoring @@ -27,7 +27,7 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; *

*/ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable { - + private static final String[] VALID_CHILDREN = { TmfFilterEventTypeNode.NODE_NAME, TmfFilterAndNode.NODE_NAME, @@ -37,7 +37,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable TmfFilterMatchesNode.NODE_NAME, TmfFilterCompareNode.NODE_NAME }; - + private ITmfFilterTreeNode parent = null; private ArrayList children = new ArrayList(); @@ -46,7 +46,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable parent.addChild(this); } } - + /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getParent() */ @@ -144,7 +144,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable this.parent = parent; } - + /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#matches(org.eclipse.linuxtools.tmf.event.TmfEvent) */ @@ -166,7 +166,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable value = event.getType().getName(); } else if (ITmfEvent.EVENT_FIELD_TIMESTAMP.equals(field)) { - value = ((Long) event.getTimestamp().getValue()).toString(); + value = event.getTimestamp().toString(); } else if (ITmfEvent.EVENT_FIELD_SOURCE.equals(field)) { value = event.getSource(); @@ -182,7 +182,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getValidChildren() - * + * * By default, all node types are valid children. Override if different. */ @Override diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index 159a30a193..26f155046f 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -32,6 +32,7 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l org.eclipse.linuxtools.tmf.ui.views.colors, org.eclipse.linuxtools.tmf.ui.views.distribution.model, org.eclipse.linuxtools.tmf.ui.views.events, + org.eclipse.linuxtools.tmf.ui.views.environment, org.eclipse.linuxtools.tmf.ui.views.filter, org.eclipse.linuxtools.tmf.ui.views.histogram, org.eclipse.linuxtools.tmf.ui.views.statistics, diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.properties b/org.eclipse.linuxtools.tmf.ui/plugin.properties index caf71c676b..e92ae2d511 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.properties +++ b/org.eclipse.linuxtools.tmf.ui/plugin.properties @@ -15,6 +15,7 @@ events.editor.name = Events Editor eventsview.editor.name = Events View uml2sd.view.name = Sequence Diagram histogram.view.name = Histogram +environment.view.name = Environment Variables wizard.category.name = Tracing project.new.wizard.name = Tracing Project diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.xml b/org.eclipse.linuxtools.tmf.ui/plugin.xml index 61e9b6b3fa..9d66f8c0b7 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui/plugin.xml @@ -35,6 +35,15 @@ id="org.eclipse.linuxtools.tmf.ui.views.timechart" name="%timechart.view.name" restorable="true"> + + columnData = new LinkedList(); for (OutputColumn outputColumn : fDefinition.outputs) { ColumnData column = new ColumnData(outputColumn.name, 0, SWT.LEFT); columnData.add(column); } - setColumnHeaders((ColumnData[]) columnData.toArray(new ColumnData[0])); + setColumnHeaders(columnData.toArray(new ColumnData[0])); } @Override - public TmfEventField[] extractItemFields(TmfEvent event) { + public TmfEventField[] extractItemFields(ITmfEvent event) { if (event instanceof CustomEvent) { TmfEventField[] fields = ((CustomEvent) event).extractItemFields(); // String[] labels = new String[fields.length]; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java index 87fdfb830a..6c3e817232 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2009, 2010, 2011 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 *******************************************************************************/ @@ -26,6 +26,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; @@ -67,15 +68,17 @@ public class OpenExperimentHandler extends AbstractHandler { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) + if (window == null) { return false; + } // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); - if (selectionProvider == null) + if (selectionProvider == null) { return false; + } ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is an experiment @@ -103,8 +106,9 @@ public class OpenExperimentHandler extends AbstractHandler { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) + if (window == null) { return false; + } try { IFile bookmarksFile = fExperiment.getProject().getExperimentsFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE); @@ -131,8 +135,8 @@ public class OpenExperimentHandler extends AbstractHandler { for (int i = 0; i < nbTraces; i++) { TmfTraceElement element = traceEntries.get(i); ITmfTrace trace = element.instantiateTrace(); - TmfEvent traceEvent = element.instantiateEvent(); - if (trace == null || traceEvent == null) { + ITmfEvent traceEvent = element.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { displayErrorMsg(Messages.OpenExperimentHandler_NoTraceType); for (int j = 0; j < i; j++) { traces[j].dispose(); @@ -168,10 +172,10 @@ public class OpenExperimentHandler extends AbstractHandler { IEditorInput editorInput = new TmfEditorInput(file, experiment); IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage(); - + String editorId = TmfEventsEditor.ID; IEditorPart editor = activePage.findEditor(new FileEditorInput(file)); - if (editor != null && editor instanceof IReusableEditor) { + if ((editor != null) && (editor instanceof IReusableEditor)) { activePage.reuseEditor((IReusableEditor) editor, editorInput); activePage.activate(editor); } else { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java index 69b6bba6ec..740f20e4a9 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2009, 2010, 2011 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 *******************************************************************************/ @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.linuxtools.tmf.core.event.TmfEvent; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; @@ -73,15 +73,17 @@ public class OpenTraceHandler extends AbstractHandler { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) + if (window == null) { return false; + } // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); - if (selectionProvider == null) + if (selectionProvider == null) { return false; + } ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is a trace @@ -109,8 +111,9 @@ public class OpenTraceHandler extends AbstractHandler { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) + if (window == null) { return null; + } // Check that the trace is valid if (fTrace == null) { @@ -128,15 +131,15 @@ public class OpenTraceHandler extends AbstractHandler { } ITmfTrace trace = fTrace.instantiateTrace(); - TmfEvent traceEvent = fTrace.instantiateEvent(); - if (trace == null || traceEvent == null) { + ITmfEvent traceEvent = fTrace.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { displayErrorMsg(Messages.OpenTraceHandler_NoTraceType); return null; } // Get the editor_id from the extension point String editorId = fTrace.getEditorId(); - boolean usesEditor = editorId != null && editorId.length() > 0; + boolean usesEditor = (editorId != null) && (editorId.length() > 0); try { trace.initTrace(fTrace.getName(), fTrace.getLocation().getPath(), traceEvent.getClass()); @@ -184,7 +187,7 @@ public class OpenTraceHandler extends AbstractHandler { IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = activePage.findEditor(new FileEditorInput(file)); - if (editor != null && editor instanceof IReusableEditor) { + if ((editor != null) && (editor instanceof IReusableEditor)) { activePage.reuseEditor((IReusableEditor) editor, editorInput); activePage.activate(editor); } else { @@ -201,7 +204,7 @@ public class OpenTraceHandler extends AbstractHandler { ITmfTrace[] traces = new ITmfTrace[] { trace }; TmfExperiment experiment = new TmfExperiment(traceEvent.getClass(), fTrace.getName(), traces, trace.getIndexPageSize()); experiment.setBookmarksFile(file); - + TmfExperiment.setCurrentExperiment(experiment); TmfSignalManager.dispatchSignal(new TmfExperimentSelectedSignal(this, experiment)); IDE.setDefaultEditor(file, EventsViewEditor.ID); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java index 0268dd5479..a4cc1dbefc 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2012 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: * Patrick Tasse - Initial API and implementation *******************************************************************************/ @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.InvalidRegistryObjectException; import org.eclipse.linuxtools.internal.tmf.ui.project.handlers.Messages; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; @@ -46,7 +47,7 @@ import org.eclipse.ui.ide.IGotoMarker; import org.eclipse.ui.part.EditorPart; /** - * + * * This editor is used to open a trace in the Events view * and set the trace as the current experiment. * It intercepts the IGotoMarker adapter and dispatches @@ -97,7 +98,7 @@ public class EventsViewEditor extends TmfEditor { throw new PartInitException("Invalid IFileEditorInput: " + input); //$NON-NLS-1$ } TmfExperiment currentExperiment = TmfExperiment.getCurrentExperiment(); - if (currentExperiment != null && fFile.equals(currentExperiment.getBookmarksFile())) { + if ((currentExperiment != null) && fFile.equals(currentExperiment.getBookmarksFile())) { fTrace = currentExperiment; super.setSite(site); super.setInput(input); @@ -128,8 +129,8 @@ public class EventsViewEditor extends TmfEditor { for (int i = 0; i < nbTraces; i++) { TmfTraceElement traceElement = traceEntries.get(i); ITmfTrace trace = traceElement.instantiateTrace(); - TmfEvent traceEvent = traceElement.instantiateEvent(); - if (trace == null || traceEvent == null) { + ITmfEvent traceEvent = traceElement.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { for (int j = 0; j < i; j++) { traces[j].dispose(); } @@ -162,8 +163,8 @@ public class EventsViewEditor extends TmfEditor { TmfTraceElement traceElement = (TmfTraceElement) projectElement; // Instantiate the experiment trace ITmfTrace trace = traceElement.instantiateTrace(); - TmfEvent traceEvent = traceElement.instantiateEvent(); - if (trace == null || traceEvent == null) { + ITmfEvent traceEvent = traceElement.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); } try { @@ -189,8 +190,8 @@ public class EventsViewEditor extends TmfEditor { TmfTraceElement traceElement = (TmfTraceElement) projectElement; // Instantiate the experiment trace ITmfTrace trace = traceElement.instantiateTrace(); - TmfEvent traceEvent = traceElement.instantiateEvent(); - if (trace == null || traceEvent == null) { + ITmfEvent traceEvent = traceElement.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); } try { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java index 9d26d4bc44..e9f736a52a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2010 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: * Patrick Tasse - Initial API and implementation *******************************************************************************/ @@ -34,6 +34,7 @@ import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace; import org.eclipse.linuxtools.internal.tmf.ui.project.handlers.Messages; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; @@ -70,7 +71,7 @@ import org.osgi.framework.Bundle; public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener { public static final String ID = "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$ - + private TmfEventsTable fEventsTable; private IFile fFile; @SuppressWarnings("rawtypes") @@ -122,8 +123,8 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus for (int i = 0; i < nbTraces; i++) { TmfTraceElement traceElement = traceEntries.get(i); ITmfTrace trace = traceElement.instantiateTrace(); - TmfEvent traceEvent = traceElement.instantiateEvent(); - if (trace == null || traceEvent == null) { + ITmfEvent traceEvent = traceElement.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { for (int j = 0; j < i; j++) { traces[j].dispose(); } @@ -156,8 +157,8 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus TmfTraceElement traceElement = (TmfTraceElement) projectElement; // Instantiate the trace ITmfTrace trace = traceElement.instantiateTrace(); - TmfEvent traceEvent = traceElement.instantiateEvent(); - if (trace == null || traceEvent == null) { + ITmfEvent traceEvent = traceElement.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); } try { @@ -179,8 +180,8 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus TmfTraceElement traceElement = (TmfTraceElement) projectElement; // Instantiate the trace ITmfTrace trace = traceElement.instantiateTrace(); - TmfEvent traceEvent = traceElement.instantiateEvent(); - if (trace == null || traceEvent == null) { + ITmfEvent traceEvent = traceElement.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); } try { @@ -286,7 +287,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus } return eventsTable; } - + private TmfEventsTable getEventsTable(Composite parent, int cacheSize) { if (fTrace instanceof TmfExperiment) { return getExperimentEventsTable((TmfExperiment) fTrace, parent, cacheSize); @@ -313,7 +314,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus break; } String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR); - if (eventsTableType == null || eventsTableType.length() == 0) { + if ((eventsTableType == null) || (eventsTableType.length() == 0)) { break; } Bundle bundle = Platform.getBundle(ce.getContributor().getName()); @@ -366,7 +367,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus return null; } String traceType = resource.getPersistentProperty(TmfTraceElement.TRACETYPE); - if (commonTraceType != null && !commonTraceType.equals(traceType)) { + if ((commonTraceType != null) && !commonTraceType.equals(traceType)) { return null; } commonTraceType = traceType; @@ -387,7 +388,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus break; } String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR); - if (eventsTableType == null || eventsTableType.length() == 0) { + if ((eventsTableType == null) || (eventsTableType.length() == 0)) { break; } Bundle bundle = Platform.getBundle(ce.getContributor().getName()); @@ -479,12 +480,12 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus public void addBookmark() { fEventsTable.addBookmark(fFile); } - + // ------------------------------------------------------------------------ // Signal handlers // ------------------------------------------------------------------------ - + @SuppressWarnings("unchecked") @TmfSignalHandler public void traceParserUpdated(TmfTraceParserUpdatedSignal signal) { @@ -527,7 +528,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus @TmfSignalHandler public void traceSelected(TmfTraceSelectedSignal signal) { - if (signal.getSource() != this && signal.getTrace().equals(fTrace)) { + if ((signal.getSource() != this) && signal.getTrace().equals(fTrace)) { getSite().getPage().bringToTop(this); } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java index e886b3e541..3c33a4e497 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2010, 2011 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 *******************************************************************************/ @@ -27,7 +27,7 @@ import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefin import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlEvent; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition; -import org.eclipse.linuxtools.tmf.core.event.TmfEvent; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; import org.eclipse.ui.IActionFilter; @@ -170,7 +170,7 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi return null; } - public TmfEvent instantiateEvent() { + public ITmfEvent instantiateEvent() { try { if (fTraceTypeId != null) { if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) { @@ -188,7 +188,7 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi } } IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId); - TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); + ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); return event; } } catch (CoreException e) { @@ -264,17 +264,21 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi @Override public Object getPropertyValue(Object id) { - if (sfName.equals(id)) + if (sfName.equals(id)) { return getName(); + } - if (sfPath.equals(id)) + if (sfPath.equals(id)) { return getPath().toString(); + } - if (sfLocation.equals(id)) + if (sfLocation.equals(id)) { return getLocation().toString(); + } - if (sfIsLinked.equals(id)) + if (sfIsLinked.equals(id)) { return Boolean.valueOf(getResource().isLinked()).toString(); + } if (sfEventType.equals(id)) { if (fTraceTypeId != null) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java index a3f39bd61d..adefd6f8f6 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2011 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: * Patrick Tasse - Initial API and implementation ******************************************************************************/ @@ -19,7 +19,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; -import org.eclipse.linuxtools.tmf.core.event.TmfEvent; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter; import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; @@ -27,34 +27,34 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; public class TmfEventsCache { public static class CachedEvent { - TmfEvent event; + ITmfEvent event; long rank; - public CachedEvent (TmfEvent event, long rank) { - this.event = event; + public CachedEvent (ITmfEvent iTmfEvent, long rank) { + this.event = iTmfEvent; this.rank = rank; } } - private CachedEvent[] fCache; + private final CachedEvent[] fCache; private int fCacheStartIndex = 0; private int fCacheEndIndex = 0; private ITmfTrace fTrace; - private TmfEventsTable fTable; + private final TmfEventsTable fTable; private ITmfFilter fFilter; - private ArrayList fFilterIndex = new ArrayList(); // contains the event rank at each 'cache size' filtered events + private final ArrayList fFilterIndex = new ArrayList(); // contains the event rank at each 'cache size' filtered events public TmfEventsCache(int cacheSize, TmfEventsTable table) { fCache = new CachedEvent[cacheSize]; fTable = table; } - + public void setTrace(ITmfTrace trace) { fTrace = trace; clear(); } - + public synchronized void clear() { fCacheStartIndex = 0; fCacheEndIndex = 0; @@ -65,12 +65,12 @@ public class TmfEventsCache { fFilter = filter; clear(); } - + public void clearFilter() { fFilter = null; clear(); } - + public synchronized CachedEvent getEvent(int index) { if ((index >= fCacheStartIndex) && (index < fCacheEndIndex)) { int i = index - fCacheStartIndex; @@ -87,8 +87,8 @@ public class TmfEventsCache { } return null; } - - public synchronized void storeEvent(TmfEvent event, long rank, int index) { + + public synchronized void storeEvent(ITmfEvent event, long rank, int index) { if (fCacheStartIndex == fCacheEndIndex) { fCacheStartIndex = index; fCacheEndIndex = index; @@ -100,28 +100,28 @@ public class TmfEventsCache { fCacheEndIndex++; } } - if (fFilter != null && index % fCache.length == 0) { + if ((fFilter != null) && ((index % fCache.length) == 0)) { int i = index / fCache.length; fFilterIndex.add(i, Integer.valueOf((int) rank)); } } - + @SuppressWarnings("unchecked") public synchronized int getFilteredEventIndex(final long rank) { int current; int startRank; - TmfDataRequest request; + TmfDataRequest request; synchronized (this) { int start = 0; int end = fFilterIndex.size(); - - if (fCacheEndIndex - fCacheStartIndex > 1) { + + if ((fCacheEndIndex - fCacheStartIndex) > 1) { if (rank < fCache[0].rank) { - end = fCacheStartIndex / fCache.length + 1; + end = (fCacheStartIndex / fCache.length) + 1; } else if (rank > fCache[fCacheEndIndex - fCacheStartIndex - 1].rank) { start = fCacheEndIndex / fCache.length; } else { - for (int i = 0; i < fCacheEndIndex - fCacheStartIndex; i++) { + for (int i = 0; i < (fCacheEndIndex - fCacheStartIndex); i++) { if (fCache[i].rank >= rank) { return fCacheStartIndex + i; } @@ -129,7 +129,7 @@ public class TmfEventsCache { return fCacheEndIndex; } } - + current = (start + end) / 2; while (current != start) { if (rank < fFilterIndex.get(current)) { @@ -142,23 +142,25 @@ public class TmfEventsCache { } startRank = fFilterIndex.get(current); } - + final int index = current * fCache.length; - - class DataRequest extends TmfDataRequest { + + class DataRequest extends TmfDataRequest { int fRank; int fIndex; - + DataRequest(Class dataType, int start, int nbRequested) { super(dataType, start, nbRequested); fRank = start; fIndex = index; } - + @Override public void handleData(T event) { super.handleData(event); - if (isCancelled()) return; + if (isCancelled()) { + return; + } if (fRank >= rank) { cancel(); return; @@ -173,21 +175,21 @@ public class TmfEventsCache { return fIndex; } } - - request = new DataRequest(TmfEvent.class, startRank, TmfDataRequest.ALL_DATA); - ((ITmfDataProvider) fTrace).sendRequest(request); + + request = new DataRequest(ITmfEvent.class, startRank, TmfDataRequest.ALL_DATA); + ((ITmfDataProvider) fTrace).sendRequest(request); try { request.waitForCompletion(); - return ((DataRequest) request).getFilteredIndex(); + return ((DataRequest) request).getFilteredIndex(); } catch (InterruptedException e) { } return 0; } - + // ------------------------------------------------------------------------ // Event cache population // ------------------------------------------------------------------------ - + // The event fetching job private Job job; private synchronized void populateCache(final int index) { @@ -196,14 +198,14 @@ public class TmfEventsCache { * 1. The job must exist * 2. It must be running (i.e. not completed) * 3. The requested index must be within the cache range - * + * * If the job meets these conditions, we simply exit. * Otherwise, we create a new job but we might have to cancel * an existing job for an obsolete range. */ if (job != null) { if (job.getState() != Job.NONE) { - if (index >= fCacheStartIndex && index < (fCacheStartIndex + fCache.length)) { + if ((index >= fCacheStartIndex) && (index < (fCacheStartIndex + fCache.length))) { return; } // The new index is out of the requested range @@ -211,7 +213,7 @@ public class TmfEventsCache { job.cancel(); } } - + fCacheStartIndex = index; fCacheEndIndex = index; @@ -233,12 +235,12 @@ public class TmfEventsCache { skipCount = index - (i * fCache.length); } } - - TmfDataRequest request = new TmfDataRequest(TmfEvent.class, startIndex, nbRequested) { + + TmfDataRequest request = new TmfDataRequest(ITmfEvent.class, startIndex, nbRequested) { private int count = 0; private long rank = startIndex; @Override - public void handleData(TmfEvent event) { + public void handleData(ITmfEvent event) { // If the job is canceled, cancel the request so waitForCompletion() will unlock if (monitor.isCanceled()) { cancel(); @@ -246,7 +248,7 @@ public class TmfEventsCache { } super.handleData(event); if (event != null) { - if ((fFilter == null || fFilter.matches(event)) && skipCount-- <= 0) { + if (((fFilter == null) || fFilter.matches(event)) && (skipCount-- <= 0)) { synchronized (TmfEventsCache.this) { fCache[count] = new CachedEvent(event.clone(), rank); count++; @@ -259,14 +261,14 @@ public class TmfEventsCache { } if (count >= fCache.length) { cancel(); - } else if (fFilter != null && count >= fTable.getTable().getItemCount() - 3) { // -1 for header row, -2 for top and bottom filter status rows + } else if ((fFilter != null) && (count >= (fTable.getTable().getItemCount() - 3))) { // -1 for header row, -2 for top and bottom filter status rows cancel(); } rank++; } }; - ((ITmfDataProvider) fTrace).sendRequest(request); + ((ITmfDataProvider) fTrace).sendRequest(request); try { request.waitForCompletion(); } catch (InterruptedException e) { @@ -274,7 +276,7 @@ public class TmfEventsCache { } fTable.cacheUpdated(true); - + // Flag the UI thread that the cache is ready if (monitor.isCanceled()) { return Status.CANCEL_STATUS; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java index 5d0abfe3cf..f1a613c3a4 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2010 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 * Patrick Tasse - Factored out from events view @@ -197,7 +197,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS private boolean fCacheUpdateBusy = false; private boolean fCacheUpdatePending = false; private boolean fCacheUpdateCompleted = false; - private Object fCacheUpdateSyncObj = new Object(); + private final Object fCacheUpdateSyncObj = new Object(); private boolean fDisposeOnClose; @@ -292,7 +292,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS } if (fTable.getData(Key.FILTER_OBJ) != null) { - if (event.index == 1 || event.index == fTable.getItemCount() - 1) { + if ((event.index == 1) || (event.index == (fTable.getItemCount() - 1))) { setFilterStatusRowItemData(item); return; } @@ -350,7 +350,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS if (!bounds.contains(event.x,event.y)) { return; } - if (tooltipShell != null && !tooltipShell.isDisposed()) { + if ((tooltipShell != null) && !tooltipShell.isDisposed()) { tooltipShell.dispose(); } tooltipShell = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); @@ -423,7 +423,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS return; } TableItem[] selection = fTable.getSelection(); - if (selection != null && selection.length > 0) { + if ((selection != null) && (selection.length > 0)) { TmfTimestamp ts = (TmfTimestamp) fTable.getSelection()[0].getData(Key.TIMESTAMP); if (ts != null) { broadcast(new TmfTimeSynchSignal(fTable, ts)); @@ -533,10 +533,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS if (item != null) { Rectangle imageBounds = item.getImageBounds(0); imageBounds.width = BOOKMARK_IMAGE.getBounds().width; - if (point.x <= imageBounds.x + imageBounds.width) { + if (point.x <= (imageBounds.x + imageBounds.width)) { // Right-click on left margin Long rank = (Long) item.getData(Key.RANK); - if (rank != null && fBookmarksFile != null) { + if ((rank != null) && (fBookmarksFile != null)) { if (fBookmarksMap.containsKey(rank)) { tablePopupMenu.add(new ToggleBookmarkAction( Messages.TmfEventsTable_RemoveBookmarkActionText, rank)); @@ -626,7 +626,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS stopFilterThread(); ColorSettingsManager.removeColorSettingsListener(this); fComposite.dispose(); - if (fTrace != null && fDisposeOnClose) { + if ((fTrace != null) && fDisposeOnClose) { fTrace.dispose(); } fResourceManager.dispose(); @@ -643,14 +643,14 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS /** * @param columnData - * + * * FIXME: Add support for column selection */ protected void setColumnHeaders(ColumnData[] columnData) { fTable.setColumnHeaders(columnData); } - protected void setItemData(TableItem item, TmfEvent event, long rank) { + protected void setItemData(TableItem item, ITmfEvent event, long rank) { ITmfEventField[] fields = extractItemFields(event); String[] content = new String[fields.length]; for (int i = 0; i < fields.length; i++) { @@ -739,7 +739,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS protected void setFilterStatusRowItemData(TableItem item) { for (int i = 0; i < fTable.getColumns().length; i++) { if (i == 0) { - if (fTrace == null || fFilterCheckCount == fTrace.getNbEvents()) { + if ((fTrace == null) || (fFilterCheckCount == fTrace.getNbEvents())) { item.setImage(FILTER_IMAGE); } else { item.setImage(STOP_IMAGE); @@ -778,7 +778,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS item = fTable.getItem(point); // Header row selected - if (item != null && fTable.indexOf(item) == 0) { + if ((item != null) && (fTable.indexOf(item) == 0)) { // Icon selected if (item.getImageBounds(0).contains(point)) { @@ -1044,7 +1044,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS private TmfEventRequest request; private boolean refreshBusy = false; private boolean refreshPending = false; - private Object syncObj = new Object(); + private final Object syncObj = new Object(); public FilterThread(ITmfFilterTreeNode filter) { super("Filter Thread"); //$NON-NLS-1$ @@ -1066,15 +1066,16 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @Override public void handleData(TmfEvent event) { super.handleData(event); - if (request.isCancelled()) + if (request.isCancelled()) { return; + } if (filter.matches(event)) { long rank = fFilterCheckCount; int index = (int) fFilterMatchCount; fFilterMatchCount++; fCache.storeEvent(event.clone(), rank, index); refreshTable(); - } else if (fFilterCheckCount % 100 == 0) { + } else if ((fFilterCheckCount % 100) == 0) { refreshTable(); } fFilterCheckCount++; @@ -1100,10 +1101,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS Display.getDefault().asyncExec(new Runnable() { @Override public void run() { - if (request.isCancelled()) + if (request.isCancelled()) { return; - if (fTable.isDisposed()) + } + if (fTable.isDisposed()) { return; + } fTable.setItemCount((int) fFilterMatchCount + 3); // +1 for header row, +2 for top and bottom filter // status rows fTable.refresh(); @@ -1215,7 +1218,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS final Display display = Display.getDefault(); if (startIndex < 0) { rank = (int) fTrace.getNbEvents() - 1; - } else if (startIndex >= fTable.getItemCount() - (eventFilter == null ? 1 : 3)) { // -1 for header row, -2 + } else if (startIndex >= (fTable.getItemCount() - (eventFilter == null ? 1 : 3))) { // -1 for header row, -2 // for top and bottom // filter status rows rank = 0; @@ -1227,7 +1230,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS break; } rank = event.rank; - if (searchFilter.matches(event.event) && (eventFilter == null || eventFilter.matches(event.event))) { + if (searchFilter.matches(event.event) && ((eventFilter == null) || eventFilter.matches(event.event))) { foundRank = event.rank; break; } @@ -1240,7 +1243,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS if (foundRank == -1) { if (direction == Direction.FORWARD) { rank++; - if (rank > fTrace.getNbEvents() - 1) { + if (rank > (fTrace.getNbEvents() - 1)) { rank = 0; } } else { @@ -1253,11 +1256,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS } int startRank = (int) rank; boolean wrapped = false; - while (!monitor.isCanceled() && foundRank == -1 && fTrace != null) { + while (!monitor.isCanceled() && (foundRank == -1) && (fTrace != null)) { int nbRequested = (direction == Direction.FORWARD ? Integer.MAX_VALUE : Math.min((int) rank + 1, fTrace.getIndexPageSize())); if (direction == Direction.BACKWARD) { rank = Math.max(0, rank - fTrace.getIndexPageSize() + 1); + } request = new TmfDataRequest(TmfEvent.class, (int) rank, nbRequested) { long currentRank = rank; @@ -1265,7 +1269,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @Override public void handleData(TmfEvent event) { super.handleData(event); - if (searchFilter.matches(event) && (eventFilter == null || eventFilter.matches(event))) { + if (searchFilter.matches(event) && ((eventFilter == null) || eventFilter.matches(event))) { foundRank = currentRank; if (direction == Direction.FORWARD) { done(); @@ -1305,7 +1309,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS rank = (int) fTrace.getNbEvents() - 1; wrapped = true; } - if (rank <= startRank && wrapped) { + if ((rank <= startRank) && wrapped) { synchronized (fSearchSyncObj) { fSearchThread = null; } @@ -1324,10 +1328,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS display.asyncExec(new Runnable() { @Override public void run() { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return; - if (fTable.isDisposed()) + } + if (fTable.isDisposed()) { return; + } fTable.setSelection(selection); fSelectedRank = foundRank; synchronized (fSearchSyncObj) { @@ -1355,8 +1361,9 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS } protected void packColumns() { - if (fPackDone) + if (fPackDone) { return; + } for (TableColumn column : fTable.getColumns()) { int headerWidth = column.getWidth(); column.pack(); @@ -1370,13 +1377,13 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS /** * @param event * @return - * + * * FIXME: Add support for column selection */ - protected ITmfEventField[] extractItemFields(TmfEvent event) { + protected ITmfEventField[] extractItemFields(ITmfEvent event) { ITmfEventField[] fields = new TmfEventField[0]; if (event != null) { - String timestamp = ((Long) event.getTimestamp().getValue()).toString(); + String timestamp = event.getTimestamp().toString(); String source = event.getSource(); String type = event.getType().getName(); String reference = event.getReference(); @@ -1403,7 +1410,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS * true if the trace should be disposed when the table is disposed */ public void setTrace(ITmfTrace trace, boolean disposeOnClose) { - if (fTrace != null && fDisposeOnClose) { + if ((fTrace != null) && fDisposeOnClose) { fTrace.dispose(); } fTrace = trace; @@ -1418,7 +1425,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS fTable.removeAll(); fCache.setTrace(fTrace); // Clear the cache if (fTrace != null) { - if (!fTable.isDisposed() && fTrace != null) { + if (!fTable.isDisposed() && (fTrace != null)) { if (fTable.getData(Key.FILTER_OBJ) == null) { fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row } else { @@ -1590,7 +1597,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS /* * (non-Javadoc) - * + * * @see * org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener#colorSettingsChanged(org.eclipse.linuxtools * .tmf.ui.views.colors.ColorSetting[]) @@ -1618,16 +1625,17 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @TmfSignalHandler public void experimentUpdated(TmfExperimentUpdatedSignal signal) { - if ((signal.getExperiment() != fTrace) || fTable.isDisposed()) + if ((signal.getExperiment() != fTrace) || fTable.isDisposed()) { return; + } // Perform the refresh on the UI thread Display.getDefault().asyncExec(new Runnable() { @Override public void run() { - if (!fTable.isDisposed() && fTrace != null) { + if (!fTable.isDisposed() && (fTrace != null)) { if (fTable.getData(Key.FILTER_OBJ) == null) { fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row - if (fPendingGotoRank != -1 && fPendingGotoRank + 1 < fTable.getItemCount()) { // +1 for header row + if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) { // +1 for header row fTable.setSelection((int) fPendingGotoRank + 1); // +1 for header row fPendingGotoRank = -1; } @@ -1635,7 +1643,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS startFilterThread(); } } - if (!fRawViewer.isDisposed() && fTrace != null) { + if (!fRawViewer.isDisposed() && (fTrace != null)) { fRawViewer.refreshEventCount(); } } @@ -1644,16 +1652,17 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @TmfSignalHandler public void traceUpdated(TmfTraceUpdatedSignal signal) { - if ((signal.getTrace() != fTrace) || fTable.isDisposed()) + if ((signal.getTrace() != fTrace) || fTable.isDisposed()) { return; + } // Perform the refresh on the UI thread Display.getDefault().asyncExec(new Runnable() { @Override public void run() { - if (!fTable.isDisposed() && fTrace != null) { + if (!fTable.isDisposed() && (fTrace != null)) { if (fTable.getData(Key.FILTER_OBJ) == null) { fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row - if (fPendingGotoRank != -1 && fPendingGotoRank + 1 < fTable.getItemCount()) { // +1 for header row + if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) { // +1 for header row fTable.setSelection((int) fPendingGotoRank + 1); // +1 for header row fPendingGotoRank = -1; } @@ -1661,7 +1670,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS startFilterThread(); } } - if (!fRawViewer.isDisposed() && fTrace != null) { + if (!fRawViewer.isDisposed() && (fTrace != null)) { fRawViewer.refreshEventCount(); } } @@ -1712,12 +1721,14 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @Override public void run() { // Return if table is disposed - if (fTable.isDisposed()) + if (fTable.isDisposed()) { return; + } int index = (int) rank; - if (fTable.isDisposed()) + if (fTable.isDisposed()) { return; + } if (fTable.getData(Key.FILTER_OBJ) != null) { index = fCache.getFilteredEventIndex(rank) + 1; // +1 for top filter status row } @@ -1738,7 +1749,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS /** * Display an exception in a message box - * + * * @param e the exception */ private void displayException(Exception e) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/environment/TmfEnvironmentView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/environment/TmfEnvironmentView.java new file mode 100644 index 0000000000..5c3e43a2a1 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/environment/TmfEnvironmentView.java @@ -0,0 +1,126 @@ +package org.eclipse.linuxtools.tmf.ui.views.environment; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.tmf.core.event.TmfEvent; +import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; +import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.ui.views.TmfView; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +public class TmfEnvironmentView extends TmfView { + + public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.environment"; //$NON-NLS-1$ + private TmfExperiment fExperiment; + private Table fTable; + final private String fTitlePrefix; + private Composite fParent; + + public TmfEnvironmentView() { + super("EnvironmentVariables"); //$NON-NLS-1$ + fTitlePrefix = getTitle(); + } + + // ------------------------------------------------------------------------ + // ViewPart + // ------------------------------------------------------------------------ + final private class Pair{ + final private String key; + final private String value; + public Pair(String k) { key = k ; value = "";} //$NON-NLS-1$ + public Pair(String k, String v){ key = k; value = v; } + public String getKey() { return key; } + public String getValue() { return value; } + } + + @Override + @SuppressWarnings("unchecked") + public void createPartControl(Composite parent) { + fParent = parent; + TableItem ti[]; + // If an experiment is already selected, update the table + TmfExperiment experiment = (TmfExperiment) TmfExperiment + .getCurrentExperiment(); + if (experiment == null) { + return; + } + fTable = new Table(parent, SWT.BORDER|SWT.FILL); + + + ArrayList tableData = new ArrayList(); + for (ITmfTrace trace : experiment.getTraces()) { + Pair traceEntry = new Pair(trace.getName()); + tableData.add(traceEntry); + if (trace instanceof CtfTmfTrace) { + CtfTmfTrace ctfTrace = (CtfTmfTrace) trace; + for (String varName : ctfTrace + .getEnvNames()) { + tableData.add(new Pair( varName, ctfTrace.getEnvValue(varName))); + } + } + } + TableColumn nameCol = new TableColumn(fTable, SWT.NONE, 0); + TableColumn valueCol = new TableColumn(fTable, SWT.NONE, 1); + nameCol.setText("Environment Variable"); //$NON-NLS-1$ + valueCol.setText("Value"); //$NON-NLS-1$ + + final int tableSize = tableData.size(); + + fTable.setItemCount(tableSize); + ti = fTable.getItems(); + for(int i = 0; i < tableSize; i++){ + final Pair currentPair = tableData.get(i); + ti[i].setText(0, currentPair.getKey()); + ti[i].setText(1, currentPair.getValue()); + } + + fTable.setHeaderVisible(true); + nameCol.pack(); + valueCol.pack(); + fTable.pack(); + + parent.layout(); + + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.WorkbenchPart#setFocus() + */ + @Override + public void setFocus() { + fTable.setFocus(); + } + + @Override + public void dispose() { + if (fTable != null) { + fTable.dispose(); + } + super.dispose(); + } + + @SuppressWarnings("unchecked") + @TmfSignalHandler + public void experimentSelected(TmfExperimentSelectedSignal signal) { + // Update the trace reference + TmfExperiment exp = (TmfExperiment) signal.getExperiment(); + if (!exp.equals(fExperiment)) { + fExperiment = exp; + if (fTable != null) { + fTable.dispose(); + } + createPartControl( fParent ); + fParent.layout(); + } + } + + +} -- 2.34.1