public static String TmfTimeGraphViewer_FollowArrowBackwardActionNameText;
public static String TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText;
+ public static String Utils_ClockCyclesUnit;
+
public static String ColorsView_AddActionToolTipText;
public static String ColorsView_BackgroundButtonText;
public static String ColorsView_BackgroundDialogText;
TmfTimeGraphViewer_FollowArrowBackwardActionNameText=Follow Arrow Backward
TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText=Follow Arrow Backward
+Utils_ClockCyclesUnit=\u0020cc
+
# org.eclipse.linuxtools.tmf.ui.views.colors
ColorsView_AddActionToolTipText=Insert new color setting
ColorsView_BackgroundButtonText=BG
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeDataProviderCyclesConverter;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;
private static final int DEFAULT_HEIGHT = 22;
private static final long RECENTERING_MARGIN_FACTOR = 50;
private static final String HIDE_ARROWS_KEY = "hide.arrows"; //$NON-NLS-1$
+ private static final long DEFAULT_FREQUENCY = 1000000000L;
private long fMinTimeInterval;
private ITimeGraphEntry fSelectedEntry;
private Object fInputElement;
private ITimeGraphContentProvider fTimeGraphContentProvider;
private ITimeGraphPresentationProvider fTimeGraphProvider;
+ private ITimeDataProvider fTimeDataProvider = this;
+ private TimeGraphTooltipHandler fToolTipHandler;
private List<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<>();
private List<ITimeGraphTimeListener> fTimeListeners = new ArrayList<>();
private List<ITimeGraphRangeListener> fRangeListeners = new ArrayList<>();
- // Time format, using Epoch reference, Relative time format(default) or
- // Number
+ // Time format, using Epoch reference, Relative time format(default),
+ // Number, or Cycles
private TimeFormat fTimeFormat = TimeFormat.RELATIVE;
+ // Clock frequency to use for Cycles time format
+ private long fClockFrequency = DEFAULT_FREQUENCY;
private int fBorderWidth = 0;
private int fTimeScaleHeight = DEFAULT_HEIGHT;
public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {
fTimeGraphProvider = timeGraphProvider;
fTimeGraphCtrl.setTimeGraphProvider(timeGraphProvider);
- TimeGraphTooltipHandler toolTipHandler = new TimeGraphTooltipHandler(fTimeGraphProvider, this);
- toolTipHandler.activateHoverHelp(fTimeGraphCtrl);
+ fToolTipHandler = new TimeGraphTooltipHandler(fTimeGraphProvider, fTimeDataProvider);
+ fToolTipHandler.activateHoverHelp(fTimeGraphCtrl);
}
/**
fDataViewer.setLayout(gl);
fTimeScaleCtrl = new TimeGraphScale(fDataViewer, fColorScheme);
- fTimeScaleCtrl.setTimeProvider(this);
+ fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
fTimeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
fTimeScaleCtrl.setHeight(fTimeScaleHeight);
*/
public void setTimeFormat(TimeFormat tf) {
this.fTimeFormat = tf;
+ if (tf == TimeFormat.CYCLES) {
+ fTimeDataProvider = new TimeDataProviderCyclesConverter(this, fClockFrequency);
+ } else {
+ fTimeDataProvider = this;
+ }
+ fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
+ if (fToolTipHandler != null) {
+ fToolTipHandler.setTimeProvider(fTimeDataProvider);
+ }
+ }
+
+ /**
+ * Sets the clock frequency. Used when the time format is set to CYCLES.
+ *
+ * @param clockFrequency
+ * the clock frequency in Hz
+ * @since 3.1
+ */
+ public void setClockFrequency(long clockFrequency) {
+ fClockFrequency = clockFrequency;
+ if (fTimeFormat == TimeFormat.CYCLES) {
+ fTimeDataProvider = new TimeDataProviderCyclesConverter(this, fClockFrequency);
+ fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
+ if (fToolTipHandler != null) {
+ fToolTipHandler.setTimeProvider(fTimeDataProvider);
+ }
+ }
}
/**
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 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:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+/**
+ * Time data provider that converts between time data units used internally and
+ * time in display units used by the caller.
+ *
+ * @since 3.1
+ */
+public interface ITimeDataProviderConverter extends ITimeDataProvider {
+
+ /**
+ * Convert a time in time data provider units to a time in display units.
+ *
+ * @param time the time in time data provider units
+ *
+ * @return the time in display units
+ */
+ long convertTime(long time);
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 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:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
+
+/**
+ * Time Data Provider wrapper that converts nanoseconds to cycles.
+ *
+ * The user of the wrapper uses cycles, the wrapped provider uses nanoseconds.
+ * @since 3.1
+ *
+ */
+public class TimeDataProviderCyclesConverter implements ITimeDataProviderConverter {
+
+ private static final long GIGAHERTZ = 1000000000L;
+
+ private final @NonNull ITimeDataProvider fProvider;
+ private final long fFreq;
+
+ /**
+ * Constructor
+ *
+ * @param provider
+ * the original time data provider
+ * @param clockFrequency
+ * the clock frequency in Hz
+ */
+ public TimeDataProviderCyclesConverter(@NonNull ITimeDataProvider provider, long clockFrequency) {
+ fProvider = provider;
+ fFreq = clockFrequency;
+ }
+
+ /**
+ * Convert nanoseconds to cycles
+ *
+ * @param nanos
+ * time in nanoseconds
+ * @return time in cycles
+ */
+ public long toCycles(long nanos) {
+ return Math.round(nanos * ((double) fFreq / GIGAHERTZ));
+ }
+
+ /**
+ * Convert cycles to nanoseconds
+ *
+ * @param cycles
+ * time in cycles
+ * @return time in nanoseconds
+ */
+ public long toNanos(long cycles) {
+ return Math.round(cycles * ((double) GIGAHERTZ / fFreq));
+ }
+
+ @Override
+ public long convertTime(long time) {
+ return toCycles(time);
+ }
+
+ @Override
+ public void setSelectionRangeNotify(long beginTime, long endTime) {
+ fProvider.setSelectionRangeNotify(toNanos(beginTime), toNanos(endTime));
+ }
+
+ @Override
+ public void setSelectionRange(long beginTime, long endTime) {
+ fProvider.setSelectionRange(toNanos(beginTime), toNanos(endTime));
+ }
+
+ @Override
+ public long getSelectionBegin() {
+ return toCycles(fProvider.getSelectionBegin());
+ }
+
+ @Override
+ public long getSelectionEnd() {
+ return toCycles(fProvider.getSelectionEnd());
+ }
+
+ @Override
+ public long getBeginTime() {
+ return toCycles(fProvider.getBeginTime());
+ }
+
+ @Override
+ public long getEndTime() {
+ return toCycles(fProvider.getEndTime());
+ }
+
+ @Override
+ public long getMinTime() {
+ return toCycles(fProvider.getMinTime());
+ }
+
+ @Override
+ public long getMaxTime() {
+ return toCycles(fProvider.getMaxTime());
+ }
+
+ @Override
+ public long getTime0() {
+ return toCycles(fProvider.getTime0());
+ }
+
+ @Override
+ public long getTime1() {
+ return toCycles(fProvider.getTime1());
+ }
+
+ @Override
+ public long getMinTimeInterval() {
+ // do not convert: this is in integer units
+ return fProvider.getMinTimeInterval();
+ }
+
+ @Override
+ public void setStartFinishTimeNotify(long time0, long time1) {
+ fProvider.setStartFinishTimeNotify(toNanos(time0), toNanos(time1));
+ }
+
+ @Override
+ public void setStartFinishTime(long time0, long time1) {
+ fProvider.setStartFinishTime(toNanos(time0), toNanos(time1));
+ }
+
+ @Override
+ public void notifyStartFinishTime() {
+ fProvider.notifyStartFinishTime();
+ }
+
+ @Override
+ public void setSelectedTimeNotify(long time, boolean ensureVisible) {
+ fProvider.setSelectedTimeNotify(toNanos(time), ensureVisible);
+ }
+
+ @Override
+ public void setSelectedTime(long time, boolean ensureVisible) {
+ fProvider.setSelectedTime(toNanos(time), ensureVisible);
+ }
+
+ @Override
+ public void resetStartFinishTime() {
+ fProvider.resetStartFinishTime();
+ }
+
+ @Override
+ public int getNameSpace() {
+ return fProvider.getNameSpace();
+ }
+
+ @Override
+ public void setNameSpace(int width) {
+ fProvider.setNameSpace(width);
+ }
+
+ @Override
+ public int getTimeSpace() {
+ return fProvider.getTimeSpace();
+ }
+
+ @Override
+ public TimeFormat getTimeFormat() {
+ return fProvider.getTimeFormat();
+ }
+
+}
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfNanoTimestamp;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampDelta;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphColorListener;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
}
private void updateStatusLine(int x) {
- if (fStatusLineManager == null || null == fTimeProvider ||
- fTimeProvider.getTime0() == fTimeProvider.getTime1()) {
+ // use the time provider of the time graph scale for the status line
+ ITimeDataProvider tdp = fTimeGraphScale.getTimeProvider();
+ if (fStatusLineManager == null || null == tdp ||
+ tdp.getTime0() == tdp.getTime1()) {
return;
}
+ TimeFormat tf = tdp.getTimeFormat();
+ Resolution res = Resolution.NANOSEC;
StringBuilder message = new StringBuilder();
if (x >= 0 && fDragState == DRAG_NONE) {
long time = getTimeAtX(x);
if (time >= 0) {
- message.append("T: "); //$NON-NLS-1$
- message.append(new TmfNanoTimestamp(time).toString());
- message.append(" T1: "); //$NON-NLS-1$
- long selectionBegin = fTimeProvider.getSelectionBegin();
- long selectionEnd = fTimeProvider.getSelectionEnd();
- message.append(new TmfNanoTimestamp(Math.min(selectionBegin, selectionEnd)).toString());
+ if (tdp instanceof ITimeDataProviderConverter) {
+ time = ((ITimeDataProviderConverter) tdp).convertTime(time);
+ }
+ long selectionBegin = tdp.getSelectionBegin();
+ long selectionEnd = tdp.getSelectionEnd();
+ message.append(NLS.bind("T: {0}{1} T1: {2}{3}", //$NON-NLS-1$
+ new Object[] {
+ tf == TimeFormat.CALENDAR ? Utils.formatDate(time) + ' ' : "", //$NON-NLS-1$
+ Utils.formatTime(time, tf, res),
+ tf == TimeFormat.CALENDAR ? Utils.formatDate(Math.min(selectionBegin, selectionEnd)) + ' ' : "", //$NON-NLS-1$
+ Utils.formatTime(Math.min(selectionBegin, selectionEnd), tf, res)
+ }));
if (selectionBegin != selectionEnd) {
- message.append(" T2: "); //$NON-NLS-1$
- message.append(new TmfNanoTimestamp(Math.max(selectionBegin, selectionEnd)).toString());
- message.append(" \u0394: "); //$NON-NLS-1$
- message.append(new TmfTimestampDelta(Math.abs(selectionBegin - selectionEnd), ITmfTimestamp.NANOSECOND_SCALE));
+ message.append(NLS.bind(" T2: {0}{1} \u0394: {2}", //$NON-NLS-1$
+ new Object[] {
+ tf == TimeFormat.CALENDAR ? Utils.formatDate(Math.max(selectionBegin, selectionEnd)) + ' ' : "", //$NON-NLS-1$
+ Utils.formatTime(Math.max(selectionBegin, selectionEnd), tf, res),
+ Utils.formatDelta(Math.abs(selectionBegin - selectionEnd), tf, res)
+ }));
}
}
} else if (fDragState == DRAG_SELECTION || fDragState == DRAG_ZOOM) {
long time0 = fDragTime0;
long time = getTimeAtX(fDragX);
- message.append("T1: "); //$NON-NLS-1$
- message.append(new TmfNanoTimestamp(Math.min(time, time0)).toString());
- if (time != time0) {
- message.append(" T2: "); //$NON-NLS-1$
- message.append(new TmfNanoTimestamp(Math.max(time, time0)).toString());
- message.append(" \u0394: "); //$NON-NLS-1$
- message.append(new TmfTimestampDelta(Math.abs(time - time0), ITmfTimestamp.NANOSECOND_SCALE));
- }
+ if (tdp instanceof ITimeDataProviderConverter) {
+ time0 = ((ITimeDataProviderConverter) tdp).convertTime(time0);
+ time = ((ITimeDataProviderConverter) tdp).convertTime(time);
+ }
+ message.append(NLS.bind("T1: {0}{1} T2: {2}{3} \u0394: {4}", //$NON-NLS-1$
+ new Object[] {
+ tf == TimeFormat.CALENDAR ? Utils.formatDate(Math.min(time, time0)) + ' ' : "", //$NON-NLS-1$
+ Utils.formatTime(Math.min(time, time0), tf, res),
+ tf == TimeFormat.CALENDAR ? Utils.formatDate(Math.max(time, time0)) + ' ' : "", //$NON-NLS-1$
+ Utils.formatTime(Math.max(time, time0), tf, res),
+ Utils.formatDelta(Math.abs(time - time0), tf, res)
+ }));
}
fStatusLineManager.setMessage(message.toString());
}
setCapture(true);
fDragX = Math.min(Math.max(e.x, fTimeProvider.getNameSpace()), getCtrlSize().x - RIGHT_MARGIN);
fDragX0 = fDragX;
+ fDragTime0 = getTimeAtX(fDragX0);
fDragState = DRAG_ZOOM;
fDragButton = e.button;
redraw();
import java.util.Date;
import java.util.TimeZone;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
private static final TimeDraw TIMEDRAW_ABS_MONTH = new TimeDrawAbsMonth();
private static final TimeDraw TIMEDRAW_ABS_YEAR = new TimeDrawAbsYear();
private static final TimeDraw TIMEDRAW_NUMBER = new TimeDrawNumber();
+ private static final TimeDraw TIMEDRAW_CYCLES = new TimeDrawCycles();
private static final int DRAG_EXTERNAL = -1;
private static final int NO_BUTTON = 0;
fTimeProvider = timeProvider;
}
+ /**
+ * Get the time provider used by this scale
+ *
+ * @return The time provider
+ * @since 3.1
+ */
+ public ITimeDataProvider getTimeProvider() {
+ return fTimeProvider;
+ }
+
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(wHint, fHeight, changed);
long timeDelta;
double minDelta = (pixelsPerNanoSec == 0) ? YEAR_IN_NS : width / pixelsPerNanoSec;
long unit = 1;
- if (fTimeProvider != null && fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider != null && fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
if (minDelta > 6 * MONTH_IN_NS) {
unit = YEAR_IN_NS;
} else if (minDelta > 3 * MONTH_IN_NS) {
TimeDraw getTimeDraw(long timeDelta) {
TimeDraw timeDraw;
if (fTimeProvider != null) {
-
- if (fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
+ switch (fTimeProvider.getTimeFormat()) {
+ case CALENDAR:
if (timeDelta >= YEAR_IN_NS) {
timeDraw = TIMEDRAW_ABS_YEAR;
} else if (timeDelta >= MONTH_IN_NS) {
timeDraw = TIMEDRAW_ABS_NANOSEC;
}
return timeDraw;
- } else if (fTimeProvider.getTimeFormat() == TimeFormat.NUMBER) {
- timeDraw = TIMEDRAW_NUMBER;
- return timeDraw;
+ case NUMBER:
+ return TIMEDRAW_NUMBER;
+ case CYCLES:
+ return TIMEDRAW_CYCLES;
+ case RELATIVE:
+ default:
}
}
rect0.width = labelWidth;
long time;
- if (fTimeProvider != null && fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider != null && fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
time = floorToCalendar(time0, timeDelta);
} else {
time = (time0 / timeDelta) * timeDelta;
int y = rect0.y + rect0.height;
- if (fTimeProvider != null && fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider != null && fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
timeDraw.drawAbsHeader(gc, time, absHeaderRect);
}
if (pixelsPerNanoSec == 0 || time > Long.MAX_VALUE - timeDelta || timeDelta == 0) {
break;
}
- if (fTimeProvider != null && fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider != null && fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
if (timeDelta >= YEAR_IN_NS) {
long millis = time / MILLISEC_IN_NS;
GREGORIAN_CALENDAR.setTime(new Date(millis));
int numDigits = 5;
long timeRange = time1 - time0;
- if (fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
// Calculate the number of digits to represent the minutes provided
// 11:222
// HH:mm:ss
int thousandGroups = (numDigits - 1) / 3;
numDigits += thousandGroups;
numDigits += 12; // .000 000 000
+ if (fTimeProvider.getTimeFormat() == TimeFormat.CYCLES) {
+ numDigits += Messages.Utils_ClockCyclesUnit.length();
+ }
}
return numDigits;
return s + n;
}
- public abstract void draw(GC gc, long time, Rectangle rect);
+ public abstract int draw(GC gc, long time, Rectangle rect);
/**
* Override to draw absolute time header. This is for the time information
class TimeDrawSec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
long sec = nanosec / SEC_IN_NS;
- Utils.drawText(gc, sep(sec), rect, true);
+ return Utils.drawText(gc, sep(sec), rect, true);
}
}
class TimeDrawMillisec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
long millisec = nanosec / MILLISEC_IN_NS;
long ms = millisec % PAD_1000;
long sec = millisec / SEC_IN_MS;
- Utils.drawText(gc, sep(sec) + "." + pad(ms), rect, true); //$NON-NLS-1$
+ return Utils.drawText(gc, sep(sec) + "." + pad(ms), rect, true); //$NON-NLS-1$
}
}
class TimeDrawMicrosec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
long microsec = nanosec / MICROSEC_IN_NS;
long us = microsec % PAD_1000;
long millisec = microsec / MILLISEC_IN_US;
long ms = millisec % PAD_1000;
long sec = millisec / SEC_IN_MS;
- Utils.drawText(gc, sep(sec) + "." + pad(ms) + " " + pad(us), rect, true); //$NON-NLS-1$ //$NON-NLS-2$
+ return Utils.drawText(gc, sep(sec) + "." + pad(ms) + " " + pad(us), rect, true); //$NON-NLS-1$ //$NON-NLS-2$
}
}
class TimeDrawNanosec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
long ns = nanosec % PAD_1000;
long microsec = nanosec / MICROSEC_IN_NS;
long us = microsec % PAD_1000;
long millisec = microsec / MILLISEC_IN_US;
long ms = millisec % PAD_1000;
long sec = millisec / SEC_IN_MS;
- Utils.drawText(gc, sep(sec) + "." + pad(ms) + " " + pad(us) + " " + pad(ns), rect, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return Utils.drawText(gc, sep(sec) + "." + pad(ms) + " " + pad(us) + " " + pad(ns), rect, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
class TimeDrawAbsYear extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = YEAR_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
}
class TimeDrawAbsMonth extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = MONTH_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
}
class TimeDrawAbsDay extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = DAY_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
@Override
class TimeDrawAbsHrs extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = HOURS_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
@Override
class TimeDrawAbsMin extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = MIN_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
@Override
class TimeDrawAbsSec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = SEC_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
@Override
class TimeDrawAbsMillisec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = SEC_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
String ns = Utils.formatNs(nanosec, Resolution.MILLISEC);
-
- Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
+ return Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
}
@Override
class TimeDrawAbsMicroSec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = SEC_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
String micr = Utils.formatNs(nanosec, Resolution.MICROSEC);
- Utils.drawText(gc, stime + "." + micr, rect, true); //$NON-NLS-1$
+ return Utils.drawText(gc, stime + "." + micr, rect, true); //$NON-NLS-1$
}
@Override
class TimeDrawAbsNanoSec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = SEC_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
String ns = Utils.formatNs(nanosec, Resolution.NANOSEC);
- Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
+ return Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
}
@Override
class TimeDrawNumber extends TimeDraw {
@Override
- public void draw(GC gc, long time, Rectangle rect) {
+ public int draw(GC gc, long time, Rectangle rect) {
String stime = NumberFormat.getInstance().format(time);
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
+ }
+}
+
+class TimeDrawCycles extends TimeDraw {
+ @Override
+ public int draw(GC gc, long time, Rectangle rect) {
+ String stime = Utils.formatTime(time, TimeFormat.CYCLES, Resolution.SECONDS);
+ return Utils.drawText(gc, stime, rect, true);
}
}
/*****************************************************************************
- * Copyright (c) 2007, 2013 Intel Corporation, Ericsson
+ * Copyright (c) 2007, 2014 Intel Corporation, 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
private Shell fTipShell;
private Composite fTipComposite;
- private final ITimeDataProvider fTimeDataProvider;
+ private ITimeDataProvider fTimeDataProvider;
private ITimeGraphPresentationProvider fTimeGraphProvider = null;
/**
this.fTimeDataProvider = timeProv;
}
+ /**
+ * Set the time data provider
+ *
+ * @param timeDataProvider
+ * The time data provider
+ *
+ * @since 3.1
+ */
+ public void setTimeProvider(ITimeDataProvider timeDataProvider) {
+ fTimeDataProvider = timeDataProvider;
+ }
+
private void createTooltipShell(Shell parent) {
final Display display = parent.getDisplay();
if (fTipShell != null && ! fTipShell.isDisposed()) {
Resolution res = Resolution.NANOSEC;
TimeFormat tf = fTimeDataProvider.getTimeFormat();
+ String startTime = "?"; //$NON-NLS-1$
+ String duration = "?"; //$NON-NLS-1$
+ String endTime = "?"; //$NON-NLS-1$
+ if (fTimeDataProvider instanceof ITimeDataProviderConverter) {
+ ITimeDataProviderConverter tdp = (ITimeDataProviderConverter) fTimeDataProvider;
+ if (eventStartTime > -1) {
+ eventStartTime = tdp.convertTime(eventStartTime);
+ startTime = Utils.formatTime(eventStartTime, tf, res);
+ }
+ if (eventEndTime > -1) {
+ eventEndTime = tdp.convertTime(eventEndTime);
+ endTime = Utils.formatTime(eventEndTime, tf, res);
+ }
+ if (eventDuration > -1) {
+ duration = Utils.formatDelta(eventEndTime - eventStartTime, tf, res);
+ }
+ } else {
+ if (eventStartTime > -1) {
+ startTime = Utils.formatTime(eventStartTime, tf, res);
+ }
+ if (eventEndTime > -1) {
+ endTime = Utils.formatTime(eventEndTime, tf, res);
+ }
+ if (eventDuration > -1) {
+ duration = Utils.formatDelta(eventDuration, tf, res);
+ }
+ }
if (tf == TimeFormat.CALENDAR) {
- addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ?
- Utils.formatDate(eventStartTime)
- : "?"); //$NON-NLS-1$
+ addItem(Messages.TmfTimeTipHandler_TRACE_DATE,
+ eventStartTime > -1 ? Utils.formatDate(eventStartTime) : "?"); //$NON-NLS-1$
}
if (eventDuration > 0) {
- addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ?
- Utils.formatTime(eventStartTime, tf, res)
- : "?"); //$NON-NLS-1$
-
- addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ?
- Utils.formatTime(eventEndTime, tf, res)
- : "?"); //$NON-NLS-1$
+ addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, startTime);
+ addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, endTime);
} else {
- addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ?
- Utils.formatTime(eventStartTime, tf, res)
- : "?"); //$NON-NLS-1$
+ addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, startTime);
}
if (eventDuration > 0) {
- // Duration in relative format in any case
- if (tf == TimeFormat.CALENDAR) {
- tf = TimeFormat.RELATIVE;
- }
- addItem(Messages.TmfTimeTipHandler_DURATION, eventDuration > -1 ?
- Utils.formatTime(eventDuration, tf, res)
- : "?"); //$NON-NLS-1$
+ addItem(Messages.TmfTimeTipHandler_DURATION, duration);
}
}
}
long sourceTime = linkEvent.getTime();
long duration = linkEvent.getDuration();
long targetTime = sourceTime + duration;
-
+ if (fTimeDataProvider instanceof ITimeDataProviderConverter) {
+ ITimeDataProviderConverter tdp = (ITimeDataProviderConverter) fTimeDataProvider;
+ sourceTime = tdp.convertTime(sourceTime);
+ targetTime = tdp.convertTime(targetTime);
+ duration = targetTime - sourceTime;
+ }
Resolution res = Resolution.NANOSEC;
TimeFormat tf = fTimeDataProvider.getTimeFormat();
if (tf == TimeFormat.CALENDAR) {
if (duration > 0) {
addItem(Messages.TmfTimeTipHandler_LINK_SOURCE_TIME, Utils.formatTime(sourceTime, tf, res));
addItem(Messages.TmfTimeTipHandler_LINK_TARGET_TIME, Utils.formatTime(targetTime, tf, res));
- // Duration in relative format in any case
- if (tf == TimeFormat.CALENDAR) {
- tf = TimeFormat.RELATIVE;
- }
- addItem(Messages.TmfTimeTipHandler_DURATION, Utils.formatTime(duration, tf, res));
+ addItem(Messages.TmfTimeTipHandler_DURATION, Utils.formatDelta(duration, tf, res));
} else {
addItem(Messages.TmfTimeTipHandler_LINK_TIME, Utils.formatTime(sourceTime, tf, res));
}
/*****************************************************************************
- * Copyright (c) 2007, 2013 Intel Corporation, Ericsson
+ * Copyright (c) 2007, 2014 Intel Corporation, 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
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimePreferences;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
* @since 2.0
*/
NUMBER,
+
+ /**
+ * Timestamp displayed as cycles
+ * @since 3.1
+ */
+ CYCLES
}
/**
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
+ private static final long HOURS_PER_DAY = 24;
+ private static final long MIN_PER_HOUR = 60;
+ private static final long SEC_PER_MIN = 60;
private static final long SEC_IN_NS = 1000000000;
private static final long MILLISEC_IN_NS = 1000000;
* @param rect
* The rectangle object which is being drawn
* @param transp
- * Should we transpose the color
- * @return The X coordinate where we have written
+ * If true the background will be transparent
+ * @return The width of the written text
*/
public static int drawText(GC gc, String text, Rectangle rect, boolean transp) {
Point size = gc.stringExtent(text);
* @param y
* the Y coordinate of the starting point
* @param transp
- * Should we transpose the color
- * @return The X coordinate where we have written
+ * If true the background will be transparent
+ * @return The width of the written text
*/
public static int drawText(GC gc, String text, int x, int y, boolean transp) {
Point size = gc.stringExtent(text);
* @return the formatted time
*/
public static String formatTime(long time, TimeFormat format, Resolution resolution) {
- // if format is absolute (Calendar)
- if (format == TimeFormat.CALENDAR) {
+ switch (format) {
+ case CALENDAR:
return formatTimeAbs(time, resolution);
- } else if (format == TimeFormat.NUMBER) {
+ case NUMBER:
return NumberFormat.getInstance().format(time);
+ case CYCLES:
+ return NumberFormat.getInstance().format(time) + Messages.Utils_ClockCyclesUnit;
+ case RELATIVE:
+ default:
}
StringBuffer str = new StringBuffer();
return str.toString();
}
+ /**
+ * Formats time delta
+ *
+ * @param delta
+ * The time delta, in ns
+ * @param format
+ * The time format to use
+ * @param resolution
+ * The resolution to use
+ * @since 3.1
+ * @return the formatted time delta
+ */
+ public static String formatDelta(long delta, TimeFormat format, Resolution resolution) {
+ if (format == TimeFormat.CALENDAR) {
+ return formatDeltaAbs(delta, resolution);
+ }
+ return formatTime(delta, format, resolution);
+ }
+
+ /**
+ * Formats time delta in ns to Calendar format, only formatting the years,
+ * days, hours or minutes if necessary.
+ *
+ * @param delta
+ * The time delta, in ns
+ * @param resolution
+ * The resolution to use
+ * @return the formatted time delta
+ * @since 3.1
+ */
+ public static String formatDeltaAbs(long delta, Resolution resolution) {
+ StringBuffer str = new StringBuffer();
+ if (delta < 0) {
+ str.append('-');
+ }
+ long ns = Math.abs(delta);
+ long seconds = TimeUnit.NANOSECONDS.toSeconds(ns);
+ long minutes = TimeUnit.NANOSECONDS.toMinutes(ns);
+ long hours = TimeUnit.NANOSECONDS.toHours(ns);
+ long days = TimeUnit.NANOSECONDS.toDays(ns);
+ if (days > 0) {
+ str.append(days);
+ str.append("d "); //$NON-NLS-1$
+ }
+ if (hours > 0) {
+ str.append(hours % HOURS_PER_DAY);
+ str.append("h "); //$NON-NLS-1$
+ }
+ if (minutes > 0) {
+ str.append(minutes % MIN_PER_HOUR);
+ str.append("m "); //$NON-NLS-1$
+ }
+ str.append(seconds % SEC_PER_MIN);
+ str.append('.');
+ // append the ms, us and ns as specified in the resolution
+ str.append(formatNs(delta, resolution));
+ str.append("s"); //$NON-NLS-1$
+ return str.toString();
+ }
+
/**
* Obtains the remainder fraction on unit Seconds of the entered value in
* nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction