instead of per context.
MAJOR performance and stability improvement.
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
package org.eclipse.linuxtools.ctf.core.tests.trace;
-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;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-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.After;
import org.junit.Before;
public void testStreamInputReaderComparator() {
assertNotNull(fixture);
}
-
- /**
- * Run the int compare(StreamInputReader,StreamInputReader) method test.
- *
- * @throws CTFReaderException
- */
- @Test
- public void testCompare() throws CTFReaderException {
- StreamInputReader sir1, sir2;
- EventDefinition ed1, ed2;
-
- sir1 = new StreamInputReader(new StreamInput(new Stream(
- TestParams.createTrace()), (FileChannel) null,
- TestParams.getEmptyFile()));
- ed1 = new EventDefinition(new EventDeclaration(),
- new StreamInputReader(new StreamInput(new Stream(
- TestParams.createTrace()), (FileChannel) null,
- TestParams.getEmptyFile())));
- ed1.setTimestamp(1L);
- sir1.setCurrentEvent(ed1);
-
- sir2 = new StreamInputReader(new StreamInput(new Stream(
- TestParams.createTrace()), (FileChannel) null,
- TestParams.getEmptyFile()));
- ed2 = new EventDefinition(new EventDeclaration(),
- new StreamInputReader(new StreamInput(new Stream(
- TestParams.createTrace()), (FileChannel) null,
- TestParams.getEmptyFile())));
-
- ed2.setTimestamp(1L);
- sir2.setCurrentEvent(ed2);
-
- int result = fixture.compare(sir1, sir2);
- assertEquals(0, result);
- }
}
package org.eclipse.linuxtools.ctf.core.tests.trace;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-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.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.StreamInputReaderTimestampComparator;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* The class <code>StreamInputReaderTimestampComparatorTest</code> contains
* tests for the class <code>{@link StreamInputReaderTimestampComparator}</code>
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
assertNotNull(fixture);
}
- /**
- * Run the int compare(StreamInputReader,StreamInputReader) method test.
- *
- * @throws CTFReaderException
- */
- @Test
- public void testCompare() throws CTFReaderException {
- StreamInputReader a, b;
- a = new StreamInputReader(new StreamInput(new Stream(
- TestParams.createTrace()), (FileChannel) null,
- TestParams.getEmptyFile()));
- a.setCurrentEvent(null);
- b = new StreamInputReader(new StreamInput(new Stream(
- TestParams.createTrace()), (FileChannel) null,
- TestParams.getEmptyFile()));
-
- int result = fixture.compare(a, b);
- assertEquals(0, result);
- }
}
(FileChannel) null, createFile());
assertEquals(s1,s2);
}
- @Test
- public void testEquals5() throws CTFReaderException{
- s1 = new StreamInput(new Stream(TestParams.createTrace()),
- (FileChannel) null, createFile());
- s2 = new StreamInput(new Stream(null),
- (FileChannel) null, new File("")); //$NON-NLS-1$
- assertFalse(s1.equals(s2));
- }
- @Test
- public void testEquals6(){
- s1 = new StreamInput(new Stream(null),
- (FileChannel) null, null);
- s2 = new StreamInput(new Stream(null),
- (FileChannel) null, new File("")); //$NON-NLS-1$
-
-
- assertFalse(s1.equals(s2));
- }
- @Test
- public void testEquals7() throws CTFReaderException{
- s1 = new StreamInput(new Stream(null),
- (FileChannel) null, new File("")); //$NON-NLS-1$
- s2 = new StreamInput(new Stream(TestParams.createTrace()),
- (FileChannel) null, createFile());
- assertFalse(s1.equals(s2));
- }
}
\ No newline at end of file
/**
* Perform pre-test initialization.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
/**
* Run the Stream(CTFTrace) constructor test.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Test
public void testStream() throws CTFReaderException {
fixture.addEvent(event);
}
- /**
- * Run the void addEvent(EventDeclaration) method test with an event
- * of which we modified the id.
- * @throws ParseException
- *
- * @throws ParseException
- */
- @Test
- public void testAddEvent_modifiedEvent() throws ParseException {
- EventDeclaration event = new EventDeclaration();
- event.setId(1L);
- fixture.addEvent(event);
- assertNotNull(fixture);
- }
-
/**
* Run the boolean eventContextIsSet() method test.
*/
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-
import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
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.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;
assertFalse(result);
}
- /**
- * Run the EventDefinition createDefinition(StreamInputReader) method test.
- *
- * @throws CTFReaderException
- * @throws FileNotFoundException
- */
- @Test
- public void testCreateDefinition() throws CTFReaderException, FileNotFoundException {
- StreamInputReader streamInputReader = new StreamInputReader(
- new StreamInput(new Stream(TestParams.createTrace()),
- (new FileInputStream(TestParams.getTraceFile())).getChannel(), TestParams.getTraceFile()));
-
- EventDefinition result = fixture.createDefinition(streamInputReader);
- assertNotNull(result);
- }
-
/**
* Run the boolean equals(Object) method test.
*
import org.eclipse.linuxtools.ctf.core.event.CTFClock;
import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
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.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.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
/**
* <b><u>CTFTrace</u></b>
// fieldJavadoc
/** map of all the event types */
- private final HashMap<Long, EventDeclaration> events;
+ private final HashMap<Long,HashMap<Long, EventDeclaration>> eventDecs;
+ /** map of all the event types */
+ private final HashMap<StreamInput,HashMap<Long, EventDefinition>> eventDefs;
+ /** map of all the indexes */
+ private final HashMap<StreamInput, StreamInputPacketIndex> indexes;
+
+
// ------------------------------------------------------------------------
// Constructors
environment = new HashMap<String, String>();
clocks = new HashMap<String, CTFClock>();
streamFileChannels = new LinkedList<FileChannel>();
+ eventDecs = new HashMap<Long, HashMap<Long, EventDeclaration>>();
+ eventDefs = new HashMap<StreamInput, HashMap<Long, EventDefinition>>();
if (!this.path.isDirectory()) {
throw new CTFReaderException("Path must be a valid directory"); //$NON-NLS-1$
/* List files not called metadata and not hidden. */
File[] files = path.listFiles(metadataFileFilter);
Arrays.sort(files, metadataComparator);
-
+ indexes = new HashMap<StreamInput, StreamInputPacketIndex>();
/* Try to open each file */
for (File streamFile : files) {
openStreamInput(streamFile);
}
- events = new HashMap<Long, EventDeclaration>();
+
/* Create their index */
for (Map.Entry<Long, Stream> stream : streams.entrySet()) {
Set<StreamInput> inputs = stream.getValue().getStreamInputs();
Map.Entry<Long, EventDeclaration> pairs = it.next();
Long eventNum = pairs.getKey();
EventDeclaration eventDec = pairs.getValue();
- events.put(eventNum, eventDec);
+ getEvents(s.getStream().getId()).put(eventNum, eventDec);
}
/*
// ------------------------------------------------------------------------
/**
- * Get an event by it's ID
- *
- * @param id
- * the ID of the event
- * @return the event declaration
+ * Gets an event declaration hashmap for a given streamID
+ * @param streanId
+ * @return the hashmap with the event declarations
+ */
+ public HashMap<Long, EventDeclaration> getEvents(Long streanId) {
+ return eventDecs.get(streanId);
+ }
+
+ /**
+ * Gets an index for a given StreamInput
+ * @param id the StreamInput
+ * @return The index
*/
- public EventDeclaration getEventType(long id) {
- return events.get(id);
+ public StreamInputPacketIndex getIndex(StreamInput id){
+ if(! indexes.containsKey(id)){
+ indexes.put(id, new StreamInputPacketIndex());
+ }
+ return indexes.get(id);
}
/**
- * Get the number of events in the trace so far.
+ * Gets an event Declaration hashmap for a given StreamInput
+ * @param id the StreamInput
+ * @return the hashmap with the event definitions
+ */
+ public HashMap<Long, EventDefinition> getEventDefs(StreamInput id) {
+ if(! eventDefs.containsKey(id)){
+ eventDefs.put(id, new HashMap<Long, EventDefinition>());
+ }
+ return eventDefs.get(id);
+ }
+
+ /**
+ * Get an event by it's ID
*
- * @return the number of events in the trace
+ * @param id
+ * the ID of the event
+ * @return the event declaration
*/
- public int getNbEventTypes() {
- return events.size();
+ public EventDeclaration getEventType(long streamId, long id) {
+ return getEvents(streamId).get(id);
}
/**
}
/*
- * If the stream we try to add has the null key, it must be the only
- * one. Thus, if the streams container is not empty, it is not valid.
+ * If the stream we try to add has the null key, it must be the onl * one. Thus, if the streams container is not empty, it is not valid.
*/
if ((stream.getId() == null) && (streams.size() != 0)) {
throw new ParseException("Stream without id with multiple streams"); //$NON-NLS-1$
/* It should be ok now. */
streams.put(stream.getId(), stream);
+ eventDecs.put(stream.getId(), new HashMap<Long,EventDeclaration>());
}
public HashMap<String, String> getEnvironment() {
return singleOffset;
}
+ public boolean hasEvents(Long id){
+ return eventDecs.containsKey(id);
+ }
+ public HashMap<Long, EventDeclaration> createEvents(Long id){
+ HashMap<Long, EventDeclaration> value = eventDecs.get(id);
+ if( value == null ) {
+ value = new HashMap<Long, EventDeclaration>();
+ eventDecs.put(id, value);
+ }
+ return value;
+ }
+
}
class MetadataFileFilter implements FileFilter {
* For each trace file of the stream.
*/
for (StreamInput streamInput : streamInputs) {
- streamInput.getIndex().getEntries().clear();
/*
* Create a reader.
*/
/**
* Maps event ID to event definitions.
*/
- private final HashMap<Long, EventDefinition> events = new HashMap<Long, EventDefinition>();
+ private final HashMap<Long, EventDefinition> events;
/**
* CPU id of current packet.
*/
getBitBuffer().setByteOrder(streamInputReader.getByteOrder());
+ events = streamInputReader.getStreamInput().getStream().getTrace()
+ .getEventDefs(streamInputReader.getStreamInput());
/*
* Create definitions needed to read the events.
*/
createDefinitions();
- lostEvents = 0 ;
- lostSoFar = 0 ;
+ lostEvents = 0;
+ lostSoFar = 0;
}
// ------------------------------------------------------------------------
/*
* Create trace packet header definition.
*/
- final Stream currentStream = getStreamInputReader().getStreamInput().getStream();
- StructDeclaration tracePacketHeaderDecl = currentStream.getTrace().getPacketHeader();
+ final Stream currentStream = getStreamInputReader().getStreamInput()
+ .getStream();
+ StructDeclaration tracePacketHeaderDecl = currentStream.getTrace()
+ .getPacketHeader();
if (tracePacketHeaderDecl != null) {
- setTracePacketHeaderDef(tracePacketHeaderDecl.createDefinition(this,
- "trace.packet.header")); //$NON-NLS-1$
+ setTracePacketHeaderDef(tracePacketHeaderDecl.createDefinition(
+ this, "trace.packet.header")); //$NON-NLS-1$
}
/*
* Create stream packet context definition.
*/
- StructDeclaration streamPacketContextDecl = currentStream.getPacketContextDecl();
+ StructDeclaration streamPacketContextDecl = currentStream
+ .getPacketContextDecl();
if (streamPacketContextDecl != null) {
setStreamPacketContextDef(streamPacketContextDecl.createDefinition(
this, "stream.packet.context")); //$NON-NLS-1$
/*
* Create stream event header definition.
*/
- StructDeclaration streamEventHeaderDecl = currentStream.getEventHeaderDecl();
+ StructDeclaration streamEventHeaderDecl = currentStream
+ .getEventHeaderDecl();
if (streamEventHeaderDecl != null) {
- setStreamEventHeaderDef(streamEventHeaderDecl.createDefinition(this,
- "stream.event.header")); //$NON-NLS-1$
+ setStreamEventHeaderDef(streamEventHeaderDecl.createDefinition(
+ this, "stream.event.header")); //$NON-NLS-1$
}
/*
* Create stream event context definition.
*/
- StructDeclaration streamEventContextDecl = currentStream.getEventContextDecl();
+ StructDeclaration streamEventContextDecl = currentStream
+ .getEventContextDecl();
if (streamEventContextDecl != null) {
setStreamEventContextDef(streamEventContextDecl.createDefinition(
this, "stream.event.context")); //$NON-NLS-1$
* Creates definitions needed to read the event. (event-defined).
*/
private void createEventDefinitions() {
- Collection<EventDeclaration> eventDecls = getStreamInputReader().getStreamInput().getStream().getEvents().values();
+ Collection<EventDeclaration> eventDecls = getStreamInputReader()
+ .getStreamInput().getStream().getEvents().values();
/*
* Create definitions for each event.
*/
for (EventDeclaration event : eventDecls) {
- EventDefinition eventDef = event.createDefinition(getStreamInputReader());
-
- events.put(event.getId(), eventDef);
+ if (!events.containsKey(event.getId())) {
+ EventDefinition eventDef = event
+ .createDefinition(getStreamInputReader());
+ events.put(event.getId(), eventDef);
+ }
}
}
*/
MappedByteBuffer bb = null;
try {
- bb = getStreamInputReader().getStreamInput().getFileChannel().map(
- MapMode.READ_ONLY, this.currentPacket.getOffsetBytes(),
- (this.currentPacket.getPacketSizeBits() + 7) / 8);
+ bb = getStreamInputReader()
+ .getStreamInput()
+ .getFileChannel()
+ .map(MapMode.READ_ONLY,
+ this.currentPacket.getOffsetBytes(),
+ (this.currentPacket.getPacketSizeBits() + 7) / 8);
} catch (IOException e) {
/*
* The streamInputReader object is already allocated, so this
* Read CPU ID
*/
- Definition cpuiddef = getStreamPacketContextDef().lookupDefinition("cpu_id"); //$NON-NLS-1$
+ Definition cpuiddef = getStreamPacketContextDef()
+ .lookupDefinition("cpu_id"); //$NON-NLS-1$
if (cpuiddef instanceof IntegerDefinition) {
- currentCpu = (int) ((IntegerDefinition) cpuiddef).getValue();
+ currentCpu = (int) ((IntegerDefinition) cpuiddef)
+ .getValue();
}
/*
* Read number of lost events
*/
- Definition lostEventsdef = getStreamPacketContextDef().lookupDefinition("events_discarded"); //$NON-NLS-1$
+ Definition lostEventsdef = getStreamPacketContextDef()
+ .lookupDefinition("events_discarded"); //$NON-NLS-1$
if (cpuiddef instanceof IntegerDefinition) {
- lostEvents = (int) ((IntegerDefinition) lostEventsdef).getValue();
+ lostEvents = (int) ((IntegerDefinition) lostEventsdef)
+ .getValue();
}
}
*/
public boolean hasMoreEvents() {
if (currentPacket != null) {
- return getBitBuffer().position() < currentPacket.getContentSizeBits();
+ return getBitBuffer().position() < currentPacket
+ .getContentSizeBits();
}
return false;
}
Long eventID = null;
long timestamp = 0;
-
- if( lostEvents > lostSoFar)
- {
- EventDefinition eventDef = EventDeclaration.getLostEventDeclaration().createDefinition(streamInputReader);
+ if (lostEvents > lostSoFar) {
+ EventDefinition eventDef = EventDeclaration
+ .getLostEventDeclaration().createDefinition(
+ streamInputReader);
eventDef.setTimestamp(this.lastTimestamp);
++lostSoFar;
return eventDef;
}
- StructDefinition sehd = getStreamEventHeaderDef(); // acronym for a long variable name
+ StructDefinition sehd = getStreamEventHeaderDef(); // acronym for a long
+ // variable name
BitBuffer currentBitBuffer = getBitBuffer();
/*
* Read the stream event header.
/*
* Check for an event id.
*/
- EnumDefinition idEnumDef = (EnumDefinition) sehd.lookupDefinition("id"); //$NON-NLS-1$
+ EnumDefinition idEnumDef = (EnumDefinition) sehd
+ .lookupDefinition("id"); //$NON-NLS-1$
assert (idEnumDef != null);
eventID = idEnumDef.getIntegerValue();
/*
* Check for the variant v.
*/
- VariantDefinition variantDef = (VariantDefinition) sehd.lookupDefinition("v"); //$NON-NLS-1$
+ VariantDefinition variantDef = (VariantDefinition) sehd
+ .lookupDefinition("v"); //$NON-NLS-1$
assert (variantDef != null);
/*
* Get the variant current field
*/
- StructDefinition variantCurrentField = (StructDefinition) variantDef.getCurrentField();
+ StructDefinition variantCurrentField = (StructDefinition) variantDef
+ .getCurrentField();
assert (variantCurrentField != null);
/*
* Try to get the id field in the current field of the variant. If
* it is present, it overrides the previously read event id.
*/
- IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
+ IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField
+ .lookupDefinition("id"); //$NON-NLS-1$
if (idIntegerDef != null) {
eventID = idIntegerDef.getValue();
}
/*
* Get the timestamp.
*/
- IntegerDefinition timestampDef = (IntegerDefinition) variantCurrentField.lookupDefinition("timestamp"); //$NON-NLS-1$
+ IntegerDefinition timestampDef = (IntegerDefinition) variantCurrentField
+ .lookupDefinition("timestamp"); //$NON-NLS-1$
assert (timestampDef != null);
/*
return lastTimestamp;
}
+ @SuppressWarnings("unused")
@Override
public Definition lookupDefinition(String lookupPath) {
// TODO Auto-generated method stub
this.streamEventHeaderDef = streamEventHeaderDef;
}
- public void setStreamPacketContextDef(StructDefinition streamPacketContextDef) {
+ public void setStreamPacketContextDef(
+ StructDefinition streamPacketContextDef) {
this.streamPacketContextDef = streamPacketContextDef;
}
/**
* Maps event ids to events
*/
- private final HashMap<Long, EventDeclaration> events = new HashMap<Long, EventDeclaration>();
+ private HashMap<Long, EventDeclaration> events;
/**
* The inputs associated to this stream
public void setId(long id) {
this.id = id;
+ this.events = trace.createEvents(this.id);
}
public Long getId() {
this.stream = stream;
this.fileChannel = fileChannel;
this.file = file;
- index = new StreamInputPacketIndex();
+ index = stream.getTrace().getIndex(this);
}
// ------------------------------------------------------------------------
/*******************************************************************************
* 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
*******************************************************************************/
*/
@Test
public void testGetFieldValue() {
- String fieldName = "ret"; //$NON-NLS-1$
- Object result = fixture.getContent().getField(fieldName).getValue();
+ String fieldName = "pid"; //$NON-NLS-1$
+ ITmfEventField result = fixture.getContent().getField(fieldName);
assertNotNull(result);
+ assertNotNull(result.getValue());
}
/**
String source = fixture.getSource();
ITmfEventType type = fixture.getType();
assertEquals(rank, 0);
- assertEquals(trace.getName(), "kernel"); //$NON-NLS-1$
+ assertEquals(trace.getName(), "test"); //$NON-NLS-1$
assertEquals(channelName, "channel0_1"); //$NON-NLS-1$
assertEquals(reference,"channel0_1"); //$NON-NLS-1$
assertEquals(source, "1"); //$NON-NLS-1$
- assertEquals(type.toString(), "exit_syscall"); //$NON-NLS-1$
+ assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
}
@Test
public void testToString() {
String s = fixture.getContent().toString();
- assertEquals("ret=4132", s); //$NON-NLS-1$
+ assertEquals("pid=1922, inode=917738, flags=134217845, end=3074342912, start=3074334720, pgoff=0", s); //$NON-NLS-1$
}
}
assertEquals(null, result.getType());
}
+ @Test
+ public void testParseEvent() throws TmfTraceException{
+ CtfTmfTrace fixture = initTrace();
+ ITmfContext ctx = fixture.seekEvent(0);
+ fixture.getNext(ctx);
+ CtfTmfEvent event = fixture.parseEvent(ctx);
+ assertNotNull(event);
+ }
+
/**
* @return
* @throws TmfTraceException
// An unexpected exception was thrown in user code while executing this test:
// org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException: Path must be a valid directory
// at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace.initTrace(CtfTmfTrace.java:98)
- assertEquals(Double.POSITIVE_INFINITY, result, 0.1);
+ assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
}
/**
public void testSeekEvent_1()
throws Exception {
CtfTmfTrace fixture = initTrace();
- double ratio = 1.0;
+ double ratio = 0.99;
ITmfContext result = fixture.seekEvent(ratio);
}
return 0;
}
+
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
--- /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;
+
+import java.util.ArrayList;
+import java.util.ListIterator;
+
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+
+/**
+ * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
+ * a boxed Long, a long and an int.
+ *
+ * @author Matthew Khouzam
+ *
+ */
+public class CtfTmfLightweightContext implements ITmfContext {
+
+ // -------------------------------------------
+ // Constants
+ // -------------------------------------------
+ private static final int MAX_COLLISIONS = 10;
+
+ // -------------------------------------------
+ // Fields
+ // -------------------------------------------
+ private CtfLocation curLocation;
+ private long curRank;
+ private int collisions;
+
+ private CtfIterator fSeeker;
+ final private ArrayList<CtfIterator> fIteratorPool;
+ private ListIterator<CtfIterator> fCurrentIterator;
+
+ // -------------------------------------------
+ // Constructor
+ // -------------------------------------------
+ /**
+ *
+ * @param iters
+ * the shared iterator pool.
+ * @param pos
+ * the iterator position.
+ */
+ public CtfTmfLightweightContext(ArrayList<CtfIterator> iters,
+ ListIterator<CtfIterator> pos) {
+ fIteratorPool = iters;
+ fCurrentIterator = pos;
+ fSeeker = getIterator();
+ curLocation = new CtfLocation((Long)null);
+ collisions = 0;
+ }
+
+ // -------------------------------------------
+ // TmfContext Overrides
+ // -------------------------------------------
+
+ @Override
+ public long getRank() {
+ return curRank;
+ }
+
+ @Override
+ public ITmfLocation<? extends Comparable<?>> getLocation() {
+ return curLocation;
+ }
+
+ @Override
+ public boolean hasValidRank() {
+ return curRank != CtfLocation.INVALID_LOCATION;
+ }
+
+ @Override
+ public void setLocation(ITmfLocation<? extends Comparable<?>> location) {
+ curLocation = (CtfLocation) location;
+ updateLocation();
+ }
+
+ @Override
+ public void setRank(long rank) {
+ curRank = rank;
+
+ }
+
+ @Override
+ public void increaseRank() {
+ if (hasValidRank()) {
+ curRank++;
+ }
+ }
+
+ // -------------------------------------------
+ // CtfTmfTrace Helpers
+ // -------------------------------------------
+
+ /**
+ * Gets the current event. Wrapper to help CtfTmfTrace
+ * @return The event or null
+ */
+ public synchronized CtfTmfEvent getCurrentEvent() {
+ updateLocation();
+ return fSeeker.getCurrentEvent();
+ }
+
+ /**
+ * Advances to a the next event. Wrapper to help CtfTmfTrace
+ * @return success or not
+ */
+ public synchronized boolean advance() {
+ updateLocation();
+ boolean retVal = fSeeker.advance();
+ CtfTmfEvent currentEvent = fSeeker.getCurrentEvent();
+ if (currentEvent != null) {
+ curLocation.setLocation(currentEvent.getTimestampValue());
+ } else {
+ curLocation.setLocation(CtfLocation.INVALID_LOCATION);
+ }
+
+ return retVal;
+ }
+
+ @Override
+ public void dispose() {
+ // do nothing
+ }
+
+ /**
+ * Seeks to a given timestamp. Wrapper to help CtfTmfTrace
+ * @param timestamp desired timestamp
+ * @return success or not
+ */
+ public synchronized boolean seek(final long timestamp) {
+ curLocation.setLocation(timestamp);
+ collisions = 0;
+ fSeeker = getIterator();
+ return updateLocation();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public CtfTmfLightweightContext clone() {
+ CtfTmfLightweightContext ret = new CtfTmfLightweightContext(
+ fIteratorPool, fCurrentIterator);
+ ret.curLocation = curLocation.clone();
+ ret.curRank = curRank;
+ return ret;
+ }
+
+ // -------------------------------------------
+ // Private helpers
+ // -------------------------------------------
+ /**
+ * This updates the position of an iterator to the location(curLocation)
+ * Since the iterators are in a pool to not exhaust the number of file
+ * pointers some of them can be shared. This means there can be collisions
+ * between contexts fighting over the same resource. A heuristic is applied
+ * that if there are MAX_COLLISIONS collisions in a row, the iterator is
+ * changed for the next one in the iterator pool.
+ *
+ * @return true if the location is correct.
+ */
+ private synchronized boolean updateLocation() {
+ if (!curLocation.getLocation().equals(
+ (fSeeker.getLocation().getLocation()))) {
+ collisions++;
+ if (collisions > MAX_COLLISIONS) {
+ fSeeker = getIterator();
+ collisions = 0;
+ }
+ fSeeker.setRank(curRank);
+ return fSeeker.seek(curLocation.getLocation());
+ }
+ collisions = 0;
+ return true;
+ }
+
+ /**
+ * gets the next iterator in a pool.
+ *
+ * @return
+ */
+ private CtfIterator getIterator() {
+ if (!fCurrentIterator.hasNext()) {
+ fCurrentIterator = fIteratorPool.listIterator(0);
+ }
+ return fCurrentIterator.next();
+ }
+
+}
package org.eclipse.linuxtools.tmf.core.ctfadaptor;
+import java.util.ArrayList;
+import java.util.ListIterator;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-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.ctfadaptor.CtfTmfTimestamp.TimestampType;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParser<CtfTmfEvent>{
+
//-------------------------------------------
// Constants
//-------------------------------------------
* Default cache size for CTF traces
*/
protected static final int DEFAULT_CACHE_SIZE = 50000;
+ private static final int ITER_POOL_SIZE = 128;
//-------------------------------------------
// Fields
/* Reference to the CTF Trace */
private CTFTrace fTrace;
+ /*
+ * The iterator pool. This is a necessary change since larger traces will
+ * need many contexts and each context must have to a file pointer. Since
+ * the OS supports only so many handles on a given file, but the UI must
+ * still be responsive, parallel seeks (up to ITER_POOL_SIZE requests)
+ * can be made with a fast response time.
+ * */
+ private ArrayList<CtfIterator> fIterators;
+ private ListIterator<CtfIterator> nextIter;
+
//-------------------------------------------
// TmfTrace Overrides
//-------------------------------------------
*/
setCacheSize();
super.initTrace(resource, path, eventType);
- EventDeclaration ed;
- ITmfEventField eventField;
@SuppressWarnings("unused")
CtfTmfEventType type;
try {
this.fTrace = new CTFTrace(path);
- for( int i =0 ; i< this.fTrace.getNbEventTypes(); i++) {
- ed = this.fTrace.getEventType(i);
- eventField = parseDeclaration(ed);
- /*
- * Populate the event manager with event types that are there in
- * the beginning.
- */
- type = new CtfTmfEventType(ed.getName(), eventField);
+ fIterators = new ArrayList<CtfIterator>(ITER_POOL_SIZE);
+ for(int i = 0 ; i < ITER_POOL_SIZE; i++){
+ fIterators.add(new CtfIterator(this, 0, 0));
}
-
+ nextIter = fIterators.listIterator(0);
/* Set the start and (current) end times for this trace */
- final CtfIterator iterator = new CtfIterator(this, 0, 0);
+ final CtfIterator iterator = getIterator();
if(iterator.getLocation().equals(CtfIterator.NULL_LOCATION)) {
/* Handle the case where the trace is empty */
this.setStartTime(TmfTimestamp.BIG_BANG);
@Override
public double getLocationRatio(ITmfLocation<?> location) {
final CtfLocation curLocation = (CtfLocation) location;
- CtfIterator iterator = new CtfIterator(this);
- iterator.seek(curLocation.getLocation());
- return ((double) iterator.getCurrentEvent().getTimestampValue() - iterator
- .getStartTime())
+ CtfIterator iterator = getIterator();
+ CtfTmfLightweightContext ctx = new CtfTmfLightweightContext(fIterators, nextIter);
+ ctx.setLocation(curLocation);
+ ctx.seek(curLocation.getLocation());
+ long currentTime = ((Long)ctx.getLocation().getLocation());
+
+ return ((double) currentTime - iterator.getStartTime())
/ (iterator.getEndTime() - iterator.getStartTime());
}
+ /**
+ * @return
+ */
+ private CtfIterator getIterator() {
+ if( !nextIter.hasNext()){
+ nextIter = fIterators.listIterator(0);
+ }
+ return nextIter.next();
+ }
+
/* (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
*/
@Override
public synchronized ITmfContext seekEvent(ITmfTimestamp timestamp) {
if( timestamp instanceof CtfTmfTimestamp){
- CtfIterator iter = new CtfIterator(this);
+ CtfTmfLightweightContext iter = new CtfTmfLightweightContext(fIterators, nextIter);
iter.seek(timestamp.getValue());
return iter;
}
@Override
public ITmfContext seekEvent(final ITmfLocation<?> location) {
CtfLocation currentLocation = (CtfLocation) location;
- CtfIterator context = new CtfIterator(this);
- context.setRank(ITmfContext.UNKNOWN_RANK);
-
+ CtfTmfLightweightContext context = new CtfTmfLightweightContext(fIterators, nextIter);
/*
* The rank is set to 0 if the iterator seeks the beginning. If not, it
* will be set to UNKNOWN_RANK, since CTF traces don't support seeking
@Override
public ITmfContext seekEvent(double ratio) {
- CtfIterator context = new CtfIterator(this);
+ CtfTmfLightweightContext context = new CtfTmfLightweightContext(fIterators, nextIter);
context.seek((long) (this.getNbEvents() * ratio));
context.setRank(ITmfContext.UNKNOWN_RANK);
return context;
@Override
public synchronized CtfTmfEvent getNext(final ITmfContext context) {
CtfTmfEvent event = null;
- if (context instanceof CtfIterator) {
- CtfIterator ctfIterator = (CtfIterator) context;
- event = ctfIterator.getCurrentEvent();
+ if (context instanceof CtfTmfLightweightContext) {
+ CtfTmfLightweightContext ctfContext = (CtfTmfLightweightContext) context;
+ event = ctfContext.getCurrentEvent();
if (event != null) {
updateAttributes(context, event.getTimestamp());
- ctfIterator.advance();
- ctfIterator.increaseRank();
+ ctfContext.advance();
+ ctfContext.increaseRank();
}
}
return this.ss;
}
- /**
- *
- * @param ed
- * @return
- */
- private static ITmfEventField parseDeclaration(EventDeclaration ed) {
- EventDefinition eventDef = ed.createDefinition(null);
- return new CtfTmfContent(ITmfEventField.ROOT_FIELD_ID,
- CtfTmfEvent.parseFields(eventDef));
- }
-
/**
* gets the CTFtrace that this is wrapping
* @return the CTF trace
@Override
public CtfTmfEvent parseEvent(ITmfContext context) {
CtfTmfEvent event = null;
- if( context instanceof CtfIterator ){
- CtfIterator itt = (CtfIterator) context.clone();
+ if( context instanceof CtfTmfLightweightContext ){
+ CtfTmfLightweightContext itt = (CtfTmfLightweightContext) context.clone();
event = itt.getCurrentEvent();
}
return event;