From: Francois Chouinard Date: Wed, 9 Sep 2009 04:23:20 +0000 (+0000) Subject: - Introduced TmfExperiment (single trace for now) X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=62d1696a93e68da0a6f8c21fdcfa0d7cb524cd6d;p=deliverable%2Ftracecompass.git - Introduced TmfExperiment (single trace for now) - Merged TmfTrace and TmfEventStream (doc to be updated) - Refactored a few classes - Fixed a few exceptions - Everything is finally ready to rebase and start uploading LTTng --- diff --git a/org.eclipse.linuxtools.lttng.tests/.classpath b/org.eclipse.linuxtools.lttng.tests/.classpath index 1fa3e6803d..64c5e31b7a 100644 --- a/org.eclipse.linuxtools.lttng.tests/.classpath +++ b/org.eclipse.linuxtools.lttng.tests/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.linuxtools.lttng.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.lttng.tests/.settings/org.eclipse.jdt.core.prefs index 55f131fead..67be45c6ba 100644 --- a/org.eclipse.linuxtools.lttng.tests/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.lttng.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#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 diff --git a/org.eclipse.linuxtools.lttng.ui.tests/.classpath b/org.eclipse.linuxtools.lttng.ui.tests/.classpath index 1fa3e6803d..64c5e31b7a 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/.classpath +++ b/org.eclipse.linuxtools.lttng.ui.tests/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.linuxtools.lttng.ui.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.lttng.ui.tests/.settings/org.eclipse.jdt.core.prefs index 164e630a27..2063af4662 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.lttng.ui.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#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 diff --git a/org.eclipse.linuxtools.lttng.ui/.classpath b/org.eclipse.linuxtools.lttng.ui/.classpath index 2a987e2854..978c0d27e1 100644 --- a/org.eclipse.linuxtools.lttng.ui/.classpath +++ b/org.eclipse.linuxtools.lttng.ui/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.linuxtools.lttng.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.lttng.ui/.settings/org.eclipse.jdt.core.prefs index 4cf62400b9..d72c8df743 100644 --- a/org.eclipse.linuxtools.lttng.ui/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.lttng.ui/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#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 diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/Labels.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/Labels.java deleted file mode 100644 index 8a2b0ec8c3..0000000000 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/Labels.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * ViewsLabels - *

