<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
-#Fri Aug 28 13:26:55 EDT 2009
+#Tue Sep 08 23:48:46 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
-#Fri Aug 28 13:28:13 EDT 2009
+#Tue Sep 08 23:49:41 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="stubs"/>
-#Fri Aug 28 09:59:03 EDT 2009
+#Tue Sep 08 23:49:00 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.lttng.ui.views;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * <b><u>ViewsLabels</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class Labels extends NLS {
-
- private static final String BUNDLE_NAME = "org.eclipse.linuxtools.lttng.ui.views.labels"; //$NON-NLS-1$
-
- // Control Flow View
- public static String ControlFlowView_ID;
-
- // Control View
- public static String ControlView_ID;
-
- // Events View
- public static String EventsView_ID;
-
- // Histogram View
- public static String HistogramView_ID;
-
- // Project View
- public static String ProjectView_ID;
-
- // resources View
- public static String ResourcesView_ID;
-
- // Statistics View
- public static String StatisticsView_ID;
-
- // Time Frame view
- public static String TimeFrameView_ID;
- public static String TimeFrameView_Seconds;
- public static String TimeFrameView_Nanosec;
- public static String TimeFrameView_StartTime;
- public static String TimeFrameView_EndTime;
- public static String TimeFrameView_TimeRange;
- public static String TimeFrameView_CurrentTime;
-
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Labels.class);
- }
-
- private Labels() {
- }
-
-}
package org.eclipse.linuxtools.lttng.ui.views;
+import org.eclipse.linuxtools.lttng.ui.views.control.ControlView;
+import org.eclipse.linuxtools.lttng.ui.views.controlflow.ControlFlowView;
+import org.eclipse.linuxtools.lttng.ui.views.events.EventsView;
+import org.eclipse.linuxtools.lttng.ui.views.histogram.HistogramView;
+import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView;
+import org.eclipse.linuxtools.lttng.ui.views.resources.ResourcesView;
+import org.eclipse.linuxtools.lttng.ui.views.statistics.StatisticsView;
+import org.eclipse.linuxtools.lttng.ui.views.timeframe.TimeFrameView;
import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class PerspectiveFactory implements IPerspectiveFactory {
// LTTng views
- private static final String PROJECT_VIEW_ID = Labels.ProjectView_ID;
- private static final String CONTROL_VIEW_ID = Labels.ControlView_ID;
- private static final String EVENTS_VIEW_ID = Labels.EventsView_ID;
- private static final String TIME_FRAME_VIEW_ID = Labels.TimeFrameView_ID;
- private static final String CONTROL_FLOW_VIEW_ID = Labels.ControlFlowView_ID;
- private static final String RESOURCES_VIEW_ID = Labels.ResourcesView_ID;
- private static final String STATISTICS_VIEW_ID = Labels.StatisticsView_ID;
- private static final String HISTOGRAM_VIEW_ID = Labels.HistogramView_ID;
+ private static final String PROJECT_VIEW_ID = ProjectView.ID;
+ private static final String CONTROL_VIEW_ID = ControlView.ID;
+ private static final String EVENTS_VIEW_ID = EventsView.ID;
+ private static final String TIME_FRAME_VIEW_ID = TimeFrameView.ID;
+ private static final String CONTROL_FLOW_VIEW_ID = ControlFlowView.ID;
+ private static final String RESOURCES_VIEW_ID = ResourcesView.ID;
+ private static final String STATISTICS_VIEW_ID = StatisticsView.ID;
+ private static final String HISTOGRAM_VIEW_ID = HistogramView.ID;
// Standard Eclipse views
private static final String PROPERTIES_VIEW_ID = IPageLayout.ID_PROP_SHEET;
package org.eclipse.linuxtools.lttng.ui.views.control;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
*/
public class ControlView extends ViewPart {
- public static final String ID = Labels.ControlView_ID;
+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.control";
/**
*
package org.eclipse.linuxtools.lttng.ui.views.controlflow;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
*/
public class ControlFlowView extends ViewPart {
- public static final String ID = Labels.ControlFlowView_ID;
+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.controlflow";
/**
*
package org.eclipse.linuxtools.lttng.ui.views.events;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.ui.views.TmfEventsView;
import org.eclipse.swt.SWT;
*/
public class EventsView extends TmfEventsView {
- public static final String ID = Labels.EventsView_ID;
+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.events";
// ========================================================================
// Table data
package org.eclipse.linuxtools.lttng.ui.views.histogram;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
*/
public class HistogramView extends ViewPart {
- public static final String ID = Labels.HistogramView_ID;
+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.histogram";
/**
*
+++ /dev/null
-ControlFlowView_ID=org.eclipse.linuxtools.lttng.ui.views.controlflow
-
-ControlView_ID=org.eclipse.linuxtools.lttng.ui.views.control
-
-EventsView_ID=org.eclipse.linuxtools.lttng.ui.views.events
-
-HistogramView_ID=org.eclipse.linuxtools.lttng.ui.views.histogram
-
-ProjectView_ID=org.eclipse.linuxtools.lttng.ui.views.project
-
-ResourcesView_ID=org.eclipse.linuxtools.lttng.ui.views.resources
-
-StatisticsView_ID=org.eclipse.linuxtools.lttng.ui.views.statistics
-
-TimeFrameView_ID=org.eclipse.linuxtools.lttng.ui.views.timeframe
-TimeFrameView_Seconds=sec
-TimeFrameView_Nanosec=ns
-TimeFrameView_StartTime=Start Time
-TimeFrameView_EndTime=End Time
-TimeFrameView_TimeRange=Interval
-TimeFrameView_CurrentTime=Current Time
package org.eclipse.linuxtools.lttng.ui.views.project;
-import org.eclipse.core.internal.resources.File;
+import org.eclipse.core.internal.resources.Folder;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.linuxtools.lttng.stubs.LTTngEventParserStub;
import org.eclipse.linuxtools.lttng.stubs.LTTngEventStreamStub;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
-import org.eclipse.linuxtools.tmf.trace.TmfTrace;
-import org.eclipse.linuxtools.tmf.trace.TmfTraceSelectedSignal;
+import org.eclipse.linuxtools.tmf.trace.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.trace.TmfExperimentSelectedSignal;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
@SuppressWarnings("restriction")
public class ProjectView extends ViewPart {
- public static final String ID = Labels.ProjectView_ID;
+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.project";
private final IWorkspace fWorkspace;
private final IResourceChangeListener fResourceChangeListener;
}
/**
- * TODO: Hook to LTTng trace instead of File (when available)
+ *
*/
private void hookMouse() {
fViewer.getTree().addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent event) {
TreeSelection selection = (TreeSelection) fViewer.getSelection();
Object element = selection.getFirstElement();
-// if (element instanceof Folder) {
-// openTraceFile((Folder) element);
-// }
- if (element instanceof File) {
- openTraceFile((File) element);
+ if (element instanceof Folder) {
+ selectExperiment((Folder) element);
}
}
});
/**
* @param trace
*
- * TODO: Handle LTTng Trace files (when available)
- * TODO: Handle multiple traces simultaneously
+ * TODO: Tie the proper parser to the trace
*/
- private void openTraceFile(File file) {
- String fname = Platform.getLocation() + file.getFullPath().toOSString();
+ private void selectExperiment(Folder folder) {
+ String expId = folder.getName();
+ TmfExperiment experiment = new TmfExperiment(expId, new ITmfTrace[] { });
try {
ITmfEventParser parser = new LTTngEventParserStub();
- ITmfEventStream stream = new LTTngEventStreamStub(fname, parser);
- TmfTrace trace = new TmfTrace(file.getName(), stream);
- TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, trace));
- stream.indexStream(false);
+ for (IResource res : folder.members()) {
+ String traceId = Platform.getLocation() + res.getFullPath().toOSString();
+ ITmfTrace trace = new LTTngEventStreamStub(traceId, parser);
+ trace.indexStream(false);
+ experiment.addTrace(trace);
+ }
} catch (Exception e) {
e.printStackTrace();
}
+ TmfSignalManager.dispatchSignal(new TmfExperimentSelectedSignal(this, experiment));
}
-// /**
-// * @param trace
-// *
-// * TODO: Handle LTTng Trace files (when available)
-// * TODO: Handle multiple traces simultaneously
-// */
-// private void openTraceFile(Folder trace) {
-// String fname = Platform.getLocation() + trace.getFullPath().toOSString();
-// try {
-// ITmfEventStream stream = new LttngEventStream(fname);
-// TmfTrace eventLog = new TmfTrace(trace.getName(), stream);
-// broadcastEvent(new TmfTraceSelectedEvent(eventLog));
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// }
-
-// public void handleEvent(ITmfEventLogEvent event) {
-//// System.out.println("ProjectView.handleEvent()");
-// }
-
/**
*
*/
package org.eclipse.linuxtools.lttng.ui.views.resources;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
*/
public class ResourcesView extends ViewPart {
- public static final String ID = Labels.ResourcesView_ID;
+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.resources";
/**
*
package org.eclipse.linuxtools.lttng.ui.views.statistics;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
*/
public class StatisticsView extends ViewPart {
- public static final String ID = Labels.StatisticsView_ID;
+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.statistics";
/**
*
package org.eclipse.linuxtools.lttng.ui.views.timeframe;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
import org.eclipse.swt.SWT;
private static final int NANOSECOND_SCALE = 1000 * 1000 * 1000;
private static final byte SCALE = -9;
+ // Labels
+ private static final String SECONDS_LABEL = "sec";
+ private static final String NANOSEC_LABEL = "ns";
+
// Widgets
private Group group;
private Spinner seconds;
seconds.setBounds(5, 25, 110, 25);
Label label = new Label(group, SWT.LEFT);
- label.setText(Labels.TimeFrameView_Seconds);
+ label.setText(SECONDS_LABEL);
label.setBounds(120, 28, 25, 22);
nanosec = new Spinner(group, SWT.BORDER);
nanosec.setBounds(150, 25, 110, 25);
label = new Label(group, SWT.LEFT);
- label.setText(Labels.TimeFrameView_Nanosec);
+ label.setText(NANOSEC_LABEL);
label.setBounds(265, 28, 25, 22);
setContent(range, current);
}
public void setStartTime(TmfTimestamp ts) {
- startTime = ts.synchronize(0, SCALE);
- startSeconds = (int) (startTime.getValue() / NANOSECOND_SCALE);
- startNanosec = (int) (startTime.getValue() % NANOSECOND_SCALE);
+ try {
+ startTime = ts.synchronize(0, SCALE);
+ startSeconds = (int) (startTime.getValue() / NANOSECOND_SCALE);
+ startNanosec = (int) (startTime.getValue() % NANOSECOND_SCALE);
+ }
+ catch (ArithmeticException e) {
+ }
}
public void setEndTime(TmfTimestamp ts) {
- endTime = ts.synchronize(0, SCALE);
- endSeconds = (int) (endTime.getValue() / NANOSECOND_SCALE);
- endNanosec = (int) (endTime.getValue() % NANOSECOND_SCALE);
+ try {
+ endTime = ts.synchronize(0, SCALE);
+ endSeconds = (int) (endTime.getValue() / NANOSECOND_SCALE);
+ endNanosec = (int) (endTime.getValue() % NANOSECOND_SCALE);
+ }
+ catch (ArithmeticException e) {
+ }
}
public void setCurrentTime(TmfTimestamp ts) {
- currentTime = ts.synchronize(0, SCALE);
- currentSeconds = (int) (currentTime.getValue() / NANOSECOND_SCALE);
- currentNanosec = (int) (currentTime.getValue() % NANOSECOND_SCALE);
+ try {
+ currentTime = ts.synchronize(0, SCALE);
+ currentSeconds = (int) (currentTime.getValue() / NANOSECOND_SCALE);
+ currentNanosec = (int) (currentTime.getValue() % NANOSECOND_SCALE);
+ }
+ catch (ArithmeticException e) {
+ }
}
// ====================================================================
package org.eclipse.linuxtools.lttng.ui.views.timeframe;
-import org.eclipse.linuxtools.lttng.ui.views.Labels;
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal;
-import org.eclipse.linuxtools.tmf.trace.TmfTrace;
-import org.eclipse.linuxtools.tmf.trace.TmfTraceSelectedSignal;
+import org.eclipse.linuxtools.tmf.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.trace.TmfExperimentSelectedSignal;
import org.eclipse.linuxtools.tmf.trace.TmfTraceUpdatedSignal;
import org.eclipse.linuxtools.tmf.ui.views.TmfViewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Slider;
/**
* FIXME: The slider is very jumpy due to the large number of async updates
* FIXME: Revisit the control flow between View, Spinners and Slider
*/
-public class TimeFrameView extends TmfViewer implements SelectionListener {
+public class TimeFrameView extends TmfViewer {
- public static final String ID = Labels.TimeFrameView_ID;
+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.timeframe";
// ========================================================================
// TimeFrameView
private TmfTimeRange fTraceSpan = new TmfTimeRange(fTraceStartTime, fTraceEndTime);
private byte fScale = 0;
+ // Labels
+ private static final String START_TIME_LABEL = "Start Time";
+ private static final String END_TIME_LABEL = "End Time";
+ private static final String TIME_RANGE_LABEL = "Interval";
+ private static final String CURRENT_TIME_LABEL = "Current Time";
+
private static final int SLIDER_RANGE = 10000;
private SpinnerGroup fStartGroup;
// The slider
private Slider fSlider;
- // The event log
- TmfTrace fEventLog = null;
+ // The current experiment
+ TmfExperiment fExperiment = null;
/**
* Constructor
GridLayout layout = new GridLayout(4, true);
parent.setLayout(layout);
- fStartGroup = new SpinnerGroup(this, parent, Labels.TimeFrameView_StartTime, fTraceTimeRange, fTraceStartTime);
- fEndGroup = new SpinnerGroup(this, parent, Labels.TimeFrameView_EndTime, fTraceTimeRange, fTraceEndTime);
- fRangeGroup = new SpinnerGroup(this, parent, Labels.TimeFrameView_TimeRange, fTraceTimeRange, fTraceEndTime);
- fCurrentGroup = new SpinnerGroup(this, parent, Labels.TimeFrameView_CurrentTime, fTraceTimeRange, fTraceStartTime);
+ fStartGroup = new SpinnerGroup(this, parent, START_TIME_LABEL, fTraceTimeRange, fTraceStartTime);
+ fEndGroup = new SpinnerGroup(this, parent, END_TIME_LABEL, fTraceTimeRange, fTraceEndTime);
+ fRangeGroup = new SpinnerGroup(this, parent, TIME_RANGE_LABEL, fTraceTimeRange, fTraceEndTime);
+ fCurrentGroup = new SpinnerGroup(this, parent, CURRENT_TIME_LABEL, fTraceTimeRange, fTraceStartTime);
// Create the slider
createSlider(parent);
*/
private void createSlider(Composite parent) {
fSlider = new Slider(parent, SWT.SMOOTH | SWT.FILL);
+ fSlider.setMinimum(0);
fSlider.setMaximum(SLIDER_RANGE + fSlider.getThumb());
+ fSlider.setIncrement(SLIDER_RANGE / 100);
+ fSlider.setPageIncrement(SLIDER_RANGE / 10);
+ fSlider.setSelection(0);
GridData gridData = new GridData(SWT.LEFT, SWT.TOP, true, false);
gridData.horizontalAlignment = SWT.FILL;
gridData.horizontalSpan = 4;
fSlider.setLayoutData(gridData);
- fSlider.addSelectionListener(this);
+ fSlider.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ int ratio = fSlider.getSelection();
+ TmfTimestamp span = fCurrentGroup.getSpan();
+ long value = span.getValue() * ratio / SLIDER_RANGE;
+ TmfTimestamp start = fCurrentGroup.getStartTime();
+ TmfTimestamp current = new TmfTimestamp(start.getValue() + value, start.getScale(), 0);
+ fCurrentGroup.setValue(current);
+ }
+ });
}
});
}
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- // TODO Auto-generated method stub
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent event) {
-
- switch (event.detail) {
- case SWT.ARROW_DOWN:
- fSlider.setSelection(fSlider.getSelection() + SLIDER_RANGE / 100);
- updateCurentTime();
- break;
-
- case SWT.ARROW_UP:
- fSlider.setSelection(fSlider.getSelection() - SLIDER_RANGE / 100);
- updateCurentTime();
- break;
-
-// case SWT.DRAG:
-// updateCurentTime();
-// break;
-//
-// case SWT.END:
-// fSlider.setSelection(SLIDER_RANGE);
-// break;
-//
-// case SWT.HOME:
-// fSlider.setSelection(0);
-// break;
-
- case SWT.PAGE_DOWN:
- fSlider.setSelection(fSlider.getSelection() + SLIDER_RANGE / 10);
- updateCurentTime();
- break;
-
- case SWT.PAGE_UP:
- fSlider.setSelection(fSlider.getSelection() - SLIDER_RANGE / 10);
- break;
-
- // The slider was released - set the current time
- case SWT.NONE:
- updateCurentTime();
- break;
- }
- }
-
- private void updateCurentTime() {
- int ratio = fSlider.getSelection();
- TmfTimestamp span = fCurrentGroup.getSpan();
- long value = span.getValue() * ratio / SLIDER_RANGE;
- TmfTimestamp start = fCurrentGroup.getStartTime();
- TmfTimestamp current = new TmfTimestamp(start.getValue() + value, start.getScale(), 0);
- fCurrentGroup.setValue(current);
- }
-
// ========================================================================
// TMF Signal Handling
// ========================================================================
* @param signal
*/
@TmfSignalHandler
- public void traceSelected(TmfTraceSelectedSignal signal) {
+ public void experimentSelected(TmfExperimentSelectedSignal signal) {
// Update the trace reference
- if (fEventLog != null)
- fEventLog.dispose();
- fEventLog = signal.getTrace();
+ if (fExperiment != null)
+ fExperiment.dispose();
+ fExperiment = signal.getExperiment();
// Update the time frame
- fTraceTimeRange = fEventLog.getTimeRange();
+ fTraceTimeRange = fExperiment.getTimeRange();
fTraceStartTime = fTraceTimeRange.getStartTime();
fTraceEndTime = fTraceTimeRange.getEndTime();
fScale = fTraceStartTime.getScale();
// Update the widgets
fStartGroup.setContent(fTraceTimeRange, fStartGroup.getCurrentTime());
- fEndGroup.setContent(fTraceTimeRange, fTraceEndTime); // fEndGroup.getCurrentTime());
+ fEndGroup.setContent(fTraceTimeRange, fTraceEndTime);
fCurrentGroup.setContent(fTraceTimeRange, fCurrentGroup.getCurrentTime());
TmfTimestamp delta = new TmfTimestamp(fTraceStartTime.getAdjustment(fTraceEndTime), fScale, 0);
import org.eclipse.linuxtools.tmf.event.TmfEventReference;
import org.eclipse.linuxtools.tmf.event.TmfEventSource;
import org.eclipse.linuxtools.tmf.event.TmfEventType;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
+import org.eclipse.linuxtools.tmf.trace.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
/**
* <b><u>TmfEventParserStub</u></b>
* @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
*/
static final String typePrefix = "Type-";
- public TmfEvent getNextEvent(ITmfEventStream eventStream) throws IOException {
+ public TmfEvent getNextEvent(ITmfTrace eventStream) throws IOException {
if (! (eventStream instanceof LTTngEventStreamStub)) {
return null;
}
RandomAccessFile stream = ((LTTngEventStreamStub) eventStream).getStream();
+ String name = eventStream.getName();
+ name = name.substring(name.lastIndexOf('/') + 1);
try {
long ts = stream.readLong();
String source = stream.readUTF();
String type = stream.readUTF();
- int reference = stream.readInt();
+ @SuppressWarnings("unused")
+ int reference = stream.readInt();
int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
String[] fields = new String[typeIndex];
for (int i = 0; i < typeIndex; i++) {
new TmfEventSource(source),
new TmfEventType(type, fFormats[typeIndex]),
new TmfEventContent(content, fFormats[typeIndex]),
- new TmfEventReference(reference));
+ new TmfEventReference(name));
return event;
} catch (EOFException e) {
}
import java.io.RandomAccessFile;
import java.util.Map;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
-import org.eclipse.linuxtools.tmf.stream.TmfEventStream;
+import org.eclipse.linuxtools.tmf.trace.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.trace.TmfTrace;
/**
* <b><u>TmfEventStreamStub</u></b>
* <p>
* TODO: Implement me. Please.
*/
-public class LTTngEventStreamStub extends TmfEventStream {
+public class LTTngEventStreamStub extends TmfTrace {
// ========================================================================
// Attributes
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
-#Fri Aug 28 16:09:39 EDT 2009
+#Tue Sep 08 23:49:15 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="stubs"/>
-#Tue Aug 25 08:59:32 EDT 2009
+#Tue Sep 08 23:49:23 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventStream.StreamContext;
import org.eclipse.linuxtools.tmf.trace.TmfEventParserStub;
import org.eclipse.linuxtools.tmf.trace.TmfEventStreamStub;
+import org.eclipse.linuxtools.tmf.trace.ITmfTrace.StreamContext;
import org.junit.BeforeClass;
import org.junit.Test;
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
import org.junit.BeforeClass;
import org.junit.Test;
private static final String DIRECTORY = "testfiles";
private static final String TEST_STREAM = "M-Test-10K";
+ private static final String EXPERIMENT = "MyExperiment";
private static String testfile;
private static int fTotalNbEvents = 10000;
private static int fDefaultBlockSize = 1000;
private static ITmfEventParser fParser;
- private static ITmfEventStream fStream;
- private static TmfTrace fTrace;
+ private static ITmfTrace fStream;
+ private static TmfExperiment fExperiment;
// private static byte SCALE = (byte) -3;
fParser = new TmfEventParserStub();
fStream = new TmfEventStreamStub(testfile, fParser);
- fTrace = new TmfTrace("MyTrace", fStream);
+ fExperiment = new TmfExperiment(EXPERIMENT, new ITmfTrace[] { fStream });
fStream.indexStream(true);
}
@Test
public void testBasicTmfEventLog() {
- assertEquals("GetId", "MyTrace", fTrace.getId());
- assertEquals("GetEpoch", TmfTimestamp.BigBang, fTrace.getEpoch());
- assertEquals("GetNbEvents", fTotalNbEvents, fTrace.getNbEvents());
+ assertEquals("GetId", EXPERIMENT, fExperiment.getExperimentId());
+ assertEquals("GetEpoch", TmfTimestamp.BigBang, fExperiment.getEpoch());
+ assertEquals("GetNbEvents", fTotalNbEvents, fExperiment.getNbEvents());
- TmfTimeRange timeRange = fTrace.getTimeRange();
+ TmfTimeRange timeRange = fExperiment.getTimeRange();
assertEquals("GetTimeRange-start", 1, timeRange.getStartTime().getValue());
assertEquals("GetTimeRange-end", fTotalNbEvents, timeRange.getEndTime().getValue());
}
}
}
};
- fTrace.processRequest(request, true);
+ fExperiment.processRequest(request, true);
assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
assertTrue("isCompleted", request.isCompleted());
final int NB_EVENTS = -1;
final int BLOCK_SIZE = 1;
final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
- int nbExpectedEvents = fTrace.getNbEvents();
+ int nbExpectedEvents = fExperiment.getNbEvents();
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
}
}
};
- fTrace.processRequest(request, true);
+ fExperiment.processRequest(request, true);
assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
assertTrue("isCompleted", request.isCompleted());
cancel();
}
};
- fTrace.processRequest(request, true);
+ fExperiment.processRequest(request, true);
assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size());
assertTrue("isCompleted", request.isCompleted());
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventStream.StreamContext;
+import org.eclipse.linuxtools.tmf.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.trace.TmfEventParserStub;
import org.eclipse.linuxtools.tmf.trace.TmfEventStreamStub;
+import org.eclipse.linuxtools.tmf.trace.ITmfTrace.StreamContext;
/**
* <b><u>TmfRequestHandlerStub</u></b>
import org.eclipse.linuxtools.tmf.event.TmfEventSource;
import org.eclipse.linuxtools.tmf.event.TmfEventType;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
/**
* <b><u>TmfEventParserStub</u></b>
* @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
*/
static final String typePrefix = "Type-";
- public TmfEvent getNextEvent(ITmfEventStream eventStream) throws IOException {
+ public TmfEvent getNextEvent(ITmfTrace eventStream) throws IOException {
if (! (eventStream instanceof TmfEventStreamStub)) {
return null;
import java.io.RandomAccessFile;
import java.util.Map;
-import org.eclipse.linuxtools.tmf.stream.TmfEventStream;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
/**
* <b><u>TmfEventStreamStub</u></b>
* <p>
* TODO: Implement me. Please.
*/
-public class TmfEventStreamStub extends TmfEventStream {
+public class TmfEventStreamStub extends TmfTrace {
// ========================================================================
// Attributes
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
-#Fri Aug 28 13:29:52 EDT 2009
+#Tue Sep 08 23:49:30 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
+ @Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
+ @Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal;
-import org.eclipse.linuxtools.tmf.stream.TmfStreamUpdatedSignal;
-import org.eclipse.linuxtools.tmf.trace.TmfTrace;
-import org.eclipse.linuxtools.tmf.trace.TmfTraceSelectedSignal;
+import org.eclipse.linuxtools.tmf.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.trace.TmfExperimentSelectedSignal;
+import org.eclipse.linuxtools.tmf.trace.TmfStreamUpdatedSignal;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
public static final String ID = "org.eclipse.linuxtools.tmf.ui.viewer.events";
- private TmfTrace fTrace;
+ private TmfExperiment fExperiment;
+ private String fTitlePrefix;
// ========================================================================
// Table data
evt[0] = (result.length > 0) ? result[0] : null;
}
};
- fTrace.processRequest(request, true);
+ fExperiment.processRequest(request, true);
item.setText(extractItemFields(evt[0]));
}
});
fTable.setItemCount(0);
+ fTitlePrefix = getTitle();
}
/**
// ========================================================================
@TmfSignalHandler
- public void traceSelected(TmfTraceSelectedSignal signal) {
+ public void experimentSelected(TmfExperimentSelectedSignal signal) {
// Update the trace reference
- if (fTrace != null)
- fTrace.dispose();
- fTrace = signal.getTrace();
+ if (fExperiment != null)
+ fExperiment.dispose();
+ fExperiment = signal.getExperiment();
+ setPartName(fTitlePrefix + " - " + fExperiment.getExperimentId());
// Perform the updates on the UI thread
fTable.getDisplay().asyncExec(new Runnable() {
public void run() {
fTable.clearAll();
- fTable.setItemCount(fTrace.getNbEvents());
+ fTable.setItemCount(fExperiment.getNbEvents());
}
});
}
fTable.getDisplay().asyncExec(new Runnable() {
public void run() {
if (!fTable.isDisposed()) {
- fTable.setItemCount(fTrace.getNbEvents());
+ fTable.setItemCount(fExperiment.getNbEvents());
}
}
});
@TmfSignalHandler
public void currentTimeUpdated(TmfTimeSynchSignal signal) {
if (signal.getSource() != fTable) {
- final int index = fTrace.getIndex(signal.getCurrentTime());
+ final int index = fExperiment.getIndex(signal.getCurrentTime());
// Perform the updates on the UI thread
fTable.getDisplay().asyncExec(new Runnable() {
public void run() {
/**
* Destructor
*/
+ @Override
public void dispose() {
TmfSignalManager.removeListener(this);
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
+ @Override
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/
+ @Override
public void setFocus() {
// TODO Auto-generated method stub
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
-#Tue Aug 25 09:07:23 EDT 2009
+#Tue Sep 08 23:48:34 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.linuxtools.tmf.event,
org.eclipse.linuxtools.tmf.request,
org.eclipse.linuxtools.tmf.signal,
- org.eclipse.linuxtools.tmf.stream,
org.eclipse.linuxtools.tmf.trace
*/
public class TmfTimeRange {
+ // ========================================================================
+ // Constants
+ // ========================================================================
+
+ public static TmfTimeRange Eternity = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+
// ========================================================================
// Attributes
// ========================================================================
*/
public int compareTo(final TmfTimestamp other, boolean withinPrecision) {
- // If values have the same time scale, perform the comparison
+ // If values have the same time scale, perform the comparison
if (fScale == other.fScale) {
if (withinPrecision) {
if ((fValue + fPrecision) < (other.fValue - other.fPrecision))
// If values have different time scales, adjust to the finest one and
// then compare. If the scaling difference is too large, revert to
// some heuristics. Hopefully, nobody will try to compare galactic and
- // atomic clock events...
+ // quantic clock events...
byte newScale = (fScale < other.fScale) ? fScale : other.fScale;
try {
TmfTimestamp ts1 = this.synchronize(0, newScale);
method.invoke(entry.getKey(), new Object[] { signal });
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
- e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
- e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
- e.printStackTrace();
}
}
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.stream;
-
-import java.io.IOException;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-
-/**
- * <b><u>ITmfEventParser</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public interface ITmfEventParser {
-
- /**
- * @return
- * @throws IOException
- */
- public TmfEvent getNextEvent(ITmfEventStream stream) throws IOException;
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.stream;
-
-import java.util.Map;
-
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-
-/**
- * <b><u>ITmfEventStream</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public interface ITmfEventStream {
-
- public class StreamContext {
- Object location;
- int index;
-
- public StreamContext(Object loc, int ind) {
- location = loc;
- index = ind;
- }
-
- public StreamContext(StreamContext other) {
- if (other != null) {
- location = other.location;
- index = other.index;
- }
- }
- }
-
- public int getNbEvents();
-
- public TmfTimeRange getTimeRange();
-
- public Map<String, Object> getAttributes();
-
- /**
- * Positions the stream at the first event with timestamp.
- *
- * @param timestamp
- * @return a context object for subsequent reads
- */
- public StreamContext seekEvent(TmfTimestamp timestamp);
-
- /**
- * Positions the stream on the event at the wanted position.
- *
- * @param index
- * @return a context object for subsequent reads
- */
- public StreamContext seekEvent(int index);
-
- /**
- * Reads and the next event on the stream and updates the context.
- * If there is no event left, return null.
- *
- * @return the next event in the stream
- */
- public TmfEvent getNextEvent(StreamContext context);
-
- public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp);
- public TmfEvent getEvent(StreamContext context, int index);
-
- /**
- * Parse the stream and creates the checkpoint structure.
- * Normally performed once at the creation of the event stream.
- */
- public void indexStream(boolean waitForCompletion);
-
- public Object getCurrentLocation();
- public StreamContext seekLocation(Object location);
-
- /**
- * Returns the index of the event at that timestamp
- *
- * @param timestamp
- * @return
- */
- public int getIndex(TmfTimestamp timestamp);
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.stream;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Vector;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
-
-/**
- * <b><u>TmfEventStream</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public abstract class TmfEventStream implements ITmfEventStream {
-
- // ========================================================================
- // Constants
- // ========================================================================
-
- // The default number of events to cache
- public static final int DEFAULT_CACHE_SIZE = 1000;
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- // The stream name
- private final String fName;
-
- // The stream parser
- private final ITmfEventParser fParser;
-
- // The cache size
- private final int fCacheSize;
-
- // The set of event stream checkpoints (for random access)
- private Vector<TmfStreamCheckpoint> fCheckpoints = new Vector<TmfStreamCheckpoint>();
-
- // The number of events collected
- private int fNbEvents = 0;
-
- // The time span of the event stream
- private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- /**
- * @param filename
- * @param parser
- * @param cacheSize
- * @throws FileNotFoundException
- */
- protected TmfEventStream(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
- fName = filename;
- fParser = parser;
- fCacheSize = cacheSize;
- }
-
- /**
- * @param filename
- * @param parser
- * @throws FileNotFoundException
- */
- protected TmfEventStream(String filename, ITmfEventParser parser) throws FileNotFoundException {
- this(filename, parser, DEFAULT_CACHE_SIZE);
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- /**
- * @return
- */
- public int getCacheSize() {
- return fCacheSize;
- }
-
- /**
- * @return
- */
- public String getName() {
- return fName;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getNbEvents()
- */
- public int getNbEvents() {
- return fNbEvents;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getTimeRange()
- */
- public TmfTimeRange getTimeRange() {
- return fTimeRange;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getIndex(org.eclipse.linuxtools.tmf.event.TmfTimestamp)
- */
- public int getIndex(TmfTimestamp timestamp) {
- StreamContext context = seekEvent(timestamp);
- return context.index;
- }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- public StreamContext seekEvent(TmfTimestamp timestamp) {
-
- // First, find the right checkpoint
- int index = Collections.binarySearch(fCheckpoints, new TmfStreamCheckpoint(timestamp, 0));
-
- // In the very likely event that the checkpoint was not found, bsearch
- // returns its negated would-be location (not an offset...). From that
- // index, we can then position the stream and get the event.
- if (index < 0) {
- index = Math.max(0, -(index + 2));
- }
-
- // Position the stream at the checkpoint
- Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
- StreamContext nextEventContext;
- synchronized(this) {
- nextEventContext = seekLocation(location);
- }
- StreamContext currentEventContext = new StreamContext(nextEventContext.location, index * fCacheSize);
-
- // And get the event
- TmfEvent event = getNextEvent(nextEventContext);
- while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
- currentEventContext.location = nextEventContext.location;
- currentEventContext.index++;
- event = getNextEvent(nextEventContext);
- }
-
- return currentEventContext;
- }
-
- public StreamContext seekEvent(int position) {
-
- // Position the stream at the previous checkpoint
- int index = position / fCacheSize;
- Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
- StreamContext nextEventContext;
- synchronized(this) {
- nextEventContext = seekLocation(location);
- }
- StreamContext currentEventContext = new StreamContext(nextEventContext);
-
- // And locate the event (if it exists)
- int current = index * fCacheSize;
- TmfEvent event = getNextEvent(nextEventContext);
- while (event != null && current < position) {
- currentEventContext.location = nextEventContext.location;
- event = getNextEvent(nextEventContext);
- current++;
- }
-
- return currentEventContext;
- }
-
- public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp) {
-
- // Position the stream and update the context object
- StreamContext ctx = seekEvent(timestamp);
- context.location = ctx.location;
-
- return getNextEvent(context);
- }
-
- public TmfEvent getEvent(StreamContext context, int position) {
-
- // Position the stream and update the context object
- StreamContext ctx = seekEvent(position);
- context.location = ctx.location;
-
- return getNextEvent(context);
- }
-
- public synchronized TmfEvent getNextEvent(StreamContext context) {
- try {
- seekLocation(context.location);
- TmfEvent event = fParser.getNextEvent(this);
- context.location = getCurrentLocation();
- return event;
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private void notifyListeners() {
- TmfSignalManager.dispatchSignal(new TmfStreamUpdatedSignal(this, this));
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#indexStream()
- */
- public void indexStream(boolean waitForCompletion) {
- IndexingJob job = new IndexingJob(fName);
- job.schedule();
- if (waitForCompletion) {
- try {
- job.join();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- private class IndexingJob extends Job {
-
- public IndexingJob(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- protected IStatus run(IProgressMonitor monitor) {
-
- int nbEvents = 0;
- TmfTimestamp startTime = new TmfTimestamp();
- TmfTimestamp lastTime = new TmfTimestamp();
-
- monitor.beginTask("Indexing " + fName, IProgressMonitor.UNKNOWN);
-
- try {
- StreamContext nextEventContext;
- synchronized(this) {
- nextEventContext = seekLocation(null);
- }
- StreamContext currentEventContext = new StreamContext(nextEventContext);
- TmfEvent event = getNextEvent(nextEventContext);
- if (event != null) {
- startTime = event.getTimestamp();
- lastTime = event.getTimestamp();
- }
-
- while (event != null) {
- lastTime = event.getTimestamp();
- if ((nbEvents++ % fCacheSize) == 0) {
- TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(lastTime, currentEventContext.location);
- synchronized(this) {
- fCheckpoints.add(bookmark);
- fNbEvents = nbEvents;
- fTimeRange = new TmfTimeRange(startTime, lastTime);
- }
- notifyListeners();
- monitor.worked(1);
- // Check monitor *after* fCheckpoints has been updated
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- }
-
- currentEventContext.location = nextEventContext.location;
- event = getNextEvent(nextEventContext);
- }
- }
- finally {
- synchronized(this) {
- fNbEvents = nbEvents;
- fTimeRange = new TmfTimeRange(startTime, lastTime);
- }
- notifyListeners();
- monitor.done();
- }
-
- return Status.OK_STATUS;
- }
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.stream;
-
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-
-/**
- * <b><u>TmfStreamCheckpoint</u></b>
- * <p>
- * This class maps an event timestamp with a trace location.
- */
-public class TmfStreamCheckpoint implements Comparable<TmfStreamCheckpoint> {
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- private final TmfTimestamp fTimestamp;
- private final Object fLocation;
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- /**
- * @param ts
- * @param location
- */
- public TmfStreamCheckpoint(TmfTimestamp ts, Object location) {
- fTimestamp = ts;
- fLocation = location;
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- /**
- * @return the checkpoint event timestamp
- */
- public TmfTimestamp getTimestamp() {
- return fTimestamp;
- }
-
- /**
- * @return the checkpoint event stream location
- */
- public Object getLocation() {
- return fLocation;
- }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- public int compareTo(TmfStreamCheckpoint other) {
- return fTimestamp.compareTo(other.fTimestamp, false);
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.stream;
-
-import org.eclipse.linuxtools.tmf.signal.TmfSignal;
-
-/**
- * <b><u>TmfStreamUpdatedEvent</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfStreamUpdatedSignal extends TmfSignal {
-
- private final ITmfEventStream fEventStream;
-
- public TmfStreamUpdatedSignal(Object source, ITmfEventStream stream) {
- super(source);
- fEventStream = stream;
- }
-
- public ITmfEventStream getEventStream() {
- return fEventStream;
- }
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import java.io.IOException;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+
+/**
+ * <b><u>ITmfEventParser</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public interface ITmfEventParser {
+
+ /**
+ * @return
+ * @throws IOException
+ */
+ public TmfEvent getNextEvent(ITmfTrace stream) throws IOException;
+}
package org.eclipse.linuxtools.tmf.trace;
-import org.eclipse.linuxtools.tmf.component.ITmfComponent;
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
/**
- * <b><u>ITmfTrace</u></b>
+ * <b><u>ITmfEventStream</u></b>
* <p>
+ * TODO: Implement me. Please.
*/
-public interface ITmfTrace extends ITmfComponent {
-
- public ITmfTrace createTraceCopy();
-
+public interface ITmfTrace {
+
/**
- * @return the trace path
+ * <b><u>StreamContext</u></b>
+ * <p>
+ * Stream context keeper to avoid conflicting, concurrent accesses to the
+ * underlying stream.
*/
- public String getPath();
+ public class StreamContext {
+ public Object location;
+ public int index;
+
+ public StreamContext(Object loc, int ind) {
+ location = loc;
+ index = ind;
+ }
+
+ public StreamContext(StreamContext other) {
+ if (other != null) {
+ location = other.location;
+ index = other.index;
+ }
+ }
+ }
/**
- * @return the trace name
+ * @return
*/
public String getName();
-
+
/**
- * @return the number of events in the trace
+ * @return the number of events in the stream
*/
- public long getNbEvents();
+ public int getNbEvents();
/**
- * Trace time range accessors
+ * @return the stream time range
*/
- public TmfTimeRange getTimeRange();
- public TmfTimestamp getStartTime();
- public TmfTimestamp getEndTime();
+ public TmfTimeRange getTimeRange();
- /**
- * Positions the trace at the first event with the specified
- * timestamp or index (i.e. the nth event in the trace).
- *
- * Returns a context which can later be used to read the event.
+// /**
+// * @return The stream time range
+// */
+// public Map<String, Object> getAttributes();
+
+ /**
+ * Positions the stream at the first event with timestamp.
*
- * @param data.timestamp
- * @param data.index
+ * @param timestamp
* @return a context object for subsequent reads
*/
- public TmfContext seekLocation(ITmfLocation<?> location);
- public TmfContext seekEvent(TmfTimestamp timestamp);
- public TmfContext seekEvent(long rank);
+ public StreamContext seekEvent(TmfTimestamp timestamp);
+ public StreamContext seekEvent(int index);
/**
- * Return the event pointed by the supplied context (or null if
- * no event left) and updates the context to the next event.
+ * Reads and the next event on the stream and updates the context.
+ * If there is no event left, return null.
*
* @return the next event in the stream
*/
- public TmfEvent getNextEvent(TmfContext context);
+ public TmfEvent peekEvent(StreamContext context);
+ public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp);
+ public TmfEvent getEvent(StreamContext context, int index);
+ public TmfEvent getNextEvent(StreamContext context);
+
+ /**
+ * Parse the stream and creates the checkpoint structure.
+ * Normally invoked once at the creation of the event stream.
+ */
+ public void indexStream(boolean waitForCompletion);
+
+ public Object getCurrentLocation();
+ public StreamContext seekLocation(Object location);
/**
- * Return the event pointed by the supplied context (or null if
- * no event left) and *does not* update the context.
+ * Returns the index of the event at that timestamp
*
- * @return the next event in the stream
+ * @param timestamp
+ * @return
*/
- public TmfEvent parseEvent(TmfContext context);
+ public int getIndex(TmfTimestamp timestamp);
+ /**
+ * Returns the timestamp of the event at position [index]
+ *
+ * @param index the event index
+ * @return the corresponding timestamp
+ */
+ public TmfTimestamp getTimestamp(int index);
}
package org.eclipse.linuxtools.tmf.trace;
+import java.util.Vector;
+
import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.request.ITmfRequestHandler;
import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.trace.ITmfTrace.StreamContext;
/**
* <b><u>TmfExperiment</u></b>
* TmfExperiment presents a time-ordered, unified view of a set of
* TmfTraces that are part of a tracing experiment.
* <p>
- * TODO: Implement me. PLease.
+ * TODO: Implement me. Please.
*/
public class TmfExperiment implements ITmfRequestHandler<TmfEvent> {
- // ========================================================================
+ // ========================================================================
// Attributes
// ========================================================================
+ private final int CACHE_SIZE = 1000;
+
+ private String fExperimentId;
+ private Vector<ITmfTrace> fTraces;
+ private int fNbEvents;
+ private TmfTimeRange fTimeRange;
+ private TmfTimestamp fEpoch;
+
// ========================================================================
- // Constructors/Destructors
+ // Constructors/Destructor
// ========================================================================
- public TmfExperiment() {
+ public TmfExperiment(String id, ITmfTrace[] traces) {
+ this(id, traces, TmfTimestamp.BigBang);
+ for (ITmfTrace trace : traces) {
+ addTrace(trace);
+ }
+ }
+
+ public TmfExperiment(String id, ITmfTrace[] traces, TmfTimestamp epoch) {
+ fExperimentId = id;
+ fTraces = new Vector<ITmfTrace>();
+ for (ITmfTrace trace : traces) {
+ fTraces.add(trace);
+ }
+ fEpoch = epoch;
+ TmfSignalManager.addListener(this);
+ }
+
+ public void dispose() {
+ TmfSignalManager.removeListener(this);
+ fTraces.clear();
}
// ========================================================================
// Accessors
// ========================================================================
+ public String getExperimentId() {
+ return fExperimentId;
+ }
+
+ public ITmfTrace[] getTraces() {
+ ITmfTrace[] result = new ITmfTrace[fTraces.size()];
+ return fTraces.toArray(result);
+ }
+
+ public TmfTimestamp getEpoch() {
+ return fEpoch;
+ }
+
+ public TmfTimeRange getTimeRange() {
+ return fTimeRange;
+ }
+
+ public int getNbEvents() {
+ return fNbEvents;
+ }
+
+ // TODO: Go over all the traces
+ public int getIndex(TmfTimestamp ts) {
+ return fTraces.firstElement().getIndex(ts);
+ }
+
+// public TmfTimestamp getTimestamp(int index) {
+// if (fIndices.size() == 0) {
+// indexExperiment();
+// }
+//
+// int offset = index / CACHE_SIZE;
+//
+// ITmfEventStream[] traces = new ITmfEventStream[0];
+// StreamContext[] contexts;
+// TmfEvent[] peekEvents;
+//
+// traces = fTraces.toArray(traces);
+// contexts = new StreamContext[traces.length];
+// peekEvents = new TmfEvent[traces.length];
+//
+// for (int i = 0; i < traces.length; i++) {
+// contexts[i] = new StreamContext(fIndices.get(offset)[i]);
+// peekEvents[i] = traces[i].peekEvent(contexts[i]);
+// }
+//
+// TmfEvent event = getNextEvent(traces, contexts, peekEvents);
+// for (int i = offset * CACHE_SIZE; i < index; i++) {
+// event = getNextEvent(traces, contexts, peekEvents);
+// }
+//
+// return event != null ? event.getTimestamp() : null;
+// }
+
// ========================================================================
// Operators
// ========================================================================
+ public void addTrace(ITmfTrace trace) {
+ fTraces.add(trace);
+ synchronized(this) {
+ updateNbEvents();
+ updateTimeRange();
+ }
+ }
+
+ private void updateNbEvents() {
+ int nbEvents = 0;
+ for (ITmfTrace trace : fTraces) {
+ nbEvents += trace.getNbEvents();
+ }
+ fNbEvents = nbEvents;
+ }
+
+ private void updateTimeRange() {
+ TmfTimestamp startTime = fTimeRange != null ? fTimeRange.getStartTime() : TmfTimestamp.BigCrunch;
+ TmfTimestamp endTime = fTimeRange != null ? fTimeRange.getEndTime() : TmfTimestamp.BigBang;
+
+ for (ITmfTrace trace : fTraces) {
+ TmfTimestamp traceStartTime = trace.getTimeRange().getStartTime();
+ if (traceStartTime.compareTo(startTime, true) < 0)
+ startTime = traceStartTime;
+
+ TmfTimestamp traceEndTime = trace.getTimeRange().getEndTime();
+ if (traceEndTime.compareTo(endTime, true) > 0)
+ endTime = traceEndTime;
+ }
+ fTimeRange = new TmfTimeRange(startTime, endTime);
+ }
+
+ // ========================================================================
+ // ITmfRequestHandler
+ // ========================================================================
+
/* (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfDataRequest, boolean)
*/
- public void processRequest(TmfDataRequest<TmfEvent> request, boolean waitForCompletion) {
- }
+ public void processRequest(TmfDataRequest<TmfEvent> request, boolean waitForCompletion) {
+ if (request.getRange() != null) {
+ processEventRequestByTimestamp(request);
+ } else {
+ processEventRequestByIndex(request);
+ }
+ if (waitForCompletion) {
+ request.waitForCompletion();
+ }
+ }
+
+ /**
+ * Process a time range request - this has to be seriously re-worked...
+ *
+ * @param request
+ */
+ private void processEventRequestByTimestamp(final TmfDataRequest<TmfEvent> request) {
+
+ Thread thread = new Thread() {
+
+ private ITmfTrace[] traces = new ITmfTrace[0];
+ private StreamContext[] contexts;
+ private TmfEvent[] peekEvents;
+
+ @Override
+ public void run() {
+ // Extract the request information
+ TmfTimestamp startTime = request.getRange().getStartTime();
+ TmfTimestamp endTime = request.getRange().getEndTime();
+ int blockSize = request.getBlockize();
+
+ int nbRequestedEvents = request.getNbRequestedItems();
+ if (nbRequestedEvents == -1) {
+ nbRequestedEvents = Integer.MAX_VALUE;
+ }
+
+ // Create the result buffer
+ Vector<TmfEvent> events = new Vector<TmfEvent>();
+ int nbEvents = 0;
+
+ // Initialize the traces array and position the streams
+ traces = fTraces.toArray(traces);
+ contexts = new StreamContext[traces.length];
+ peekEvents = new TmfEvent[traces.length];
+ for (int i = 0; i < contexts.length; i++) {
+ contexts[i] = traces[i].seekEvent(startTime);
+ peekEvents[i] = traces[i].peekEvent(contexts[i]);
+ }
+
+ // Get the ordered events
+ TmfEvent event = getNextEvent(traces, contexts, peekEvents);
+ while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null
+ && event.getTimestamp().compareTo(endTime, false) <= 0)
+ {
+ events.add(event);
+ if (++nbEvents % blockSize == 0) {
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+ request.handleData();
+ events.removeAllElements();
+ }
+ // To avoid an unnecessary read passed the last event requested
+ if (nbEvents < nbRequestedEvents)
+ event = getNextEvent(traces, contexts, peekEvents);
+ }
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+
+ request.handleData();
+ request.done();
+ }
+ };
+ thread.start();
+ }
+
+ /**
+ * Process an index range request - this has to be seriously re-worked...
+ * Does not work for multiple traces - yet
+ *
+ * @param request
+ */
+ private void processEventRequestByIndex(final TmfDataRequest<TmfEvent> request) {
+
+ Thread thread = new Thread() {
+
+ private ITmfTrace[] traces = new ITmfTrace[0];
+ private StreamContext[] contexts;
+ private TmfEvent[] peekEvents;
+
+ @Override
+ public void run() {
+ // Extract the request information
+ int blockSize = request.getBlockize();
+
+ int nbRequestedEvents = request.getNbRequestedItems();
+ if (nbRequestedEvents == -1) {
+ nbRequestedEvents = Integer.MAX_VALUE;
+ }
+
+ // Create the result buffer
+ Vector<TmfEvent> events = new Vector<TmfEvent>();
+ int nbEvents = 0;
+
+ // Initialize the traces array and position the streams
+ traces = fTraces.toArray(traces);
+ contexts = new StreamContext[traces.length];
+ peekEvents = new TmfEvent[traces.length];
+ for (int i = 0; i < contexts.length; i++) {
+ contexts[i] = traces[i].seekEvent(request.getIndex());
+ peekEvents[i] = traces[i].peekEvent(contexts[i]);
+ }
+
+ // Get the ordered events
+ TmfEvent event = getNextEvent(traces, contexts, peekEvents);
+ while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null) {
+ events.add(event);
+ if (++nbEvents % blockSize == 0) {
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+ request.handleData();
+ events.removeAllElements();
+ }
+ // To avoid an unnecessary read passed the last event
+ // requested
+ if (nbEvents < nbRequestedEvents)
+ event = getNextEvent(traces, contexts, peekEvents);
+ }
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+
+ request.setData(result);
+ request.handleData();
+ request.done();
+ }
+ };
+ thread.start();
+ }
+
+ // Returns the next event in chronological order
+ // TODO: Consider the time adjustment
+ private TmfEvent getNextEvent(ITmfTrace[] traces, StreamContext[] contexts, TmfEvent[] peekEvents) {
+ int index = 0;
+ TmfEvent evt = peekEvents[0];
+ TmfTimestamp ts0 = evt != null ? evt.getTimestamp() : TmfTimestamp.BigCrunch;
+ for (int i = 1; i < traces.length; i++) {
+ if (peekEvents[i] != null) {
+ TmfTimestamp ts1 = peekEvents[i].getTimestamp();
+ if (ts1.compareTo(ts0, true) < 0) {
+ index = i;
+ ts0 = ts1;
+ }
+ }
+ }
+ TmfEvent event = traces[index].getNextEvent(contexts[index]);
+ peekEvents[index] = traces[index].peekEvent(contexts[index]);
+ return event;
+ }
+
+ // TODO: Redesign me
+ private Vector<StreamContext[]> fIndices = new Vector<StreamContext[]>();
+ public void indexExperiment() {
+ ITmfTrace[] traces = new ITmfTrace[0];
+ StreamContext[] contexts;
+ TmfEvent[] peekEvents;
+
+ traces = fTraces.toArray(traces);
+ contexts = new StreamContext[traces.length];
+ peekEvents = new TmfEvent[traces.length];
+ for (int i = 0; i < contexts.length; i++) {
+ contexts[i] = traces[i].seekEvent(TmfTimestamp.BigBang);
+ peekEvents[i] = traces[i].peekEvent(contexts[i]);
+ }
+
+ // Initialize the indices
+ StreamContext[] ctx = new StreamContext[contexts.length];
+ for (int i = 0; i < ctx.length; i++) {
+ ctx[i] = new StreamContext(contexts[i]);
+ }
+ fIndices.add(ctx);
+
+ // Get the ordered events and populate the indices
+ int nbEvents = 0;
+ while (getNextEvent(traces, contexts, peekEvents) != null)
+ {
+ if (++nbEvents % CACHE_SIZE == 0) {
+ ctx = new StreamContext[contexts.length];
+ for (int i = 0; i < ctx.length; i++) {
+ ctx[i] = new StreamContext(contexts[i]);
+ }
+ fIndices.add(ctx);
+ }
+ }
+ }
// ========================================================================
- // Helper functions
+ // Signal handlers
// ========================================================================
+ @TmfSignalHandler
+ public void streamUpdated(TmfStreamUpdatedSignal signal) {
+ synchronized(this) {
+ updateNbEvents();
+ updateTimeRange();
+ }
+ TmfSignalManager.dispatchSignal(new TmfTraceUpdatedSignal(this, this));
+ }
+
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import org.eclipse.linuxtools.tmf.signal.TmfSignal;
+
+/**
+ * <b><u>TmfExperimentSelectedSignal</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfExperimentSelectedSignal extends TmfSignal {
+
+ private final TmfExperiment fExperiment;
+
+ public TmfExperimentSelectedSignal(Object source, TmfExperiment experiment) {
+ super(source);
+ fExperiment = experiment;
+ }
+
+ public TmfExperiment getExperiment() {
+ return fExperiment;
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+
+/**
+ * <b><u>TmfStreamCheckpoint</u></b>
+ * <p>
+ * This class maps an event timestamp with a trace location.
+ */
+public class TmfStreamCheckpoint implements Comparable<TmfStreamCheckpoint> {
+
+ // ========================================================================
+ // Attributes
+ // ========================================================================
+
+ private final TmfTimestamp fTimestamp;
+ private final Object fLocation;
+
+ // ========================================================================
+ // Constructors
+ // ========================================================================
+
+ /**
+ * @param ts
+ * @param location
+ */
+ public TmfStreamCheckpoint(TmfTimestamp ts, Object location) {
+ fTimestamp = ts;
+ fLocation = location;
+ }
+
+ // ========================================================================
+ // Accessors
+ // ========================================================================
+
+ /**
+ * @return the checkpoint event timestamp
+ */
+ public TmfTimestamp getTimestamp() {
+ return fTimestamp;
+ }
+
+ /**
+ * @return the checkpoint event stream location
+ */
+ public Object getLocation() {
+ return fLocation;
+ }
+
+ // ========================================================================
+ // Operators
+ // ========================================================================
+
+ public int compareTo(TmfStreamCheckpoint other) {
+ return fTimestamp.compareTo(other.fTimestamp, false);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.signal.TmfSignal;
+
+/**
+ * <b><u>TmfStreamUpdatedEvent</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfStreamUpdatedSignal extends TmfSignal {
+
+ private final ITmfTrace fEventStream;
+ private final TmfTimeRange fTimeRange;
+
+ public TmfStreamUpdatedSignal(Object source, ITmfTrace stream, TmfTimeRange range) {
+ super(source);
+ fEventStream = stream;
+ fTimeRange = range;
+ }
+
+ public ITmfTrace getEventStream() {
+ return fEventStream;
+ }
+
+ public TmfTimeRange getEventRange() {
+ return fTimeRange;
+ }
+}
package org.eclipse.linuxtools.tmf.trace;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Collections;
import java.util.Vector;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.request.ITmfRequestHandler;
-import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
-import org.eclipse.linuxtools.tmf.stream.TmfStreamUpdatedSignal;
-import org.eclipse.linuxtools.tmf.stream.ITmfEventStream.StreamContext;
/**
- * <b><u>TmfTrace</u></b>
+ * <b><u>TmfEventStream</u></b>
* <p>
- * TmfTrace represents a time-ordered set of events tied to a single event
- * stream. It keeps track of the global information about the event log:
- * <ul>
- * <li> the epoch, a reference timestamp for the whole log (t0)
- * <li> the span of the log i.e. the timestamps range
- * <li> the total number of events
- * </ul>
- * As an ITmfRequestHandler, it provides an implementation of process()
- * which handles event requests.
- * <p>
- * TODO: Handle concurrent and possibly overlapping requests in a way that
- * optimizes the stream access and event parsing.
+ * TODO: Implement me. Please.
*/
-public class TmfTrace implements ITmfRequestHandler<TmfEvent> {
+public abstract class TmfTrace implements ITmfTrace {
+
+ // ========================================================================
+ // Constants
+ // ========================================================================
+
+ // The default number of events to cache
+ public static final int DEFAULT_CACHE_SIZE = 1000;
// ========================================================================
// Attributes
// ========================================================================
- private final String fId;
- private final ITmfEventStream fStream;
- private final TmfTimestamp fEpoch;
-
+ // The stream name
+ private final String fName;
+
+ // The stream parser
+ private final ITmfEventParser fParser;
+
+ // The cache size
+ private final int fCacheSize;
+
+ // The set of event stream checkpoints (for random access)
+ private Vector<TmfStreamCheckpoint> fCheckpoints = new Vector<TmfStreamCheckpoint>();
+
+ // The number of events collected
+ private int fNbEvents = 0;
+
+ // The time span of the event stream
+ private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
+
// ========================================================================
// Constructors
// ========================================================================
- public TmfTrace(String id, ITmfEventStream stream) {
- this(id, stream, TmfTimestamp.BigBang);
- }
-
- public TmfTrace(String id, ITmfEventStream stream, TmfTimestamp epoch) {
- assert stream != null;
- fId = id;
- fStream = stream;
- fEpoch = epoch;
- TmfSignalManager.addListener(this);
+ /**
+ * @param filename
+ * @param parser
+ * @param cacheSize
+ * @throws FileNotFoundException
+ */
+ protected TmfTrace(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
+ fName = filename;
+ fParser = parser;
+ fCacheSize = cacheSize;
}
- public void dispose() {
- TmfSignalManager.removeListener(this);
+ /**
+ * @param filename
+ * @param parser
+ * @throws FileNotFoundException
+ */
+ protected TmfTrace(String filename, ITmfEventParser parser) throws FileNotFoundException {
+ this(filename, parser, DEFAULT_CACHE_SIZE);
}
// ========================================================================
// Accessors
// ========================================================================
- public String getId() {
- return fId;
+ /**
+ * @return
+ */
+ public int getCacheSize() {
+ return fCacheSize;
}
- public ITmfEventStream getStream() {
- return fStream;
+ /**
+ * @return
+ */
+ public String getName() {
+ return fName;
}
- public TmfTimestamp getEpoch() {
- return fEpoch;
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getNbEvents()
+ */
+ public int getNbEvents() {
+ return fNbEvents;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getTimeRange()
+ */
public TmfTimeRange getTimeRange() {
- return fStream.getTimeRange();
+ return fTimeRange;
}
- public int getNbEvents() {
- return fStream.getNbEvents();
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getIndex(org.eclipse.linuxtools.tmf.event.TmfTimestamp)
+ */
+ public int getIndex(TmfTimestamp timestamp) {
+ StreamContext context = seekEvent(timestamp);
+ return context.index;
}
- public int getIndex(TmfTimestamp ts) {
- return fStream.getIndex(ts);
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getTimestamp(int)
+ */
+ public TmfTimestamp getTimestamp(int index) {
+ StreamContext context = seekEvent(index);
+ TmfEvent event = peekEvent(context);
+ return event.getTimestamp();
}
// ========================================================================
// Operators
// ========================================================================
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfDataRequest, boolean)
- */
- public void processRequest(TmfDataRequest<TmfEvent> request, boolean waitForCompletion) {
- if (request.getRange() != null) {
- serviceEventRequestByTimestamp(request);
- } else {
- serviceEventRequestByIndex(request);
- }
- if (waitForCompletion) {
- request.waitForCompletion();
+ public StreamContext seekEvent(TmfTimestamp timestamp) {
+
+ // First, find the right checkpoint
+ int index = Collections.binarySearch(fCheckpoints, new TmfStreamCheckpoint(timestamp, 0));
+
+ // In the very likely event that the checkpoint was not found, bsearch
+ // returns its negated would-be location (not an offset...). From that
+ // index, we can then position the stream and get the event.
+ if (index < 0) {
+ index = Math.max(0, -(index + 2));
+ }
+
+ // Position the stream at the checkpoint
+ Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(location);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext.location, index * fCacheSize);
+
+ // And get the event
+ TmfEvent event = getNextEvent(nextEventContext);
+ while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
+ currentEventContext.location = nextEventContext.location;
+ currentEventContext.index++;
+ event = getNextEvent(nextEventContext);
+ }
+
+ return currentEventContext;
+ }
+
+ public StreamContext seekEvent(int position) {
+
+ // Position the stream at the previous checkpoint
+ int index = position / fCacheSize;
+ Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(location);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext);
+
+ // And locate the event (if it exists)
+ int current = index * fCacheSize;
+ TmfEvent event = getNextEvent(nextEventContext);
+ while (event != null && current < position) {
+ currentEventContext.location = nextEventContext.location;
+ event = getNextEvent(nextEventContext);
+ current++;
}
+
+ return currentEventContext;
}
- // ========================================================================
- // Signal handlers
- // ========================================================================
+ public TmfEvent peekEvent(StreamContext context) {
+ StreamContext ctx = new StreamContext(context);
+ return getNextEvent(ctx);
+ }
- @TmfSignalHandler
- public void streamUpdated(TmfStreamUpdatedSignal signal) {
- TmfSignalManager.dispatchSignal(new TmfTraceUpdatedSignal(this, this));
+ public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp) {
+
+ // Position the stream and update the context object
+ StreamContext ctx = seekEvent(timestamp);
+ context.location = ctx.location;
+
+ return getNextEvent(context);
}
- // ========================================================================
- // Helper functions
- // ========================================================================
+ public TmfEvent getEvent(StreamContext context, int position) {
- /* (non-Javadoc)
- *
- * @param request
- */
- private void serviceEventRequestByTimestamp(final TmfDataRequest<TmfEvent> request) {
- Thread thread = new Thread() {
- @Override
- public void run() {
- TmfTimestamp startTime = request.getRange().getStartTime();
- TmfTimestamp endTime = request.getRange().getEndTime();
- int blockSize = request.getBlockize();
-
- int nbRequestedEvents = request.getNbRequestedItems();
- if (nbRequestedEvents == -1) {
- nbRequestedEvents = Integer.MAX_VALUE;
- }
+ // Position the stream and update the context object
+ StreamContext ctx = seekEvent(position);
+ context.location = ctx.location;
- Vector<TmfEvent> events = new Vector<TmfEvent>();
- int nbEvents = 0;
-
- StreamContext context = new StreamContext(null);
- TmfEvent event = fStream.getEvent(context, startTime);
-
- while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null &&
- event.getTimestamp().compareTo(endTime, false) <= 0 )
- {
- events.add(event);
- if (++nbEvents % blockSize == 0) {
- TmfEvent[] result = new TmfEvent[events.size()];
- events.toArray(result);
- request.setData(result);
- request.handleData();
- events.removeAllElements();
- }
- // To avoid an unnecessary read passed the last event requested
- if (nbEvents < nbRequestedEvents)
- event = fStream.getNextEvent(context);
- }
- TmfEvent[] result = new TmfEvent[events.size()];
- events.toArray(result);
- request.setData(result);
+ return getNextEvent(context);
+ }
- request.handleData();
- request.done();
- }
- };
- thread.start();
+ public synchronized TmfEvent getNextEvent(StreamContext context) {
+ try {
+ seekLocation(context.location);
+ TmfEvent event = fParser.getNextEvent(this);
+ context.location = getCurrentLocation();
+ return event;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
}
+ private void notifyListeners(TmfTimeRange range) {
+ TmfSignalManager.dispatchSignal(new TmfStreamUpdatedSignal(this, this, range));
+ }
+
/* (non-Javadoc)
- *
- * @param request
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#indexStream()
*/
- private void serviceEventRequestByIndex(final TmfDataRequest<TmfEvent> request) {
- Thread thread = new Thread() {
- @Override
- public void run() {
- int blockSize = request.getBlockize();
-
- int nbRequestedEvents = request.getNbRequestedItems();
- if (nbRequestedEvents == -1) {
- nbRequestedEvents = Integer.MAX_VALUE;
+ public void indexStream(boolean waitForCompletion) {
+ IndexingJob job = new IndexingJob(fName);
+ job.schedule();
+ if (waitForCompletion) {
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private class IndexingJob extends Job {
+
+ public IndexingJob(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+
+ int nbEvents = 0;
+ TmfTimestamp startTime = new TmfTimestamp();
+ TmfTimestamp lastTime = new TmfTimestamp();
+ TmfTimestamp rangeStartTime = new TmfTimestamp();
+
+ monitor.beginTask("Indexing " + fName, IProgressMonitor.UNKNOWN);
+
+ try {
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(null);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext);
+ TmfEvent event = getNextEvent(nextEventContext);
+ if (event != null) {
+ startTime = event.getTimestamp();
+ lastTime = event.getTimestamp();
}
- Vector<TmfEvent> events = new Vector<TmfEvent>();
- int nbEvents = 0;
-
- StreamContext context = new StreamContext(null);
- TmfEvent event = fStream.getEvent(context, request.getIndex());
-
- while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null)
- {
- events.add(event);
- if (++nbEvents % blockSize == 0) {
- TmfEvent[] result = new TmfEvent[events.size()];
- events.toArray(result);
- request.setData(result);
- request.handleData();
- events.removeAllElements();
+ rangeStartTime = startTime;
+ while (event != null) {
+ lastTime = event.getTimestamp();
+ if ((nbEvents++ % fCacheSize) == 0) {
+ TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(lastTime, currentEventContext.location);
+ synchronized(this) {
+ fCheckpoints.add(bookmark);
+ fNbEvents = nbEvents;
+ fTimeRange = new TmfTimeRange(startTime, lastTime);
+ }
+ notifyListeners(new TmfTimeRange(rangeStartTime, lastTime));
+ monitor.worked(1);
+ // Check monitor *after* fCheckpoints has been updated
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
}
- // To avoid an unnecessary read passed the last event requested
- if (nbEvents < nbRequestedEvents)
- event = fStream.getNextEvent(context);
- }
- TmfEvent[] result = new TmfEvent[events.size()];
- events.toArray(result);
- request.setData(result);
- request.handleData();
- request.done();
+ currentEventContext.location = nextEventContext.location;
+ event = getNextEvent(nextEventContext);
+ }
+ }
+ finally {
+ synchronized(this) {
+ fNbEvents = nbEvents;
+ fTimeRange = new TmfTimeRange(startTime, lastTime);
+ }
+ notifyListeners(new TmfTimeRange(rangeStartTime, lastTime));
+ monitor.done();
}
- };
- thread.start();
+
+ return Status.OK_STATUS;
+ }
}
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.trace;
-
-import org.eclipse.linuxtools.tmf.signal.TmfSignal;
-
-/**
- * <b><u>TmfTraceSelectedEvent</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfTraceSelectedSignal extends TmfSignal {
-
- private final TmfTrace fTrace;
-
- public TmfTraceSelectedSignal(Object source, TmfTrace trace) {
- super(source);
- fTrace = trace;
- }
-
- public TmfTrace getTrace() {
- return fTrace;
- }
-}
*/
public class TmfTraceUpdatedSignal extends TmfSignal {
- private final TmfTrace fTrace;
+ private final TmfExperiment fExperiment;
- public TmfTraceUpdatedSignal(Object source, TmfTrace trace) {
+ public TmfTraceUpdatedSignal(Object source, TmfExperiment experiment) {
super(source);
- fTrace = trace;
+ fExperiment = experiment;
}
- public TmfTrace getTrace() {
- return fTrace;
+ public TmfExperiment getTrace() {
+ return fExperiment;
}
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import java.util.Vector;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.request.ITmfRequestHandler;
+import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.trace.ITmfTrace.StreamContext;
+
+/**
+ * <b><u>TmfTrace</u></b>
+ * <p>
+ * TmfTrace represents a time-ordered set of events tied to a single event
+ * stream. It keeps track of the global information about the event log:
+ * <ul>
+ * <li> the epoch, a reference timestamp for the whole log (t0)
+ * <li> the span of the log i.e. the timestamps range
+ * <li> the total number of events
+ * </ul>
+ * As an ITmfRequestHandler, it provides an implementation of processRequest()
+ * which handles event requests.
+ * <p>
+ * TODO: Handle concurrent and possibly overlapping requests in a way that
+ * optimizes the stream access and event parsing.
+ */
+public class TmfTrace_old implements ITmfRequestHandler<TmfEvent> {
+
+ // ========================================================================
+ // Attributes
+ // ========================================================================
+
+ private final String fTraceId;
+ private final ITmfTrace fStream;
+ private final TmfTimestamp fEpoch;
+
+ // ========================================================================
+ // Constructors
+ // ========================================================================
+
+ public TmfTrace_old(String id, ITmfTrace stream) {
+ this(id, stream, TmfTimestamp.BigBang);
+ }
+
+ public TmfTrace_old(String id, ITmfTrace stream, TmfTimestamp epoch) {
+ assert stream != null;
+ fTraceId = id;
+ fStream = stream;
+ fEpoch = epoch;
+ TmfSignalManager.addListener(this);
+ }
+
+ public void dispose() {
+ TmfSignalManager.removeListener(this);
+ }
+
+ // ========================================================================
+ // Accessors
+ // ========================================================================
+
+ public String getTraceId() {
+ return fTraceId;
+ }
+
+ public ITmfTrace getStream() {
+ return fStream;
+ }
+
+ public TmfTimestamp getEpoch() {
+ return fEpoch;
+ }
+
+ public TmfTimeRange getTimeRange() {
+ return fStream.getTimeRange();
+ }
+
+ public int getNbEvents() {
+ return fStream.getNbEvents();
+ }
+
+ public int getIndex(TmfTimestamp ts) {
+ return fStream.getIndex(ts);
+ }
+
+ // ========================================================================
+ // Operators
+ // ========================================================================
+
+ private StreamContext fContext;
+
+ public TmfEvent getEvent(TmfTimestamp timestamp) {
+ fContext = fStream.seekEvent(timestamp);
+ return fStream.getNextEvent(fContext);
+ }
+
+ public TmfEvent getEvent(int index) {
+ fContext = fStream.seekEvent(index);
+ return fStream.getNextEvent(fContext);
+ }
+
+ public TmfEvent getNextEvent() {
+ if (fContext == null) {
+ fContext = fStream.seekEvent(TmfTimestamp.BigBang);
+ }
+ return fStream.getNextEvent(fContext);
+ }
+
+ // ========================================================================
+ // ITmfRequestHandler
+ // ========================================================================
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfDataRequest, boolean)
+ */
+ public void processRequest(TmfDataRequest<TmfEvent> request, boolean waitForCompletion) {
+ if (request.getRange() != null) {
+ serviceEventRequestByTimestamp(request);
+ } else {
+ serviceEventRequestByIndex(request);
+ }
+ if (waitForCompletion) {
+ request.waitForCompletion();
+ }
+ }
+
+ /* (non-Javadoc)
+ *
+ * @param request
+ */
+ private void serviceEventRequestByTimestamp(final TmfDataRequest<TmfEvent> request) {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ TmfTimestamp startTime = request.getRange().getStartTime();
+ TmfTimestamp endTime = request.getRange().getEndTime();
+ int blockSize = request.getBlockize();
+
+ int nbRequestedEvents = request.getNbRequestedItems();
+ if (nbRequestedEvents == -1) {
+ nbRequestedEvents = Integer.MAX_VALUE;
+ }
+
+ Vector<TmfEvent> events = new Vector<TmfEvent>();
+ int nbEvents = 0;
+
+ StreamContext context = new StreamContext(null);
+ TmfEvent event = fStream.getEvent(context, startTime);
+
+ while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null &&
+ event.getTimestamp().compareTo(endTime, false) <= 0 )
+ {
+ events.add(event);
+ if (++nbEvents % blockSize == 0) {
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+ request.handleData();
+ events.removeAllElements();
+ }
+ // To avoid an unnecessary read passed the last event requested
+ if (nbEvents < nbRequestedEvents)
+ event = fStream.getNextEvent(context);
+ }
+ TmfEvent[] result = new TmfEvent[events.size()];
+ events.toArray(result);
+ request.setData(result);
+
+ request.handleData();
+ request.done();
+ }
+ };
+ thread.start();
+ }
+
+ /* (non-Javadoc)
+ *
+ * @param request
+ */
+ private void serviceEventRequestByIndex(final TmfDataRequest<TmfEvent> request) {
+// Thread thread = new Thread() {
+// @Override
+// public void run() {
+// int blockSize = request.getBlockize();
+//
+// int nbRequestedEvents = request.getNbRequestedItems();
+// if (nbRequestedEvents == -1) {
+// nbRequestedEvents = Integer.MAX_VALUE;
+// }
+//
+// Vector<TmfEvent> events = new Vector<TmfEvent>();
+// int nbEvents = 0;
+//
+// StreamContext context = new StreamContext(null);
+// TmfEvent event = fStream.getEvent(context, request.getIndex());
+//
+// while (!request.isCancelled() && nbEvents < nbRequestedEvents && event != null)
+// {
+// events.add(event);
+// if (++nbEvents % blockSize == 0) {
+// TmfEvent[] result = new TmfEvent[events.size()];
+// events.toArray(result);
+// request.setData(result);
+// request.handleData();
+// events.removeAllElements();
+// }
+// // To avoid an unnecessary read passed the last event requested
+// if (nbEvents < nbRequestedEvents)
+// event = fStream.getNextEvent(context);
+// }
+// TmfEvent[] result = new TmfEvent[events.size()];
+// events.toArray(result);
+//
+// request.setData(result);
+// request.handleData();
+// request.done();
+// }
+// };
+// thread.start();
+ }
+
+// // ========================================================================
+// // Signal handlers
+// // ========================================================================
+//
+// @TmfSignalHandler
+// public void streamUpdated(TmfStreamUpdatedSignal signal) {
+// TmfSignalManager.dispatchSignal(new TmfTraceUpdatedSignal(this, this));
+// }
+
+}