Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 185278 Details for
Bug 331467
[LTTng] Add a latency analysis compoment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Latency View (updated)
LatencyView.patch (text/plain), 193.33 KB, created by
Francois Chouinard
on 2010-12-15 18:02:31 EST
(
hide
)
Description:
Latency View (updated)
Filename:
MIME Type:
Creator:
Francois Chouinard
Created:
2010-12-15 18:02:31 EST
Size:
193.33 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.linuxtools.lttng.ui >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/AbstractView.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/AbstractView.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/AbstractView.java (revision 0) >@@ -0,0 +1,313 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency; >+ >+import org.eclipse.linuxtools.lttng.ui.views.latency.handlers.ViewHandler; >+import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractMouseListener; >+import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractPaintListener; >+import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.ZoomListener; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.SWTException; >+import org.eclipse.swt.widgets.Canvas; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Display; >+ >+ >+/** >+ * Abstract view. >+ * >+ * @author Philippe Sawicki >+ */ >+public abstract class AbstractView extends Canvas { >+ >+ /** >+ * Parent composite node. >+ */ >+ protected Composite parent_; >+ >+ /** >+ * View handler (retrieves the information). >+ */ >+ protected ViewHandler viewHandler_ = null; >+ >+ /** >+ * Horizontal axis min value. >+ */ >+ protected long xMin_; >+ /** >+ * Horizontal axis max value. >+ */ >+ protected long xMax_; >+ /** >+ * Vertical axis min value. >+ */ >+ protected long yMin_; >+ /** >+ * Vertical axis max value. >+ */ >+ protected long yMax_; >+ >+ /** >+ * Paint listener. >+ */ >+ protected AbstractPaintListener paintListener_; >+ >+ /** >+ * Zoom listener, to zoom in and out of a graph using the scroll wheel. >+ */ >+ protected ZoomListener zoomListener_; >+ >+ /** >+ * Tooltip listener. >+ */ >+ protected AbstractMouseListener mouseListener_; >+ >+ >+ /** >+ * Constructor. >+ * @param parent The parent composite node. >+ * @param style The SWT style to use to render the view. >+ */ >+ public AbstractView(Composite parent, int style) { >+ super(parent, style); >+ >+ parent_ = parent; >+ } >+ >+ /** >+ * Sets the min value of the horizontal axis. >+ * @param xMin The min value of the horizontal axis. >+ */ >+ public void setXMin(long xMin) { >+ xMin_ = xMin; >+ } >+ >+ /** >+ * Returns the min value of the horizontal axis. >+ * @return The min value of the horizontal axis. >+ */ >+ public long getXMin() { >+ return xMin_; >+ } >+ >+ /** >+ * Sets the max value of the horizontal axis. >+ * @param xMax The max value of the horizontal axis. >+ */ >+ public void setXMax(long xMax) { >+ xMax_ = xMax; >+ } >+ >+ /** >+ * Returns the max value of the horizontal axis. >+ * @return The max value of the horizontal axis. >+ */ >+ public long getXMax() { >+ return xMax_; >+ } >+ >+ /** >+ * Sets the min value of the vertical axis. >+ * @param yMin The min value of the vertical axis. >+ */ >+ public void setYMin(long yMin) { >+ yMin_ = yMin; >+ } >+ /** >+ * Returns the min value of the vertical axis. >+ * @return The min value of the vertical axis. >+ */ >+ public long getYMin() { >+ return yMin_; >+ } >+ >+ /** >+ * Sets the max value of the vertical axis. >+ * @param yMax The max value of the vertical axis. >+ */ >+ public void setYMax(long yMax) { >+ yMax_ = yMax; >+ } >+ /** >+ * Returns the max value of the vertical axis. >+ * @return The max value of the vertical axis. >+ */ >+ public long getYMax() { >+ return yMax_; >+ } >+ >+ /** >+ * Adds a point to the view. >+ * @param point The point to add to the view. >+ */ >+ public abstract void addPoint(int point); >+ >+ /** >+ * Adds a buffer of points to the view. >+ * @param points The buffer of points to add to the view. >+ * @param nbPoints The number of points in the buffer. >+ */ >+ public abstract void addPoints(ChartPoint[] points, int nbPoints); >+ >+ /** >+ * Clears the view. >+ */ >+ public abstract void clear(); >+ >+ /** >+ * Clears the background of the view but keeps min and max values. >+ */ >+ public abstract void clearBackground(); >+ >+ /** >+ * Clears the points buffer, if any exists. >+ */ >+ public void clearPoints() { >+ paintListener_.clearPoints(); >+ } >+ >+ /** >+ * Sets the view handler. >+ * @param viewHandler The view handler. >+ */ >+ public void setViewHandler(ViewHandler viewHandler) { >+ viewHandler_ = viewHandler; >+ } >+ >+ /** >+ * Draw horizontal label each "nbTicks" ticks. >+ * @param nbTicks The draw interval. >+ */ >+ public void drawLabelEachNTicks(int nbTicks) { >+ paintListener_.drawLabelEachNTicks(nbTicks); >+ } >+ >+ /** >+ * Sets the title of the graph. >+ * @param graphTitle The title of the graph. >+ */ >+ public void setGraphTitle(String graphTitle) { >+ paintListener_.setGraphTitle(graphTitle); >+ } >+ >+ /** >+ * Sets the horizontal axis label. >+ * @param xLabel The horizontal axis label. >+ * @param offset The horizontal axis draw offset (in pixels). >+ */ >+ public void setXAxisLabel(String xLabel, int offset) { >+ paintListener_.setXAxisLabel(xLabel, offset); >+ } >+ >+ /** >+ * Sets the vertical axis label. >+ * @param yLabel The vertical axis label. >+ */ >+ public void setYAxisLabel(String yLabel) { >+ paintListener_.setYAxisLabel(yLabel); >+ } >+ >+ /** >+ * Asks for the view to be redrawn, synchronously or asynchronously. >+ * @param asyncRedraw If "true", the view will be redrawn asynchronously, otherwise it will be >+ * redraw synchronously. >+ */ >+ public void askForRedraw(boolean asyncRedraw) { >+ if (asyncRedraw == true) { >+ Display.getDefault().asyncExec(new Runnable() { >+ public void run() { >+ try { >+ redraw(); >+ } catch (SWTException e) { >+ // ... >+ } >+ } >+ }); >+ } else { >+ Display.getDefault().syncExec(new Runnable() { >+ public void run() { >+ try { >+ redraw(); >+ } catch (SWTException e) { >+ // ... >+ } >+ } >+ }); >+ } >+ } >+ >+ /** >+ * Asks for the view to be redrawn (asynchronously). >+ */ >+ public void askForRedraw() { >+ askForRedraw(true); >+ } >+ >+ /** >+ * Returns the zoom factor for the canvas. >+ * @return The zoom factor for the canvas. >+ */ >+ public int getZoomFactor() { >+ if (zoomListener_ != null) { >+ return zoomListener_.getZoomFactor(); >+ } else { >+ return 1; >+ } >+ } >+ >+ /** >+ * Returns the zoom increment for the canvas. >+ * @return The zoom increment for the canvas. >+ */ >+ public int getZoomIncrement() { >+ if (zoomListener_ != null) { >+ return zoomListener_.getZoomIncrement(); >+ } else { >+ return 1; >+ } >+ } >+ >+ /** >+ * Redraws the title after a zoom to display the new zoom factor. >+ */ >+ public void redrawTitle() { >+ paintListener_.paintGraphTitle(); >+ } >+ >+ /** >+ * Removes the view's listeners before disposing of it. >+ */ >+ public void dispose() { >+ try { >+ if (paintListener_ != null) { >+ removePaintListener(paintListener_); >+ paintListener_ = null; >+ } >+ if (zoomListener_ != null) { >+ removeListener(SWT.MouseWheel, zoomListener_); >+ zoomListener_ = null; >+ } >+ if (mouseListener_ != null) { >+ removeListener(SWT.MouseMove, mouseListener_); >+ mouseListener_ = null; >+ } >+ } catch (SWTException e) { >+ // This exception will be thrown if the user closes the view >+ // while it is receiving data from the Analyser. >+ >+ // ... >+ } >+ >+ super.dispose(); >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/ChartPoint.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/ChartPoint.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/ChartPoint.java (revision 0) >@@ -0,0 +1,80 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency; >+ >+ >+/** >+ * Class holding data values to later draw points/bars to the screen. >+ * >+ * @author Philippe Sawicki >+ */ >+public class ChartPoint { >+ >+ /** >+ * Point x-value. >+ */ >+ private long x_; >+ /** >+ * Point y-value. >+ */ >+ private long y_; >+ >+ >+ /** >+ * Constructor. >+ * @param x The point's x-value. >+ * @param y The point's y-value. >+ */ >+ public ChartPoint(long x, long y) { >+ x_ = x; >+ y_ = y; >+ } >+ >+ /** >+ * Constructor. >+ */ >+ public ChartPoint() { >+ this(0L, 0L); >+ } >+ >+ /** >+ * Sets the point's x-value. >+ * @param x The point's x-value. >+ */ >+ public void setX(long x) { >+ x_ = x; >+ } >+ >+ /** >+ * Returns the point's x-value. >+ * @return The point's x-value. >+ */ >+ public long getX() { >+ return x_; >+ } >+ >+ /** >+ * Sets the point's y-value. >+ * @param y The point's y-value. >+ */ >+ public void setY(long y) { >+ y_ = y; >+ } >+ >+ /** >+ * Returns the point's y-value. >+ * @return The point's y-value. >+ */ >+ public long getY() { >+ return y_; >+ } >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/GraphView.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/GraphView.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/GraphView.java (revision 0) >@@ -0,0 +1,74 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency; >+ >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.GraphPaintListener; >+import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.TimePointerListener; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Composite; >+ >+ >+/** >+ * Graph view. >+ * >+ * @author Philippe Sawicki >+ */ >+public class GraphView extends AbstractView { >+ >+ /** >+ * Constructor. >+ * @param parent The parent composite node. >+ * @param style The SWT style to use to render the view. >+ */ >+ public GraphView(Composite parent, int style) { >+ super(parent, style); >+ >+ // Register the paint listener >+ paintListener_ = new GraphPaintListener(this); >+ addPaintListener(paintListener_); >+ >+ // Register the mouse click listener >+ mouseListener_ = new TimePointerListener(this, (GraphPaintListener)paintListener_); >+ addListener(SWT.MouseMove, mouseListener_); >+ } >+ >+ @Override >+ public void addPoint(int point) { >+ if (Config.PRINT_GRAPH_VIEW_STATUS) >+ System.out.println("GRAPH : ADDING 1 POINT"); >+ } >+ >+ @Override >+ public void addPoints(ChartPoint[] points, int nbPoints) { >+ if (Config.PRINT_GRAPH_VIEW_STATUS) >+ System.out.println("GRAPH : ADDING " + nbPoints + " POINTS"); >+ paintListener_.addPoints(points, nbPoints); >+ } >+ >+ @Override >+ public void clear() { >+ xMin_ = 0L; >+ xMax_ = 0L; >+ >+ yMin_ = 0L; >+ yMax_ = 0L; >+ >+ paintListener_.clear(); >+ } >+ >+ @Override >+ public void clearBackground() { >+ paintListener_.clear(); >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/HistogramView.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/HistogramView.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/HistogramView.java (revision 0) >@@ -0,0 +1,114 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency; >+ >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.HistogramPaintListener; >+import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.TooltipListener; >+import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.ZoomListener; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Composite; >+ >+ >+/** >+ * Histogram view. >+ * >+ * @author Philippe Sawicki >+ */ >+public class HistogramView extends AbstractView { >+ >+ /** >+ * Usable width for data plotting. >+ */ >+ protected int usableWidth_; >+ >+ /** >+ * Standard latencies table. >+ */ >+ protected double[] standardLatencies_; >+ >+ >+ /** >+ * Constructor. >+ * @param parent The parent composite node. >+ * @param style The SWT style to use to render the view. >+ */ >+ public HistogramView(Composite parent, int style) { >+ super(parent, style); >+ >+ // Register the paint listener >+ paintListener_ = new HistogramPaintListener(this); >+ addPaintListener(paintListener_); >+ >+ // Register the zoom listener >+ zoomListener_ = new ZoomListener(this); >+ addListener(SWT.MouseWheel, zoomListener_); >+ >+ // Register the mouse click listener >+ mouseListener_ = new TooltipListener(this, (HistogramPaintListener)paintListener_); >+ addListener(SWT.MouseMove, mouseListener_); >+ } >+ >+ @Override >+ public void addPoint(int point) { >+ if (Config.PRINT_HISTO_VIEW_STATUS) >+ System.out.println("HISTOGRAM : ADDING 1 POINT"); >+ } >+ >+ @Override >+ public void addPoints(ChartPoint[] points, int nbPoints) { >+ if (Config.PRINT_HISTO_VIEW_STATUS) >+ System.out.println("HISTOGRAM : ADDING " + nbPoints + " POINTS"); >+ paintListener_.addPoints(points, nbPoints); >+ } >+ >+ @Override >+ public void clear() { >+ xMin_ = 0L; >+ xMax_ = 0L; >+ >+ yMin_ = 0L; >+ yMax_ = 0L; >+ >+ paintListener_.clear(); >+ } >+ >+ @Override >+ public void clearBackground() { >+ paintListener_.clear(); >+ } >+ >+ /** >+ * Returns the number of bars available. >+ * @return The number of bars available. >+ */ >+ public int getNumberOfBars() { >+ usableWidth_ = getClientArea().width - 2*Config.GRAPH_PADDING; >+ return usableWidth_ / Config.HISTOGRAM_BAR_WIDTH; >+ } >+ >+ /** >+ * Notify the view handler of the number of bars available. >+ */ >+ public void notifyNumberOfBars() { >+ viewHandler_.notifyNumberOfBars( getNumberOfBars() ); >+ } >+ >+ /** >+ * Sets the standard latencies table. >+ * @param standardLatencies The standard latencies table. >+ */ >+ public void setStandardLatencies(double[] standardLatencies) { >+ standardLatencies_ = standardLatencies; >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/LatencyView.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/LatencyView.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/LatencyView.java (revision 0) >@@ -0,0 +1,502 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency; >+ >+import org.eclipse.jface.action.Action; >+import org.eclipse.jface.action.IMenuManager; >+import org.eclipse.jface.action.IToolBarManager; >+import org.eclipse.jface.action.Separator; >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.analysis.InterfaceMediator; >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+import org.eclipse.linuxtools.lttng.ui.views.latency.dialogs.AddDialog; >+import org.eclipse.linuxtools.lttng.ui.views.latency.dialogs.DeleteDialog; >+import org.eclipse.linuxtools.lttng.ui.views.latency.dialogs.ListDialog; >+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.experiment.TmfExperiment; >+import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal; >+import org.eclipse.linuxtools.tmf.signal.TmfRangeSynchSignal; >+import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; >+import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal; >+import org.eclipse.linuxtools.tmf.trace.ITmfTrace; >+import org.eclipse.linuxtools.tmf.trace.TmfContext; >+import org.eclipse.linuxtools.tmf.ui.views.TmfView; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.ControlEvent; >+import org.eclipse.swt.events.ControlListener; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.ui.IActionBars; >+import org.eclipse.ui.plugin.AbstractUIPlugin; >+ >+ >+/** >+ * TmfView displaying the latency views (i.e. the two latency charts). >+ * >+ * @author Philippe Sawicki >+ */ >+public class LatencyView extends TmfView { >+ >+ /** >+ * The view's unique ID. >+ */ >+ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView"; >+ >+ /** >+ * A reference to the currently selected experiment. >+ */ >+ protected static TmfExperiment<LttngEvent> experiment_ = null; >+ >+ /** >+ * Parent composite. >+ */ >+ protected static Composite parent_; >+ >+ /** >+ * Graph view. >+ */ >+ protected GraphView graphView_; >+ /** >+ * Histogram view. >+ */ >+ protected HistogramView histogramView_; >+ >+ /** >+ * Action executed when the user wants to see the list of matching events. >+ */ >+ protected Action listMatchingEvents_; >+ /** >+ * Action executed when the user wants to add matching events. >+ */ >+ protected Action addMatchingEvents_; >+ /** >+ * Action executed when the user wants to delete matching events. >+ */ >+ protected Action deleteMatchingEvents_; >+ /** >+ * Action executed when the user wants to increase the width of the histogram bars. >+ */ >+ protected Action increaseBarWidth_; >+ /** >+ * Action executed when the user wants to decrease the width of the histogram bars. >+ */ >+ protected Action decreaseBarWidth_; >+ >+ /** >+ * The current histogram window time range. >+ */ >+ protected static TmfTimeRange timeRange_ = null; >+ >+ /** >+ * A reference to the last TmfRangeSynchSignal recorded. >+ */ >+ protected static TmfRangeSynchSignal rangeSyncSignal_; >+ /** >+ * A reference to the last TmfExperimentSelectedSignal<TmfEvent> recorded. >+ */ >+ protected TmfExperimentSelectedSignal<TmfEvent> experimentSelectedSignal_; >+ >+ >+ >+ /** >+ * Constructor. >+ */ >+ public LatencyView() { >+ super("LatencyView"); >+ } >+ >+ /** >+ * Create the UI controls of this view. >+ * >+ * @param parent The composite parent of this view. >+ */ >+ @Override >+ public void createPartControl(Composite parent) { >+ // Save the parent >+ parent_ = parent; >+ >+ makeActions(); >+ contributeToActionBars(); >+ >+ // Add a control listener to handle the view resize events (to redraw the canvas) >+ parent_.addControlListener(new ControlListener() { >+ @Override >+ public void controlMoved(ControlEvent event) { >+ resendSignalsIfNeeded(); >+ } >+ >+ @Override >+ public void controlResized(ControlEvent event) { >+ resendSignalsIfNeeded(); >+ } >+ >+ /** >+ * Resend trace signals if the resize or the move forced the views >+ * to be cleared, so that after the view is resized/moved, the events >+ * from the trace start being plotted. >+ */ >+ protected void resendSignalsIfNeeded() { >+ if (rangeSyncSignal_ != null) { >+ synchToTimeRange(rangeSyncSignal_); >+ } else if (experimentSelectedSignal_ != null) { >+ experimentSelected(experimentSelectedSignal_); >+ } else { >+ graphView_.clear(); >+ histogramView_.clear(); >+ } >+ } >+ }); >+ >+ >+ >+ ///////////////////////////////////////////////////////////////////////////////////// >+ // Layout for the whole view, other elements will be in a child composite of this one >+ // Contains : >+ // Composite layoutSelectionWindow >+ // Composite layoutTimesSpinner >+ // Composite layoutExperimentHistogram >+ ///////////////////////////////////////////////////////////////////////////////////// >+ Composite layoutFullView = new Composite(parent_, SWT.FILL); >+ FillLayout gridFullView = new FillLayout(); >+ gridFullView.marginHeight = 0; >+ gridFullView.marginWidth = 0; >+ layoutFullView.setLayout(gridFullView); >+ >+ // Create the graph views >+ graphView_ = new GraphView(layoutFullView, SWT.DOUBLE_BUFFERED); >+ graphView_.drawLabelEachNTicks(2); >+ graphView_.setGraphTitle(Messages.getString("LatencyView.Graphs.Graph.Title")); >+ graphView_.setXAxisLabel(Messages.getString("LatencyView.Graphs.Graph.XAxisLabel"), 40); >+ graphView_.setYAxisLabel(Messages.getString("LatencyView.Graphs.Graph.YAxisLabel")); >+ >+ histogramView_ = new HistogramView(layoutFullView, SWT.DOUBLE_BUFFERED); >+ histogramView_.setGraphTitle(Messages.getString("LatencyView.Graphs.Histogram.Title")); >+ histogramView_.setXAxisLabel(Messages.getString("LatencyView.Graphs.Histogram.XAxisLabel"), 55); >+ histogramView_.setYAxisLabel(Messages.getString("LatencyView.Graphs.Histogram.YAxisLabel")); >+ >+ // Register the graph views to the InterfaceMediator >+ InterfaceMediator.getInstance().registerGraphView(graphView_); >+ InterfaceMediator.getInstance().registerHistogramView(histogramView_); >+ } >+ >+ @Override >+ public String toString() { >+ return "[LatencyView]"; >+ } >+ >+ /** >+ * Returns the currently selected experiment. >+ * @return The currently selected experiment. >+ */ >+ public static TmfExperiment<LttngEvent> getExperiment() { >+ return (TmfExperiment<LttngEvent>) experiment_; >+ } >+ >+ >+ // ------------------------------------------------------------------------ >+ // Signal handlers >+ // ------------------------------------------------------------------------ >+ >+ @SuppressWarnings("unchecked") >+ @TmfSignalHandler >+ public void experimentSelected(TmfExperimentSelectedSignal<TmfEvent> signal) { >+ experimentSelectedSignal_ = signal; >+ >+ // Clear the views >+ graphView_.clear(); >+ histogramView_.clear(); >+ >+ histogramView_.notifyNumberOfBars(); >+ >+ if (parent_ != null) { >+ // Update the trace reference >+ experiment_ = (TmfExperiment<LttngEvent>) experimentSelectedSignal_.getExperiment(); >+ >+ sendAnalysisRequest(); >+ } >+ } >+ >+ /** >+ * Ask the analyser to compute the latencies for the current experiment. >+ */ >+ public static void sendAnalysisRequest() { >+ if (parent_ != null) { >+ Display display = parent_.getDisplay(); >+ display.asyncExec(new Runnable() { >+ public void run() { >+ new Thread() { >+ public void run() { >+ try { >+ TmfTimestamp startTime = getExperimentTimeRange().getStartTime(); >+ TmfTimestamp endTime = new TmfTimestamp(startTime.getValue() + org.eclipse.linuxtools.lttng.ui.views.histogram.HistogramView.getDEFAULT_WINDOW_SIZE()); >+ timeRange_ = new TmfTimeRange(startTime, endTime); >+ >+ InterfaceMediator.getInstance().analyseLatencyForAllEvents(); >+ } catch (NullPointerException e) { >+ // Thrown when the user has not selected an experiment yet but reset the latency pairs to >+ // default in the dialog. >+ } >+ } >+ }.start(); >+ } >+ }); >+ } >+ } >+ >+ /** >+ * Called when the LatencyView is closed: disposes of the canvas and >+ * unregisters them from the InterfaceMediator. >+ */ >+ @Override >+ public void dispose() { >+ graphView_.dispose(); >+ histogramView_.dispose(); >+ >+ InterfaceMediator.getInstance().unregisterViews(); >+ >+ super.dispose(); >+ } >+ >+ >+ >+ >+ >+ /** >+ * Method called when synchonization is active and that the user select an event.<p> >+ * We update the current event timeTextGroup and move the selected window if needed. >+ * >+ * @param signal Signal received from the framework. Contain the event. >+ */ >+ @TmfSignalHandler >+ public void currentTimeUpdated(TmfTimeSynchSignal signal) { >+ >+ } >+ >+ @TmfSignalHandler >+ public void synchToTimeRange(TmfRangeSynchSignal signal) { >+ rangeSyncSignal_ = signal; >+ if (rangeSyncSignal_ != null && rangeSyncSignal_.getSource() != this) { >+ // Erase the graph views >+ graphView_.clear(); >+ histogramView_.clear(); >+ >+ TmfTimestamp startTime = rangeSyncSignal_.getCurrentRange().getStartTime(); >+ TmfTimestamp endTime = rangeSyncSignal_.getCurrentRange().getEndTime(); >+ timeRange_ = new TmfTimeRange(startTime, endTime); >+ >+ InterfaceMediator.getInstance().analyseLatencyForAllEvents(); >+ } >+ } >+ >+ >+ >+ >+ >+ /** >+ * Fills the local pull down menu. >+ * @param manager The menu manager. >+ */ >+ private void fillLocalPullDown(IMenuManager manager) { >+ manager.add(new Separator()); >+ manager.add(increaseBarWidth_); >+ manager.add(decreaseBarWidth_); >+ manager.add(new Separator()); >+ manager.add(listMatchingEvents_); >+ manager.add(addMatchingEvents_); >+ manager.add(deleteMatchingEvents_); >+ manager.add(new Separator()); >+ } >+ >+ /** >+ * Fills the local toolbar. >+ * @param manager The toolbar manager >+ */ >+ private void fillLocalToolBar(IToolBarManager manager) { >+ manager.add(new Separator()); >+ manager.add(increaseBarWidth_); >+ manager.add(decreaseBarWidth_); >+ manager.add(new Separator()); >+ manager.add(listMatchingEvents_); >+ manager.add(addMatchingEvents_); >+ manager.add(deleteMatchingEvents_); >+ manager.add(new Separator()); >+ } >+ >+ /** >+ * Creates the actions required by the dialog events. >+ */ >+ private void makeActions() { >+ // Increase the histogram bar width >+ increaseBarWidth_ = new Action() { >+ public void run() { >+ Config.HISTOGRAM_BAR_WIDTH += 5; >+ if (Config.HISTOGRAM_BAR_WIDTH > 300) >+ Config.HISTOGRAM_BAR_WIDTH = 300; >+ histogramView_.notifyNumberOfBars(); >+ sendAnalysisRequest(); >+ } >+ }; >+ String tooltipText = Messages.getString("LatencyView.Action.IncreaseBarWidth.Tooltip"); >+ increaseBarWidth_.setText(tooltipText); >+ increaseBarWidth_.setToolTipText(tooltipText); >+ increaseBarWidth_.setImageDescriptor( >+ AbstractUIPlugin.imageDescriptorFromPlugin( >+ Messages.getString("LatencyView.tmf.UI"), >+ "icons/increasebar_button.gif")); >+ >+ >+ >+ >+ >+ // Decrease the histogram bar width >+ decreaseBarWidth_ = new Action() { >+ public void run() { >+ Config.HISTOGRAM_BAR_WIDTH -= 5; >+ if (Config.HISTOGRAM_BAR_WIDTH < 5) >+ Config.HISTOGRAM_BAR_WIDTH = 5; >+ histogramView_.notifyNumberOfBars(); >+ sendAnalysisRequest(); >+ } >+ }; >+ tooltipText = Messages.getString("LatencyView.Action.DecreaseBarWidth.Tooltip"); >+ decreaseBarWidth_.setText(tooltipText); >+ decreaseBarWidth_.setToolTipText(tooltipText); >+ decreaseBarWidth_.setImageDescriptor( >+ AbstractUIPlugin.imageDescriptorFromPlugin( >+ Messages.getString("LatencyView.tmf.UI"), >+ "icons/decreasebar_button.gif")); >+ >+ >+ >+ >+ // List matching events dialog >+ listMatchingEvents_ = new Action() { >+ public void run() { >+ ListDialog listDialog = new ListDialog( >+ parent_.getShell(), >+ Messages.getString("LatencyView.Dialogs.ListEvents.Title"), >+ Messages.getString("LatencyView.Dialogs.ListEvents.Message") ); >+ listDialog.create(); >+ listDialog.open(); >+ } >+ }; >+ tooltipText = Messages.getString("LatencyView.Action.ListEvents.Tooltip"); >+ listMatchingEvents_.setText(tooltipText); >+ listMatchingEvents_.setToolTipText(tooltipText); >+ listMatchingEvents_.setImageDescriptor( >+ AbstractUIPlugin.imageDescriptorFromPlugin( >+ Messages.getString("LatencyView.tmf.UI"), >+ "icons/events_view.gif")); >+ >+ >+ >+ // Add matching events dialog >+ addMatchingEvents_ = new Action() { >+ public void run() { >+ AddDialog addDialog = new AddDialog( >+ parent_.getShell(), >+ Messages.getString("LatencyView.Dialogs.AddEvents.Title"), >+ Messages.getString("LatencyView.Dialogs.AddEvents.Message") ); >+ addDialog.create(); >+ addDialog.open(); >+ } >+ }; >+ tooltipText = Messages.getString("LatencyView.Action.AddEvents.Tooltip"); >+ addMatchingEvents_.setText(tooltipText); >+ addMatchingEvents_.setToolTipText(tooltipText); >+ addMatchingEvents_.setImageDescriptor( >+ AbstractUIPlugin.imageDescriptorFromPlugin( >+ Messages.getString("LatencyView.tmf.UI"), >+ "icons/add_button.gif")); >+ >+ >+ >+ // Remove matching events dialog >+ deleteMatchingEvents_ = new Action() { >+ public void run() { >+ DeleteDialog deleteDialog = new DeleteDialog( >+ parent_.getShell(), >+ Messages.getString("LatencyView.Dialogs.DeleteEvents.Title"), >+ Messages.getString("LatencyView.Dialogs.DeleteEvents.Message") ); >+ deleteDialog.create(); >+ deleteDialog.open(); >+ } >+ }; >+ tooltipText = Messages.getString("LatencyView.Action.DeleteEvents.Tooltip"); >+ deleteMatchingEvents_.setText(tooltipText); >+ deleteMatchingEvents_.setToolTipText(tooltipText); >+ deleteMatchingEvents_.setImageDescriptor( >+ AbstractUIPlugin.imageDescriptorFromPlugin( >+ Messages.getString("LatencyView.tmf.UI"), >+ "icons/delete_button.gif")); >+ } >+ >+ /** >+ * Build the toolbar and menu by adding action buttons for dialogs. >+ */ >+ private void contributeToActionBars() { >+ IActionBars bars = getViewSite().getActionBars(); >+ fillLocalPullDown(bars.getMenuManager()); >+ fillLocalToolBar(bars.getToolBarManager()); >+ } >+ >+ >+ >+ >+ >+ >+ >+ >+ /** >+ * Before completing its indexing, the experiment doesn't know start/end time. However, LTTng individual traces have this >+ * knowledge so we should ask them directly. >+ * @return The experiment's time range. >+ */ >+ public static TmfTimeRange getExperimentTimeRange() { >+ TmfTimestamp startTime = TmfTimestamp.BigCrunch; >+ TmfTimestamp endTime = TmfTimestamp.BigBang; >+ >+ if (rangeSyncSignal_ != null) { >+ startTime = rangeSyncSignal_.getCurrentRange().getStartTime(); >+ endTime = rangeSyncSignal_.getCurrentRange().getEndTime(); >+ timeRange_ = new TmfTimeRange(startTime, endTime); >+ } else if (experiment_ != null) { >+ for (ITmfTrace trace : experiment_.getTraces()) { >+ TmfContext context = trace.seekLocation(null); >+ context.setRank(0); >+ TmfEvent event = trace.getNextEvent(context); >+ >+ TmfTimestamp traceStartTime = event.getTimestamp(); >+ if (traceStartTime.compareTo(startTime, true) < 0) >+ startTime = traceStartTime; >+ >+ TmfTimestamp traceEndTime = trace.getEndTime(); >+ if (traceEndTime.compareTo(endTime, true) > 0) >+ endTime = traceEndTime; >+ } >+ } >+ >+ return new TmfTimeRange(startTime, endTime); >+ } >+ >+ /** >+ * Returns the current histogram window time range. >+ * @return The current histogram window time range. >+ */ >+ public static TmfTimeRange getTimeRange() { >+ return timeRange_; >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/Messages.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/Messages.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/Messages.java (revision 0) >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency; >+ >+import java.util.MissingResourceException; >+import java.util.ResourceBundle; >+ >+ >+/** >+ * Returns localised strings from the resource bundle (i.e. "messages.properties"). >+ * >+ * @author Philippe Sawicki >+ */ >+public class Messages { >+ >+ /** >+ * Bundle name. >+ */ >+ private static final String BUNDLE_NAME = "org.eclipse.linuxtools.lttng.ui.views.latency.messages"; //$NON-NLS-1$ >+ >+ /** >+ * A reference to the resource bundle. >+ */ >+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); >+ >+ >+ /** >+ * Private constructor to defeat instantiation. >+ */ >+ private Messages() { >+ >+ } >+ >+ /** >+ * Returns the localised String for the given key-ID. >+ * @param key The key of the localised String. >+ * @return The localised String for the given key-ID. >+ */ >+ public static String getString(String key) { >+ try { >+ return RESOURCE_BUNDLE.getString(key); >+ } catch (MissingResourceException e) { >+ return '!' + key + '!'; >+ } >+ } >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/AbstractDialog.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/AbstractDialog.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/AbstractDialog.java (revision 0) >@@ -0,0 +1,214 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.dialogs; >+ >+import java.util.Vector; >+ >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.dialogs.IMessageProvider; >+import org.eclipse.jface.dialogs.TitleAreaDialog; >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher; >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair; >+import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; >+import org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+ >+/** >+ * Abstract dialog class, regroups the main functions shared by all the >+ * different dialogs. >+ * >+ * @author Philippe Sawicki >+ */ >+public abstract class AbstractDialog extends TitleAreaDialog { >+ >+ /** >+ * The dialog window title. >+ */ >+ protected String dialogTitle_; >+ /** >+ * The dialog window message. >+ */ >+ protected String dialogMessage_; >+ >+ /** >+ * The code returned by the dialog when the user closes the "Add" dialog. >+ */ >+ public static final int ADD = 53445; >+ /** >+ * The code returned by the dialog when the user closes the "Delete" dialog. >+ */ >+ public static final int DELETE = ADD+1; >+ /** >+ * The code returned by the dialog when the user resets the latency pair to default. >+ */ >+ public static final int RESET = DELETE+1; >+ >+ /** >+ * String ID of the number of pairs saved in the settings file. >+ */ >+ protected static final String LATENCY_NB_MATCH_PAIRS = "NB_LATENCY_MATCH_PAIRS"; >+ /** >+ * String ID of the start event pairs saved in the settings file. >+ */ >+ protected static final String LATENCY_PAIRS_START = "LATENCY_PAIRS_START"; >+ /** >+ * String ID of the end event pairs saved in the settings file. >+ */ >+ protected static final String LATENCY_PAIRS_END = "LATENCY_PAIRS_END"; >+ >+ /** >+ * Dialog settings, saves the event pairs across sessions. >+ */ >+ protected IDialogSettings settings_; >+ >+ /** >+ * Do the graphs canvas need to be redrawn due to latency pairs changes ? >+ */ >+ protected boolean redrawGraphs_ = false; >+ >+ >+ /** >+ * Constructor. >+ * @param parentShell The parent shell. >+ * @param title The dialog window's title. >+ * @param message The dialog window's message. >+ */ >+ public AbstractDialog(Shell parentShell, String title, String message) { >+ super(parentShell); >+ dialogTitle_ = title; >+ dialogMessage_ = message; >+ >+ settings_ = LTTngUiPlugin.getDefault().getDialogSettings(); >+ } >+ >+ /** >+ * Constructor >+ * @param parentShell The parent shell. >+ * @param title The dialog window's title. >+ */ >+ public AbstractDialog(Shell parentShell, String title) { >+ this(parentShell, title, ""); >+ } >+ >+ /** >+ * Constructor. >+ * @param parentShell The parent shell. >+ */ >+ public AbstractDialog(Shell parentShell) { >+ this(parentShell, "", ""); >+ } >+ >+ /** >+ * Creates the dialog. >+ * >+ * <b>Note :</b> Since there is an issue with the table's vertical scrollbar, >+ * this dialog "resize" is necessary to ensure a minimal height for the window. >+ */ >+ @Override >+ public void create() { >+ super.create(); >+ // Set the title >+ setTitle(dialogTitle_); >+ // Set the message >+ setMessage(dialogMessage_, IMessageProvider.INFORMATION); >+ >+ // Position the dialog at the center of the screen >+ int windowWidth = Display.getCurrent().getPrimaryMonitor().getBounds().width; >+ int windowHeight = Display.getCurrent().getPrimaryMonitor().getBounds().height; >+ int dialogWidth = getShell().getSize().x; >+ int dialogHeight = windowHeight / 2; >+ >+ int x = (windowWidth - dialogWidth) / 2; >+ int y = (windowHeight - dialogHeight) / 2; >+ >+ getShell().setSize(getShell().getSize().x, dialogHeight); >+ getShell().setLocation(x, y); >+ } >+ >+ /** >+ * Formats the "#" of the event in the table by adding "00" before it. >+ * @param number The number to format. >+ * @param max The maximum number of event pairs in the list. >+ * @return The formatted string. >+ */ >+ protected String formatListNumber(int number, int max) { >+ return String.format("%0"+max+"d", number); >+ } >+ >+ /** >+ * Returns the match pairs saved in the settings file. >+ * @return The match pairs saved in the settings file. >+ */ >+ protected Pair<Vector<String>,Vector<String>> getMatchPairs() { >+ try { >+ // Check if the settings file has already some data (i.e. try provoking an exception) >+ settings_.getInt(LATENCY_NB_MATCH_PAIRS); >+ >+ String[] starts = settings_.getArray(LATENCY_PAIRS_START); >+ String[] ends = settings_.getArray(LATENCY_PAIRS_END); >+ >+ EventMatcher.getInstance().resetMatches(); >+ for (int i = 0; i < starts.length; i++) { >+ EventMatcher.getInstance().addMatch(starts[i], ends[i]); >+ } >+ >+ return EventMatcher.getInstance().getEvents(); >+ } catch (NumberFormatException e) { >+ return EventMatcher.getInstance().getEvents(); >+ } >+ } >+ >+ /** >+ * Saves the event match pairs to a settings file. >+ * @param start The start event types. >+ * @param end The end event types. >+ */ >+ protected void saveMatchPairs(Vector<String> start, Vector<String> end) { >+ settings_.put(LATENCY_NB_MATCH_PAIRS, start.size()); >+ settings_.put(LATENCY_PAIRS_START, start.toArray(new String[]{})); >+ settings_.put(LATENCY_PAIRS_END, end.toArray(new String[]{})); >+ } >+ >+ /** >+ * Ask the LatencyView to send a new analysis request to the views, so that they can be redrawn. >+ */ >+ protected void redrawGraphs() { >+ LatencyView.sendAnalysisRequest(); >+ } >+ >+ /** >+ * Creates the dialog area. >+ * @param parent The parent. >+ */ >+ @Override >+ protected abstract Control createDialogArea(Composite parent); >+ >+ /** >+ * Creates the buttons for the button bar. >+ * @param parent The parent. >+ */ >+ @Override >+ protected abstract void createButtonsForButtonBar(Composite parent); >+ >+ /** >+ * Is the dialog resizable ? >+ */ >+ @Override >+ protected boolean isResizable() { >+ return true; >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/AddDialog.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/AddDialog.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/AddDialog.java (revision 0) >@@ -0,0 +1,468 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.dialogs; >+ >+import java.util.Vector; >+ >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher; >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair; >+import org.eclipse.linuxtools.lttng.ui.views.latency.Messages; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Table; >+import org.eclipse.swt.widgets.TableColumn; >+import org.eclipse.swt.widgets.TableItem; >+ >+ >+/** >+ * Add dialog, lets the user add custom start/end event pairs. >+ * >+ * @author Philippe Sawicki >+ */ >+public class AddDialog extends AbstractDialog { >+ >+ /** >+ * The dialog's start table. >+ */ >+ protected Table startTable_; >+ /** >+ * The dialog's end table. >+ */ >+ protected Table endTable_; >+ /** >+ * The dialog's list table. >+ */ >+ protected Table listTable_; >+ >+ /** >+ * Start table columns. >+ */ >+ protected TableColumn[] startColumns_; >+ /** >+ * End table columns. >+ */ >+ protected TableColumn[] endColumns_; >+ /** >+ * List table columns. >+ */ >+ protected TableColumn[] listColumns_; >+ >+ /** >+ * Start table column names (header titles). >+ */ >+ protected static final String[] START_COLUMN_NAMES = {"", Messages.getString("LatencyView.Dialogs.AddEvents.Columns.Start")}; >+ /** >+ * End table column names (header titles). >+ */ >+ protected static final String[] END_COLUMN_NAMES = {"", Messages.getString("LatencyView.Dialogs.AddEvents.Columns.End")}; >+ /** >+ * List table column names (header titles). >+ */ >+ protected static final String[] LIST_COLUMN_NAMES = {"#", Messages.getString("LatencyView.Dialogs.AddEvents.Columns.List.Trigger"), Messages.getString("LatencyView.Dialogs.AddEvents.Columns.List.End")}; >+ /** >+ * Column widths. >+ */ >+ protected static final int[] COLUMN_WIDTHS = {25, 250, 250}; >+ >+ /** >+ * Possible event types. >+ */ >+ protected Vector<String> eventTypes_ = new Vector<String>(); >+ >+ /** >+ * Start event types. >+ */ >+ protected Vector<String> eventStartTypes_; >+ /** >+ * End event types. >+ */ >+ protected Vector<String> eventEndTypes_; >+ >+ /** >+ * Selected start type. >+ */ >+ protected String startType_; >+ /** >+ * Selected end type. >+ */ >+ protected String endType_; >+ >+ >+ /** >+ * Constructor. >+ * @param parentShell The parent shell. >+ * @param title The dialog's window title. >+ * @param message The dialog's window message. >+ */ >+ public AddDialog(Shell parentShell, String title, String message) { >+ super(parentShell, title, message); >+ >+ // Get the possible events from the list >+ eventTypes_ = EventMatcher.getInstance().getTypeList(); >+ >+ // Get the list of start and end types from the EventMatcher >+ Pair<Vector<String>,Vector<String>> pair = getMatchPairs(); >+ eventStartTypes_ = pair.getFirst(); >+ eventEndTypes_ = pair.getSecond(); >+ } >+ >+ /** >+ * Creates the start table's columns (i.e. the table header). >+ */ >+ protected void createStartColumns() { >+ startColumns_ = new TableColumn[START_COLUMN_NAMES.length]; >+ for (int i = 0; i < START_COLUMN_NAMES.length; i++) { >+ startColumns_[i] = new TableColumn(startTable_, SWT.LEFT); >+ startColumns_[i].setText(START_COLUMN_NAMES[i]); >+ startColumns_[i].setWidth(COLUMN_WIDTHS[i]); >+ } >+ } >+ >+ /** >+ * Creates the end table's columns (i.e. the table header). >+ */ >+ protected void createEndColumns() { >+ endColumns_ = new TableColumn[END_COLUMN_NAMES.length]; >+ for (int i = 0; i < END_COLUMN_NAMES.length; i++) { >+ endColumns_[i] = new TableColumn(endTable_, SWT.LEFT); >+ endColumns_[i].setText(END_COLUMN_NAMES[i]); >+ endColumns_[i].setWidth(COLUMN_WIDTHS[i]); >+ } >+ } >+ >+ /** >+ * Creates the list table's columns (i.e. the table header). >+ */ >+ protected void createListColumns() { >+ listColumns_ = new TableColumn[LIST_COLUMN_NAMES.length]; >+ for (int i = 0; i < LIST_COLUMN_NAMES.length; i++) { >+ listColumns_[i] = new TableColumn(listTable_, SWT.LEFT); >+ listColumns_[i].setText(LIST_COLUMN_NAMES[i]); >+ listColumns_[i].setWidth(COLUMN_WIDTHS[i]); >+ } >+ } >+ >+ /** >+ * Creates the start column list. >+ * @param parent The parent composite. >+ */ >+ protected void createStartColumn(Composite parent) { >+ final int style = SWT.SINGLE | SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL; >+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); >+ startTable_ = new Table(parent, style); >+ startTable_.setLayoutData(layoutData); >+ >+ // Some cosmetic enhancements >+ startTable_.setHeaderVisible(true); >+ startTable_.setLinesVisible(true); >+ >+ createStartColumns(); >+ >+ for (int i = 0; i < eventTypes_.size(); i++) { >+ TableItem item = new TableItem(startTable_, SWT.RIGHT); >+ >+ String[] columns = { >+ eventTypes_.get(i), >+ eventTypes_.get(i) >+ }; >+ >+ item.setText(columns); >+ } >+ >+ startTable_.setItemCount( eventTypes_.size() ); >+ >+ startTable_.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event event) { >+ if (event.detail == SWT.CHECK) { >+ TableItem[] items = startTable_.getItems(); >+ for (TableItem item : items) { >+ if (item != event.item) { >+ item.setChecked(false); >+ } >+ } >+ } >+ } >+ }); >+ } >+ >+ /** >+ * Creates the end column list. >+ * @param parent The parent composite. >+ */ >+ protected void createEndColumn(Composite parent) { >+ final int style = SWT.SINGLE | SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL; >+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); >+ endTable_ = new Table(parent, style); >+ endTable_.setLayoutData(layoutData); >+ >+ // Some cosmetic enhancements >+ endTable_.setHeaderVisible(true); >+ endTable_.setLinesVisible(true); >+ >+ createEndColumns(); >+ >+ for (int i = 0; i < eventTypes_.size(); i++) { >+ TableItem item = new TableItem(endTable_, SWT.RIGHT); >+ >+ String[] columns = { >+ eventTypes_.get(i), >+ eventTypes_.get(i) >+ }; >+ >+ item.setText(columns); >+ } >+ >+ endTable_.setItemCount( eventTypes_.size() ); >+ >+ endTable_.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event event) { >+ if (event.detail == SWT.CHECK) { >+ TableItem[] items = endTable_.getItems(); >+ for (TableItem item : items) { >+ if (item != event.item) { >+ item.setChecked(false); >+ } >+ } >+ } >+ } >+ }); >+ } >+ >+ /** >+ * Creates the list column for already existing event pairs. >+ * @param parent The parent composite. >+ */ >+ protected void createListColumn(Composite parent) { >+ final int style = SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL; >+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); >+ layoutData.horizontalSpan = 2; >+ listTable_ = new Table(parent, style); >+ listTable_.setLayoutData(layoutData); >+ >+ // Some cosmetic enhancements >+ listTable_.setHeaderVisible(true); >+ listTable_.setLinesVisible(true); >+ >+ createListColumns(); >+ >+ for (int i = 0; i < eventStartTypes_.size(); i++) { >+ TableItem item = new TableItem(listTable_, SWT.RIGHT); >+ >+ String max = "" + eventStartTypes_.size(); >+ String number = formatListNumber(i+1, max.length()); >+ >+ String[] columns = { >+ number, >+ eventStartTypes_.get(i), >+ eventEndTypes_.get(i) >+ }; >+ >+ item.setText(columns); >+ } >+ >+ listTable_.setItemCount( 103 ); >+ listTable_.remove(eventTypes_.size(), 103-1); >+ } >+ >+ /** >+ * Creates the dialog area. >+ * @param parent The parent. >+ */ >+ @Override >+ protected Control createDialogArea(Composite parent) { >+ GridLayout layout = new GridLayout(2, true); >+ parent.setLayout(layout); >+ >+ createStartColumn(parent); >+ createEndColumn(parent); >+ createListColumn(parent); >+ >+ return parent; >+ } >+ >+ /** >+ * Creates the buttons for the button bar. >+ * @param parent The parent. >+ */ >+ @Override >+ protected void createButtonsForButtonBar(Composite parent) { >+ GridData gridData = new GridData(); >+ gridData.verticalAlignment = GridData.FILL; >+ gridData.horizontalSpan = 1; >+ gridData.grabExcessHorizontalSpace = true; >+ gridData.grabExcessVerticalSpace = true; >+ gridData.horizontalAlignment = SWT.RIGHT; >+ >+ parent.setLayoutData(gridData); >+ >+ // Create the "Add" button >+ Button addButton = createButton(parent, ADD, Messages.getString("LatencyView.Dialogs.AddEvents.Buttons.Add"), false); >+ addButton.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event event) { >+ if (isValidInput()) { >+ // Add the event pair to the EventMatcher and save the pairs >+ EventMatcher.getInstance().addMatch(startType_, endType_); >+ eventStartTypes_.add(startType_); >+ eventEndTypes_.add(endType_); >+ saveMatchPairs(eventStartTypes_, eventEndTypes_); >+ >+ Pair<Vector<String>,Vector<String>> pairs = EventMatcher.getInstance().getEvents(); >+ eventStartTypes_ = pairs.getFirst(); >+ eventEndTypes_ = pairs.getSecond(); >+ >+ listTable_.removeAll(); >+ >+ for (int i = 0; i < eventStartTypes_.size(); i++) { >+ TableItem item = new TableItem(listTable_, SWT.RIGHT); >+ >+ String max = "" + eventStartTypes_.size(); >+ String number = formatListNumber(i+1, max.length()); >+ >+ String[] columns = { >+ number, >+ eventStartTypes_.get(i), >+ eventEndTypes_.get(i) >+ }; >+ >+ item.setText(columns); >+ } >+ >+ saveMatchPairs(eventStartTypes_, eventEndTypes_); >+ } >+ >+ redrawGraphs_ = true; >+ } >+ }); >+ >+ // Create the "Close" button >+ Button closeButton = createButton(parent, CANCEL, Messages.getString("LatencyView.Dialogs.AddEvents.Buttons.Close"), false); >+ closeButton.addListener(SWT.Selection, new Listener() { >+ @Override >+ public void handleEvent(Event event) { >+ setReturnCode(CANCEL); >+ >+ if (redrawGraphs_ == true) >+ redrawGraphs(); >+ >+ close(); >+ } >+ }); >+ } >+ >+ /** >+ * Validate the list before adding event pairs. >+ * @return "true" if the input is valid, "false" otherwise. >+ */ >+ protected boolean isValidInput() { >+ // Remove the previous error message >+ setErrorMessage(null); >+ >+ boolean valid = true; >+ >+ // Check if an item from the start list is selected >+ TableItem[] items = startTable_.getItems(); >+ startType_ = null; >+ boolean startHasSelectedItem = false; >+ for (int i = 0; i < items.length && !startHasSelectedItem; i++) { >+ if (items[i].getChecked() == true) { >+ startType_ = items[i].getText(); >+ startHasSelectedItem = true; >+ } >+ } >+ >+ // Check if an item from the end list is selected >+ items = endTable_.getItems(); >+ endType_ = null; >+ boolean endHasSelectedItem = false; >+ for (int i = 0; i < items.length && !endHasSelectedItem; i++) { >+ if (items[i].getChecked() == true) { >+ endType_ = items[i].getText(); >+ endHasSelectedItem = true; >+ } >+ } >+ >+ // Print error message if needed. >+ if (!startHasSelectedItem && !endHasSelectedItem) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.NoSelection") ); >+ valid = false; >+ } else if (!startHasSelectedItem) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.StartNotSelected") ); >+ valid = false; >+ } else if (!endHasSelectedItem) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.EndNotSelected") ); >+ valid = false; >+ } >+ >+ // Check if the same item is selected in both lists >+ if (startHasSelectedItem && endHasSelectedItem) { >+ if ( startType_.equalsIgnoreCase(endType_) ) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.SameSelected") ); >+ valid = false; >+ } >+ } >+ >+ // Check if the selected item is already in the list >+ if (startHasSelectedItem && endHasSelectedItem) { >+ Pair<Vector<String>,Vector<String>> pairs = getMatchPairs(); >+ Vector<String> startEvents = pairs.getFirst(); >+ Vector<String> endEvents = pairs.getSecond(); >+ >+ boolean startAlreadyUsed = false; >+ boolean endAlreadyUsed = false; >+ boolean startAsEndAlreadyUsed = false; >+ boolean endAsStartAlreadyUsed = false; >+ >+ if (startEvents.contains(startType_)) { >+ startAlreadyUsed = true; >+ } >+ if (endEvents.contains(endType_)) { >+ endAlreadyUsed = true; >+ } >+ if (startEvents.contains(endType_)) { >+ endAsStartAlreadyUsed = true; >+ } >+ if (endEvents.contains(startType_)) { >+ startAsEndAlreadyUsed = true; >+ } >+ >+ if (startAlreadyUsed && endAlreadyUsed) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.AlreadyMatched") ); >+ valid = false; >+ } else if (startAlreadyUsed) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.StartAlreadyMatched") ); >+ valid = false; >+ } else if (endAlreadyUsed) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.EndAlreadyMatched") ); >+ valid = false; >+ } >+ >+ if (startAsEndAlreadyUsed) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.StartAsEnd") ); >+ valid = false; >+ } >+ if (endAsStartAlreadyUsed) { >+ setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.EndAsStart") ); >+ valid = false; >+ } >+ } >+ >+ return valid; >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/DeleteDialog.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/DeleteDialog.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/DeleteDialog.java (revision 0) >@@ -0,0 +1,146 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.dialogs; >+ >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher; >+import org.eclipse.linuxtools.lttng.ui.views.latency.Messages; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.TableItem; >+ >+ >+/** >+ * Remove dialog, lets the user remove start/end event pairs. >+ * >+ * @author Philippe Sawicki >+ */ >+public class DeleteDialog extends ListDialog { >+ >+ /** >+ * Constructor. >+ * @param parentShell The parent shell. >+ * @param title The dialog's window title. >+ * @param message The dialog's window message. >+ */ >+ public DeleteDialog(Shell parentShell, String title, String message) { >+ super(parentShell, title, message); >+ >+ // Set the table style >+ style_ = SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL; >+ } >+ >+ /** >+ * Creates the buttons for the button bar. >+ * @param parent The parent. >+ */ >+ @Override >+ protected void createButtonsForButtonBar(Composite parent) { >+ GridData gridData = new GridData(); >+ gridData.verticalAlignment = GridData.FILL; >+ gridData.horizontalSpan = 1; >+ gridData.grabExcessHorizontalSpace = true; >+ gridData.grabExcessVerticalSpace = true; >+ gridData.horizontalAlignment = SWT.RIGHT; >+ >+ parent.setLayoutData(gridData); >+ >+ // Create the "Delete" button >+ Button deleteButton = createButton(parent, DELETE, Messages.getString("LatencyView.Dialogs.DeleteEvents.Buttons.Delete"), false); >+ deleteButton.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event event) { >+ TableItem selectedItem = table_.getSelection()[0]; >+ if (selectedItem == null) >+ return; >+ >+ int[] selectedIndices = table_.getSelectionIndices(); >+ >+ String deletePairs = ""; >+ for (int i = 0; i < selectedIndices.length; i++) { >+ int index = selectedIndices[i]; >+ deletePairs += "\t* " + eventStartTypes_.get(index) + " / " + eventEndTypes_.get(index); >+ >+ if (i < selectedIndices.length-1) { >+ deletePairs += "\n"; >+ } >+ } >+ >+ boolean confirmDeletion = MessageDialog.openQuestion( >+ getShell(), >+ Messages.getString("LatencyView.Dialogs.DeleteEvents.Confirm.Title"), >+ Messages.getString("LatencyView.Dialogs.DeleteEvents.Confirm.Message") + "\n\n" + deletePairs); >+ >+ if (confirmDeletion) { >+ // Remove the events starting from the end of the list, otherwise the TableItem elements will lose their >+ // index from the table and may trigger an exception when removing an index that is no longer valid. >+ for (int i = selectedIndices.length-1; i >= 0; i--) { >+ int selectedIndex = selectedIndices[i]; >+ EventMatcher.getInstance().removeMatch(eventStartTypes_.get(selectedIndex), eventEndTypes_.get(selectedIndex)); >+ >+ table_.remove(selectedIndex); >+ >+ // Update the list of events >+ eventStartTypes_.remove(selectedIndex); >+ eventEndTypes_.remove(selectedIndex); >+ } >+ >+ // Save the events pairs in the settings file so it can be retrieved in the next session >+ saveMatchPairs(eventStartTypes_, eventEndTypes_); >+ >+ table_.setItemCount( eventStartTypes_.size() ); >+ >+ TableItem[] newItems = table_.getItems(); >+ table_.removeAll(); >+ for (int i = 0; i < newItems.length; i++) { >+ TableItem item = new TableItem(table_, SWT.RIGHT); >+ >+ String max = "" + eventStartTypes_.size(); >+ String number = formatListNumber(i+1, max.length()); >+ >+ String[] columns = { >+ number, >+ eventStartTypes_.get(i), >+ eventEndTypes_.get(i) >+ }; >+ >+ item.setText(columns); >+ } >+ >+ redrawGraphs_ = true; >+ } >+ } >+ }); >+ >+ // Create the "Close" button >+ Button closeButton = createButton(parent, CANCEL, Messages.getString("LatencyView.Dialogs.AddEvents.Buttons.Close"), false); >+ closeButton.addListener(SWT.Selection, new Listener() { >+ @Override >+ public void handleEvent(Event event) { >+ // Remember the user's list >+ saveMatchPairs(eventStartTypes_, eventEndTypes_); >+ >+ setReturnCode(CANCEL); >+ >+ if (redrawGraphs_ == true) >+ redrawGraphs(); >+ >+ close(); >+ } >+ }); >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/ListDialog.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/ListDialog.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/ListDialog.java (revision 0) >@@ -0,0 +1,233 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.dialogs; >+ >+import java.util.Vector; >+ >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher; >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair; >+import org.eclipse.linuxtools.lttng.ui.views.latency.Messages; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Table; >+import org.eclipse.swt.widgets.TableColumn; >+import org.eclipse.swt.widgets.TableItem; >+ >+ >+/** >+ * List dialog, shows the list of start/end event pairs. >+ * >+ * @author Philippe Sawicki >+ */ >+public class ListDialog extends AbstractDialog { >+ >+ /** >+ * The dialog's table. >+ */ >+ protected Table table_; >+ >+ /** >+ * Start event types. >+ */ >+ protected Vector<String> eventStartTypes_; >+ /** >+ * End event types. >+ */ >+ protected Vector<String> eventEndTypes_; >+ >+ /** >+ * Table columns >+ */ >+ protected TableColumn[] columns_; >+ >+ /** >+ * Column names (header titles). >+ */ >+ protected static final String[] COLUMN_NAMES = {"#", Messages.getString("LatencyView.Dialogs.ListEvents.Columns.Trigger"), Messages.getString("LatencyView.Dialogs.ListEvents.Columns.End")}; >+ /** >+ * Column widths. >+ */ >+ protected static final int[] COLUMN_WIDTHS = {25, 250, 250}; >+ >+ /** >+ * The table style. >+ */ >+ protected int style_; >+ >+ >+ /** >+ * Constructor. >+ * @param parentShell The parent shell. >+ * @param title The dialog's window title. >+ * @param message The dialog's window message. >+ */ >+ public ListDialog(Shell parentShell, String title, String message) { >+ super(parentShell, title, message); >+ >+ // Set the table style >+ style_ = SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL; >+ >+ // Get the list of start and end types from the EventMatcher >+ Pair<Vector<String>,Vector<String>> pair = getMatchPairs(); >+ eventStartTypes_ = pair.getFirst(); >+ eventEndTypes_ = pair.getSecond(); >+ } >+ >+ /** >+ * Creates the table's column (i.e. the table header). >+ */ >+ protected void createColumns() { >+ columns_ = new TableColumn[COLUMN_NAMES.length]; >+ for (int i = 0; i < COLUMN_NAMES.length; i++) { >+ columns_[i] = new TableColumn(table_, SWT.LEFT); >+ columns_[i].setText(COLUMN_NAMES[i]); >+ columns_[i].setWidth(COLUMN_WIDTHS[i]); >+ } >+ } >+ >+ /** >+ * Creates the dialog area. >+ * @param parent The parent. >+ */ >+ @Override >+ protected Control createDialogArea(Composite parent) { >+ GridLayout layout = new GridLayout(1, true); >+ parent.setLayout(layout); >+ >+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); >+ table_ = new Table(parent, style_); >+ table_.setLayoutData(layoutData); >+ >+ // Some cosmetic enhancements >+ table_.setHeaderVisible(true); >+ table_.setLinesVisible(true); >+ >+ createColumns(); >+ >+ for (int i = 0; i < eventStartTypes_.size(); i++) { >+ TableItem item = new TableItem(table_, SWT.RIGHT); >+ >+ String max = "" + eventStartTypes_.size(); >+ String number = formatListNumber(i+1, max.length()); >+ >+ String[] columns = { >+ number, >+ eventStartTypes_.get(i), >+ eventEndTypes_.get(i) >+ }; >+ >+ item.setText(columns); >+ } >+ >+ return parent; >+ } >+ >+ /** >+ * Creates the buttons for the button bar. >+ * @param parent The parent. >+ */ >+ @Override >+ protected void createButtonsForButtonBar(Composite parent) { >+ GridData gridData = new GridData(); >+ gridData.verticalAlignment = GridData.FILL; >+ gridData.horizontalSpan = 1; >+ gridData.grabExcessHorizontalSpace = true; >+ gridData.grabExcessVerticalSpace = true; >+ gridData.horizontalAlignment = SWT.RIGHT; >+ >+ parent.setLayoutData(gridData); >+ >+ // Create the "Reset" button >+ Button resetButton = createButton(parent, RESET, Messages.getString("LatencyView.Dialogs.ListEvents.Buttons.Reset"), false); >+ resetButton.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event event) { >+ boolean confirmDeletion = MessageDialog.openQuestion( >+ getShell(), >+ Messages.getString("LatencyView.Dialogs.ListEvents.Confirm.Title"), >+ Messages.getString("LatencyView.Dialogs.ListEvents.Confirm.Message")); >+ >+ if (confirmDeletion) { >+ EventMatcher.getInstance().resetMatches(); >+ >+ table_.removeAll(); >+ >+ Vector<String> defaultStarts = new Vector<String>(); >+ Vector<String> defaultEnds = new Vector<String>(); >+ >+ defaultStarts.add(EventMatcher.PAGE_FAULT_GET_USER_ENTRY); defaultEnds.add(EventMatcher.PAGE_FAULT_GET_USER_EXIT); >+ defaultStarts.add(EventMatcher.TASKLET_LOW_ENTRY); defaultEnds.add(EventMatcher.TASKLET_LOW_EXIT); >+ defaultStarts.add(EventMatcher.PAGE_FAULT_ENTRY); defaultEnds.add(EventMatcher.PAGE_FAULT_EXIT); >+ defaultStarts.add(EventMatcher.SYSCALL_ENTRY); defaultEnds.add(EventMatcher.SYSCALL_EXIT); >+ defaultStarts.add(EventMatcher.IRQ_ENTRY); defaultEnds.add(EventMatcher.IRQ_EXIT); >+ defaultStarts.add(EventMatcher.READ); defaultEnds.add(EventMatcher.WRITE); >+ defaultStarts.add(EventMatcher.OPEN); defaultEnds.add(EventMatcher.CLOSE); >+ defaultStarts.add(EventMatcher.BUFFER_WAIT_START); defaultEnds.add(EventMatcher.BUFFER_WAIT_END); >+ defaultStarts.add(EventMatcher.START_COMMIT); defaultEnds.add(EventMatcher.END_COMMIT); >+ defaultStarts.add(EventMatcher.WAIT_ON_PAGE_START); defaultEnds.add(EventMatcher.WAIT_ON_PAGE_END); >+ >+ saveMatchPairs(defaultStarts, defaultEnds); >+ >+ for (int i = 0; i < defaultStarts.size(); i++) { >+ EventMatcher.getInstance().addMatch(defaultStarts.get(i), defaultEnds.get(i)); >+ } >+ >+ >+ // Get the list of start and end types from the EventMatcher >+ Pair<Vector<String>,Vector<String>> pair = getMatchPairs(); >+ eventStartTypes_ = pair.getFirst(); >+ eventEndTypes_ = pair.getSecond(); >+ >+ for (int i = 0; i < eventStartTypes_.size(); i++) { >+ TableItem item = new TableItem(table_, SWT.RIGHT); >+ >+ String max = "" + eventStartTypes_.size(); >+ String number = formatListNumber(i+1, max.length()); >+ >+ String[] columns = { >+ number, >+ eventStartTypes_.get(i), >+ eventEndTypes_.get(i) >+ }; >+ >+ item.setText(columns); >+ } >+ >+ table_.setItemCount(eventStartTypes_.size()); >+ >+ redrawGraphs_ = true; >+ } >+ } >+ }); >+ >+ // Create the "Close" button >+ Button closeButton = createButton(parent, CANCEL, Messages.getString("LatencyView.Dialogs.ListEvents.Buttons.Close"), false); >+ closeButton.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event event) { >+ setReturnCode(CANCEL); >+ >+ if (redrawGraphs_ == true) >+ redrawGraphs(); >+ >+ close(); >+ } >+ }); >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/handlers/ViewHandler.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/handlers/ViewHandler.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/handlers/ViewHandler.java (revision 0) >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.handlers; >+ >+ >+/** >+ * View handler, catches the view requests for data. >+ * >+ * @author Philippe Sawicki >+ */ >+public interface ViewHandler { >+ >+ /** >+ * Analyses the latency for all event types. >+ */ >+ public void analyseLatencyForAllEvents(); >+ >+ /** >+ * Notifies the view handlers of the number of bars available. >+ * @param nbBars The number of bars available. >+ */ >+ public void notifyNumberOfBars(int nbBars); >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/AbstractMouseListener.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/AbstractMouseListener.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/AbstractMouseListener.java (revision 0) >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.listeners; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+ >+ >+/** >+ * AbstractMouseListener, base class for the canvas mouse listener. >+ * >+ * @author Philippe Sawicki >+ */ >+public abstract class AbstractMouseListener implements Listener { >+ >+ /** >+ * Mouse x-coordinate. >+ */ >+ protected long mouseX_; >+ /** >+ * Mouse y-coordinate. >+ */ >+ protected long mouseY_; >+ >+ >+ /** >+ * Handles the event. >+ */ >+ public void handleEvent(Event event) { >+ switch (event.type) { >+ case SWT.MouseMove: >+ mouseX_ = event.x; >+ mouseY_ = event.y; >+ >+ display(); >+ >+ break; >+ } >+ } >+ >+ /** >+ * Tooltip display callback. >+ */ >+ protected abstract void display(); >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/AbstractPaintListener.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/AbstractPaintListener.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/AbstractPaintListener.java (revision 0) >@@ -0,0 +1,649 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.listeners; >+ >+import java.util.Collections; >+import java.util.Vector; >+ >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView; >+import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.PaintEvent; >+import org.eclipse.swt.events.PaintListener; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.GC; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Display; >+ >+ >+/** >+ * Abstract paint listener. Draws the graphs on the view canvas. >+ * >+ * @author Philippe Sawicki >+ */ >+public abstract class AbstractPaintListener implements PaintListener { >+ >+ /** >+ * A reference to the listener's view. >+ */ >+ protected AbstractView view_; >+ >+ /** >+ * Graph title >+ */ >+ protected String graphTitle_; >+ >+ /** >+ * X-axis label. >+ */ >+ protected String xAxisLabel_; >+ /** >+ * Y-axis label. >+ */ >+ protected String yAxisLabel_; >+ >+ /** >+ * Horizontal offset for the x-axis label. >+ */ >+ protected int xAxisLabelOffset_; >+ >+ /** >+ * Vertical offset for the horizontal axis offset. >+ */ >+ protected int horizontalAxisYOffset_ = 20; >+ >+ /** >+ * Graph padding. >+ */ >+ protected int padding_ = Config.GRAPH_PADDING; >+ >+ /** >+ * Graph client area. >+ */ >+ protected Rectangle clientArea_ = new Rectangle(0, 0, 1, 1); >+ >+ /** >+ * Foreground color. >+ */ >+ protected Color foregroundColor_; >+ /** >+ * Background color. >+ */ >+ protected Color backgroundColor_; >+ /** >+ * Data plotting color. >+ */ >+ protected Color dataColor_; >+ /** >+ * Axis label color. >+ */ >+ protected Color labelColor_; >+ /** >+ * Text color. >+ */ >+ protected Color textColor_; >+ /** >+ * Red. >+ */ >+ protected Color redColor_; >+ /** >+ * White. >+ */ >+ protected Color whiteColor_; >+ >+ /** >+ * Original canvas font. >+ */ >+ protected Font originalFont_; >+ /** >+ * Font for the title of the graph. >+ */ >+ protected Font titleFont_; >+ /** >+ * Font for the values on the horizontal and vertical axis. >+ */ >+ protected Font valuesFont_; >+ /** >+ * Font for the horizontal and vertical labels. >+ */ >+ protected Font labelFont_; >+ >+ /** >+ * Horizontal offset for the axis arrow. >+ */ >+ protected final int ARROW_DELTA_X = 10; >+ /** >+ * Vertical offset for the axis arrow. >+ */ >+ protected final int ARROW_DELTA_Y = 4; >+ >+ /** >+ * Max horizontal distance between ticks. >+ */ >+ protected final int MAX_WIDTH_BETWEEN_TICKS = 40; >+ /** >+ * Max vertical distance between ticks. >+ */ >+ protected final int MAX_HEIGHT_BETWEEN_TICKS = 30; >+ /** >+ * Max characters that can be displayed on the vertical axis. >+ */ >+ protected final int MAX_CHAR_VERTICAL_DISPLAY = 5; >+ >+ /** >+ * Draw label each "drawLabelEachNTicks_" ticks. >+ */ >+ protected int drawLabelEachNTicks_ = 1; >+ >+ /** >+ * Image drawn on the canvas. >+ */ >+ protected Image image_; >+ /** >+ * Paint canvas, where the values are plotted. >+ */ >+ protected GC axisImage_; >+ >+ /** >+ * Is the paint listener initialized ? >+ */ >+ protected boolean initialised_ = false; >+ /** >+ * Does the listener need to be redrawn ? >+ */ >+ protected boolean redraw_ = true; >+ >+ /** >+ * Draw area. >+ */ >+ protected Rectangle drawArea_; >+ >+ /** >+ * Left padding (in pixels). >+ */ >+ protected int paddingLeft_ = 10; >+ /** >+ * Right padding (in pixels). >+ */ >+ protected int paddingRight_ = 10; >+ /** >+ * Top padding (in pixels). >+ */ >+ protected int paddingTop_ = 10; >+ /** >+ * Bottom padding (in pixels). >+ */ >+ protected int paddingBottom_ = 10; >+ >+ /** >+ * Vertical axis offset (in pixels). >+ */ >+ protected int verticalAxisOffset_ = 20; >+ >+ /** >+ * Vertical axis factor for values (10^delta). >+ * When values larger than MAX_CHAR_VERTICAL_DISPLAY. >+ */ >+ protected int delta = 0; >+ >+ >+ /** >+ * Constructor. >+ * @param view A reference to the listener's view. >+ */ >+ public AbstractPaintListener(AbstractView view) { >+ view_ = view; >+ } >+ >+ @Override >+ public void paintControl(PaintEvent e) { >+ clientArea_ = view_.getClientArea(); >+ >+ foregroundColor_ = e.gc.getForeground(); >+ backgroundColor_ = e.gc.getBackground(); >+ dataColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_RED); >+ labelColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK); >+ textColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_DARK_GRAY); >+ redColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_RED); >+ whiteColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_WHITE); >+ >+ originalFont_ = e.gc.getFont(); >+ titleFont_ = new Font(e.display, "Arial", 10, SWT.BOLD); >+ valuesFont_ = new Font(e.display, "Arial", 7, SWT.NORMAL); >+ labelFont_ = new Font(e.display, "Arial", 8, SWT.NORMAL); >+ >+ >+ if (!initialised_) { >+ image_ = new Image(Display.getDefault(), view_.getBounds()); >+ >+ axisImage_ = new GC(image_); >+ >+ axisImage_.setForeground(foregroundColor_); >+ axisImage_.setBackground(backgroundColor_); >+ axisImage_.fillRectangle(image_.getBounds()); >+ paintBackground(); >+ >+ initialised_ = true; >+ } >+ >+ paintGraphTitle(); >+ paintHorizontalAxis(); >+ paintVerticalAxis(); >+ postAddDraw(); >+ >+ e.gc.drawImage(image_, 0, 0); >+ redraw_ = false; >+ } >+ >+ /** >+ * Paints the title of the graph. >+ */ >+ public void paintGraphTitle() { >+ if (graphTitle_ != null) { >+ axisImage_.setFont(titleFont_); >+ axisImage_.setForeground(labelColor_); >+ axisImage_.setBackground(backgroundColor_); >+ >+ int zoomFactor = view_.getZoomFactor() / view_.getZoomIncrement() + 1; >+ int labelWidth = axisImage_.stringExtent(graphTitle_).x; >+ // Draws the zoom factor in the title only if there is one >+ if (view_.getZoomFactor() > 1) >+ axisImage_.drawText(graphTitle_+ " (" + zoomFactor + "x)", (view_.getBounds().width-padding_ - labelWidth)/2, 0); >+ else >+ axisImage_.drawText(graphTitle_, (view_.getBounds().width-padding_ - labelWidth)/2, 0); >+ } >+ } >+ >+ /** >+ * Paints the background of the draw area. >+ */ >+ public void paintBackground() { >+ axisImage_.setBackground(whiteColor_); >+ >+ Rectangle rectangle = image_.getBounds(); >+ axisImage_.fillRectangle(padding_+verticalAxisOffset_, padding_+paddingTop_, rectangle.width-2*padding_-20, rectangle.height-2*padding_-paddingTop_-10); >+ } >+ >+ /** >+ * Paints the horizontal axis. >+ */ >+ public void paintHorizontalAxis() { >+ axisImage_.setForeground(foregroundColor_); >+ >+ int y = clientArea_.height - 2*padding_; >+ >+ axisImage_.drawLine( clientArea_.x+padding_+verticalAxisOffset_, >+ y, >+ clientArea_.width-padding_, >+ y ); >+ >+ paintHorizontalArrow(clientArea_.width-padding_, y); >+ // Draw the axis graphic details only if there are some data points (i.e. do not draw the axis graphic details >+ // if the window timerange is so small that no latency can be computed, or if there are no matching events in >+ // the timerange (for example, when an experiment has many traces with a large time gap between the logged events sets). >+ if (view_.getXMin() != Long.MAX_VALUE && view_.getXMax() != Long.MIN_VALUE && view_.getXMin() != view_.getXMax()) { >+ paintHorizontalTicks(y); >+ paintHorizontalAxisValues(y+30); >+ } >+ paintHorizontalAxisLabel(y+5); >+ } >+ >+ /** >+ * Paints the vertical axis. >+ */ >+ public void paintVerticalAxis() { >+ axisImage_.setForeground(foregroundColor_); >+ >+ int x = clientArea_.x + padding_ + verticalAxisOffset_; >+ >+ axisImage_.drawLine( x, >+ clientArea_.y + padding_, >+ x, >+ clientArea_.height - 2*padding_ ); >+ >+ paintVerticalArrow(x, clientArea_.y + padding_); >+ // Draw the axis graphic details only if there are some data points (i.e. do not draw the axis graphic details >+ // if the window timerange is so small that no latency can be computed, or if there are no matching events in >+ // the timerange (for example, when an experiment has many traces with a large time gap between the logged events sets). >+ if (view_.getXMin() != Long.MAX_VALUE && view_.getXMax() != Long.MIN_VALUE && view_.getXMin() != view_.getXMax()) { >+ //paintVerticalTicks(x); >+ paintVerticalAxisValues(x); >+ } >+ paintVerticalAxisLabel(x); >+ } >+ >+ /** >+ * Paints the arrow on the horizontal axis. >+ * @param x The x-coordinate of the point where the arrow points. >+ * @param y The y-coordinate of the point where the arrow points. >+ */ >+ public void paintHorizontalArrow(int x, int y) { >+ // Arrow top line >+ axisImage_.drawLine(x-ARROW_DELTA_X, y-ARROW_DELTA_Y, x, y); >+ // Arrow bottom line >+ axisImage_.drawLine(x-ARROW_DELTA_X, y+ARROW_DELTA_Y, x, y ); >+ } >+ >+ /** >+ * Paints the arrow on the vertical axis. >+ * @param x The x-coordinate of the point where the arrow points. >+ * @param y The y-coordinate of the point where the arrow points. >+ */ >+ public void paintVerticalArrow(int x, int y) { >+ // Arrow left line >+ axisImage_.drawLine(x-ARROW_DELTA_Y, y+ARROW_DELTA_X, x, y); >+ // Arrow right line >+ axisImage_.drawLine(x+ARROW_DELTA_Y, y+ARROW_DELTA_X, x, y); >+ } >+ >+ /** >+ * Paints the horizontal ticks. >+ * @param y The y coordinate where to draw the axis. >+ */ >+ public void paintHorizontalTicks(int y) { >+ long xMin = view_.getXMin(); >+ long xMax = view_.getXMax(); >+ >+ if (xMin != 0L && xMax != 0L) { >+ int nbTicks = (view_.getBounds().width - 2*padding_ - ARROW_DELTA_X - verticalAxisOffset_) / MAX_WIDTH_BETWEEN_TICKS - 1; >+ >+ for (int i = 0; i <= nbTicks+1; i++) { >+ int x = i*MAX_WIDTH_BETWEEN_TICKS + padding_ + verticalAxisOffset_; >+ axisImage_.drawLine(x, y, x, y+3); >+ } >+ } >+ } >+ >+ /** >+ * Paints the horizontal axis values. >+ * @param y The y coordinate where to draw the axis. >+ */ >+ public void paintHorizontalAxisValues(int y) { >+ long xMin = view_.getXMin(); >+ long xMax = view_.getXMax(); >+ >+ if (xMin != 0L && xMax != 0L) { >+ axisImage_.setForeground(textColor_); >+ axisImage_.setBackground(backgroundColor_); >+ >+ int nbTicks = (view_.getBounds().width - 2*padding_ - ARROW_DELTA_X - verticalAxisOffset_) / MAX_WIDTH_BETWEEN_TICKS; >+ //System.out.println("nbTicks = " + nbTicks); >+ >+ for (int i = 0; i < nbTicks; i++) { >+ if (i % drawLabelEachNTicks_ == 0) { >+ int x = i*MAX_WIDTH_BETWEEN_TICKS + padding_ + verticalAxisOffset_; >+ >+ double step = (double)(xMax-xMin) / (double)nbTicks; >+ long currentValue = (long) (xMin + i*step); >+ String currentLabel = formatStringForHorizontalAxis(currentValue); >+ >+ axisImage_.setFont(valuesFont_); >+ axisImage_.drawText(currentLabel, x, y-24); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Paints the horizontal axis label. >+ * @param y The y-coordinate where to draw the label. >+ */ >+ public void paintHorizontalAxisLabel(int y) { >+ if (xAxisLabel_ != null) { >+ axisImage_.setFont(labelFont_); >+ axisImage_.setForeground(labelColor_); >+ >+ int labelWidth = axisImage_.stringExtent(xAxisLabel_).x; >+ >+ axisImage_.drawText(xAxisLabel_, view_.getBounds().width-padding_-labelWidth, y); >+ } >+ } >+ >+ /** >+ * Paints the vertical axis ticks. >+ * @param x The x-coordinate where to draw the ticks. >+ * @deprecated The vertical ticks are now drawn at the same time as the vertical axis values. >+ */ >+ public void paintVerticalTicks(int x) { >+ long xMin = view_.getXMin(); >+ long xMax = view_.getXMax(); >+ >+ if (xMin != 0L && xMax != 0L) { >+ int nbTicks = (view_.getBounds().height-2*padding_-paddingTop_) / MAX_HEIGHT_BETWEEN_TICKS + 1; >+ >+ for (int i = 0; i <= nbTicks+1; i++) { >+ int y = view_.getBounds().height - 2*padding_ - paddingTop_ - i*MAX_HEIGHT_BETWEEN_TICKS; >+ axisImage_.drawLine(x-3, y+paddingTop_, x, y+paddingTop_); >+ } >+ } >+ } >+ >+ /** >+ * Paints the vertical axis values. >+ * @param x The x-coordinate where to draw the values. >+ */ >+ public void paintVerticalAxisValues(int x) { >+ long xMin = view_.getXMin(); >+ long xMax = view_.getXMax(); >+ int zoomFactor = 1; >+ >+ zoomFactor = view_.getZoomFactor(); >+ >+ if (xMin != 0L && xMax != 0L) { >+ axisImage_.setForeground(textColor_); >+ axisImage_.setBackground(backgroundColor_); >+ >+ long yMin = view_.getYMin(); >+ // Apply the zoom to the max value of the graph for the next calculations >+ long yMax = view_.getYMax() / zoomFactor; >+ >+ int nbTicks = (view_.getBounds().height-2*padding_-paddingTop_) / MAX_HEIGHT_BETWEEN_TICKS + 1; >+ >+ Vector<Integer> values = new Vector<Integer>(); >+ boolean multipleSameValues = true; >+ while (multipleSameValues) { >+ double valueStep = (double)(yMax-yMin) / (double)(nbTicks-1); >+ >+ for (int i = 0; i < nbTicks; i++) { >+ double currentValue = (double) (yMin + i*valueStep)/(Math.pow(10, delta)); >+ >+ values.add((int) currentValue); >+ } >+ >+ Collections.sort(values); >+ boolean hasRepetition = false; >+ for (int i = 1; i < values.size(); i++) { >+ if (values.get(i) == values.get(i-1)) { >+ hasRepetition = true; >+ } >+ } >+ >+ if (hasRepetition) { >+ nbTicks--; >+ values.clear(); >+ } else { >+ multipleSameValues = false; >+ >+ // Draw rectangle over the old values >+ int height = view_.getBounds().height-4*padding_-paddingTop_; >+ axisImage_.fillRectangle(0, padding_+paddingTop_, padding_+verticalAxisOffset_, height); >+ >+ double pixelStep = (getHeight() + 2.0*padding_ + paddingTop_ + 1)/*(view_.getBounds().height - 2*padding_ - 1*paddingTop_)*/ / values.size(); >+ >+ for (int i = 0; i < values.size(); i++) { >+ double currentValue = values.get(i); >+ >+ int y = (int) (view_.getBounds().height - 2*padding_ - i*pixelStep); >+ String currentLabel = formatStringForVerticalAxis((long) currentValue); >+ >+ axisImage_.setFont(valuesFont_); >+ >+ Point textDimensions = axisImage_.stringExtent(currentLabel); >+ axisImage_.drawText(currentLabel, x-textDimensions.x-5, y-textDimensions.y/2); >+ axisImage_.drawLine(x-3, y, x, y); >+ } >+ } >+ } >+ } >+ } >+ >+ /** >+ * Paints the vertical axis label. >+ * @param x The x-coordinate where to draw the label. >+ */ >+ public void paintVerticalAxisLabel(int x) { >+ if (yAxisLabel_ != null) { >+ axisImage_.setFont(labelFont_); >+ axisImage_.setForeground(labelColor_); >+ axisImage_.setBackground(backgroundColor_); >+ >+ if (delta >= 1) >+ axisImage_.drawText(yAxisLabel_ + " (x10^" + delta + ")", x+10, paddingTop_-5); >+ else >+ axisImage_.drawText(yAxisLabel_, x+10, paddingTop_-5); >+ } >+ } >+ >+ /** >+ * Adds points to the graph and draws them to the canvas. >+ * @param points The buffer of points to draw. >+ * @param nbPoints The number of points in the buffer. >+ */ >+ public abstract void addPoints(ChartPoint[] points, int nbPoints); >+ >+ /** >+ * Draw horizontal label each "nbTicks" ticks. >+ * @param nbTicks The draw interval. >+ */ >+ public void drawLabelEachNTicks(int nbTicks) { >+ drawLabelEachNTicks_ = nbTicks; >+ } >+ >+ /** >+ * Sets the title of the graph. >+ * @param graphTitle The title of the graph. >+ */ >+ public void setGraphTitle(String graphTitle) { >+ graphTitle_ = graphTitle; >+ } >+ >+ /** >+ * Sets the horizontal axis label. >+ * @param xAxisLabel The horizontal axis label. >+ * @param offset The horizontal axis draw offset (in pixels). >+ */ >+ public void setXAxisLabel(String xAxisLabel, int offset) { >+ xAxisLabel_ = xAxisLabel; >+ xAxisLabelOffset_ = offset; >+ } >+ >+ /** >+ * Sets the vertical axis label. >+ * @param yAxisLabel The vertical axis label. >+ */ >+ public void setYAxisLabel(String yAxisLabel) { >+ yAxisLabel_ = yAxisLabel; >+ } >+ >+ /** >+ * Clears the image and prepares it for redrawing. >+ */ >+ public void clear() { >+ initialised_ = false; >+ view_.askForRedraw(); >+ } >+ >+ /** >+ * Returns a string representing the given value. This method is >+ * redefined in "HistogramPaintListener.java" to convert value to >+ * engineering notation. >+ * @param value The numeric value to convert to String. >+ * @return The String-formatted value. >+ */ >+ public String formatStringForHorizontalAxis(long value) { >+ return "" + value; >+ } >+ >+ /** >+ * Returns a string representing the given value. This method is >+ * redefined in "GraphPaintListener.java" to convert value to >+ * scientific notation. >+ * @param value The numeric value to convert to String. >+ * @return The String-formatted value. >+ */ >+ public String formatStringForVerticalAxis(long value) { >+ return "" + value; >+ } >+ >+ /** >+ * Clears the points buffer, if any exists. >+ */ >+ public void clearPoints() { } >+ >+ /** >+ * Called for drawing elements after points are added to the graph. >+ */ >+ public void postAddDraw() { } >+ >+ /** >+ * Returns the draw area height. >+ * @return The draw area height. >+ */ >+ public double getHeight() { >+ return (clientArea_.height - 2.0*padding_ - horizontalAxisYOffset_ - 0*paddingTop_ - 1); >+ } >+ >+ /** >+ * Returns the histogram's draw area width. >+ * @return The histogram's draw area width. >+ */ >+ public double getWidth() { >+ return (clientArea_.width - 2.0*padding_ - verticalAxisOffset_); //width of the plot area; >+ } >+ >+ /** >+ * Returns the histogram's draw area padding. >+ * @return The histogram's draw area padding. >+ */ >+ public int getPadding() { >+ return padding_; >+ } >+ >+ /** >+ * Returns the histogram's draw area top padding. >+ * @return The histogram's draw area top padding. >+ */ >+ public int getPaddingTop() { >+ return paddingTop_; >+ } >+ >+ /** >+ * Returns the histogram's vertical axis offset. >+ * @return The histogram's vertical axis offset. >+ */ >+ public int getVerticalAxisOffset() { >+ return verticalAxisOffset_; >+ } >+ >+ /** >+ * Returns the histogram's horizontal axis offset. >+ * @return The histogram's horizontal axis offset. >+ */ >+ public int getHorizontalAxisYOffset() { >+ return horizontalAxisYOffset_; >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/GraphPaintListener.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/GraphPaintListener.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/GraphPaintListener.java (revision 0) >@@ -0,0 +1,77 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.listeners; >+ >+import java.text.DecimalFormat; >+ >+import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView; >+import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; >+ >+ >+/** >+ * Graph paint listener. >+ * >+ * @author Philippe Sawicki >+ */ >+public class GraphPaintListener extends AbstractPaintListener { >+ >+ /** >+ * Constructor. >+ * @param view A reference to the listener's view. >+ */ >+ public GraphPaintListener(AbstractView view) { >+ super(view); >+ } >+ >+ /** >+ * Adds points to the graph and draws them to the canvas. >+ * @param points The buffer of points to draw. >+ * @param nbPoints The number of points in the buffer. >+ */ >+ public void addPoints(ChartPoint[] points, int nbPoints) { >+ axisImage_.setForeground(dataColor_); >+ axisImage_.setBackground(dataColor_); >+ >+ double width = clientArea_.width - 2.0*padding_ - verticalAxisOffset_; >+ double height = clientArea_.height - 2.0*padding_ - paddingTop_ - horizontalAxisYOffset_ - 1; >+ >+ double xMin = view_.getXMin(); >+ double xMax = view_.getXMax(); >+ >+ double yMin = view_.getYMin(); >+ double yMax = view_.getYMax(); >+ >+ for (int i = 0; i < nbPoints; i++) { >+ long pointX = points[i].getX(); >+ long pointY = points[i].getY(); >+ >+ double x = padding_ + ((pointX-xMin) / (xMax-xMin)) * width + verticalAxisOffset_; >+ double y = paddingTop_ + padding_ + height - ((pointY-yMin) / (yMax-yMin)) * height; >+ >+ axisImage_.fillOval((int)x, (int)y, 3, 3); >+ } >+ >+ redraw_ = true; >+ view_.askForRedraw(); >+ } >+ >+ /** >+ * Paints the vertical horizontal axis values in scientific notation in which the exponent is a multiple of three. >+ * @param value The numeric value to convert to scientific notation. >+ * @return The given value formatted according to the scientific notation. >+ */ >+ public String formatStringForVerticalAxis(long value) { >+ DecimalFormat formatter = new DecimalFormat("0.0E0"); >+ return formatter.format(value); >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/HistogramPaintListener.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/HistogramPaintListener.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/HistogramPaintListener.java (revision 0) >@@ -0,0 +1,230 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.listeners; >+ >+import java.text.DecimalFormat; >+ >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView; >+import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; >+import org.eclipse.linuxtools.lttng.ui.views.latency.Messages; >+import org.eclipse.swt.SWTException; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.ui.plugin.AbstractUIPlugin; >+ >+ >+/** >+ * Histogram paint listener. >+ * >+ * @author Philippe Sawicki >+ */ >+public class HistogramPaintListener extends AbstractPaintListener { >+ >+ /** >+ * Histogram points buffer. >+ */ >+ protected ChartPoint[] points_; >+ /** >+ * Number of points to consider in the buffer. >+ */ >+ protected int nbPoints_ = 0; >+ >+ /** >+ * Is a histogram bar so high that it is clipped from the draw area ? >+ */ >+ protected boolean barIsClipped_ = false; >+ >+ >+ /** >+ * Constructor. >+ * @param view A reference to the listener's view. >+ */ >+ public HistogramPaintListener(AbstractView view) { >+ super(view); >+ } >+ >+ /** >+ * Adds points to the graph and draws them to the canvas. >+ * @param points The buffer of points to draw. >+ * @param nbPoints The number of points in the buffer. >+ @author Philippe Sawicki, modified by Ali Jawhar >+ */ >+ public void addPoints(ChartPoint[] points, int nbPoints) { >+ points_ = points; >+ nbPoints_ = nbPoints; >+ >+ // These lines must stay at the end of this function : >+ redraw_ = true; >+ Display.getDefault().syncExec(new Runnable() { >+ public void run() { >+ try { >+ postAddDraw(); >+ view_.redraw(); >+ } catch (SWTException e) { >+ // This exception will be thrown if the user closes the view >+ // while it is receiving data from the Analyser. >+ >+ // ... >+ } >+ } >+ }); >+ } >+ >+ public void postAddDraw() { >+ if (nbPoints_ == 0 || points_ == null) >+ return; >+ >+ /** >+ * @todo Rethink this way of redrawing the histogram, because it starts getting crazy about here... >+ */ >+ double zoomFactor = view_.getZoomFactor(); >+ >+ // Calculate the vertical axis factor and see if it has changed >+ double tmpDelta = delta; >+ delta = 0; >+ if (Long.toString(view_.getYMax()/(long)zoomFactor).length() > MAX_CHAR_VERTICAL_DISPLAY){ >+ delta = Long.toString(view_.getYMax()/(long)zoomFactor).length() - MAX_CHAR_VERTICAL_DISPLAY; >+ } >+ if (tmpDelta != delta) { >+ view_.clearBackground(); >+ } >+ >+ paintBackground(); >+ paintVerticalAxis(); >+ paintHorizontalAxis(); >+ >+ axisImage_.setForeground(dataColor_); >+ axisImage_.setBackground(dataColor_); >+ >+ //axisImage_.setBackground(backgroundColor_); >+ // 1.a Iterate over the points, from 0 to nbPoints >+ // 1.b Find the max counter value >+ >+ long maxValue = points_[0].getY(); >+ for (int i = 1; i < nbPoints_; i++) { >+ if (points_[i].getY() > maxValue) { >+ maxValue = points_[i].getY(); >+ } >+ } >+ >+ // 2. Assign the max value to the "yMax_" class attribute >+ view_.setYMax(maxValue);// set the maximum vertical value >+ >+ // 3. Draw the histogram bars using "axisImage_.fillRectangle(...)" >+ // width of the plot area >+ double width = clientArea_.width - 2.0*padding_ - verticalAxisOffset_; >+ // height of the plot area >+ double height = clientArea_.height - 2.0*padding_ - horizontalAxisYOffset_ - 1; >+ >+ double yMin = view_.getYMin(); >+ double yMax = view_.getYMax(); >+ double barWidth = width/(nbPoints_); >+ >+ boolean oneBarIsClipped = false; >+ >+ for (int i = 0; i < nbPoints_; i++) { >+ double pointY = points_[i].getY(); >+ >+ // in pixels >+ double x = padding_ + i*barWidth + verticalAxisOffset_ + 1; >+ if (i == nbPoints_-1) >+ x -= 1.0; >+ double barHeight = zoomFactor * ((pointY-yMin) / (yMax-yMin)) * height; >+ >+ if (barHeight > height + 1) { >+ barHeight = height; >+ oneBarIsClipped = true; >+ >+ Image image = AbstractUIPlugin.imageDescriptorFromPlugin( >+ Messages.getString("LatencyView.tmf.UI"), >+ "icons/warning.gif").createImage(Display.getCurrent()); >+ axisImage_.drawImage(image, 5, 3); >+ } >+ >+ // Only draw the bars that have a barHeight of more than 1 pixel >+ if (barHeight >= 1) { >+ double y = 2*padding_ + height - barHeight; >+ axisImage_.setBackground(dataColor_); >+ >+ if (barHeight > height-1) { >+ axisImage_.fillRectangle((int)x, (int)y, (int)barWidth+1, (int)(barHeight+1)); >+ } else { >+ axisImage_.fillRectangle((int)x, (int)y, (int)barWidth+1, (int)(barHeight+2)); >+ } >+ } >+ } >+ >+ if (oneBarIsClipped) >+ barIsClipped_ = true; >+ else >+ barIsClipped_ = false; >+ } >+ >+ /** >+ * Clears the image and prepares it for redrawing. >+ */ >+ public void clearPoints() { >+ points_ = new ChartPoint[nbPoints_]; >+ for (int i = 0; i < points_.length; i++) { >+ points_[i] = new ChartPoint(0, 0); >+ } >+ //nbPoints_ = 0; >+ >+ view_.askForRedraw(); >+ } >+ >+ /** >+ * Paints the histogram horizontal axis values in engineering notation in which the exponent is a multiple of three. >+ * @param value The numeric value to convert to engineering notation. >+ * @return The given value formatted according to the engineering notation. >+ */ >+ public String formatStringForHorizontalAxis(long value) { >+ DecimalFormat formatter = new DecimalFormat("##0.#E0"); >+ return formatter.format(value); >+ } >+ >+ /** >+ * Returns the histogram's data points. >+ * @return The histogram's data points. >+ */ >+ public ChartPoint[] getPoints() { >+ return points_; >+ } >+ >+ /** >+ * Returns the histogram's number of data points. >+ * @return The histogram's number of data points. >+ */ >+ public int getNBPoints() { >+ return nbPoints_; >+ } >+ >+ /** >+ * Returns the histogram's bar Width. >+ * @return The histogram's bar Width. >+ */ >+ public double getBarWidth() { >+ if (clientArea_ == null) >+ return Config.HISTOGRAM_BAR_WIDTH; >+ return (clientArea_.width - 2.0*padding_ - verticalAxisOffset_) / nbPoints_; >+ } >+ >+ /** >+ * Returns "true" if a histogram bar is so high that it cannot be drawn in the draw area, "false" otherwise. >+ * @return "true" if a histogram bar is so high that it cannot be drawn in the draw area, "false" otherwise. >+ */ >+ public boolean barIsClipped() { >+ return barIsClipped_; >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/TimePointerListener.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/TimePointerListener.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/TimePointerListener.java (revision 0) >@@ -0,0 +1,73 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.listeners; >+ >+import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView; >+ >+ >+/** >+ * Displays a tooltip showing the approximate values of the point under >+ * the mouse cursor. >+ * >+ * @author Philippe Sawicki >+ */ >+public class TimePointerListener extends AbstractMouseListener { >+ >+ /** >+ * A reference to the observed view. >+ */ >+ protected AbstractView view_; >+ >+ /** >+ * A reference to the HistogramPaintListener. >+ */ >+ protected GraphPaintListener graph_ ; >+ >+ >+ /** >+ * Constructor. >+ * @param view A reference to the observed view. >+ * @param histogramPaintListener A reference to the histogram's paintListener. >+ */ >+ public TimePointerListener(AbstractView view, GraphPaintListener graphPaintListener) { >+ view_ = view; >+ graph_ = graphPaintListener; >+ } >+ >+ @Override >+ protected void display() { >+ long chartWidth = (long) graph_.getWidth(); >+ long chartHeight = (long) graph_.getHeight(); >+ >+ mouseX_ -= graph_.getPadding() + graph_.getVerticalAxisOffset(); >+ mouseY_ -= graph_.getPadding() + graph_.getPaddingTop() + 1 ; >+ mouseY_ = chartHeight - mouseY_; // Reverse the coordinates since (0;0) is a the top of the screen >+ >+ long xMin = view_.getXMin(); >+ long xMax = view_.getXMax(); >+ long yMin = view_.getYMin(); >+ long yMax = view_.getYMax(); >+ >+ long xValue = mouseX_ * (xMax - xMin) / chartWidth + xMin; >+ long yValue = mouseY_ * (yMax - yMin) / chartHeight + yMin; >+ >+ if (mouseX_ > 0 && mouseX_ < chartWidth >+ && mouseY_ > 0 && mouseY_ < chartHeight >+ && xValue != 0L && yValue != 0L >+ && xValue != Long.MAX_VALUE && yValue != Long.MAX_VALUE) { >+ view_.setToolTipText("(x;y) ≈ (" + xValue + ";" + yValue + ")"); >+ } else { >+ view_.setToolTipText(""); >+ } >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/TooltipListener.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/TooltipListener.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/TooltipListener.java (revision 0) >@@ -0,0 +1,108 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.listeners; >+ >+import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView; >+import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; >+ >+ >+/** >+ * Tooltip listener, displays the event count for each latency selected >+ * by the mouse click area on histogram. >+ * >+ * @author Ali Jawhar >+ */ >+public class TooltipListener extends AbstractMouseListener { >+ >+ /** >+ * A reference to the observed view. >+ */ >+ protected AbstractView view_; >+ >+ /** >+ * A reference to the HistogramPaintListener. >+ */ >+ protected HistogramPaintListener histogram_ ; >+ >+ /** >+ * Is the mouse over the warning icon, indicating that a bar is higher than the draw area due to zooming ? >+ */ >+ boolean displayWarning_ = false; >+ >+ >+ /** >+ * Constructor. >+ * @param view A reference to the observed view. >+ * @param histogramPaintListener A reference to the histogram's paintListener. >+ */ >+ public TooltipListener(AbstractView view, HistogramPaintListener histogramPaintListener) { >+ view_ = view; >+ histogram_ = histogramPaintListener; >+ } >+ >+ @Override >+ protected void display() { >+ displayWarningTooltip(); >+ displayTooltip(); >+ } >+ >+ /** >+ * Displays a tooltip if the mouse is over the warning icon indication that a bar cannot be draw entirely >+ * due to the zoom factor. >+ */ >+ protected void displayWarningTooltip() { >+ if (histogram_.barIsClipped() >+ && mouseX_ > 5 && mouseX_ < 21 >+ && mouseY_ > 3 && mouseY_ < 18) { >+ view_.setToolTipText("One or more bars is higher than the draw area due to zooming."); >+ displayWarning_ = true; >+ } else { >+ displayWarning_ = false; >+ } >+ } >+ >+ /** >+ * Displays the tooltip showing the details of the histogram bar pointed >+ * by the mouse. >+ */ >+ protected void displayTooltip() { >+ double barWidth = histogram_.getBarWidth(); >+ double height = histogram_.getHeight(); // height of the plot area >+ long yMin = view_.getYMin(); >+ long yMax = view_.getYMax(); >+ double zoomFactor = view_.getZoomFactor(); >+ int padding = histogram_.getPadding(); >+ int verticalAxisOffset = histogram_.getVerticalAxisOffset(); >+ ChartPoint[] points = histogram_.getPoints(); >+ int nbPoints = histogram_.getNBPoints(); >+ int index = (int)((mouseX_ - padding - verticalAxisOffset)/barWidth); >+ >+ double barHeight = 0.0; >+ if (index >= 0 && index < nbPoints) { >+ barHeight = (zoomFactor * height*(points[index].getY()-yMin) / (yMax-yMin)); >+ } >+ mouseY_ = (long)height - (mouseY_ - 2*padding); >+ >+ // Verifying mouse pointer is over histogram bar >+ if (index >= 0 && index < nbPoints && mouseY_ < barHeight && mouseY_ < height && mouseX_ > (verticalAxisOffset+padding)) { >+ if (index+1 < nbPoints){ >+ view_.setToolTipText("(lat;#evt) = (["+points[index].getX()+ ","+(points[index+1].getX()-1)+"] ; " + points[index].getY() + ")"); >+ } else { >+ long delta = points[index].getX() - points[index-1].getX(); >+ view_.setToolTipText("(lat;#evt) = (["+points[index].getX()+ ","+(points[index].getX()+delta-1)+"] ; " + points[index].getY() + ")"); >+ } >+ } else if (displayWarning_ == false) { >+ view_.setToolTipText(""); >+ } >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/ZoomListener.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/ZoomListener.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/ZoomListener.java (revision 0) >@@ -0,0 +1,113 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.ui.views.latency.listeners; >+ >+import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Canvas; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+ >+/** >+ * Canvas zoom listener. >+ * >+ * @author Philippe Sawicki >+ */ >+public class ZoomListener implements Listener { >+ >+ /** >+ * A reference to the observed view. >+ */ >+ protected AbstractView view_; >+ /** >+ * Default zoom factor. >+ */ >+ protected int zoomFactor_; >+ /** >+ * Zoom increment. >+ */ >+ protected int zoomIncrement_ = 30; >+ >+ >+ /** >+ * Constructor. >+ * @param view A reference to the observed view. >+ * @param defaultZoomFactor Default zoom factor. >+ */ >+ public ZoomListener(AbstractView view, int defaultZoomFactor) { >+ view_ = view; >+ zoomFactor_ = defaultZoomFactor; >+ } >+ >+ /** >+ * Constructor. >+ * @param view A reference to the observed view. >+ */ >+ public ZoomListener(AbstractView view) { >+ this(view, 0); >+ } >+ >+ /** >+ * Handles the event. >+ */ >+ public void handleEvent(Event event) { >+ switch (event.type) { >+ case SWT.MouseWheel: >+ /** >+ * @todo Find a better way to get the mouse wheel scroll direction >+ */ >+ boolean scrollDown = (event.count == 0 ? false : (event.count > 0 ? false : true)); >+ int zoomStep = zoomIncrement_; >+ if (scrollDown) >+ zoomStep = -zoomIncrement_; >+ zoomFactor_ = Math.max(0, zoomFactor_ + zoomStep); >+ >+ Canvas canvas = (Canvas)event.widget; >+ if (view_ != null){ >+ // clear the background to allow redraw of values of the vertical axis. >+ view_.clearBackground(); >+ view_.redrawTitle(); >+ view_.askForRedraw(); >+ } >+ canvas.redraw(); >+ break; >+ } >+ } >+ >+ /** >+ * Returns the zoom factor. >+ * @return The zoom factor. >+ */ >+ public int getZoomFactor() { >+ if (zoomFactor_ < 1) >+ return 1; >+ else >+ return zoomFactor_; >+ } >+ >+ /** >+ * Returns the zoom increment. >+ * @return The zoom increment. >+ */ >+ public int getZoomIncrement() { >+ return zoomIncrement_; >+ } >+ >+ /** >+ * Sets the zoom increment. >+ * @param zoomIncrement The new zoom increment. >+ */ >+ public void setZoomIncrement(int zoomIncrement) { >+ zoomIncrement_ = zoomIncrement; >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/ui/views/latency/messages.properties >=================================================================== >--- src/org/eclipse/linuxtools/lttng/ui/views/latency/messages.properties (revision 0) >+++ src/org/eclipse/linuxtools/lttng/ui/views/latency/messages.properties (revision 0) >@@ -0,0 +1,44 @@ >+LatencyView.Action.IncreaseBarWidth.Tooltip=Increase histogram bar width >+LatencyView.Action.DecreaseBarWidth.Tooltip=Decrease histogram bar width >+LatencyView.Action.AddEvents.Tooltip=Add matching events >+LatencyView.Action.DeleteEvents.Tooltip=Deleted matching events >+LatencyView.Action.ListEvents.Tooltip=List matching events >+LatencyView.Dialogs.AddEvents.Title=Add event pairs >+LatencyView.Dialogs.AddEvents.Message=Select a pair of events to add it to the match list : >+LatencyView.Dialogs.AddEvents.Buttons.Add=Add >+LatencyView.Dialogs.AddEvents.Buttons.Close=Close >+LatencyView.Dialogs.AddEvents.Columns.Start=Start event types >+LatencyView.Dialogs.AddEvents.Columns.End=End event types >+LatencyView.Dialogs.AddEvents.Columns.List.Trigger=Trigger event type >+LatencyView.Dialogs.AddEvents.Columns.List.End=End event type >+LatencyView.Dialogs.AddEvents.Errors.NoSelection=You must select one item from both lists. >+LatencyView.Dialogs.AddEvents.Errors.StartNotSelected=You must select one item from the start event list. >+LatencyView.Dialogs.AddEvents.Errors.EndNotSelected=You must select one item from the end event list. >+LatencyView.Dialogs.AddEvents.Errors.SameSelected=The same event cannot be selected in both list at the same time. >+LatencyView.Dialogs.AddEvents.Errors.AlreadyMatched=The start and end events are already matched. >+LatencyView.Dialogs.AddEvents.Errors.StartAlreadyMatched=The start event is already matched. >+LatencyView.Dialogs.AddEvents.Errors.EndAlreadyMatched=The end event is already matched. >+LatencyView.Dialogs.AddEvents.Errors.StartAsEnd=The start event is already matched as an end event. >+LatencyView.Dialogs.AddEvents.Errors.EndAsStart=The end event is already matched as a start event. >+LatencyView.Dialogs.DeleteEvents.Title=Delete event pairs >+LatencyView.Dialogs.DeleteEvents.Message=Select a pair of matched events to remove it from the list : >+LatencyView.Dialogs.DeleteEvents.Buttons.Close=Close >+LatencyView.Dialogs.DeleteEvents.Buttons.Delete=Delete >+LatencyView.Dialogs.DeleteEvents.Confirm.Title=Confirm event deletion >+LatencyView.Dialogs.DeleteEvents.Confirm.Message=Are you sure you want to delete these event pairs? >+LatencyView.Dialogs.ListEvents.Title=Matched events list >+LatencyView.Dialogs.ListEvents.Message=List of matched events for latency computation : >+LatencyView.Dialogs.ListEvents.Buttons.Close=Close >+LatencyView.Dialogs.ListEvents.Buttons.Reset=Reset to default pairs >+LatencyView.Dialogs.ListEvents.Columns.Trigger=Trigger event type >+LatencyView.Dialogs.ListEvents.Columns.End=End event type >+LatencyView.Dialogs.ListEvents.Confirm.Title=Confirm pairs reset >+LatencyView.Dialogs.ListEvents.Confirm.Message=Are you sure you want to reset the event pairs to their default values? >+LatencyView.Graphs.Graph.Title=Latency VS Time >+LatencyView.Graphs.Graph.XAxisLabel=time (ns) >+LatencyView.Graphs.Graph.YAxisLabel=latency (ms) >+LatencyView.Graphs.Histogram.Title=Latency Distribution >+LatencyView.Graphs.Histogram.XAxisLabel=latency (ns) >+LatencyView.Graphs.Histogram.YAxisLabel=# events >+LatencyView.msgSlogan=Latency View >+LatencyView.tmf.UI=org.eclipse.linuxtools.lttng.ui >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/analysis/Config.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/Config.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/Config.java (revision 0) >@@ -0,0 +1,94 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis; >+ >+ >+/** >+ * Configuration class, holds some application constants. >+ * >+ * @author Philippe Sawicki >+ */ >+public class Config { >+ >+ /** >+ * Private constructor to defeat instantiation. >+ */ >+ private Config() { } >+ >+ >+ /** >+ * Size of the point buffer holding point values before sending them to the view. >+ */ >+ public static final int POINT_BUFFER_SIZE = 5000; >+ >+ /** >+ * Histogram bar width. >+ */ >+ public static int HISTOGRAM_BAR_WIDTH = 5; >+ >+ /** >+ * Diameter of a point drawn on the chart (in pixels). >+ */ >+ public static final int GRAPH_POINT_DIAMETER = 1; >+ >+ /** >+ * Graph padding. >+ */ >+ public static final int GRAPH_PADDING = 10; >+ >+ /** >+ * Write computed data value to .csv files ? >+ */ >+ public static final boolean WRITE_COMPUTED_DATA_TO_FILE = false; >+ >+ /** >+ * Print all debug info to the console ? >+ */ >+ public static final boolean PRINT_ALL = false; >+ >+ /** >+ * Print state changes info to the console ? >+ */ >+ public static final boolean PRINT_STATE_CHANGES = (PRINT_ALL ? true : false); >+ /** >+ * Print state constructors info to the console ? >+ */ >+ public static final boolean PRINT_STATE_CONSTRUCTOR = (PRINT_ALL ? true : false); >+ >+ /** >+ * Print counter state info to the console ? >+ */ >+ public static final boolean PRINT_COUNTER_STATE_STATUS = (PRINT_ALL ? true : false); >+ /** >+ * Print empty state info to the console ? >+ */ >+ public static final boolean PRINT_EMPTY_STATE_STATUS = (PRINT_ALL ? true : false); >+ /** >+ * Print time range state info to the console ? >+ */ >+ public static final boolean PRINT_TIMERANGE_STATE_STATUS = (PRINT_ALL ? true : false); >+ >+ /** >+ * Print graph view info to the console ? >+ */ >+ public static final boolean PRINT_GRAPH_VIEW_STATUS = (PRINT_ALL ? true : false); >+ /** >+ * Print histogram view info to the console ? >+ */ >+ public static final boolean PRINT_HISTO_VIEW_STATUS = (PRINT_ALL ? true : false); >+ >+ /** >+ * Print added points info to the console ? >+ */ >+ public static final boolean PRINT_INTERFACE_POINT_ADD = (PRINT_ALL ? false : false); >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/analysis/InterfaceMediator.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/InterfaceMediator.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/InterfaceMediator.java (revision 0) >@@ -0,0 +1,278 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis; >+ >+import java.util.Vector; >+ >+import org.eclipse.linuxtools.lttng.analysis.analyser.Analyser; >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair; >+import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView; >+import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; >+import org.eclipse.linuxtools.lttng.ui.views.latency.GraphView; >+import org.eclipse.linuxtools.lttng.ui.views.latency.HistogramView; >+import org.eclipse.linuxtools.lttng.ui.views.latency.handlers.ViewHandler; >+ >+ >+/** >+ * Interface mediator. >+ * >+ * @author Philippe Sawicki >+ */ >+public class InterfaceMediator implements ViewHandler { >+ >+ /** >+ * Class instance (Singleton pattern). >+ */ >+ private static InterfaceMediator instance_; >+ >+ /** >+ * List of graph views registered for analyser updates. >+ */ >+ private Vector<GraphView> graphViews_; >+ /** >+ * List of histogram views registered for analyser updates. >+ */ >+ private Vector<HistogramView> histogramViews_; >+ >+ /** >+ * Graph point buffer. >+ */ >+ private ChartPoint[] graphPoints_; >+ /** >+ * Histogram point buffer. >+ */ >+ private ChartPoint[] histogramPoints_; >+ /** >+ * Point counter. >+ */ >+ private int pointCounter_; >+ >+ /** >+ * The number of bars available in the histogram views. >+ */ >+ protected int nbBars_; >+ >+ >+ /** >+ * Private constructor to defeat instantiation (Singleton pattern). >+ */ >+ private InterfaceMediator() { >+ graphViews_ = new Vector<GraphView>(); >+ histogramViews_ = new Vector<HistogramView>(); >+ >+ graphPoints_ = new ChartPoint[Config.POINT_BUFFER_SIZE]; >+ pointCounter_ = 0; >+ } >+ >+ /** >+ * Returns an instance of the InterfaceMediator (Singleton pattern). >+ * @return An instance of the InterfaceMediator. >+ */ >+ public static InterfaceMediator getInstance() { >+ if (instance_ == null) >+ instance_ = new InterfaceMediator(); >+ return instance_; >+ } >+ >+ /** >+ * Releases the instance of the InterfaceMediator. >+ */ >+ public static void releaseInstance() { >+ instance_ = null; >+ } >+ >+ /** >+ * Registers a graph view to be notified of updates. >+ * @param view The graph view to notify about updates. >+ */ >+ public void registerGraphView(GraphView view) { >+ view.setViewHandler(this); >+ graphViews_.add(view); >+ } >+ >+ /** >+ * Registers a histogram view to be notified of updates. >+ * @param view The histogram view to notify about updates. >+ */ >+ public void registerHistogramView(HistogramView view) { >+ view.setViewHandler(this); >+ histogramViews_.add(view); >+ } >+ >+ /** >+ * Unregisters the views from the mediator. >+ */ >+ public void unregisterViews() { >+ // Unregister the InterfaceMediator as the view handler from the views. >+ for (AbstractView view : graphViews_) { >+ view.setViewHandler(null); >+ } >+ graphViews_.clear(); >+ >+ // Unregister the InterfaceMediator as the view handler from the views. >+ for (HistogramView view : histogramViews_) { >+ view.setViewHandler(null); >+ } >+ histogramViews_.clear(); >+ } >+ >+ /** >+ * Clears the view. >+ */ >+ public void clearViews() { >+ for (GraphView view : graphViews_) { >+ view.clear(); >+ view.clearBackground(); >+ } >+ for (HistogramView view : histogramViews_) { >+ view.clear(); >+ view.clearBackground(); >+ } >+ } >+ >+ >+ /** >+ * Clears the point buffer. >+ */ >+ public void clearPointsBuffer() { >+ graphPoints_ = new ChartPoint[Config.POINT_BUFFER_SIZE]; >+ >+ pointCounter_ = 0; >+ } >+ >+ /** >+ * Resets the histogram data points. >+ */ >+ public void clearHistogramData() { >+ for (int i = 0; i < histogramViews_.size(); i++) { >+ histogramViews_.get(i).clearPoints(); >+ } >+ } >+ >+ /** >+ * Sets the horizontal axis values for the graph views. >+ * @param xMin The min x-axis value. >+ * @param xMax The max x-axis value. >+ */ >+ public void pushHorizontalAxisForGraph(long xMin, long xMax) { >+ for (AbstractView view : graphViews_) { >+ view.setXMin(xMin); >+ view.setXMax(xMax); >+ } >+ } >+ >+ /** >+ * Sets the vertical axis values for the graph views. >+ * @param yMin The min y-axis value. >+ * @param yMax The max y-axis value. >+ */ >+ public void pushVerticalAxisForGraph(long yMin, long yMax) { >+ for (AbstractView view : graphViews_) { >+ view.setYMin(yMin); >+ view.setYMax(yMax); >+ } >+ } >+ >+ /** >+ * Sets the horizontal axis values for the histogram views. >+ * @param xMin The min x-axis value. >+ * @param xMax The max x-axis value. >+ */ >+ public void pushHorizontalAxisForHistogram(long xMin, long xMax) { >+ for (AbstractView view : histogramViews_) { >+ view.setXMin(xMin); >+ view.setXMax(xMax); >+ } >+ } >+ >+ /** >+ * Adds a point to the graph views. >+ * @param graphPoint The point to add to the graph views. >+ * @param histogramPoint The point to add to the histogram views. >+ */ >+ public void addPointToViews(ChartPoint graphPoint, Pair<Integer,ChartPoint> histogramPoint) { >+ graphPoints_[pointCounter_] = graphPoint; >+ histogramPoints_[histogramPoint.getFirst()] = histogramPoint.getSecond(); >+ pointCounter_++; >+ >+ if (Config.PRINT_INTERFACE_POINT_ADD) >+ System.out.println("Adding a new point to the buffer (size = " + pointCounter_ + ") ; (x;y) = (" + graphPoint.getX() + ";" + graphPoint.getY() + ")"); >+ >+ if (pointCounter_ == Config.POINT_BUFFER_SIZE) { >+ pushPointsToViews(); >+ clearPointsBuffer(); >+ } >+ } >+ >+ /** >+ * Pushes the point buffer to the views. >+ */ >+ public void pushPointsToViews() { >+ if (pointCounter_ != 0) { >+ for (AbstractView view : graphViews_) { >+ view.addPoints(graphPoints_, pointCounter_); >+ } >+ } >+ >+ for (AbstractView view : histogramViews_) { >+ view.addPoints(histogramPoints_, histogramPoints_.length); >+ } >+ } >+ >+ /** >+ * Push the standard latencies array to the histogram views. >+ * @param standardLatencies The standard latencies array to push to the views. >+ */ >+ public void pushStandardLatenciesToViews(double[] standardLatencies) { >+ histogramPoints_ = new ChartPoint[standardLatencies.length]; >+ for (int i = 0; i < standardLatencies.length; i++) { >+ histogramPoints_[i] = new ChartPoint((long)standardLatencies[i], 0L); >+ } >+ } >+ >+ /** >+ * Redraws the views. >+ */ >+ public void redrawViews() { >+ for (int i = 0; i < graphViews_.size(); i++) { >+ graphViews_.get(i).askForRedraw(); >+ } >+ for (int i = 0; i < histogramViews_.size(); i++) { >+ histogramViews_.get(i).askForRedraw(); >+ } >+ } >+ >+ /** >+ * Returns the maximum number of bars in the histogram views. >+ * @return The maximum number of bars in the histogram views. >+ */ >+ public int getMaxBarNumberFromViews() { >+ return nbBars_; >+ } >+ >+ /** >+ * Analyses the latency for all event types. >+ */ >+ public void analyseLatencyForAllEvents() { >+ Analyser.getInstance().analyseLatencyForAllEvents(); >+ } >+ >+ /** >+ * Sets the number of bars available in the histogram views. >+ * @param nbBars The number of bars available in the histogram views. >+ */ >+ @Override >+ public void notifyNumberOfBars(int nbBars) { >+ nbBars_ = nbBars; >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/Analyser.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/Analyser.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/Analyser.java (revision 0) >@@ -0,0 +1,80 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser; >+ >+import org.eclipse.linuxtools.lttng.analysis.analyser.states.AnalyserState; >+import org.eclipse.linuxtools.lttng.analysis.analyser.states.MinMaxLatencyState; >+ >+/** >+ * Analyser class, computes latencies in a trace, following the State pattern. >+ * >+ * @author Philippe Sawicki >+ */ >+public class Analyser { >+ >+ /** >+ * Class instance (Singleton pattern). >+ */ >+ private static Analyser instance_; >+ >+ /** >+ * Analyser state (State pattern). >+ */ >+ private AnalyserState state_; >+ >+ >+ /** >+ * Private constructor to defeat instantiation (Singleton pattern). >+ */ >+ private Analyser() { >+ >+ } >+ >+ /** >+ * Returns an instance of the Analyser. >+ * @return An instance of the Analyser. >+ */ >+ public static Analyser getInstance() { >+ if (instance_ == null) >+ instance_ = new Analyser(); >+ return instance_; >+ } >+ >+ /** >+ * Releases the instance of the Analyser. >+ */ >+ public static void releaseInstance() { >+ instance_ = null; >+ } >+ >+ /** >+ * Changes the state of the analyser (State pattern). >+ * @param newState The new state of the analyser. >+ */ >+ public void changeState(AnalyserState newState) { >+ state_ = newState; >+ >+ if (state_ != null) >+ state_.process(); >+ } >+ >+ /** >+ * Analyses the latency for all types of events. >+ */ >+ public void analyseLatencyForAllEvents() { >+ // If a state is currently active, cancel it before starting the new one >+ if (state_ != null) >+ state_.handleCancel(); >+ changeState( new MinMaxLatencyState() ); >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/matcher/EventMatcher.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/matcher/EventMatcher.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/matcher/EventMatcher.java (revision 0) >@@ -0,0 +1,491 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser.matcher; >+ >+import java.util.Collection; >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.Map.Entry; >+import java.util.Set; >+import java.util.Stack; >+import java.util.Vector; >+ >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair; >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+ >+ >+/** >+ * Event matching class. Saves events in a list a returns the previously saved >+ * event if the currently processed one is its response, so that the latency >+ * can be computed by subtracting their respective timestamps. >+ * >+ * @author Philippe Sawicki >+ */ >+public class EventMatcher { >+ >+ /** >+ * Class instance (Singleton pattern). >+ */ >+ private static EventMatcher instance_ = null; >+ >+ /** >+ * Stack abstraction, used to save the events in a list. >+ */ >+ private StackWrapper stack_; >+ >+ /** >+ * Match table, associates a request class to a response class. >+ */ >+ private HashMap<String,String> match_; >+ /** >+ * Inverse match table, associates a response class to a request class. >+ */ >+ private HashMap<String,String> inverseMatch_; >+ >+ /** >+ * The number of events processed. >+ */ >+ private int processedEvents_; >+ /** >+ * The number of events matched. >+ */ >+ private int matchedEvents_; >+ >+ /** >+ * Event types identification Strings. >+ */ >+ public static String >+ ADD_TO_PAGE_CACHE = "add_to_page_cache", >+ BIO_BACKMERGE = "bio_backmerge", >+ BIO_FRONTMERGE = "bio_frontmerge", >+ BIO_QUEUE = "bio_queue", >+ BUFFER_WAIT_END = "buffer_wait_end", >+ BUFFER_WAIT_START = "buffer_wait_start", >+ CALL = "call", >+ CLOSE = "close", >+ CORE_MARKER_FORMAT = "core_marker_format", >+ CORE_MARKER_ID = "core_marker_id", >+ DEV_RECEIVE = "dev_receive", >+ DEV_XMIT = "dev_xmit", >+ END_COMMIT = "end_commit", >+ EXEC = "exec", >+ FILE_DESCRIPTOR = "file_descriptor", >+ GETRQ = "getrq", >+ GETRQ_BIO = "getrq_bio", >+ IDT_TABLE = "idt_table", >+ INTERRUPT = "interrupt", >+ IOCTL = "ioctl", >+ IRQ_ENTRY = "irq_entry", >+ IRQ_EXIT = "irq_exit", >+ LIST_MODULE = "list_module", >+ LLSEEK = "llseek", >+ LSEEK = "lseek", >+ NAPI_COMPLETE = "napi_complete", >+ NAPI_POLL = "napi_poll", >+ NAPI_SCHEDULE = "napi_schedule", >+ NETWORK_IPV4_INTERFACE = "network_ipv4_interface", >+ NETWORK_IP_INTERFACE = "network_ip_interface", >+ OPEN = "open", >+ PAGE_FAULT_ENTRY = "page_fault_entry", >+ PAGE_FAULT_EXIT = "page_fault_exit", >+ PAGE_FAULT_GET_USER_ENTRY = "page_fault_get_user_entry", >+ PAGE_FAULT_GET_USER_EXIT = "page_fault_get_user_exit", >+ PAGE_FREE = "page_free", >+ PLUG = "plug", >+ POLLFD = "pollfd", >+ PREAD64 = "pread64", >+ PRINTF = "printf", >+ PRINTK = "printk", >+ PROCESS_EXIT = "process_exit", >+ PROCESS_FORK = "process_fork", >+ PROCESS_FREE = "process_free", >+ PROCESS_STATE = "process_state", >+ PROCESS_WAIT = "process_wait", >+ READ = "read", >+ REMAP = "remap", >+ REMOVE_FROM_PAGE_CACHE = "remove_from_page_cache", >+ RQ_COMPLETE_FS = "rq_complete_fs", >+ RQ_COMPLETE_PC = "rq_complete_pc", >+ RQ_INSERT_FS = "rq_insert_fs", >+ RQ_INSERT_PC = "rq_insert_pc", >+ RQ_ISSUE_FS = "rq_issue_fs", >+ RQ_ISSUE_PC = "rq_issue_pc", >+ RQ_REQUEUE_PC = "rq_requeue_pc", >+ SCHED_MIGRATE_TASK = "sched_migrate_task", >+ SCHED_SCHEDULE = "sched_schedule", >+ SCHED_TRY_WAKEUP = "sched_try_wakeup", >+ SCHED_WAKEUP_NEW_TASK = "sched_wakeup_new_task", >+ SELECT = "select", >+ SEM_CREATE = "sem_create", >+ SEND_SIGNAL = "send_signal", >+ SHM_CREATE = "shm_create", >+ SLEEPRQ_BIO = "sleeprq_bio", >+ SOCKET_ACCEPT = "socket_accept", >+ SOCKET_BIND = "socket_bind", >+ SOCKET_CALL = "socket_call", >+ SOCKET_CONNECT = "socket_connect", >+ SOCKET_CREATE = "socket_create", >+ SOCKET_GETPEERNAME = "socket_getpeername", >+ SOCKET_GETSOCKNAME = "socket_getsockname", >+ SOCKET_GETSOCKOPT = "socket_getsockopt", >+ SOCKET_LISTEN = "socket_listen", >+ SOCKET_SETSOCKOPT = "socket_setsockopt", >+ SOCKET_SHUTDOWN = "socket_shutdown", >+ SOCKET_SOCKETPAIR = "socket_socketpair", >+ SOFTIRQ_ENTRY = "softirq_entry", >+ SOFTIRQ_EXIT = "softirq_exit", >+ SOFTIRQ_RAISE = "softirq_raise", >+ SOFTIRQ_VEC = "softirq_vec", >+ START_COMMIT = "start_commit", >+ STATEDUMP_END = "statedump_end", >+ SYS_CALL_TABLE = "sys_call_table", >+ SYSCALL_ENTRY = "syscall_entry", >+ SYSCALL_EXIT = "syscall_exit", >+ TASKLET_LOW_ENTRY = "tasklet_low_entry", >+ TASKLET_LOW_EXIT = "tasklet_low_exit", >+ TCPV4_RCV = "tcpv4_rcv", >+ TIMER_ITIMER_EXPIRED = "timer_itimer_expired", >+ TIMER_ITIMER_SET = "timer_itimer_set", >+ TIMER_SET = "timer_set", >+ TIMER_TIMEOUT = "timer_timeout", >+ TIMER_UPDATE_TIME = "timer_update_time", >+ UDPV4_RCV = "udpv4_rcv", >+ UNPLUG_IO = "unplug_io", >+ UNPLUG_TIMER = "unplug_timer", >+ VM_MAP = "vm_map", >+ VPRINTK = "vprintk", >+ WAIT_ON_PAGE_END = "wait_on_page_end", >+ WAIT_ON_PAGE_START = "wait_on_page_start", >+ WRITE = "write", >+ WRITEV = "writev"; >+ >+ >+ /** >+ * Private constructor to defeat instantiation (Singleton pattern). >+ */ >+ private EventMatcher() { >+ stack_ = new StackWrapper(); >+ match_ = new HashMap<String,String>(); >+ inverseMatch_ = new HashMap<String,String>(); >+ >+ processedEvents_ = 0; >+ matchedEvents_ = 0; >+ >+ createMatchTable(); >+ } >+ >+ /** >+ * Returns an instance to the EventMatcher class (Singleton pattern). >+ * @return An instance to the EventMatcher class (Singleton pattern). >+ */ >+ public static EventMatcher getInstance() { >+ if (instance_ == null) >+ instance_ = new EventMatcher(); >+ return instance_; >+ } >+ >+ /** >+ * Releases the instance to the EventMatcher class. >+ */ >+ public static void releaseInstance() { >+ instance_ = null; >+ } >+ >+ /** >+ * Creates the event matching table, linking a response class to a >+ * request class. >+ */ >+ private void createMatchTable() { >+ // Build the default matches >+ match_.put(PAGE_FAULT_GET_USER_EXIT, PAGE_FAULT_GET_USER_ENTRY); >+ match_.put(TASKLET_LOW_EXIT, TASKLET_LOW_ENTRY); >+ match_.put(PAGE_FAULT_EXIT, PAGE_FAULT_ENTRY); >+ match_.put(SYSCALL_EXIT, SYSCALL_ENTRY); >+ match_.put(IRQ_EXIT, IRQ_ENTRY); >+ match_.put(WRITE, READ); >+ match_.put(CLOSE, OPEN); >+ match_.put(BUFFER_WAIT_END, BUFFER_WAIT_START); >+ match_.put(END_COMMIT, START_COMMIT); >+ match_.put(WAIT_ON_PAGE_END, WAIT_ON_PAGE_START); >+ >+ // Build the inverse matches based on the matches >+ Set<Entry<String,String>> pairs = match_.entrySet(); >+ Iterator<Entry<String,String>> it = pairs.iterator(); >+ while (it.hasNext()) { >+ Entry<String,String> pair = it.next(); >+ inverseMatch_.put(pair.getValue(), pair.getKey()); >+ } >+ } >+ >+ /** >+ * Processes an event received: if it is identified as a response, try to >+ * get its request to remove it from the list. If no request was saved, >+ * dismiss the current response. If it is a request, save it to the list of >+ * requests waiting for a response. >+ * @param event The event to identify, and maybe process if it is a response. >+ * @return The request event associated with the current event (a response), >+ * or null if nothing was found (no request associated with this response, or >+ * the event to identify was a request that was added to the list). >+ */ >+ public LttngEvent process(LttngEvent event) { >+ processedEvents_++; >+ >+ String markerName = event.getMarkerName(); >+ >+ if (match_.containsKey(markerName)) { >+ String startEventType = match_.get(markerName); >+ Stack<LttngEvent> events = stack_.getStackOf(startEventType); >+ >+ if (events != null) { >+ for (int i = events.size()-1; i >= 0; i--) { >+ LttngEvent request = events.get(i); >+ >+ if (request.getCpuId() == event.getCpuId() && >+ event.getTimestamp().getValue() > request.getTimestamp().getValue()) { >+ stack_.removeEvent(startEventType, request); >+ matchedEvents_++; >+ return request; >+ } >+ } >+ } >+ return null; >+ } else { >+ // Add only if there can later be a match for this request >+ if (match_.containsValue(event.getMarkerName())) { >+ stack_.put(event.clone()); >+ } >+ return null; >+ } >+ } >+ >+ /** >+ * Clears the stack content. >+ */ >+ public void clearStack() { >+ stack_.clear(); >+ >+ // Reset the processed and matched events counter >+ processedEvents_ = 0; >+ matchedEvents_ = 0; >+ } >+ >+ /** >+ * Resets all. >+ */ >+ public void resetMatches() { >+ match_.clear(); >+ inverseMatch_.clear(); >+ >+ stack_.clear(); >+ >+ // Reset the processed and matched events counter >+ processedEvents_ = 0; >+ matchedEvents_ = 0; >+ } >+ >+ /** >+ * Returns the list of start events. >+ * @return The list of start events. >+ */ >+ public Collection<String> getStartEvents() { >+ return match_.values(); >+ } >+ >+ /** >+ * Returns the list of end events. >+ * @return The list of end events. >+ */ >+ public Set<String> getEndEvents() { >+ return match_.keySet(); >+ } >+ >+ /** >+ * Returns the alphabetically-sorted list of start/end events pairs. >+ * @return The alphabetically-sorted list of start/end events pairs. >+ */ >+ public Pair<Vector<String>,Vector<String>> getEvents() { >+ Vector<String> start = new Vector<String>( getStartEvents() ); >+ Vector<String> end = new Vector<String>( match_.size() ); >+ >+ Collections.sort(start); >+ for (int i = 0; i < start.size(); i++) { >+ end.add( inverseMatch_.get(start.get(i)) ); >+ } >+ >+ return new Pair<Vector<String>,Vector<String>>(start, end); >+ } >+ >+ /** >+ * Adds a match to the list of events pairs. >+ * @param startType The start event type. >+ * @param endType The end event type. >+ */ >+ public void addMatch(String startType, String endType) { >+ match_.put(endType, startType); >+ inverseMatch_.put(startType, endType); >+ } >+ >+ /** >+ * Removes a matched pair based on the their type. >+ * >+ * <b>Note :</b> For now, only the pair's end type is used, since a type >+ * can only be either one start or one end. This function takes both types >+ * to account for the future, if a pairing process ever becomes more complex. >+ * >+ * @param startType The type of the pair's start type. >+ * @param endType The type of the pair's end type. >+ */ >+ public void removeMatch(String startType, String endType) { >+ match_.remove(endType); >+ inverseMatch_.remove(startType); >+ } >+ >+ /** >+ * Returns the list of all event possible types. >+ * @return The list of all event possible types. >+ */ >+ public Vector<String> getTypeList() { >+ // Reserve some space for the 103 default event types. >+ Vector<String> eventsList = new Vector<String>(103); >+ >+ eventsList.add(ADD_TO_PAGE_CACHE); >+ eventsList.add(BIO_BACKMERGE); >+ eventsList.add(BIO_FRONTMERGE); >+ eventsList.add(BIO_QUEUE); >+ eventsList.add(BUFFER_WAIT_END); >+ eventsList.add(BUFFER_WAIT_START); >+ eventsList.add(CALL); >+ eventsList.add(CLOSE); >+ eventsList.add(CORE_MARKER_FORMAT); >+ eventsList.add(CORE_MARKER_ID); >+ eventsList.add(DEV_RECEIVE); >+ eventsList.add(DEV_XMIT); >+ eventsList.add(END_COMMIT); >+ eventsList.add(EXEC); >+ eventsList.add(FILE_DESCRIPTOR); >+ eventsList.add(GETRQ); >+ eventsList.add(GETRQ_BIO); >+ eventsList.add(IDT_TABLE); >+ eventsList.add(INTERRUPT); >+ eventsList.add(IOCTL); >+ eventsList.add(IRQ_ENTRY); >+ eventsList.add(IRQ_EXIT); >+ eventsList.add(LIST_MODULE); >+ eventsList.add(LLSEEK); >+ eventsList.add(LSEEK); >+ eventsList.add(NAPI_COMPLETE); >+ eventsList.add(NAPI_POLL); >+ eventsList.add(NAPI_SCHEDULE); >+ eventsList.add(NETWORK_IPV4_INTERFACE); >+ eventsList.add(NETWORK_IP_INTERFACE); >+ eventsList.add(OPEN); >+ eventsList.add(PAGE_FAULT_ENTRY); >+ eventsList.add(PAGE_FAULT_EXIT); >+ eventsList.add(PAGE_FAULT_GET_USER_ENTRY); >+ eventsList.add(PAGE_FAULT_GET_USER_EXIT); >+ eventsList.add(PAGE_FREE); >+ eventsList.add(PLUG); >+ eventsList.add(POLLFD); >+ eventsList.add(PREAD64); >+ eventsList.add(PRINTF); >+ eventsList.add(PRINTK); >+ eventsList.add(PROCESS_EXIT); >+ eventsList.add(PROCESS_FORK); >+ eventsList.add(PROCESS_FREE); >+ eventsList.add(PROCESS_STATE); >+ eventsList.add(PROCESS_WAIT); >+ eventsList.add(READ); >+ eventsList.add(REMAP); >+ eventsList.add(REMOVE_FROM_PAGE_CACHE); >+ eventsList.add(RQ_COMPLETE_FS); >+ eventsList.add(RQ_COMPLETE_PC); >+ eventsList.add(RQ_INSERT_FS); >+ eventsList.add(RQ_INSERT_PC); >+ eventsList.add(RQ_ISSUE_FS); >+ eventsList.add(RQ_ISSUE_PC); >+ eventsList.add(RQ_REQUEUE_PC); >+ eventsList.add(SCHED_MIGRATE_TASK); >+ eventsList.add(SCHED_SCHEDULE); >+ eventsList.add(SCHED_TRY_WAKEUP); >+ eventsList.add(SCHED_WAKEUP_NEW_TASK); >+ eventsList.add(SELECT); >+ eventsList.add(SEM_CREATE); >+ eventsList.add(SEND_SIGNAL); >+ eventsList.add(SHM_CREATE); >+ eventsList.add(SLEEPRQ_BIO); >+ eventsList.add(SOCKET_ACCEPT); >+ eventsList.add(SOCKET_BIND); >+ eventsList.add(SOCKET_CALL); >+ eventsList.add(SOCKET_CONNECT); >+ eventsList.add(SOCKET_CREATE); >+ eventsList.add(SOCKET_GETPEERNAME); >+ eventsList.add(SOCKET_GETSOCKNAME); >+ eventsList.add(SOCKET_GETSOCKOPT); >+ eventsList.add(SOCKET_LISTEN); >+ eventsList.add(SOCKET_SETSOCKOPT); >+ eventsList.add(SOCKET_SHUTDOWN); >+ eventsList.add(SOCKET_SOCKETPAIR); >+ eventsList.add(SOFTIRQ_ENTRY); >+ eventsList.add(SOFTIRQ_EXIT); >+ eventsList.add(SOFTIRQ_RAISE); >+ eventsList.add(SOFTIRQ_VEC); >+ eventsList.add(START_COMMIT); >+ eventsList.add(STATEDUMP_END); >+ eventsList.add(SYS_CALL_TABLE); >+ eventsList.add(SYSCALL_ENTRY); >+ eventsList.add(SYSCALL_EXIT); >+ eventsList.add(TASKLET_LOW_ENTRY); >+ eventsList.add(TASKLET_LOW_EXIT); >+ eventsList.add(TCPV4_RCV); >+ eventsList.add(TIMER_ITIMER_EXPIRED); >+ eventsList.add(TIMER_ITIMER_SET); >+ eventsList.add(TIMER_SET); >+ eventsList.add(TIMER_TIMEOUT); >+ eventsList.add(TIMER_UPDATE_TIME); >+ eventsList.add(UDPV4_RCV); >+ eventsList.add(UNPLUG_IO); >+ eventsList.add(UNPLUG_TIMER); >+ eventsList.add(VM_MAP); >+ eventsList.add(VPRINTK); >+ eventsList.add(WAIT_ON_PAGE_END); >+ eventsList.add(WAIT_ON_PAGE_START); >+ eventsList.add(WRITE); >+ eventsList.add(WRITEV); >+ >+ return eventsList; >+ } >+ >+ /** >+ * Returns the number of events processed. >+ * @return The number of events processed. >+ */ >+ public int getNBProcessedEvents() { >+ return processedEvents_; >+ } >+ >+ /** >+ * Returns the number of events matched. >+ * @return The number of events matched. >+ */ >+ public int getNBMatchedEvents() { >+ return matchedEvents_; >+ } >+ >+ /** >+ * Prints the stack content to the console. >+ */ >+ public void print() { >+ stack_.printContent(); >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/matcher/StackWrapper.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/matcher/StackWrapper.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/matcher/StackWrapper.java (revision 0) >@@ -0,0 +1,141 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser.matcher; >+ >+import java.util.Collection; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.Set; >+import java.util.Stack; >+ >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+ >+ >+/** >+ * Stack pile. >+ * >+ * TODO Change the types of the HashMaps from <String,String> to >+ * <Integer,Integer>, in order to take advantage of the compilation-time >+ * String.hashCode() speedup over execution-time String hash computation. >+ * >+ * @author Philippe Sawicki >+ */ >+public class StackWrapper { >+ >+ /** >+ * Hash map of event stacks. >+ */ >+ private HashMap<String,Stack<LttngEvent>> stacks_ = null; >+ >+ >+ /** >+ * Constructor. >+ */ >+ public StackWrapper() { >+ stacks_ = new HashMap<String,Stack<LttngEvent>>(); >+ } >+ >+ /** >+ * Adds an event to the list of events of the same type. >+ * @param event The event to add to the list. >+ */ >+ public void put(LttngEvent event) { >+ String key = event.getMarkerName(); >+ >+ if (stacks_.containsKey(key)) { >+ stacks_.get(key).add(event); >+ } else { >+ Stack<LttngEvent> newStack = new Stack<LttngEvent>(); >+ newStack.add(event); >+ stacks_.put(key, newStack); >+ } >+ } >+ >+ /** >+ * Checks if the stack contains a list of events of the given type. >+ * @param key The type of events to check for. >+ * @return "true" if the stack contains events of the given type, "false" otherwise. >+ */ >+ public boolean containsKey(String key) { >+ return stacks_.containsKey(key); >+ } >+ >+ /** >+ * Returns the list of events of the given type. >+ * @param key The type of events to return. >+ * @return The list of events of the given type, or null. >+ */ >+ public Stack<LttngEvent> getStackOf(String key) { >+ if (stacks_.containsKey(key)) { >+ return stacks_.get(key); >+ } else { >+ return null; >+ } >+ } >+ >+ /** >+ * Removes the given event from the given stack list. >+ * @param key The given stack type. >+ * @param event The event to remove from the given stack type. >+ * @return "true" if the event was removed, "false" otherwise. >+ */ >+ public boolean removeEvent(String key, LttngEvent event) { >+ Stack<LttngEvent> stack = stacks_.get(key); >+ >+ boolean removed = false; >+ >+ try { >+ /** >+ * TODO Correct this... >+ * Here, no matter what CPU or other content field, we always >+ * remove the last event added to the stack. Should be >+ * something like : >+ * return stack.remove(event); >+ */ >+ stack.pop(); >+ removed = true; >+ } catch (Exception e) { >+ e.printStackTrace(); >+ } >+ >+ // Remove the stack from the stack list if it is empty >+ if (stack.isEmpty()) { >+ stacks_.remove(key); >+ } >+ >+ return removed; >+ } >+ >+ /** >+ * Clears the stack content. >+ */ >+ public void clear() { >+ stacks_.clear(); >+ } >+ >+ /** >+ * Prints the content of the stack to the console. >+ */ >+ public void printContent() { >+ Collection<Stack<LttngEvent>> values = stacks_.values(); >+ Iterator<Stack<LttngEvent>> valueIt = values.iterator(); >+ >+ Set<String> keys = stacks_.keySet(); >+ Iterator<String> keyIt = keys.iterator(); >+ >+ while ( valueIt.hasNext() && keyIt.hasNext() ) { >+ Stack<LttngEvent> stack = valueIt.next(); >+ >+ System.out.println( " " + keyIt.next() + " [" + stack.size() + "] : " + stack ); >+ } >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/states/AnalyserState.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/states/AnalyserState.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/states/AnalyserState.java (revision 0) >@@ -0,0 +1,91 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser.states; >+ >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.analysis.InterfaceMediator; >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher; >+import org.eclipse.linuxtools.lttng.analysis.facade.DataHandler; >+ >+ >+/** >+ * Abstract analyser state. >+ * >+ * @author Philippe Sawicki >+ */ >+public abstract class AnalyserState extends DataHandler { >+ >+ /** >+ * State name. >+ */ >+ protected String stateName_; >+ >+ /** >+ * The state's next state. >+ */ >+ protected AnalyserState nextState_; >+ >+ /** >+ * Is the state cancelled ? >+ */ >+ protected boolean isCancelled_ = false; >+ >+ >+ /** >+ * Abstract analyser state constructor. >+ * @param stateName The state name. >+ * @param nextState The state's next state. >+ */ >+ public AnalyserState(String stateName, AnalyserState nextState) { >+ stateName_ = stateName; >+ nextState_ = nextState; >+ >+ if (Config.PRINT_STATE_CONSTRUCTOR) >+ System.out.println("[" + stateName_ + "]"); >+ } >+ >+ /** >+ * Abstract analyser state constructor. >+ * @param stateName The state name. >+ */ >+ public AnalyserState(String stateName) { >+ this(stateName, null); >+ >+ isCancelled_ = false; >+ } >+ >+ /** >+ * Process the state. >+ */ >+ public abstract void process(); >+ >+ /** >+ * Cancel the state's activity (i.e. clear the stack and redraw the views). >+ */ >+ public void handleCancel() { >+ isCancelled_ = true; >+ >+ EventMatcher.getInstance().clearStack(); >+ InterfaceMediator.getInstance().clearHistogramData(); >+ InterfaceMediator.getInstance().clearPointsBuffer(); >+ InterfaceMediator.getInstance().clearViews(); >+ } >+ >+ /** >+ * Returns the state's name. >+ * @return The state's name. >+ */ >+ public String getName() { >+ return stateName_; >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/states/CounterState.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/states/CounterState.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/states/CounterState.java (revision 0) >@@ -0,0 +1,107 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser.states; >+ >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.analysis.InterfaceMediator; >+import org.eclipse.linuxtools.lttng.analysis.analyser.Analyser; >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher; >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.EventCountPerLatency; >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair; >+import org.eclipse.linuxtools.lttng.analysis.facade.TraceFacade; >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; >+import org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView; >+import org.eclipse.linuxtools.tmf.event.TmfTimeRange; >+import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; >+ >+ >+/** >+ * Counts the event latencies. >+ * >+ * @author Philippe Sawicki >+ */ >+public class CounterState extends AnalyserState { >+ >+ /** >+ * Event counter, used to generate bar graphs. >+ */ >+ private EventCountPerLatency eventCounter_; >+ >+ /** >+ * Min trace latency. >+ */ >+ private long minLatency_; >+ /** >+ * Max trace latency. >+ */ >+ private long maxLatency_; >+ >+ >+ /** >+ * Constructor. >+ * @param minLatency Min trace latency. >+ * @param maxLatency Max trace latency. >+ */ >+ public CounterState(long minLatency, long maxLatency) { >+ super("Counter state"); >+ >+ minLatency_ = minLatency; >+ maxLatency_ = maxLatency; >+ >+ eventCounter_ = new EventCountPerLatency(); >+ >+ int nbBars = InterfaceMediator.getInstance().getMaxBarNumberFromViews(); >+ eventCounter_.generateStandardLatencies(minLatency_, maxLatency_, nbBars); >+ InterfaceMediator.getInstance().pushStandardLatenciesToViews( eventCounter_.getStandardLatencies() ); >+ } >+ >+ @Override >+ public void process() { >+ if (Config.PRINT_COUNTER_STATE_STATUS) >+ System.out.println(" CounterState.process()"); >+ >+ TmfExperiment<LttngEvent> experiment = LatencyView.getExperiment(); >+ >+ TmfTimeRange timeRange = LatencyView.getTimeRange(); >+ >+ TraceFacade.getInstance().getAllEvents(experiment, timeRange, this); >+ } >+ >+ @Override >+ public void handleData(LttngEvent event) { >+ if (isCancelled_) >+ return; >+ >+ LttngEvent startEvent = EventMatcher.getInstance().process(event); >+ >+ if (startEvent != null) { >+ long latency = event.getTimestamp().getValue() - startEvent.getTimestamp().getValue(); >+ ChartPoint timeValue = new ChartPoint(startEvent.getTimestamp().getValue(), latency); >+ Pair<Integer,ChartPoint> numberValue = eventCounter_.updateStandardCounter(latency); >+ >+ InterfaceMediator.getInstance().addPointToViews( timeValue, numberValue ); >+ } >+ } >+ >+ public void handleCompleted() { >+ if (isCancelled_) >+ return; >+ >+ EventMatcher.getInstance().clearStack(); >+ InterfaceMediator.getInstance().pushPointsToViews(); >+ InterfaceMediator.getInstance().redrawViews(); >+ >+ Analyser.getInstance().changeState( new EmptyState() ); >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/states/EmptyState.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/states/EmptyState.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/states/EmptyState.java (revision 0) >@@ -0,0 +1,45 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser.states; >+ >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+ >+ >+/** >+ * Empty state, for demonstration only. >+ * >+ * @author Philippe Sawicki >+ */ >+public class EmptyState extends AnalyserState { >+ >+ /** >+ * Constructor. >+ */ >+ public EmptyState() { >+ super("Empty state"); >+ } >+ >+ @Override >+ public void process() { >+ if (Config.PRINT_EMPTY_STATE_STATUS) >+ System.out.println(" EmptyState.process()"); >+ >+ // Nothing to do here... >+ } >+ >+ @Override >+ public void handleData(LttngEvent event) { >+ >+ } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/states/MinMaxLatencyState.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/states/MinMaxLatencyState.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/states/MinMaxLatencyState.java (revision 0) >@@ -0,0 +1,108 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser.states; >+ >+import org.eclipse.linuxtools.lttng.analysis.Config; >+import org.eclipse.linuxtools.lttng.analysis.InterfaceMediator; >+import org.eclipse.linuxtools.lttng.analysis.analyser.Analyser; >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher; >+import org.eclipse.linuxtools.lttng.analysis.facade.TraceFacade; >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+import org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView; >+import org.eclipse.linuxtools.tmf.event.TmfTimeRange; >+import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; >+ >+/** >+ * State used to find out the min an max values for the view's horizontal axis. >+ * >+ * @author Philippe Sawicki >+ */ >+public class MinMaxLatencyState extends AnalyserState { >+ >+ /** >+ * Min latency time. >+ */ >+ private long latencyMin_; >+ /** >+ * Max latency time. >+ */ >+ private long latencyMax_; >+ >+ /** >+ * Min trace time. >+ */ >+ private long timeMin_; >+ /** >+ * Max trace time. >+ */ >+ private long timeMax_; >+ >+ >+ /** >+ * Constructor. >+ */ >+ public MinMaxLatencyState() { >+ super("Min max latency state"); >+ >+ // Initialise min and max latency times with some values >+ latencyMin_ = Long.MAX_VALUE; >+ latencyMax_ = Long.MIN_VALUE; >+ >+ // Initialise min and max trace times with some values >+ timeMin_ = Long.MAX_VALUE; >+ timeMax_ = Long.MIN_VALUE; >+ } >+ >+ public void process() { >+ if (Config.PRINT_TIMERANGE_STATE_STATUS) >+ System.out.println(" MinMaxLatencyState()"); >+ >+ TmfExperiment<LttngEvent> experiment = LatencyView.getExperiment(); >+ >+ TmfTimeRange timeRange = LatencyView.getTimeRange(); >+ >+ TraceFacade.getInstance().getAllEvents(experiment, timeRange, this); >+ } >+ >+ @Override >+ public void handleData(LttngEvent event) { >+ if (isCancelled_) >+ return; >+ >+ LttngEvent startEvent = EventMatcher.getInstance().process(event); >+ >+ if (startEvent != null) { >+ long latency = event.getTimestamp().getValue() - startEvent.getTimestamp().getValue(); >+ >+ latencyMax_ = Math.max(latencyMax_, latency); >+ latencyMin_ = Math.min(latencyMin_, latency); >+ } >+ >+ >+ timeMin_ = Math.min(timeMin_, event.getTimestamp().getValue()); >+ timeMax_ = Math.max(timeMax_, event.getTimestamp().getValue()); >+ } >+ >+ public void handleCompleted() { >+ if (isCancelled_) >+ return; >+ >+ EventMatcher.getInstance().clearStack(); >+ >+ InterfaceMediator.getInstance().pushHorizontalAxisForGraph(timeMin_, timeMax_); >+ InterfaceMediator.getInstance().pushVerticalAxisForGraph(latencyMin_, latencyMax_); >+ InterfaceMediator.getInstance().pushHorizontalAxisForHistogram(latencyMin_, latencyMax_); >+ >+ Analyser.getInstance().changeState( new CounterState(latencyMin_, latencyMax_) ); >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/utilities/EventCountPerLatency.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/utilities/EventCountPerLatency.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/utilities/EventCountPerLatency.java (revision 0) >@@ -0,0 +1,135 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Ali Jawar - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser.utilities; >+ >+import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; >+ >+ >+/** >+ * This class generates dynamically the standard latencies and updates the >+ * event count for each bin/bucket. >+ * >+ * Standards latencies values are generated dynamically and depend to three >+ * variables: minLatency, maxLatency, nbBar. >+ * >+ * <ul> >+ * <li><em>minLatency</em> is the smallest latency value</li> >+ * <li><em>maxLatency</em> is the biggest latency value</li> >+ * <li><em>nbBar</em> is the number of divisions along the axis of latencies</li> >+ * </ul> >+ * >+ * Algorithm complexity: O(1)... actually O(<em>nbBar</em>) but <em>nbBar</em> >+ * is limited to a constant. >+ * >+ * @author Ali Jawhar >+ * @author Philippe Sawicki >+ */ >+public class EventCountPerLatency { >+ >+ /** >+ * Standard latencies values. >+ */ >+ private double[] standardLatencies_; >+ >+ /** >+ * One counter for each standard latency. >+ */ >+ private int[] standardCounter_; >+ >+ /** >+ * Distance between each latency. >+ */ >+ private double delta_; >+ >+ /** >+ * Minimum latency. >+ */ >+ private long minLatency_; >+ >+ >+ /** >+ * Constructor. >+ */ >+ public EventCountPerLatency() { >+ >+ } >+ >+ /** >+ * Method to generate the standard latencies table. >+ * >+ * @param minLatency Latency min. >+ * @param maxLatency Latency max. >+ * @param nbBars Number of bars in the histogram graph. >+ */ >+ public void generateStandardLatencies(long minLatency, long maxLatency, int nbBars) { >+ delta_ = (double)(maxLatency-minLatency) / nbBars; >+ minLatency_ = minLatency; >+ >+ // Initialisation of standard counter table >+ standardCounter_ = new int[nbBars+1]; // one counter for each standard latency >+ for (int i = 0; i < standardCounter_.length; i++) { // initiate counters values >+ standardCounter_[i] = 0; >+ } >+ >+ // Create standard latencies table >+ standardLatencies_ = new double[nbBars+1]; >+ >+ for (int i = 0 ; i < standardLatencies_.length; i++) { >+ standardLatencies_[i] = minLatency + (i * delta_); >+ } >+ } >+ >+ /** >+ * Updates the standard latencies counter. >+ * @param latency The latency to add to the counter. >+ * @return The new updates values (index of standard latency ; new counter value). >+ */ >+ public Pair<Integer,ChartPoint> updateStandardCounter(long latency) { >+ int index = 0; >+ index = (int)((latency - minLatency_) / delta_); >+ standardCounter_[index]++; >+ ChartPoint point = new ChartPoint((long)standardLatencies_[index], standardCounter_[index]); >+ return new Pair<Integer,ChartPoint>(index, point); >+ } >+ >+ /** >+ * Prints the standard latencies table. >+ */ >+ public void printStandardLatencies() { >+ System.out.print("The standard latencies table is: "); >+ >+ for (int i = 0; i < standardLatencies_.length; i++) { >+ System.out.print(standardLatencies_[i] + " "); >+ } >+ System.out.println(); >+ } >+ >+ /** >+ * Prints the event count per standard latency. >+ */ >+ public void printEventCountPerStandardLatency() { >+ System.out.println("here is the Event count per standard latency: "); >+ >+ for (int j = 0; j < standardLatencies_.length; j++) { >+ System.out.println("latency = " + standardLatencies_[j] + " EventCount = " + standardCounter_[j]); >+ } >+ } >+ >+ /** >+ * Returns the standard latencies table. >+ * @return The standard latencies table. >+ */ >+ public double[] getStandardLatencies() { >+ return standardLatencies_; >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/utilities/Pair.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/utilities/Pair.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/utilities/Pair.java (revision 0) >@@ -0,0 +1,119 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.analyser.utilities; >+ >+ >+/** >+ * Pair utility class, encapsulates a pair of objects. >+ * >+ * @author Philippe Sawicki >+ * >+ * @param <A> The type of the first object. >+ * @param <B> The type of the second object. >+ */ >+public class Pair<A,B> { >+ >+ /** >+ * A reference to the first object. >+ */ >+ protected A first_; >+ /** >+ * A reference to the second object. >+ */ >+ protected B second_; >+ >+ >+ /** >+ * Constructor. >+ * @param first The pair's first object. >+ * @param second The pair's second object. >+ */ >+ public Pair(A first, B second) { >+ first_ = first; >+ second_ = second; >+ } >+ >+ /** >+ * Constructor. >+ */ >+ public Pair() { >+ this(null, null); >+ } >+ >+ /** >+ * Pair hash code. >+ */ >+ public int hashCode() { >+ int hashFirst = first_ != null ? first_.hashCode() : 0; >+ int hashSecond = second_ != null ? second_.hashCode() : 0; >+ >+ return (hashFirst + hashSecond) * hashSecond + hashFirst; >+ } >+ >+ /** >+ * Object comparison. >+ */ >+ @SuppressWarnings("unchecked") >+ public boolean equals(Object other) { >+ if (other instanceof Pair) { >+ Pair<A,B> otherPair = (Pair<A,B>) other; >+ return ( >+ ( first_ == otherPair.first_ || >+ ( first_ != null && otherPair.first_ != null && >+ first_.equals(otherPair.first_))) && >+ ( second_ == otherPair.second_ || >+ ( second_ != null && otherPair.second_ != null && >+ second_.equals(otherPair.second_))) >+ ); >+ } >+ return false; >+ } >+ >+ /** >+ * Object to string. >+ */ >+ public String toString() { >+ return "(" + first_ + ", " + second_ + ")"; >+ } >+ >+ /** >+ * Returns a reference to the pair's first object. >+ * @return A reference to the pair's first object. >+ */ >+ public A getFirst() { >+ return first_; >+ } >+ >+ /** >+ * Sets the pair's first object. >+ * @param first The pair's first object. >+ */ >+ public void setFirst(A first) { >+ first_ = first; >+ } >+ >+ /** >+ * Returns a reference to the pair's second object. >+ * @return A reference to the pair's second object. >+ */ >+ public B getSecond() { >+ return second_; >+ } >+ >+ /** >+ * Sets the pair's second object. >+ * @param second The pair's second object. >+ */ >+ public void setSecond(B second) { >+ second_ = second; >+ } >+} >Index: src/org/eclipse/linuxtools/lttng/analysis/facade/DataHandler.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/facade/DataHandler.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/facade/DataHandler.java (revision 0) >@@ -0,0 +1,51 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.facade; >+ >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+ >+/** >+ * Data handler interface. >+ * >+ * Classes who want to register to the TraceFacade to receive data must implement >+ * this class's interface. >+ * >+ * @author Philippe Sawicki >+ */ >+public abstract class DataHandler { >+ >+ /** >+ * Handles the data received from TraceFacade. >+ */ >+ public abstract void handleData(LttngEvent event); >+ >+ /** >+ * Handles transaction completion. >+ */ >+ public void handleCompleted() { } >+ >+ /** >+ * Handles transaction success. >+ */ >+ public void handleSuccess() { } >+ >+ /** >+ * Handles transaction failure. >+ */ >+ public void handleFailure() { } >+ >+ /** >+ * Handles transaction cancellation. >+ */ >+ public void handleCancel() { } >+ >+} >Index: src/org/eclipse/linuxtools/lttng/analysis/facade/TraceFacade.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/facade/TraceFacade.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/facade/TraceFacade.java (revision 0) >@@ -0,0 +1,140 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Ericsson >+ * >+ * All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.linuxtools.lttng.analysis.facade; >+ >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+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.experiment.TmfExperiment; >+import org.eclipse.linuxtools.tmf.request.TmfEventRequest; >+ >+ >+/** >+ * Facade for obtaining traced events through TMF given their type and/or timerange. >+ * >+ * @author Philippe Sawicki >+ */ >+public class TraceFacade { >+ >+ /** >+ * TraceFacade instance (Singleton pattern). >+ */ >+ private static TraceFacade instance_ = null; >+ >+ /** >+ * Private constructor to defeat instantiation (Singleton pattern). >+ */ >+ private TraceFacade() { } >+ >+ /** >+ * Returns an instance of the TraceFacade (Singleton pattern). >+ * >+ * @return An instance of the TraceFacade (Singleton pattern). >+ */ >+ public static TraceFacade getInstance() { >+ if (instance_ == null) >+ instance_ = new TraceFacade(); >+ return instance_; >+ } >+ >+ /** >+ * Returns all the trace events between the given time range. >+ * @param experiment The current experiment. >+ * @param timeRange The considered time range. >+ * @param handler The object that will receive the trace events. >+ */ >+ public void getAllEvents(TmfExperiment<LttngEvent> experiment, TmfTimeRange timeRange, DataHandler handler) { >+ UnfilteredRequest request = new UnfilteredRequest(LttngEvent.class, timeRange, handler); >+ experiment.sendRequest(request); >+ } >+ >+ >+ >+ /** >+ * TmfEventRequest extension to forward data handling to a designated object, unfiltered by type(s). >+ * >+ * @author Philippe Sawicki >+ */ >+ private class UnfilteredRequest extends TmfEventRequest<LttngEvent> { >+ >+ /** >+ * Data handler. >+ */ >+ private DataHandler handler_ = null; >+ >+ /** >+ * Start of considered time range. >+ */ >+ private TmfTimestamp startTime_ = null; >+ /** >+ * End of considered time range. >+ */ >+ private TmfTimestamp endTime_ = null; >+ >+ >+ @SuppressWarnings("unchecked") >+ public UnfilteredRequest(Class<? extends TmfEvent> dataType, TmfTimeRange timeRange, DataHandler handler, int nbRequested) { >+ super((Class<LttngEvent>)dataType, timeRange, nbRequested, 1); >+ handler_ = handler; >+ >+ startTime_ = timeRange.getStartTime(); >+ endTime_ = timeRange.getEndTime(); >+ } >+ >+ @SuppressWarnings("unchecked") >+ public UnfilteredRequest(Class<? extends TmfEvent> dataType, TmfTimeRange timeRange, DataHandler handler) { >+ super((Class<LttngEvent>)dataType, timeRange, Integer.MAX_VALUE, 1); >+ handler_ = handler; >+ >+ startTime_ = timeRange.getStartTime(); >+ endTime_ = timeRange.getEndTime(); >+ } >+ >+ public void handleData(LttngEvent event) { >+ if ( event != null >+ && event.getTimestamp().getValue() >= startTime_.getValue() >+ && event.getTimestamp().getValue() <= endTime_.getValue() ) { >+ handler_.handleData(event); >+ } >+ } >+ >+ /** >+ * Forward completion notification to the handler. >+ */ >+ public void handleCompleted() { >+ handler_.handleCompleted(); >+ } >+ >+ /** >+ * Forward success notification to the handler. >+ */ >+ public void handleSuccess() { >+ handler_.handleSuccess(); >+ } >+ >+ /** >+ * Forward failure notification to the handler. >+ */ >+ public void handleFailure() { >+ handler_.handleFailure(); >+ } >+ >+ /** >+ * Forward cancellation notification to the handler. >+ */ >+ public void handleCancel() { >+ handler_.handleCancel(); >+ } >+ } >+ >+} >Index: plugin.xml >=================================================================== >--- plugin.xml (revision 27089) >+++ plugin.xml (working copy) >@@ -90,6 +90,15 @@ > name="%histogram.view.name" > restorable="true"> > </view> >+ <view >+ allowMultiple="false" >+ category="org.eclipse.linuxtools.lttng.ui.views.category" >+ class="org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView" >+ icon="icons/graph.gif" >+ id="org.eclipse.linuxtools.lttng.ui.views.latency" >+ name="%latency.view.name" >+ restorable="true"> >+ </view> > </extension> > <extension > point="org.eclipse.ui.newWizards"> >Index: plugin.properties >=================================================================== >--- plugin.properties (revision 27089) >+++ plugin.properties (working copy) >@@ -14,6 +14,7 @@ > resources.view.name = Resources > statistics.view.name = Statistics > histogram.view.name = Histogram >+latency.view.name = Latency View > > wizard.category.name = LTTng > project.new.wizard.name = LTTng Project >#P org.eclipse.linuxtools.lttng.tests >Index: src/org/eclipse/linuxtools/lttng/AllLTTngTests.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/AllLTTngTests.java (revision 27081) >+++ src/org/eclipse/linuxtools/lttng/AllLTTngTests.java (working copy) >@@ -3,6 +3,7 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > >+import org.eclipse.linuxtools.lttng.analysis.analyser.test.AnalysisTests; > import org.eclipse.linuxtools.lttng.control.LTTngSyntheticEventProviderTest; > import org.eclipse.linuxtools.lttng.model.LTTngTreeNodeTest; > import org.eclipse.linuxtools.lttng.state.resource.LTTngStateResourceTest; >@@ -45,6 +46,8 @@ > suite.addTestSuite(LTTngTreeNodeTest.class); > // suite.addTestSuite(StateExperimentManagerTextTest.class); > suite.addTestSuite(LTTngStateResourceTest.class); >+ >+ suite.addTestSuite(AnalysisTests.class); > > //$JUnit-END$ > return suite; >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/test/AnalysisTests.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/test/AnalysisTests.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/test/AnalysisTests.java (revision 0) >@@ -0,0 +1,281 @@ >+package org.eclipse.linuxtools.lttng.analysis.analyser.test; >+ >+ >+import junit.framework.TestCase; >+import org.junit.After; >+import org.junit.Before; >+ >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher; >+import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.StackWrapper; >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.EventCountPerLatency; >+import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair; >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; >+ >+ >+/** >+ * Define the class test >+ * this class initialize the variables test in the setup() method, free all variables of data in tesrDown(), and >+ * define the preparation of each test, define also the case test, >+ * and finally execute all test cases in testGlobalAnalyser() method. >+ * >+ * @author Abdelhaq Saoudi >+ */ >+ >+public class AnalysisTests extends TestCase{ >+ >+ /** >+ * Variables for test >+ */ >+ >+ private LttngEvent eventAsked_1= null; >+ private LttngEvent eventAsked_2= null; >+ private LttngEvent newEvent = null; >+ private LttngEvent newEvent1 = null; >+ private static int matched = 0; >+ private static int processed = 0; >+ >+ private String key_1 = null; >+ private String key_2 = null; >+ private String type1 = null; >+ private String type2 = null; >+ private StackWrapper stw = null; >+ >+ private EventCountPerLatency ecpl= null; >+ private long minLatency = 10; >+ private long maxLatency = 30; >+ private int nbBar = 10; >+ private Pair<Integer,ChartPoint> pair; >+ private Pair<String,String> eventType; >+ >+ /** >+ * Constructor of the class test >+ */ >+ >+ public AnalysisTests(final String name){ >+ super(name); >+ >+ /** >+ * search all event and registration in the vector traceEvents >+ */ >+ RequestsEvents.getInstance().findEvents(); >+ } >+ >+ /** >+ * preparation for test of Event data received >+ */ >+ public void preparationtoTestDataEvent(){ >+ eventAsked_1 = RequestsEvents.traceEvents.elementAt(0); >+ eventAsked_2 = RequestsEvents.traceEvents.elementAt(1); >+ } >+ >+ /** >+ * preparation for test of EventMatcher class >+ */ >+ public void preparationtoTestProcess(){ >+ //eventAsked_1 = RequestsEvents.traceEvents.elementAt(0); >+ //eventAsked_2 = RequestsEvents.traceEvents.elementAt(1); >+ newEvent = EventMatcher.getInstance().process(eventAsked_1); >+ newEvent1 = EventMatcher.getInstance().process(eventAsked_2); >+ processed = EventMatcher.getInstance().getNBProcessedEvents(); >+ matched = EventMatcher.getInstance().getNBMatchedEvents(); >+ } >+ >+ /** >+ * preparation to test of clearStack method in EventMatcher class. >+ */ >+ public void preparationtoTestClearStack(){ >+ EventMatcher.getInstance().clearStack(); >+ } >+ >+ /** >+ * preparation for test of stackWrraper class >+ */ >+ public void preparationtoTestStack(){ >+ //eventAsked_1 = RequestsEvents.traceEvents.elementAt(0); >+ //eventAsked_2 = RequestsEvents.traceEvents.elementAt(1); >+ key_1 = eventAsked_1.getMarkerName(); >+ key_2 = eventAsked_2.getMarkerName(); >+ stw = new StackWrapper(); >+ int size = RequestsEvents.traceEvents.size(); >+ >+ // for all requests event, we put it in the stack. >+ for(int i = 0 ; i < size -1; i++) >+ stw.put(RequestsEvents.traceEvents.elementAt(i)); >+ } >+ >+ /** >+ * preparation for test of EventCountPerLatency class >+ */ >+ public void preparationtoTestEventCountPerLatency(){ >+ ecpl = new EventCountPerLatency(); >+ ecpl.generateStandardLatencies(minLatency, maxLatency, nbBar); >+ pair = ecpl.updateStandardCounter(18); >+ } >+ >+ /** >+ * preparation for test of Pair class >+ */ >+ public void preparationtoTestPairClass(){ >+ eventType = new Pair<String, String>(eventAsked_1.getMarkerName(), eventAsked_2.getMarkerName()); >+ type1 = eventAsked_1.getMarkerName(); >+ type2 = eventAsked_2.getMarkerName(); >+ } >+ /** >+ * this method let us to initializes the variables. >+ * */ >+ @Before >+ public void setUp() throws Exception { >+ super.setUp(); >+ preparationtoTestDataEvent(); >+ preparationtoTestProcess(); >+ preparationtoTestStack(); >+ preparationtoTestEventCountPerLatency(); >+ preparationtoTestPairClass(); >+ } >+ >+ /** >+ * this method let us to free the variables. >+ * */ >+ @After >+ public void tearDown() throws Exception { >+ super.setUp(); >+ eventAsked_1 = null; >+ eventAsked_2 = null; >+ newEvent = null; >+ newEvent1= null; >+ stw = null; >+ ecpl = null; >+ pair = null; >+ eventType = null; >+ } >+ >+ /** >+ * test the data of event >+ */ >+ public void EventDataTestT0() { >+ System.out.println("test T0 of good data event"); >+ //System.out.println("ev 1 : " + eventAsked_1); >+ //System.out.println("ev 2 : " + eventAsked_2); >+ assertEquals(0|1, eventAsked_1.getCpuId()); >+ assertEquals(0|1, eventAsked_2.getCpuId()); >+ assertNotSame(eventAsked_1.getTimestamp().getValue(), eventAsked_2.getTimestamp().getValue()); >+ assertNotSame(eventAsked_1.getContent(), eventAsked_2.getContent()); >+ assertNotSame(eventAsked_1.getMarkerName(), eventAsked_2.getMarkerName()); >+ assertNotSame(eventAsked_1, eventAsked_2); >+ } >+ >+ >+ public void EventDataTestT1() { >+ System.out.println("test T1 of errone data event"); >+ assertNotSame("not exist marker",eventAsked_1.getMarkerName()); >+ assertNotSame("not exist marker",eventAsked_2.getMarkerName()); >+ assertNotSame(1345679853422L ,eventAsked_1.getTimestamp().getValue()); >+ assertNotSame(1345679853422L ,eventAsked_2.getTimestamp().getValue()); >+ } >+ >+ /** >+ * test process() method of EventMacher class >+ */ >+ >+ public void EventMatcherProcessTestT10() { >+ System.out.println("test T10 of good process method"); >+ assertEquals(2,processed); >+ assertNotNull(matched); >+ >+ } >+ public void EventMatcherProcessTestT11() { >+ System.out.println("test T11 of errone process method"); >+ assertNotSame(3,processed); >+ assertNotSame(3,matched); >+ } >+ >+ >+ public void EventMatcherClearStackTestT101() { >+ System.out.println("test T101 of good clear Stack methode"); >+ preparationtoTestClearStack(); >+ assertSame(0,EventMatcher.getInstance().getNBProcessedEvents()); >+ assertSame(0,EventMatcher.getInstance().getNBMatchedEvents()); >+ } >+ >+ >+ /** >+ * test the key of event in the stack WRraper. >+ */ >+ public void StackTestT13() { >+ System.out.println("test T13 of errone content stack"); >+ assertTrue(stw.containsKey(key_2)); >+ stw.removeEvent(key_2, eventAsked_2); >+ assertFalse(stw.containsKey(key_2)); >+ } >+ >+ >+ /** >+ * test of EventCounterPerLatency. >+ */ >+ >+ public void GetStandardLatencyTestT14() { >+ System.out.println("test T14 of good event counter"); >+ for(int i = 0; i < ecpl.getStandardLatencies().length; i++) >+ System.out.println(ecpl.getStandardLatencies()[i]); >+ //System.out.println(pair.getFirst()); >+ assertSame(4, pair.getFirst()); >+ assertEquals(nbBar + 1, ecpl.getStandardLatencies().length); >+ >+ } >+ >+ public void GetStandardLatencyTestT15() { >+ System.out.println("test T15 of errone event counter"); >+ assertNotSame(0&1&2&3&5&6&7&8&9&10, pair.getFirst()); >+ assertNotSame(20, ecpl.getStandardLatencies().length); >+ >+ } >+ >+ >+ /** >+ * test of Pair Class. >+ */ >+ public void PairTestT16() { >+ System.out.println(" test T16 for good job of Pair"); >+ assertEquals(type1, eventType.getFirst()); >+ assertEquals(type2, eventType.getSecond()); >+ assertNotSame(eventType.getFirst(), eventType.getSecond()); >+ assertNotNull(eventType.hashCode()); >+ assertFalse(eventType.equals(pair)); >+ assertTrue(eventType.equals(eventType)); >+ } >+ >+ >+ public void PairTestT17() { >+ System.out.println("test T17 for errone job of Pair "); >+ assertNotSame(type1, eventType.getSecond()); >+ assertNotSame(type2, eventType.getFirst()); >+ assertNotSame("event", eventType.getFirst()); >+ assertNotSame("something", eventType.getSecond()); >+ assertNotSame(0,eventType.hashCode()); >+ assertNotSame("OBJECT",eventType.equals(pair)); >+ } >+ >+ /** >+ * this method execute all test cases, >+ * >+ * because, if we start the test individual and number of test upper than one, >+ * we have the error message in the console " ** (process: number): DEBUG (recursed) " >+ * >+ */ >+ public void testGlobalAnalyser(){ >+ EventDataTestT0(); >+ EventDataTestT1(); >+ EventMatcherProcessTestT10(); >+ EventMatcherProcessTestT11(); >+ EventMatcherClearStackTestT101(); >+ StackTestT13(); >+ GetStandardLatencyTestT14(); >+ GetStandardLatencyTestT15(); >+ PairTestT16(); >+ PairTestT17(); >+ } >+} >+ >+ >+ >Index: src/org/eclipse/linuxtools/lttng/analysis/analyser/test/RequestsEvents.java >=================================================================== >--- src/org/eclipse/linuxtools/lttng/analysis/analyser/test/RequestsEvents.java (revision 0) >+++ src/org/eclipse/linuxtools/lttng/analysis/analyser/test/RequestsEvents.java (revision 0) >@@ -0,0 +1,92 @@ >+package org.eclipse.linuxtools.lttng.analysis.analyser.test; >+ >+import java.util.Vector; >+ >+import org.eclipse.linuxtools.lttng.analysis.facade.DataHandler; >+import org.eclipse.linuxtools.lttng.analysis.facade.TraceFacade; >+import org.eclipse.linuxtools.lttng.event.LttngEvent; >+import org.eclipse.linuxtools.lttng.trace.LTTngTrace; >+import org.eclipse.linuxtools.tmf.event.TmfTimeRange; >+import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; >+import org.eclipse.linuxtools.tmf.trace.ITmfTrace; >+ >+ >+/** >+ * this class find all event from TMF by Trace Facade, >+ * and register it in the static Vector traceEvents. >+ * >+ * @author Abdelhaq Saoudi >+ */ >+ >+public class RequestsEvents extends DataHandler { >+ >+ /** >+ * (class implemented as Singleton). >+ */ >+ >+ private static RequestsEvents instance_ = null; >+ >+ >+ private RequestsEvents() { } >+ >+ public static RequestsEvents getInstance() { >+ if (instance_ == null) >+ instance_ = new RequestsEvents(); >+ return instance_; >+ } >+ >+ >+ private final String TRACE_PATH = "/home/l3819/Bureau/traces/trace_0"; >+ >+ public static Vector<LttngEvent> traceEvents = new Vector<LttngEvent>(); >+ >+ private TmfExperiment<LttngEvent> experiment = null; >+ >+ private TmfTimeRange timeRange = null; >+ >+ /** >+ * this method findEvent() retrieves all event fromTMF by traceFacade, the received event pass in the handler "this" >+ */ >+ public void findEvents(){ >+ >+ try { >+ ITmfTrace[] traces = new ITmfTrace[1]; >+ traces[0] = new LTTngTrace(TRACE_PATH); >+ >+ // Create our new experiment >+ experiment = new TmfExperiment<LttngEvent>(LttngEvent.class, "firstExperiment", traces); >+ //long x=experiment.getStartTime().getValue(); >+ //long y=experiment.getEndTime().getValue(); >+ //System.out.println("valeur de x: "+ x +" y: "+ y +"y-x :"+ (y-x)); >+ timeRange = experiment.getTimeRange(); >+ TraceFacade.getInstance().getAllEvents(experiment, timeRange, this); >+ } >+ >+ catch (NullPointerException e) { >+ } >+ catch (Exception e) { >+ e.printStackTrace(); >+ } >+ >+ } >+ >+ /** >+ * this handler register the event in the vector. >+ */ >+ public void handleData(LttngEvent event) { >+ //System.out.println("start handler"); >+ traceEvents.add(event.clone()); >+ } >+ >+ /** >+ * Forward completion notification to the handler. >+ */ >+ public void handleCompleted() { >+ >+ } >+ >+ >+} >+ >+ >+ >Index: .classpath >=================================================================== >--- .classpath (revision 27081) >+++ .classpath (working copy) >@@ -3,5 +3,6 @@ > <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> > <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> > <classpathentry kind="src" path="src"/> >+ <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.linuxtools.lttng.ui"/> > <classpathentry kind="output" path="bin"/> > </classpath>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 331467
:
184440
|
185278
|
185279
|
201090
|
201276
|
201280
|
209983