From aa572e2229b6097f1d4d2342e2ba58a0c61205b7 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Wed, 9 May 2012 11:19:35 -0400 Subject: [PATCH] Improve API. Update test cases. Signed-off-by: Matthew Khouzam --- .../ctf/core/tests/headless/ReadTrace.java | 6 +- .../core/tests/trace/CTFTraceReaderTest.java | 2 +- .../StreamInputReaderComparatorTest.java | 17 +++--- .../tests/trace/StreamInputReaderTest.java | 2 +- .../tests/types/EventDeclarationTest.java | 2 +- .../ctf/core/event/EventDeclaration.java | 4 +- .../ctf/core/event/EventDefinition.java | 36 +++++++++-- .../linuxtools/ctf/core/trace/CTFTrace.java | 60 ++++++++++++++++--- .../ctf/core/trace/CTFTraceReader.java | 8 +-- .../linuxtools/ctf/core/trace/Metadata.java | 13 ++-- .../core/trace/StreamInputPacketReader.java | 12 ++-- .../ctf/core/trace/StreamInputReader.java | 2 +- .../trace/StreamInputReaderComparator.java | 4 +- .../StreamInputReaderTimestampComparator.java | 4 +- .../tests/ctfadaptor/CtfTmfEventTypeTest.java | 29 +++++---- .../tests/ctfadaptor/headless/Benchmark.java | 24 ++++---- .../tmf/core/ctfadaptor/CtfTmfEvent.java | 25 +++----- .../tmf/core/ctfadaptor/CtfTmfEventType.java | 10 +++- .../tmf/core/ctfadaptor/CtfTmfTrace.java | 21 +++++-- 19 files changed, 188 insertions(+), 93 deletions(-) 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 index 9f09b810fb..f090d273ae 100644 --- 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 @@ -29,7 +29,7 @@ public class ReadTrace { */ @SuppressWarnings("nls") public static void main(String[] args) { - final String TRACE_PATH = "/home/ematkho/lttng-traces/lt-hello-4175-20120405-092230"; + final String TRACE_PATH = "traces/kernel"; // Change this to enable text output final boolean USE_TEXT = true; @@ -66,7 +66,7 @@ public class ReadTrace { } prev = traceReader.getIndex(); if (USE_TEXT) { - String output = formatDate(ed.timestamp + String output = formatDate(ed.getTimestamp() + trace.getOffset()); System.out.println(traceReader.getIndex() + ", " + output + ", " + ed.getDeclaration().getName() @@ -102,7 +102,7 @@ public class ReadTrace { */ private static long getTimestamp(CTFTraceReader fixture) { if (fixture.getCurrentEventDef() != null) { - return fixture.getCurrentEventDef().timestamp; + return fixture.getCurrentEventDef().getTimestamp(); } return Long.MIN_VALUE; } 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 02617795d3..d28f89a91f 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 @@ -328,6 +328,6 @@ public class CTFTraceReaderTest { * @return */ private long getTimestamp() { - return fixture.getCurrentEventDef().timestamp; + return fixture.getCurrentEventDef().getTimestamp(); } } 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 2b03b3825f..08896a93ea 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 @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.nio.channels.FileChannel; + import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.ctf.core.tests.TestParams; @@ -12,12 +13,14 @@ 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.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderComparator; -import org.junit.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * The class StreamInputReaderComparatorTest contains tests for the * class {@link StreamInputReaderComparator}. - * + * * @author ematkho * @version $Revision: 1.0 $ */ @@ -27,7 +30,7 @@ public class StreamInputReaderComparatorTest { /** * Launch the test. - * + * * @param args * the command line arguments */ @@ -61,8 +64,8 @@ public class StreamInputReaderComparatorTest { /** * Run the int compare(StreamInputReader,StreamInputReader) method test. - * - * @throws CTFReaderException + * + * @throws CTFReaderException */ @Test public void testCompare() throws CTFReaderException { @@ -76,7 +79,7 @@ public class StreamInputReaderComparatorTest { new StreamInputReader(new StreamInput(new Stream( TestParams.createTrace()), (FileChannel) null, TestParams.getEmptyFile()))); - ed1.timestamp = 1L; + ed1.setTimestamp(1L); sir1.setCurrentEvent(ed1); sir2 = new StreamInputReader(new StreamInput(new Stream( @@ -87,7 +90,7 @@ public class StreamInputReaderComparatorTest { TestParams.createTrace()), (FileChannel) null, TestParams.getEmptyFile()))); - ed2.timestamp = 1L; + ed2.setTimestamp(1L); sir2.setCurrentEvent(ed2); int result = fixture.compare(sir1, sir2); 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 f10138f576..bcc7da2ffd 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 @@ -178,7 +178,7 @@ public class StreamInputReaderTest { public void testSeek_eventDefinition() throws CTFReaderException { EventDefinition eventDefinition = new EventDefinition( new EventDeclaration(), getStreamInputReader()); - eventDefinition.timestamp = 1L; + eventDefinition.setTimestamp(1L); fixture.setCurrentEvent(eventDefinition); } } \ No newline at end of file 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 af3cd0a7dc..c2ea934f22 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 @@ -356,7 +356,7 @@ public class EventDeclarationTest { assertNotNull(ed.lookupDefinition("fields")); //$NON-NLS-1$ assertNull(ed.lookupDefinition("other")); //$NON-NLS-1$ assertNotNull(ed.toString()); - ed.context = ed.getFields(); + ed.setContext( ed.getFields()); assertNotNull(ed.toString()); } 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 258eb77894..e8f833b061 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 @@ -72,11 +72,11 @@ public class EventDeclaration { EventDefinition event = new EventDefinition(this, streamInputReader); if (context != null) { - event.context = context.createDefinition(event, "context"); //$NON-NLS-1$ + event.setContext( context.createDefinition(event, "context")); //$NON-NLS-1$ } if (this.fields != null) { - event.fields = this.fields.createDefinition(event, "fields"); //$NON-NLS-1$ + event.setFields(this.fields.createDefinition(event, "fields")); //$NON-NLS-1$ } return event; diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java index 5e3be16ae8..afc14bff55 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java @@ -34,22 +34,22 @@ public class EventDefinition implements IDefinitionScope { /** * The corresponding event declaration. */ - public final EventDeclaration declaration; + private final EventDeclaration declaration; /** * The timestamp of the current event. */ - public long timestamp; + private long timestamp; /** * The event context structure definition. */ - public StructDefinition context; + private StructDefinition context; /** * The event fields structure definition. */ - public StructDefinition fields; + private StructDefinition fields; /** * The StreamInputReader that reads this event definition. @@ -105,6 +105,34 @@ public class EventDefinition implements IDefinitionScope { return streamInputReader.getCPU(); } + /** + * @return the timestamp + */ + public long getTimestamp() { + return timestamp; + } + + /** + * @param timestamp the timestamp to set + */ + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + /** + * @param context the context to set + */ + public void setContext(StructDefinition context) { + this.context = context; + } + + /** + * @param fields the fields to set + */ + public void setFields(StructDefinition fields) { + this.fields = fields; + } + // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ 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 ff1e1c64c1..9581988fdd 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 @@ -24,13 +24,16 @@ import java.nio.channels.FileChannel.MapMode; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.UUID; import org.eclipse.linuxtools.ctf.core.event.CTFClock; +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; 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; @@ -138,6 +141,9 @@ public class CTFTrace implements IDefinitionScope { private final static FileFilter metadataFileFilter = new MetadataFileFilter(); private final static Comparator metadataComparator = new MetadataComparator(); + /** map of all the event types */ + private final HashMap events; + // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ @@ -151,6 +157,7 @@ public class CTFTrace implements IDefinitionScope { */ public CTFTrace(String path) throws CTFReaderException { this(new File(path)); + } /** @@ -196,11 +203,26 @@ public class CTFTrace implements IDefinitionScope { for (File streamFile : files) { openStreamInput(streamFile); } - + events = new HashMap(); /* Create their index */ for (Map.Entry stream : streams.entrySet()) { Set inputs = stream.getValue().getStreamInputs(); for (StreamInput s : inputs) { + /* + * Copy the events + */ + Iterator> it = s.getStream() + .getEvents().entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = it.next(); + Long eventNum = pairs.getKey(); + EventDeclaration eventDec = pairs.getValue(); + events.put(eventNum, eventDec); + } + + /* + * index the trace + */ s.createIndex(); } } @@ -214,6 +236,7 @@ public class CTFTrace implements IDefinitionScope { try { fc.close(); } catch (IOException e) { + // do nothing it's ok, we tried to close it. } } } @@ -223,6 +246,26 @@ public class CTFTrace implements IDefinitionScope { // Getters/Setters/Predicates // ------------------------------------------------------------------------ + /** + * Get an event by it's ID + * + * @param id + * the ID of the event + * @return the event declaration + */ + public EventDeclaration getEventType(long id) { + return events.get(id); + } + + /** + * Get the number of events in the trace so far. + * + * @return the number of events in the trace + */ + public int getNbEventTypes() { + return events.size(); + } + /** * Method getStream gets the stream for a given id * @@ -427,8 +470,7 @@ public class CTFTrace implements IDefinitionScope { * must use * @throws CTFReaderException */ - private void openStreamInput(File streamFile) - throws CTFReaderException { + private void openStreamInput(File streamFile) throws CTFReaderException { MappedByteBuffer byteBuffer; BitBuffer streamBitBuffer; Stream stream; @@ -459,20 +501,23 @@ public class CTFTrace implements IDefinitionScope { packetHeaderDef.read(streamBitBuffer); /* Check the magic number */ - IntegerDefinition magicDef = (IntegerDefinition) packetHeaderDef.lookupDefinition("magic"); //$NON-NLS-1$ + IntegerDefinition magicDef = (IntegerDefinition) packetHeaderDef + .lookupDefinition("magic"); //$NON-NLS-1$ int magic = (int) magicDef.getValue(); if (magic != Utils.CTF_MAGIC) { throw new CTFReaderException("CTF magic mismatch"); //$NON-NLS-1$ } /* Check UUID */ - ArrayDefinition uuidDef = (ArrayDefinition) packetHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$ + ArrayDefinition uuidDef = (ArrayDefinition) packetHeaderDef + .lookupDefinition("uuid"); //$NON-NLS-1$ assert ((uuidDef != null) && (uuidDef.getDeclaration().getLength() == Utils.UUID_LEN)); if (uuidDef != null) { byte[] uuidArray = new byte[Utils.UUID_LEN]; for (int i = 0; i < Utils.UUID_LEN; i++) { - IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getElem(i); + IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef + .getElem(i); uuidArray[i] = (byte) uuidByteDef.getValue(); } @@ -487,7 +532,8 @@ public class CTFTrace implements IDefinitionScope { // TODO: it hasn't been checked that the stream_id field exists and // is an unsigned // integer - IntegerDefinition streamIDDef = (IntegerDefinition) packetHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$ + IntegerDefinition streamIDDef = (IntegerDefinition) packetHeaderDef + .lookupDefinition("stream_id"); //$NON-NLS-1$ assert (streamIDDef != null); long streamID = streamIDDef.getValue(); 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 294663e2f5..920b34d455 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 @@ -102,7 +102,7 @@ public class CTFTraceReader { */ this.startTime = 0;// prio.peek().getPacketReader().getCurrentPacket().getTimestampBegin(); if (hasMoreEvents()) { - this.startTime = prio.peek().getCurrentEvent().timestamp; + this.startTime = prio.peek().getCurrentEvent().getTimestamp(); this.endTime = this.startTime; this.fIndex = 0; } @@ -270,7 +270,7 @@ public class CTFTraceReader { * Add it back in the queue. */ this.prio.add(top); - final long topEnd = top.getCurrentEvent().timestamp; + final long topEnd = top.getCurrentEvent().getTimestamp(); this.endTime = Math.max(topEnd, this.endTime); this.eventCountPerTraceFile[top.getName()]++; /* @@ -370,7 +370,7 @@ public class CTFTraceReader { } if (currentEvent != null) { tempTimestamp = Math.max(tempTimestamp, - currentEvent.timestamp); + currentEvent.getTimestamp()); } else { /* * probably beyond the last event @@ -404,7 +404,7 @@ public class CTFTraceReader { /* * advance for offset */ - while ((prio.peek().getCurrentEvent().timestamp < tempTimestamp) + while ((prio.peek().getCurrentEvent().getTimestamp() < tempTimestamp) && hasMoreEvents()) { this.advance(); } 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 cfc94fb25a..db82ea0521 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 @@ -81,7 +81,7 @@ public class Metadata { /** * Constructs a Metadata object. - * + * * @param trace * The trace to which belongs this metadata file. */ @@ -102,7 +102,7 @@ public class Metadata { /** * Returns the ByteOrder that was detected while parsing the metadata. - * + * * @return The byte order. */ public ByteOrder getDetectedByteOrder() { @@ -115,7 +115,7 @@ public class Metadata { /** * Parse the metadata file. - * + * * @throws CTFReaderException */ public void parse() throws CTFReaderException { @@ -196,18 +196,21 @@ public class Metadata { try { metadataTextInput.close(); } catch (IOException e) { + // Do nothing } } if (metadataFileChannel != null) { try { metadataFileChannel.close(); } catch (IOException e) { + // Do nothing } } if (fis != null) { try { fis.close(); } catch (IOException e) { + // Do nothing } } @@ -220,7 +223,7 @@ public class Metadata { * Determines whether the metadata file is packet-based by looking at the * TSDL magic number. If it is packet-based, it also gives information about * the endianness of the trace using the detectedByteOrder attribute. - * + * * @param metadataFileChannel * FileChannel of the metadata file. * @return True if the metadata is packet-based. @@ -266,7 +269,7 @@ public class Metadata { /** * Reads a metadata packet from the given metadata FileChannel, do some * basic validation and append the text to the StringBuffer. - * + * * @param metadataFileChannel * Metadata FileChannel * @param metadataText 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 42df3011a2..b38ef26b5f 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 @@ -318,7 +318,7 @@ class StreamInputPacketReader implements IDefinitionScope { if( lostEvents > lostSoFar) { EventDefinition eventDef = EventDeclaration.getLostEventDeclaration().createDefinition(streamInputReader); - eventDef.timestamp = this.lastTimestamp; + eventDef.setTimestamp(this.lastTimestamp); ++lostSoFar; return eventDef; } @@ -390,22 +390,22 @@ class StreamInputPacketReader implements IDefinitionScope { /* * Read the event context. */ - if (eventDef.context != null) { - eventDef.context.read(currentBitBuffer); + if (eventDef.getContext() != null) { + eventDef.getContext().read(currentBitBuffer); } /* * Read the event fields. */ - if (eventDef.fields != null) { - eventDef.fields.read(currentBitBuffer); + if (eventDef.getFields() != null) { + eventDef.getFields().read(currentBitBuffer); } /* * Set the event timestamp using the timestamp calculated by * updateTimestamp. */ - eventDef.timestamp = timestamp; + eventDef.setTimestamp(timestamp); return eventDef; } 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 e6710aaad6..8ec6291aaf 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 @@ -188,7 +188,7 @@ public class StreamInputReader { */ readNextEvent(); boolean done = (this.getCurrentEvent() == null); - while (!done && (this.getCurrentEvent().timestamp < timestamp)) { + while (!done && (this.getCurrentEvent().getTimestamp() < timestamp)) { readNextEvent(); done = (this.getCurrentEvent() == null); offset++; diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderComparator.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderComparator.java index 105e96de5f..17188adda4 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderComparator.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderComparator.java @@ -39,8 +39,8 @@ public class StreamInputReaderComparator implements @Override public int compare(StreamInputReader a, StreamInputReader b) { // TODO: use unsigned comparison to avoid sign errors if needed - long ta = a.getCurrentEvent().timestamp; - long tb = b.getCurrentEvent().timestamp; + long ta = a.getCurrentEvent().getTimestamp(); + long tb = b.getCurrentEvent().getTimestamp(); if (ta < tb) { return -1; diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java index 7bc12e79b8..a732315be0 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java @@ -45,8 +45,8 @@ public class StreamInputReaderTimestampComparator implements if (b.getCurrentEvent() == null) { return 0; } - long ta = a.getCurrentEvent().timestamp; - long tb = b.getCurrentEvent().timestamp; + long ta = a.getCurrentEvent().getTimestamp(); + long tb = b.getCurrentEvent().getTimestamp(); if (ta < tb) { return -1; diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java index 0ce7d82670..76aaed0483 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java @@ -1,10 +1,14 @@ package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventType; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; -import org.junit.*; -import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * The class CtfTmfEventTypeTest contains tests for the class {@link CtfTmfEventType}. @@ -22,19 +26,18 @@ public class CtfTmfEventTypeTest { * @generatedBy CodePro at 03/05/12 2:29 PM */ @Test - public void testCtfTmfEventType_1() - throws Exception { - String contextId = ""; - String eventName = ""; - ITmfEventField content = new TmfEventField("", new ITmfEventField[] {}); + public void testCtfTmfEventType_1() { + String contextId = ""; //$NON-NLS-1$ + String eventName = ""; //$NON-NLS-1$ + ITmfEventField content = new TmfEventField("", new ITmfEventField[] {}); //$NON-NLS-1$ - CtfTmfEventType result = new CtfTmfEventType(contextId, eventName, content); + CtfTmfEventType result = new CtfTmfEventType( eventName, content); // add additional test code here assertNotNull(result); - assertEquals("", result.toString()); - assertEquals("", result.getName()); - assertEquals("", result.getContext()); + assertEquals("", result.toString()); //$NON-NLS-1$ + assertEquals("", result.getName()); //$NON-NLS-1$ + assertEquals("Ctf Event", result.getContext()); //$NON-NLS-1$ } /** @@ -47,12 +50,12 @@ public class CtfTmfEventTypeTest { @Test public void testToString_1() throws Exception { - CtfTmfEventType fixture = new CtfTmfEventType("", "", new TmfEventField("", new ITmfEventField[] {})); + CtfTmfEventType fixture = new CtfTmfEventType("", new TmfEventField("", new ITmfEventField[] {})); //$NON-NLS-1$ //$NON-NLS-2$ String result = fixture.toString(); // add additional test code here - assertEquals("", result); + assertEquals("", result); //$NON-NLS-1$ } /** 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 index 34e2c1f86c..addd1403a9 100644 --- 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 @@ -11,7 +11,6 @@ *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless; -import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -29,17 +28,17 @@ public class Benchmark { */ @SuppressWarnings("nls") public static void main(final String[] args) { - final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m1"; + final String TRACE_PATH = "testfiles/kernel"; final int NUM_LOOPS = 100; // Change this to enable text output - final boolean USE_TEXT = false; + final boolean USE_TEXT = true; - try { - System.in.read(); - } catch (final IOException e1) { - e1.printStackTrace(); - } +// try { +// System.in.read(); +// } catch (final IOException e1) { +// e1.printStackTrace(); +// } // Work variables Long nbEvent = 0L; final Vector benchs = new Vector(); @@ -64,10 +63,10 @@ public class Benchmark { while (current != null) { nbEvent++; if (USE_TEXT) { - final String output = formatDate(current.getTimestampValue()); + System.out.println("Event " + traceReader.getRank() + " Time " - + output + " type " + current.getSource() - + " on CPU " + current.getCPU()); + + current.getTimestamp().toString() + " type " + current.getEventName() + + " on CPU " + current.getSource() + " " + current.getContent().toString()) ; } traceReader.advance(); current = traceReader.getCurrentEvent(); @@ -80,8 +79,9 @@ public class Benchmark { } System.out.println(""); double avg = 0; - for (final Double val : benchs) + for (final Double val : benchs) { avg += val; + } avg /= benchs.size(); System.out.println("Time to read = " + avg + " events/ns"); for (final Double val : benchs) { 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 acb3a658c2..4ef6ae992c 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 @@ -13,6 +13,7 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map.Entry; @@ -38,7 +39,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 @@ -82,7 +83,7 @@ public final class CtfTmfEvent implements ITmfEvent { /* Read the base event info */ Long offset = originTrace.getCTFTrace().getOffset(); - this.timestamp = eventDef.timestamp + offset; + this.timestamp = eventDef.getTimestamp() + offset; this.sourceCPU = eventDef.getCPU(); this.typeId = eventDef.getDeclaration().getId(); this.eventName = eventDef.getDeclaration().getName(); @@ -101,7 +102,7 @@ public final class CtfTmfEvent implements ITmfEvent { * @return CtfTmfEventField[] */ - private static CtfTmfEventField[] parseFields(EventDefinition eventDef) { + public static CtfTmfEventField[] parseFields(EventDefinition eventDef) { List fields = new ArrayList(); StructDefinition structFields = eventDef.getFields(); @@ -109,16 +110,12 @@ public final class CtfTmfEvent implements ITmfEvent { String curFieldName; Definition curFieldDef; CtfTmfEventField curField; - - for (Entry entry : definitions.entrySet()) { + Iterator> it = definitions.entrySet().iterator(); + while(it.hasNext()) { + Entry entry = it.next(); curFieldName = entry.getKey(); curFieldDef = entry.getValue(); curField = CtfTmfEventField.parseField(curFieldDef, curFieldName); - if (curField == null) { -// TmfCorePlugin.getDefault().log( -// "We've parsed an unimplemented field type for event \"" + this.eventName //$NON-NLS-1$ -// + "\", field \"" + curFieldName + "\" of type " + curFieldDef.getClass().toString()); //$NON-NLS-1$ //$NON-NLS-2$ - } fields.add(curField); } @@ -156,7 +153,7 @@ public final class CtfTmfEvent implements ITmfEvent { this.typeId = -1; this.fileName = NO_STREAM; this.eventName = EMPTY_CTF_EVENT_NAME; - this.fContent = new CtfTmfContent("", new CtfTmfEventField[0]); + this.fContent = new CtfTmfContent("", new CtfTmfEventField[0]); //$NON-NLS-1$ } @@ -273,7 +270,6 @@ public final class CtfTmfEvent implements ITmfEvent { return fSource; } - private CtfTmfEventType type = null; /** * Method getType. * @return ITmfEventType @@ -281,10 +277,7 @@ public final class CtfTmfEvent implements ITmfEvent { */ @Override public ITmfEventType getType() { - if(type == null){ - type = new CtfTmfEventType(CONTEXT_ID, eventName, fContent); - } - return type; + return CtfTmfEventType.get(eventName); } /** 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 index b841800ff9..7cd7b83602 100644 --- 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 @@ -13,20 +13,22 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventType; +import org.eclipse.linuxtools.tmf.core.event.TmfEventTypeManager; /** */ public class CtfTmfEventType extends TmfEventType { + private static final String CONTEXT_ID = "Ctf Event"; //$NON-NLS-1$ /** * Constructor for CtfTmfEventType. * @param contextId String * @param eventName String * @param content ITmfEventField */ - public CtfTmfEventType(String contextId, String eventName, + public CtfTmfEventType( String eventName, ITmfEventField content) { - super(contextId, eventName, content); + super(CONTEXT_ID, eventName, content); } /** @@ -38,4 +40,8 @@ public class CtfTmfEventType extends TmfEventType { { return this.getName(); } + + public static CtfTmfEventType get(String eventName){ + return (CtfTmfEventType) TmfEventTypeManager.getInstance().getType(CONTEXT_ID, eventName); + } } 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 febe5c4ee5..991520b29b 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 @@ -15,9 +15,12 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +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.tmf.core.component.TmfEventProvider; +import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; @@ -89,6 +92,11 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr this.fResource = resource; try { this.fTrace = new CTFTrace(path); + for( int i =0 ; i< this.fTrace.getNbEventTypes(); i++) { + EventDeclaration ed = this.fTrace.getEventType(i); + ITmfEventField eventField = parseDeclaration(ed); + new CtfTmfEventType(ed.getName(), eventField); + } } catch (final CTFReaderException e) { /* * If it failed at the init(), we can assume it's because the file @@ -116,6 +124,12 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr } } + private static ITmfEventField parseDeclaration(EventDeclaration ed) { + EventDefinition eventDef = ed.createDefinition(null); + return new CtfTmfContent(ITmfEventField.ROOT_FIELD_ID, + CtfTmfEvent.parseFields(eventDef)); + } + /** * Method dispose. * @see org.eclipse.linuxtools.tmf.core.component.ITmfComponent#dispose() @@ -348,11 +362,9 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr * @param context ITmfContext * @return CtfTmfEvent */ - @SuppressWarnings("unused") @Override public CtfTmfEvent getNext(final ITmfContext context) { - iterator.advance(); - return iterator.getCurrentEvent(); + return readNextEvent(context); } // ------------------------------------------------------------------------ @@ -447,8 +459,9 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr @SuppressWarnings("unused") @Override public CtfTmfEvent readNextEvent(final ITmfContext context) { + CtfTmfEvent event = iterator.getCurrentEvent(); iterator.advance(); - return iterator.getCurrentEvent(); + return event; } /** -- 2.34.1