- * 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() { - } - -} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/PerspectiveFactory.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/PerspectiveFactory.java index c89d698869..bd28bc3c82 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/PerspectiveFactory.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/PerspectiveFactory.java @@ -12,6 +12,14 @@ 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; @@ -24,14 +32,14 @@ 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; diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/ControlView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/ControlView.java index 82908c6fd2..5571fac589 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/ControlView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/ControlView.java @@ -12,7 +12,6 @@ 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; @@ -23,7 +22,7 @@ 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"; /** * diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/ControlFlowView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/ControlFlowView.java index 6874fd8e76..158a2d809f 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/ControlFlowView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/ControlFlowView.java @@ -12,7 +12,6 @@ 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; @@ -23,7 +22,7 @@ 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"; /** * diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/events/EventsView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/events/EventsView.java index 8d2ce02ae5..5799205b07 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/events/EventsView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/events/EventsView.java @@ -12,7 +12,6 @@ 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; @@ -26,7 +25,7 @@ import org.eclipse.swt.widgets.TableColumn; */ 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 diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/histogram/HistogramView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/histogram/HistogramView.java index 9f8364c8eb..4de5699b4a 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/histogram/HistogramView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/histogram/HistogramView.java @@ -12,7 +12,6 @@ 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; @@ -23,7 +22,7 @@ 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"; /** * diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/labels.properties b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/labels.properties deleted file mode 100644 index 47ff9d51a1..0000000000 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/labels.properties +++ /dev/null @@ -1,21 +0,0 @@ -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 diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/ProjectView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/ProjectView.java index 0ec2ee235d..e3cd7320c5 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/ProjectView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/ProjectView.java @@ -12,7 +12,8 @@ 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; @@ -26,12 +27,11 @@ import org.eclipse.jface.viewers.TreeSelection; 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; @@ -54,7 +54,7 @@ import org.eclipse.ui.part.ViewPart; @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; @@ -113,7 +113,7 @@ public class ProjectView extends ViewPart { } /** - * TODO: Hook to LTTng trace instead of File (when available) + * */ private void hookMouse() { fViewer.getTree().addMouseListener(new MouseAdapter() { @@ -121,11 +121,8 @@ public class ProjectView extends ViewPart { 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); } } }); @@ -134,43 +131,25 @@ public class ProjectView extends ViewPart { /** * @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()"); -// } - /** * */ diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/ResourcesView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/ResourcesView.java index 9e3ea144e1..f92a1f2099 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/ResourcesView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/ResourcesView.java @@ -12,7 +12,6 @@ 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; @@ -23,7 +22,7 @@ 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"; /** * diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/statistics/StatisticsView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/statistics/StatisticsView.java index baff1a6c07..315606ac4b 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/statistics/StatisticsView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/statistics/StatisticsView.java @@ -12,7 +12,6 @@ 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; @@ -23,7 +22,7 @@ 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"; /** * diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/SpinnerGroup.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/SpinnerGroup.java index 31552f5863..703003295f 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/SpinnerGroup.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/SpinnerGroup.java @@ -12,7 +12,6 @@ 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; @@ -43,6 +42,10 @@ public class SpinnerGroup { 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; @@ -101,7 +104,7 @@ public class SpinnerGroup { 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); @@ -124,7 +127,7 @@ public class SpinnerGroup { 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); @@ -164,21 +167,33 @@ public class SpinnerGroup { } 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) { + } } // ==================================================================== diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/TimeFrameView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/TimeFrameView.java index de9fd7733d..62c3da6958 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/TimeFrameView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/TimeFrameView.java @@ -12,22 +12,21 @@ 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; /** @@ -54,9 +53,9 @@ 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 @@ -72,6 +71,12 @@ public class TimeFrameView extends TmfViewer implements SelectionListener { 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; @@ -82,8 +87,8 @@ public class TimeFrameView extends TmfViewer implements SelectionListener { // The slider private Slider fSlider; - // The event log - TmfTrace fEventLog = null; + // The current experiment + TmfExperiment fExperiment = null; /** * Constructor @@ -102,10 +107,10 @@ public class TimeFrameView extends TmfViewer implements SelectionListener { 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); @@ -187,14 +192,27 @@ public class TimeFrameView extends TmfViewer implements SelectionListener { */ 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); + } + }); } @@ -219,66 +237,6 @@ public class TimeFrameView extends TmfViewer implements SelectionListener { }); } - /* (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 // ======================================================================== @@ -287,15 +245,15 @@ public class TimeFrameView extends TmfViewer implements SelectionListener { * @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(); @@ -326,7 +284,7 @@ public class TimeFrameView extends TmfViewer implements SelectionListener { // 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); diff --git a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java index 1a195cedbe..7eb9b1f24d 100644 --- a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java +++ b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java @@ -23,8 +23,8 @@ import org.eclipse.linuxtools.tmf.event.TmfEventFormat; 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; /** * TmfEventParserStub @@ -68,19 +68,22 @@ public class LTTngEventParserStub implements ITmfEventParser { * @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++) { @@ -97,7 +100,7 @@ public class LTTngEventParserStub implements ITmfEventParser { new TmfEventSource(source), new TmfEventType(type, fFormats[typeIndex]), new TmfEventContent(content, fFormats[typeIndex]), - new TmfEventReference(reference)); + new TmfEventReference(name)); return event; } catch (EOFException e) { } diff --git a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventStreamStub.java b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventStreamStub.java index ea41f1e5c3..d5885bba93 100644 --- a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventStreamStub.java +++ b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventStreamStub.java @@ -17,15 +17,15 @@ import java.io.IOException; 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; /** * TmfEventStreamStub *

