/**
* number of lost events in this packet
*/
- private int lostEvents;
-
private int lostSoFar;
private int lostEventsInThisPacket;
*/
createDefinitions();
- lostEvents = 0;
lostSoFar = 0;
}
*/
if (getStreamPacketContextDef() != null) {
getStreamPacketContextDef().read(getBitBuffer());
- /*
- * Read CPU ID
- */
+ /* Read CPU ID */
if (this.getCurrentPacket().getTarget() != null) {
- this.currentCpu = (int) this.getCurrentPacket()
- .getTargetId();
+ this.currentCpu = (int) this.getCurrentPacket().getTargetId();
}
- /*
- * Read number of lost events
- */
- int totalLostEvents = (int) this.getCurrentPacket()
- .getLostEvents();
- lostEventsInThisPacket = totalLostEvents - lostEvents;
- lostEvents = totalLostEvents;
- currentPacket.setLostEvents(lostEventsInThisPacket);
+ /* Read number of lost events */
+ lostEventsInThisPacket = (int) this.getCurrentPacket().getLostEvents();
lostSoFar = 0;
}
++lostSoFar;
return eventDef;
}
+
StructDefinition sehd = getStreamEventHeaderDef(); // acronym for a long
// variable name
BitBuffer currentBitBuffer = getBitBuffer();
.getCurrentPacket();
if (prevPacket != null) {
goToNextPacket();
- @SuppressWarnings("unused")
- final StreamInputPacketIndexEntry currentPacket = this.packetReader.getCurrentPacket();
}
}
*/
StructDefinition streamPacketContextDef = null;
+ /*
+ * Total number of lost events in this stream
+ */
+ long lostSoFar = 0;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
packetIndex.addAttribute(field,
((StringDefinition) id).getValue());
}
-
}
Long contentSize = (Long) packetIndex.lookupAttribute("content_size"); //$NON-NLS-1$
Long packetSize = (Long) packetIndex.lookupAttribute("packet_size"); //$NON-NLS-1$
- Long timestampBegin = (Long) packetIndex
- .lookupAttribute("timestamp_begin"); //$NON-NLS-1$
+ Long timestampBegin = (Long) packetIndex.lookupAttribute("timestamp_begin"); //$NON-NLS-1$
Long timestampEnd = (Long) packetIndex.lookupAttribute("timestamp_end"); //$NON-NLS-1$
String device = (String) packetIndex.lookupAttribute("device"); //$NON-NLS-1$
// LTTng Specific
Long CPU_ID = (Long) packetIndex.lookupAttribute("cpu_id"); //$NON-NLS-1$
- /*
- * Read the content size in bits
- */
+ Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$
+
+ /* Read the content size in bits */
if (contentSize != null) {
packetIndex.setContentSizeBits(contentSize.intValue());
} else {
packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
}
- /*
- * Read the packet size in bits
- */
-
+ /* Read the packet size in bits */
if (packetSize != null) {
packetIndex.setPacketSizeBits(packetSize.intValue());
} else {
}
}
- /*
- * Read the begin timestamp
- */
-
+ /* Read the begin timestamp */
if (timestampBegin != null) {
packetIndex.setTimestampBegin(timestampBegin.longValue());
}
- /*
- * Read the end timestamp
- */
+ /* Read the end timestamp */
if (timestampEnd != null) {
if( timestampEnd == -1 ) {
timestampEnd = Long.MAX_VALUE;
if (CPU_ID != null) {
packetIndex.setTarget("CPU" + CPU_ID.toString()); //$NON-NLS-1$
}
+
+ if (lostEvents != null) {
+ packetIndex.setLostEvents(lostEvents - lostSoFar);
+ this.lostSoFar = lostEvents;
+ }
}
/*
}
/**
- * @return the lostEvents
+ * @return the lostEvents in this packet
*/
public long getLostEvents() {
return lostEvents;
* Add an attribute to this index entry
*
* @param field
- * The name of the atrribute
+ * The name of the attribute
* @param value
* The value to insert
*/
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
@Before
public void setUp() throws TmfTraceException {
fixture = new CtfIterator(createTrace());
- CtfLocation ctfLocation = new CtfLocation(Long.valueOf(1));
- ctfLocation.setLocation(Long.valueOf(1));
+ CtfLocation ctfLocation = new CtfLocation(new CtfLocationData(1, 0));
+ ctfLocation.setLocation(new CtfLocationData(1, 0));
fixture.setLocation(ctfLocation);
fixture.increaseRank();
}
CtfTmfTrace trace = createTrace();
long timestampValue = 1L;
long rank = 1L;
- CtfIterator result = new CtfIterator(trace, timestampValue, rank);
+ CtfIterator result = new CtfIterator(trace, new CtfLocationData(timestampValue, 0), rank);
assertNotNull(result);
}
@Test
public void testEquals_other() throws TmfTraceException {
CtfIterator obj = new CtfIterator(createTrace());
- CtfLocation ctfLocation1 = new CtfLocation(Long.valueOf(1));
- ctfLocation1.setLocation(Long.valueOf(1));
+ CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationData(1, 0));
+ ctfLocation1.setLocation(new CtfLocationData(1, 0));
obj.setLocation(ctfLocation1);
obj.increaseRank();
*/
@Test
public void testSetLocation() {
- CtfLocation location = new CtfLocation(Long.valueOf(1));
- location.setLocation(Long.valueOf(1));
+ CtfLocation location = new CtfLocation(new CtfLocationData(1, 0));
+ location.setLocation(new CtfLocationData(1, 0));
fixture.setLocation(location);
}
}
--- /dev/null
+/*******************************************************************************
+ * 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:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Collection of tests for the {@link CtfLocationData}
+ *
+ * @author alexmont
+ */
+public class CtfLocationDataTest {
+
+ private CtfLocationData fixture;
+
+ /**
+ * Launch the test.
+ *
+ * @param args
+ * the command line arguments
+ */
+ public static void main(String[] args) {
+ new org.junit.runner.JUnitCore().run(CtfLocationDataTest.class);
+ }
+
+ /**
+ * Perform pre-test initialization.
+ */
+ @Before
+ public void setUp() {
+ fixture = new CtfLocationData(1, 0);
+ }
+
+ /**
+ * Perform post-test clean-up.
+ */
+ @After
+ public void tearDown() {
+ // Add additional tear down code here
+ }
+
+
+ /**
+ * Test for the .getTimestamp() and .getIndex() methods
+ */
+ @Test
+ public void testGetters() {
+ long timestamp = fixture.getTimestamp();
+ long index = fixture.getIndex();
+
+ assertEquals(1, timestamp);
+ assertEquals(0, index);
+ }
+
+ /**
+ * Test for the .hashCode() method
+ */
+ @Test
+ public void testHashCode() {
+ int code = fixture.hashCode();
+ assertEquals(962, code);
+ }
+
+ /**
+ * Test for the .equals() method
+ */
+ @Test
+ public void testEquals() {
+ CtfLocationData same = new CtfLocationData(1, 0);
+ CtfLocationData diff1 = new CtfLocationData(100, 0);
+ CtfLocationData diff2 = new CtfLocationData(1, 10);
+
+ assertTrue(fixture.equals(same));
+ assertFalse(fixture.equals(diff1));
+ assertFalse(fixture.equals(diff2));
+ }
+
+ /**
+ * Test for the .compareTo() method
+ */
+ @Test
+ public void testCompareTo() {
+ CtfLocationData same = new CtfLocationData(1, 0);
+ CtfLocationData smaller = new CtfLocationData(0, 0);
+ CtfLocationData bigger1 = new CtfLocationData(1000, 500);
+ CtfLocationData bigger2 = new CtfLocationData(1, 1);
+
+ assertEquals(0, same.compareTo(fixture));
+ assertEquals(-1, smaller.compareTo(fixture));
+ assertEquals(1, bigger1.compareTo(fixture));
+ assertEquals(1, bigger2.compareTo(fixture));
+ }
+
+ /**
+ * Test for the .toString() method
+ */
+ @Test
+ public void testToString() {
+ String expected = "Element [1/0]"; //$NON-NLS-1$
+ assertEquals(expected, fixture.toString());
+ }
+}
import static org.junit.Assert.assertNotNull;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.junit.After;
*/
@Before
public void setUp() {
- fixture = new CtfLocation(Long.valueOf(1));
- fixture.setLocation(Long.valueOf(1));
+ fixture = new CtfLocation(new CtfLocationData(1, 0));
+ fixture.setLocation(new CtfLocationData(1, 0));
}
/**
*/
@Test
public void testCtfLocation_long() {
- Long location = Long.valueOf(1);
+ CtfLocationData location = new CtfLocationData(1, 0);
CtfLocation result = new CtfLocation(location);
assertNotNull(result);
- assertEquals(Long.valueOf(1), result.getLocation());
+ assertEquals(Long.valueOf(1), (Long)result.getLocation().getTimestamp());
}
/**
CtfLocation result = new CtfLocation(timestamp);
assertNotNull(result);
- assertEquals(new Long(0L), result.getLocation());
+ assertEquals(new Long(0L), (Long)result.getLocation().getTimestamp());
}
/**
CtfLocation result = fixture.clone();
assertNotNull(result);
- assertEquals(Long.valueOf(1), result.getLocation());
+ assertEquals(Long.valueOf(1), (Long)result.getLocation().getTimestamp());
}
/**
*/
@Test
public void testGetLocation() {
- Long result = fixture.getLocation();
-
+ CtfLocationData location = fixture.getLocation();
+ Long result = location.getTimestamp();
assertNotNull(result);
assertEquals("1", result.toString()); //$NON-NLS-1$
assertEquals((byte) 1, result.byteValue());
*/
@Test
public void testSetLocation() {
- Long location = Long.valueOf(1);
+ CtfLocationData location = new CtfLocationData(1337, 7331);
fixture.setLocation(location);
}
*/
@Test
public void testToString_valid(){
- CtfLocation fixture2 = new CtfLocation(new Long(1337L));
- assertEquals("CtfLocation: 1337",fixture2.toString()); //$NON-NLS-1$
+ CtfLocation fixture2 = new CtfLocation(new CtfLocationData(1337, 7331));
+ assertEquals("CtfLocation: Element [1337/7331]",fixture2.toString()); //$NON-NLS-1$
}
/**
*/
@Test
public void testToString_invalid(){
- CtfLocation fixture2 = new CtfLocation(new Long(-1L));
+ CtfLocation fixture2 = new CtfLocation(new CtfLocationData(-1, -1));
assertEquals("CtfLocation: INVALID",fixture2.toString()); //$NON-NLS-1$
}
}
lwc.seek(val);
fixture.getNext(lwc);
synchronized(fixture){
- vals.add(lwc.getCurrentEvent().getTimestampValue());
+ if (lwc.getCurrentEvent() != null) {
+ vals.add(lwc.getCurrentEvent().getTimestampValue());
+ }
tooManyContexts.add(lwc);
}
}
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
*/
@Test
public void testGetLocationRatio() {
- CtfLocation location = new CtfLocation(Long.valueOf(1));
- location.setLocation(Long.valueOf(1));
+ final CtfLocationData location2 = new CtfLocationData(1, 0);
+ CtfLocation location = new CtfLocation(location2);
+ location.setLocation(location2);
double result = fixture.getLocationRatio(location);
assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
@Test
public void testGetNbEvents() {
long result = fixture.getNbEvents();
- assertEquals(0L, result);
+ assertEquals(1L, result);
}
/**
*/
@Test
public void testSeekEvent_location() {
- CtfLocation ctfLocation = new CtfLocation(new Long(1L));
+ final CtfLocationData location2 = new CtfLocationData(1L, 0L);
+ CtfLocation ctfLocation = new CtfLocation(location2);
ITmfContext result = fixture.seekEvent(ctfLocation);
assertNotNull(result);
}
@RunWith(Suite.class)
@Suite.SuiteClasses({
CtfIteratorTest.class,
+ CtfLocationDataTest.class,
CtfLocationTest.class,
CtfTmfContentTest.class,
CtfTmfEventFieldTest.class,
* @version 1.0
* @author Matthew Khouzam
*/
-public class CtfIterator extends CTFTraceReader implements ITmfContext, Comparable<CtfIterator>, Cloneable {
+public class CtfIterator extends CTFTraceReader implements ITmfContext,
+ Comparable<CtfIterator>, Cloneable {
private final CtfTmfTrace ctfTmfTrace;
/**
* An invalid location
*/
- final public static CtfLocation NULL_LOCATION = new CtfLocation(
- CtfLocation.INVALID_LOCATION);
+ final public static CtfLocation NULL_LOCATION = new CtfLocation(CtfLocation.INVALID_LOCATION);
+
private CtfLocation curLocation;
private long curRank;
* Create a new CTF trace iterator, which initially points at the first
* event in the trace.
*
- * @param trace the trace to iterate over
+ * @param trace
+ * the trace to iterate over
*/
public CtfIterator(final CtfTmfTrace trace) {
super(trace.getCTFTrace());
this.ctfTmfTrace = trace;
if (this.hasMoreEvents()) {
-
this.curLocation = new CtfLocation(trace.getStartTime());
this.curRank = 0;
} else {
}
}
- /**
- *
- */
private void setUnknownLocation() {
this.curLocation = NULL_LOCATION;
this.curRank = UNKNOWN_RANK;
/**
* Constructor for CtfIterator.
- * @param trace CtfTmfTrace the trace
- * @param timestampValue long the timestamp in ns of the trace for positioning
- * @param rank long the index of the trace for positioning
+ *
+ * @param trace
+ * CtfTmfTrace the trace
+ * @param ctfLocationData
+ * long the timestamp in ns of the trace for positioning
+ * @param rank
+ * long the index of the trace for positioning
+ * @since 2.0
*/
- public CtfIterator(final CtfTmfTrace trace, final long timestampValue,
- final long rank) {
+ public CtfIterator(final CtfTmfTrace trace,
+ final CtfLocationData ctfLocationData, final long rank) {
super(trace.getCTFTrace());
this.ctfTmfTrace = trace;
if (this.hasMoreEvents()) {
- this.curLocation = (new CtfLocation(this.getCurrentEvent()
- .getTimestampValue()));
- if (this.getCurrentEvent().getTimestampValue() != timestampValue) {
- this.seek(timestampValue);
+ this.curLocation = new CtfLocation(ctfLocationData);
+ if (this.getCurrentEvent().getTimestampValue() != ctfLocationData.getTimestamp()) {
+ this.seek(ctfLocationData);
this.curRank = rank;
}
} else {
}
/**
- * Method seek. Seeks to a given timestamp
- * @param timestamp long the timestamp in ns (utc)
+ * Seek this iterator to a given location.
+ *
+ * @param ctfLocationData
+ * The LocationData representing the position to seek to
* @return boolean
+ * @since 2.0
*/
- @Override
- public boolean seek(final long timestamp) {
+ public boolean seek(final CtfLocationData ctfLocationData) {
boolean ret = false;
- final long offsetTimestamp = timestamp
- - this.getTrace().getOffset();
+
+ /* Adjust the timestamp depending on the trace's offset */
+ long currTimestamp = ctfLocationData.getTimestamp();
+ final long offsetTimestamp = currTimestamp - this.getTrace().getOffset();
if (offsetTimestamp < 0) {
ret = super.seek(0L);
} else {
ret = super.seek(offsetTimestamp);
}
+ /*
+ * Check if there is already one or more events for that timestamp, and
+ * assign the location index correctly
+ */
+ currTimestamp = this.getCurrentEvent().getTimestampValue();
+ long index = 0;
+ for (long i = 0; i < ctfLocationData.getIndex(); i++) {
+ if (currTimestamp == this.getCurrentEvent().getTimestampValue()) {
+ index++;
+ } else {
+ index = 0;
+ }
+ this.advance();
+ }
+
+ /* Seek the current location accordingly */
if (ret) {
- curLocation.setLocation(getCurrentEvent().getTimestampValue());
+ curLocation.setLocation(new CtfLocationData(getCurrentEvent().getTimestampValue(), index));
} else {
curLocation = NULL_LOCATION;
}
@Override
public CtfIterator clone() {
CtfIterator clone = null;
- clone = new CtfIterator(ctfTmfTrace, this.getCurrentEvent().getTimestampValue(), curRank);
+ clone = new CtfIterator(ctfTmfTrace, this.getLocation().getLocation(), curRank);
return clone;
}
*/
@Override
public boolean advance() {
+ long index = curLocation.getLocation().getIndex();
+ long timestamp = curLocation.getLocation().getTimestamp();
boolean ret = super.advance();
+
if (ret) {
- curLocation.setLocation(getCurrentEvent().getTimestampValue());
+ final long timestampValue = getCurrentEvent().getTimestampValue();
+ if (timestamp == timestampValue) {
+ curLocation.setLocation(timestampValue, index + 1);
+ } else {
+ curLocation.setLocation(timestampValue, 0L);
+ }
} else {
curLocation = NULL_LOCATION;
}
*/
retVal = replaceRandomElement(context);
}
- retVal.seek((Long) context.getLocation().getLocation());
+ final CtfLocationData location = (CtfLocationData) context.getLocation().getLocation();
+ retVal.seek( location);
}
return retVal;
}
/**
* The nugget of information that is unique to a location in a CTF trace.
- *
+ *
* It can be copied and used to restore a position in a given trace.
- *
+ *
* @version 1.0
* @author Matthew Khouzam
*/
-public class CtfLocation implements ITmfLocation<Long>, Cloneable {
+public class CtfLocation implements ITmfLocation<CtfLocationData>, Cloneable {
+
+ private CtfLocationData fLocation;
/**
* An invalid location
*/
- public static final Long INVALID_LOCATION = -1L;
+ public static final CtfLocationData INVALID_LOCATION = new CtfLocationData(-1, -1);
/**
- * Constructor for CtfLocation.
- * @param location Long
+ * Copy constructor
+ *
+ * @param location
+ * Other location to copy
+ * @since 2.0
*/
- public CtfLocation(Long location) {
+ public CtfLocation(CtfLocationData location) {
setLocation(location);
}
/**
- * Constructor for CtfLocation.
- * @param timestamp ITmfTimestamp
+ * Standard constructor
+ *
+ * @param timestamp
+ * The timestamp of this location
+ * @param index
+ * The index of this location for this timestamp
+ * @since 2.0
+ */
+ public CtfLocation(ITmfTimestamp timestamp, long index) {
+ setLocation(new CtfLocationData(timestamp.getValue(), index));
+ }
+
+ /**
+ * Constructor for CtfLocation. Uses a default index of 0.
+ *
+ * @param timestamp
+ * The timestamp of this location
*/
+ @Deprecated
public CtfLocation(ITmfTimestamp timestamp) {
- setLocation(timestamp.getValue());
+ setLocation(new CtfLocationData(timestamp.getValue(), 0));
}
- private Long fTimestamp;
+ /**
+ * Move this location to another location's position.
+ *
+ * @param location
+ * The location to seek to
+ * @since 2.0
+ */
+ public void setLocation(CtfLocationData location) {
+ this.fLocation = location;
+ }
/**
- * Method setLocation.
- * @param location Long
+ * Change this location's timestamp and index values.
+ *
+ * @param timestampValue
+ * The new timestamp
+ * @param index
+ * The new index
+ * @since 2.0
*/
- public void setLocation(Long location) {
- this.fTimestamp = location;
+ public void setLocation(long timestampValue, long index) {
+ this.fLocation = new CtfLocationData(timestampValue, index);
}
+
/**
- * Method getLocation.
- * @return Long
+ * Get the Location Data of this location
+ *
+ * @return The CtfLocationData
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
+ * @since 2.0
*/
@Override
- public Long getLocation() {
- return this.fTimestamp;
+ public CtfLocationData getLocation() {
+ return fLocation;
}
- /**
- * Method clone.
- * @return CtfLocation
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#clone()
- */
@Override
public CtfLocation clone() {
- return new CtfLocation(getLocation().longValue());
+ return new CtfLocation(new CtfLocationData(fLocation.getTimestamp(), fLocation.getIndex()));
}
+
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
final int prime = 31;
int result = 1;
result = (prime * result)
- + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
+ + ((fLocation == null) ? 0 : fLocation.hashCode());
return result;
}
return false;
}
CtfLocation other = (CtfLocation) obj;
- if (fTimestamp == null) {
- if (other.fTimestamp != null) {
+ if (fLocation == null) {
+ if (other.fLocation != null) {
return false;
}
- } else if (!fTimestamp.equals(other.fTimestamp)) {
+ } else if (!fLocation.equals(other.fLocation)) {
return false;
}
return true;
return "CtfLocation: " + getLocation().toString(); //$NON-NLS-1$
}
+
}
--- /dev/null
+/*******************************************************************************
+ * 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.ctfadaptor;
+
+/**
+ * CtfLocationData, the data in a CTF location.
+ *
+ * @author Matthew Khouzam
+ * @since 2.0
+ */
+public class CtfLocationData implements Comparable<CtfLocationData> {
+
+ private final long timestamp;
+ private final long index;
+
+ /**
+ * @param ts
+ * Timestamp
+ * @param index
+ * Index of this event (if there are N elements with the same
+ * timestamp, which one is it.)
+ */
+ public CtfLocationData(long ts, long index) {
+ this.timestamp = ts;
+ this.index = index;
+ }
+
+ /**
+ * @return The timestamp
+ */
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ * @return The index of the element
+ */
+ public long getIndex() {
+ return index;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = (prime * result) + (int) (index ^ (index >>> 32));
+ result = (prime * result) + (int) (timestamp ^ (timestamp >>> 32));
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof CtfLocationData)) {
+ return false;
+ }
+ CtfLocationData other = (CtfLocationData) obj;
+ if (index != other.index) {
+ return false;
+ }
+ if (timestamp != other.timestamp) {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "Element [" + timestamp + '/' + index + ']'; //$NON-NLS-1$
+ }
+
+ @Override
+ public int compareTo(CtfLocationData other) {
+ if (this.timestamp > other.getTimestamp()) {
+ return 1;
+ }
+ if (this.timestamp < other.getTimestamp()) {
+ return -1;
+ }
+ if (this.index > other.getIndex()) {
+ return 1;
+ }
+ if (this.index < other.getIndex()) {
+ return -1;
+ }
+ return 0;
+ }
+
+}
* Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
* a boxed Long, a long and an int.
*
- * @versionj 1.0
+ * @version 1.0
* @author Matthew Khouzam
*/
public class CtfTmfLightweightContext implements ITmfContext {
public CtfTmfLightweightContext(ArrayList<CtfIterator> iters,
ListIterator<CtfIterator> pos) {
fTrace = iters.get(0).getCtfTmfTrace();
- curLocation = new CtfLocation((Long) null);
+ curLocation = new CtfLocation(new CtfLocationData(0, 0));
}
/**
*/
public CtfTmfLightweightContext(CtfTmfTrace ctfTmfTrace) {
fTrace = ctfTmfTrace;
- curLocation = new CtfLocation((Long) null);
+ curLocation = new CtfLocation(new CtfLocationData(0, 0));
}
// -------------------------------------------
@Override
public boolean hasValidRank() {
- return curRank != CtfLocation.INVALID_LOCATION;
+ return curRank != CtfLocation.INVALID_LOCATION.getTimestamp();
}
@Override
* @return success or not
*/
public synchronized boolean advance() {
+ final CtfLocationData curLocationData = this.curLocation.getLocation();
boolean retVal = getIterator().advance();
CtfTmfEvent currentEvent = getIterator().getCurrentEvent();
+
if (currentEvent != null) {
- curLocation.setLocation(currentEvent.getTimestampValue());
+ final long timestampValue = currentEvent.getTimestampValue();
+ if (curLocationData.getTimestamp() == timestampValue) {
+ curLocation.setLocation(timestampValue, curLocationData.getIndex() + 1);
+ } else {
+ curLocation.setLocation(timestampValue, 0L);
+ }
} else {
curLocation.setLocation(CtfLocation.INVALID_LOCATION);
}
* @return success or not
*/
public synchronized boolean seek(final long timestamp) {
- curLocation.setLocation(timestamp);
+ curLocation.setLocation(timestamp, 0);
return getIterator().seek(timestamp);
}
+ /**
+ * Seeks to a given location. Wrapper to help CtfTmfTrace
+ * @param location
+ * unique location to find the event.
+ *
+ * @return success or not
+ * @since 2.0
+ */
+ public synchronized boolean seek(final CtfLocationData location) {
+ curLocation.setLocation(location);
+ return getIterator().seek(location);
+ }
+
/*
* (non-Javadoc)
*
CtfIteratorManager.addTrace(this);
CtfTmfLightweightContext ctx;
/* Set the start and (current) end times for this trace */
- ctx = new CtfTmfLightweightContext(this);
- ctx.setLocation(new CtfLocation(0L));
+ ctx = (CtfTmfLightweightContext) seekEvent(0L);
+ CtfTmfEvent event = getNext(ctx);
if(ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) {
/* Handle the case where the trace is empty */
this.setStartTime(TmfTimestamp.BIG_BANG);
} else {
- final ITmfTimestamp curTime = ctx.getCurrentEvent().getTimestamp();
+ final ITmfTimestamp curTime = event.getTimestamp();
this.setStartTime(curTime);
this.setEndTime(curTime);
}
final CtfTmfLightweightContext context = new CtfTmfLightweightContext(this);
context.setLocation(curLocation);
context.seek(curLocation.getLocation());
- final long currentTime = ((Long)context.getLocation().getLocation());
+ final CtfLocationData currentTime = ((CtfLocationData)context.getLocation().getLocation());
final long startTime = getIterator(this, context).getStartTime();
final long endTime = getIterator(this, context).getEndTime();
- return ((double) currentTime - startTime)
+ return ((double) currentTime.getTimestamp() - startTime)
/ (endTime - startTime);
}
* by rank for now.
*/
if (currentLocation == null) {
- currentLocation = new CtfLocation(0L);
+ currentLocation = new CtfLocation(new CtfLocationData(0L, 0L));
context.setRank(0);
}
if (currentLocation.getLocation() == CtfLocation.INVALID_LOCATION) {
((CtfTmfTimestamp) getEndTime()).setType(TimestampType.NANOS);
- currentLocation.setLocation(getEndTime().getValue() + 1);
+ currentLocation.setLocation(getEndTime().getValue() + 1, 0L);
}
context.setLocation(currentLocation);
if(context.getRank() != 0) {