* TODO: Implement me. Please. */ -public class LTTngEventStreamStub extends TmfEventStream { +public class LTTngEventStreamStub extends TmfTrace { // ======================================================================== // Attributes diff --git a/org.eclipse.linuxtools.lttng/.classpath b/org.eclipse.linuxtools.lttng/.classpath index 1fa3e6803d..64c5e31b7a 100644 --- a/org.eclipse.linuxtools.lttng/.classpath +++ b/org.eclipse.linuxtools.lttng/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.linuxtools.lttng/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.lttng/.settings/org.eclipse.jdt.core.prefs index 7e62292217..6854ec54db 100644 --- a/org.eclipse.linuxtools.lttng/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.lttng/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#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 diff --git a/org.eclipse.linuxtools.tmf.tests/.classpath b/org.eclipse.linuxtools.tmf.tests/.classpath index 2a987e2854..978c0d27e1 100644 --- a/org.eclipse.linuxtools.tmf.tests/.classpath +++ b/org.eclipse.linuxtools.tmf.tests/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.linuxtools.tmf.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.tmf.tests/.settings/org.eclipse.jdt.core.prefs index 59f179b1a9..0837699f8c 100644 --- a/org.eclipse.linuxtools.tmf.tests/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.tmf.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#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 diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/stream/TmfEventStreamTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/stream/TmfEventStreamTest.java index de5e605a76..26790d577d 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/stream/TmfEventStreamTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/stream/TmfEventStreamTest.java @@ -18,9 +18,9 @@ import java.io.File; 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; diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java index 0feeb9d6b0..28a006db62 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java @@ -23,8 +23,6 @@ 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.TmfDataRequest; -import org.eclipse.linuxtools.tmf.stream.ITmfEventParser; -import org.eclipse.linuxtools.tmf.stream.ITmfEventStream; import org.junit.BeforeClass; import org.junit.Test; @@ -37,13 +35,14 @@ public class TmfTraceTest { 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; @@ -54,7 +53,7 @@ public class TmfTraceTest { fParser = new TmfEventParserStub(); fStream = new TmfEventStreamStub(testfile, fParser); - fTrace = new TmfTrace("MyTrace", fStream); + fExperiment = new TmfExperiment(EXPERIMENT, new ITmfTrace[] { fStream }); fStream.indexStream(true); } @@ -64,11 +63,11 @@ public class TmfTraceTest { @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()); } @@ -119,7 +118,7 @@ public class TmfTraceTest { } } }; - fTrace.processRequest(request, true); + fExperiment.processRequest(request, true); assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); assertTrue("isCompleted", request.isCompleted()); @@ -137,7 +136,7 @@ public class TmfTraceTest { final int NB_EVENTS = -1; final int BLOCK_SIZE = 1; final Vector requestedEvents = new Vector(); - int nbExpectedEvents = fTrace.getNbEvents(); + int nbExpectedEvents = fExperiment.getNbEvents(); TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); final TmfDataRequest request = new TmfDataRequest(range, 0, NB_EVENTS, BLOCK_SIZE) { @@ -149,7 +148,7 @@ public class TmfTraceTest { } } }; - fTrace.processRequest(request, true); + fExperiment.processRequest(request, true); assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size()); assertTrue("isCompleted", request.isCompleted()); @@ -247,7 +246,7 @@ public class TmfTraceTest { cancel(); } }; - fTrace.processRequest(request, true); + fExperiment.processRequest(request, true); assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size()); assertTrue("isCompleted", request.isCompleted()); diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java index 33f2f49deb..862a095f05 100644 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java +++ b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java @@ -18,10 +18,10 @@ import java.util.Vector; 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; /** * TmfRequestHandlerStub diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java index bc49915795..68d32fb043 100644 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java +++ b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java @@ -24,8 +24,6 @@ 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.event.TmfTimestamp; -import org.eclipse.linuxtools.tmf.stream.ITmfEventParser; -import org.eclipse.linuxtools.tmf.stream.ITmfEventStream; /** * TmfEventParserStub @@ -65,7 +63,7 @@ public class TmfEventParserStub implements ITmfEventParser { * @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; diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventStreamStub.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventStreamStub.java index 5046759323..a190642f12 100644 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventStreamStub.java +++ b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventStreamStub.java @@ -17,15 +17,13 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.util.Map; -import org.eclipse.linuxtools.tmf.stream.TmfEventStream; -import org.eclipse.linuxtools.tmf.stream.ITmfEventParser; /** * TmfEventStreamStub *

* TODO: Implement me. Please. */ -public class TmfEventStreamStub extends TmfEventStream { +public class TmfEventStreamStub extends TmfTrace { // ======================================================================== // Attributes diff --git a/org.eclipse.linuxtools.tmf.ui.tests/.classpath b/org.eclipse.linuxtools.tmf.ui.tests/.classpath index 1fa3e6803d..64c5e31b7a 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/.classpath +++ b/org.eclipse.linuxtools.tmf.ui.tests/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.linuxtools.tmf.ui.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.tmf.ui.tests/.settings/org.eclipse.jdt.core.prefs index 8b39726989..642de97b99 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.tmf.ui.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#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 diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/TmfUiPlugin.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/TmfUiPlugin.java index eaf0a092b0..8902c935bb 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/TmfUiPlugin.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/TmfUiPlugin.java @@ -63,6 +63,7 @@ public class TmfUiPlugin extends AbstractUIPlugin { * (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; @@ -72,6 +73,7 @@ public class TmfUiPlugin extends AbstractUIPlugin { * (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); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java index 3a64b436e4..854a153605 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java @@ -18,9 +18,9 @@ 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.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; @@ -44,7 +44,8 @@ public class TmfEventsView extends TmfViewer { public static final String ID = "org.eclipse.linuxtools.tmf.ui.viewer.events"; - private TmfTrace fTrace; + private TmfExperiment fExperiment; + private String fTitlePrefix; // ======================================================================== // Table data @@ -156,12 +157,13 @@ public class TmfEventsView extends TmfViewer { 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(); } /** @@ -209,17 +211,18 @@ public class TmfEventsView extends TmfViewer { // ======================================================================== @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()); } }); } @@ -230,7 +233,7 @@ public class TmfEventsView extends TmfViewer { fTable.getDisplay().asyncExec(new Runnable() { public void run() { if (!fTable.isDisposed()) { - fTable.setItemCount(fTrace.getNbEvents()); + fTable.setItemCount(fExperiment.getNbEvents()); } } }); @@ -239,7 +242,7 @@ public class TmfEventsView extends TmfViewer { @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() { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfViewer.java index 995345d120..0aef8f57fe 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfViewer.java @@ -34,6 +34,7 @@ public abstract class TmfViewer extends ViewPart implements ITmfComponent { /** * Destructor */ + @Override public void dispose() { TmfSignalManager.removeListener(this); } @@ -41,6 +42,7 @@ public abstract class TmfViewer extends ViewPart implements ITmfComponent { /* (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 } @@ -48,6 +50,7 @@ public abstract class TmfViewer extends ViewPart implements ITmfComponent { /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#setFocus() */ + @Override public void setFocus() { // TODO Auto-generated method stub } diff --git a/org.eclipse.linuxtools.tmf/.classpath b/org.eclipse.linuxtools.tmf/.classpath index 1fa3e6803d..64c5e31b7a 100644 --- a/org.eclipse.linuxtools.tmf/.classpath +++ b/org.eclipse.linuxtools.tmf/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.linuxtools.tmf/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.tmf/.settings/org.eclipse.jdt.core.prefs index 4d0badb932..f7cae28389 100644 --- a/org.eclipse.linuxtools.tmf/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.tmf/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#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 diff --git a/org.eclipse.linuxtools.tmf/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf/META-INF/MANIFEST.MF index 366244c191..e186545c8a 100644 --- a/org.eclipse.linuxtools.tmf/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf/META-INF/MANIFEST.MF @@ -16,5 +16,4 @@ Export-Package: org.eclipse.linuxtools.tmf, 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 diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java index 549ba3d858..f58fe5f974 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java @@ -19,6 +19,12 @@ package org.eclipse.linuxtools.tmf.event; */ public class TmfTimeRange { + // ======================================================================== + // Constants + // ======================================================================== + + public static TmfTimeRange Eternity = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); + // ======================================================================== // Attributes // ======================================================================== diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java index 447b2b5184..4cbdd370a1 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java @@ -210,7 +210,7 @@ public class TmfTimestamp { */ 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)) @@ -226,7 +226,7 @@ public class TmfTimestamp { // 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); diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/signal/TmfSignalManager.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/signal/TmfSignalManager.java index 63759041e0..c0fa6a214c 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/signal/TmfSignalManager.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/signal/TmfSignalManager.java @@ -132,13 +132,10 @@ public class TmfSignalManager { 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(); } } } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/ITmfEventParser.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/ITmfEventParser.java deleted file mode 100644 index fde43153d4..0000000000 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/ITmfEventParser.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * ITmfEventParser - *

- * TODO: Implement me. Please. - */ -public interface ITmfEventParser { - - /** - * @return - * @throws IOException - */ - public TmfEvent getNextEvent(ITmfEventStream stream) throws IOException; -} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/ITmfEventStream.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/ITmfEventStream.java deleted file mode 100644 index bb9fb37d91..0000000000 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/ITmfEventStream.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * ITmfEventStream - *

- * 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 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); -} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfEventStream.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfEventStream.java deleted file mode 100644 index 93573aa10d..0000000000 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfEventStream.java +++ /dev/null @@ -1,302 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * TmfEventStream - *

- * 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 fCheckpoints = new Vector(); - - // 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; - } - } - -} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfStreamCheckpoint.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfStreamCheckpoint.java deleted file mode 100644 index 86408a85a3..0000000000 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfStreamCheckpoint.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * TmfStreamCheckpoint - *

- * This class maps an event timestamp with a trace location. - */ -public class TmfStreamCheckpoint implements Comparable { - - // ======================================================================== - // 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); - } - -} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfStreamUpdatedSignal.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfStreamUpdatedSignal.java deleted file mode 100644 index 808c6211f8..0000000000 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfStreamUpdatedSignal.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * TmfStreamUpdatedEvent - *

- * 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; - } -} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfEventParser.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfEventParser.java new file mode 100644 index 0000000000..51a8ee0d4f --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfEventParser.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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; + +/** + * ITmfEventParser + *

+ * TODO: Implement me. Please. + */ +public interface ITmfEventParser { + + /** + * @return + * @throws IOException + */ + public TmfEvent getNextEvent(ITmfTrace stream) throws IOException; +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfTrace.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfTrace.java index 5b349515a2..feb9d09af5 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfTrace.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfTrace.java @@ -12,69 +12,102 @@ 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; /** - * ITmfTrace + * ITmfEventStream *

+ * TODO: Implement me. Please. */ -public interface ITmfTrace extends ITmfComponent { - - public ITmfTrace createTraceCopy(); - +public interface ITmfTrace { + /** - * @return the trace path + * StreamContext + *

+ * 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 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); } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java index 7512ca0165..3f33cc7019 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java @@ -12,9 +12,16 @@ 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; /** * TmfExperiment @@ -22,37 +29,357 @@ import org.eclipse.linuxtools.tmf.request.TmfDataRequest; * TmfExperiment presents a time-ordered, unified view of a set of * TmfTraces that are part of a tracing experiment. *

- * TODO: Implement me. PLease. + * TODO: Implement me. Please. */ public class TmfExperiment implements ITmfRequestHandler { - // ======================================================================== + // ======================================================================== // Attributes // ======================================================================== + private final int CACHE_SIZE = 1000; + + private String fExperimentId; + private Vector 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(); + 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 request, boolean waitForCompletion) { - } + public void processRequest(TmfDataRequest 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 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 events = new Vector(); + 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 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 events = new Vector(); + 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 fIndices = new Vector(); + 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)); + } + } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperimentSelectedSignal.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperimentSelectedSignal.java new file mode 100644 index 0000000000..6f4df50ef6 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperimentSelectedSignal.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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; + +/** + * TmfExperimentSelectedSignal + *

+ * 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; + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfStreamCheckpoint.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfStreamCheckpoint.java new file mode 100644 index 0000000000..e4548b1877 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfStreamCheckpoint.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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; + +/** + * TmfStreamCheckpoint + *

+ * This class maps an event timestamp with a trace location. + */ +public class TmfStreamCheckpoint implements Comparable { + + // ======================================================================== + // 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); + } + +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfStreamUpdatedSignal.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfStreamUpdatedSignal.java new file mode 100644 index 0000000000..f87dd92b5a --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfStreamUpdatedSignal.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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; + +/** + * TmfStreamUpdatedEvent + *

+ * 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; + } +} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java index 250ff63248..60f83cda3a 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java @@ -12,217 +12,307 @@ 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; /** - * TmfTrace + * TmfEventStream *

- * 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: - *

    - *
  • the epoch, a reference timestamp for the whole log (t0) - *
  • the span of the log i.e. the timestamps range - *
  • the total number of events - *
- * As an ITmfRequestHandler, it provides an implementation of process() - * which handles event requests. - *

- * 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 { +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 fCheckpoints = new Vector(); + + // 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 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 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 events = new Vector(); - 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 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 events = new Vector(); - 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; + } } } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTraceSelectedSignal.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTraceSelectedSignal.java deleted file mode 100644 index 2812fa7ae9..0000000000 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTraceSelectedSignal.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * TmfTraceSelectedEvent - *

- * 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; - } -} diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTraceUpdatedSignal.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTraceUpdatedSignal.java index f21e2d24ec..a81cbf9fb9 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTraceUpdatedSignal.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTraceUpdatedSignal.java @@ -21,14 +21,14 @@ import org.eclipse.linuxtools.tmf.signal.TmfSignal; */ 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; } } diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace_old.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace_old.java new file mode 100644 index 0000000000..67e0d92309 --- /dev/null +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace_old.java @@ -0,0 +1,244 @@ +/******************************************************************************* + * 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; + +/** + * TmfTrace + *

+ * 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: + *

    + *
  • the epoch, a reference timestamp for the whole log (t0) + *
  • the span of the log i.e. the timestamps range + *
  • the total number of events + *
+ * As an ITmfRequestHandler, it provides an implementation of processRequest() + * which handles event requests. + *

+ * TODO: Handle concurrent and possibly overlapping requests in a way that + * optimizes the stream access and event parsing. + */ +public class TmfTrace_old implements ITmfRequestHandler { + + // ======================================================================== + // 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 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 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 events = new Vector(); + 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 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 events = new Vector(); +// 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)); +// } + +}