-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Comparator;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.NullProgressMonitor;\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IToolBarManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;\r
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;\r
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r
-import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;\r
-import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;\r
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;\r
-import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.ui.IActionBars;\r
-\r
-public class ResourcesView extends TmfView {\r
-\r
- // ------------------------------------------------------------------------\r
- // Constants\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * View ID.\r
- */\r
- public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$\r
-\r
- /**\r
- * Initial time range\r
- */\r
- private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec\r
-\r
- // ------------------------------------------------------------------------\r
- // Fields\r
- // ------------------------------------------------------------------------\r
-\r
- // The time graph viewer\r
- TimeGraphViewer fTimeGraphViewer;\r
-\r
- // The selected experiment\r
- private TmfExperiment<ITmfEvent> fSelectedExperiment;\r
-\r
- // The time graph entry list\r
- private ArrayList<TraceEntry> fEntryList;\r
-\r
- // The start time\r
- private long fStartTime;\r
-\r
- // The end time\r
- private long fEndTime;\r
-\r
- // The display width\r
- private int fDisplayWidth;\r
-\r
- // The next resource action\r
- private Action fNextResourceAction;\r
-\r
- // The previous resource action\r
- private Action fPreviousResourceAction;\r
-\r
- // The zoom thread\r
- private ZoomThread fZoomThread;\r
-\r
- // ------------------------------------------------------------------------\r
- // Classes\r
- // ------------------------------------------------------------------------\r
-\r
- private class TraceEntry implements ITimeGraphEntry {\r
- // The Trace\r
- private CtfKernelTrace fTrace;\r
- // The start time\r
- private long fTraceStartTime;\r
- // The end time\r
- private long fTraceEndTime; \r
- // The children of the entry\r
- private ArrayList<ResourcesEntry> fChildren;\r
- // The name of entry\r
- private String fName;\r
-\r
- public TraceEntry(CtfKernelTrace trace, String name, long startTime, long endTime) {\r
- fTrace = trace;\r
- fChildren = new ArrayList<ResourcesEntry>();\r
- fName = name;\r
- fTraceStartTime = startTime;\r
- fTraceEndTime = endTime;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getParent() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public boolean hasChildren() {\r
- return fChildren != null && fChildren.size() > 0;\r
- }\r
-\r
- @Override\r
- public ResourcesEntry[] getChildren() {\r
- return fChildren.toArray(new ResourcesEntry[0]);\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return fName;\r
- }\r
-\r
- @Override\r
- public long getStartTime() {\r
- return fTraceStartTime;\r
- }\r
-\r
- @Override\r
- public long getEndTime() {\r
- return fTraceEndTime;\r
- }\r
-\r
- @Override\r
- public boolean hasTimeEvents() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public Iterator<ITimeEvent> getTimeEventsIterator() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {\r
- return null;\r
- }\r
-\r
- public CtfKernelTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- public void addChild(ResourcesEntry entry) {\r
- int index;\r
- for (index = 0; index < fChildren.size(); index++) {\r
- ResourcesEntry other = fChildren.get(index);\r
- if (entry.getType().compareTo(other.getType()) < 0) {\r
- break;\r
- } else if (entry.getType().equals(other.getType())) {\r
- if (entry.getId() < other.getId()) {\r
- break;\r
- }\r
- }\r
- }\r
- entry.setParent(this);\r
- fChildren.add(index, entry);\r
- }\r
- }\r
- \r
- private static class TraceEntryComparator implements Comparator<ITimeGraphEntry> {\r
- @Override\r
- public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {\r
- int result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;\r
- if (result == 0) {\r
- result = o1.getName().compareTo(o2.getName());\r
- }\r
- return result;\r
- }\r
- }\r
-\r
- private class ZoomThread extends Thread {\r
- private long fZoomStartTime;\r
- private long fZoomEndTime;\r
- private IProgressMonitor fMonitor;\r
-\r
- public ZoomThread(long startTime, long endTime) {\r
- super("ResourcesView zoom"); //$NON-NLS-1$\r
- fZoomStartTime = startTime;\r
- fZoomEndTime = endTime;\r
- fMonitor = new NullProgressMonitor();\r
- }\r
-\r
- @Override\r
- public void run() {\r
- ArrayList<TraceEntry> entryList = fEntryList;\r
- if (entryList == null) {\r
- return;\r
- }\r
- long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);\r
- for (TraceEntry traceEntry : entryList) {\r
- for (ITimeGraphEntry child : traceEntry.getChildren()) {\r
- ResourcesEntry entry = (ResourcesEntry) child;\r
- if (fMonitor.isCanceled()) {\r
- break;\r
- }\r
- List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, resolution, true, fMonitor);\r
- if (fMonitor.isCanceled()) {\r
- break;\r
- }\r
- entry.setZoomedEventList(zoomedEventList);\r
- redraw();\r
- }\r
- }\r
- }\r
-\r
- public void cancel() {\r
- fMonitor.setCanceled(true);\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructors\r
- // ------------------------------------------------------------------------\r
-\r
- public ResourcesView() {\r
- super(ID);\r
- fDisplayWidth = Display.getDefault().getBounds().width;\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // ViewPart\r
- // ------------------------------------------------------------------------\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)\r
- */\r
- @Override\r
- public void createPartControl(Composite parent) {\r
- fTimeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);\r
-\r
- fTimeGraphViewer.setTimeGraphProvider(new ResourcesPresentationProvider());\r
-\r
- fTimeGraphViewer.setTimeCalendarFormat(true);\r
-\r
- fTimeGraphViewer.addRangeListener(new ITimeGraphRangeListener() {\r
- @Override\r
- public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {\r
- long startTime = event.getStartTime();\r
- long endTime = event.getEndTime();\r
- TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));\r
- TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphViewer.getSelectedTime());\r
- broadcast(new TmfRangeSynchSignal(ResourcesView.this, range, time));\r
- startZoomThread(startTime, endTime);\r
- }\r
- });\r
-\r
- fTimeGraphViewer.addTimeListener(new ITimeGraphTimeListener() {\r
- @Override\r
- public void timeSelected(TimeGraphTimeEvent event) {\r
- long time = event.getTime();\r
- broadcast(new TmfTimeSynchSignal(ResourcesView.this, new CtfTmfTimestamp(time)));\r
- }\r
- });\r
-\r
- final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- if (TmfExperiment.getCurrentExperiment() != null) {\r
- selectExperiment(TmfExperiment.getCurrentExperiment());\r
- }\r
- }\r
- };\r
- thread.start();\r
-\r
- // View Action Handling\r
- makeActions();\r
- contributeToActionBars();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r
- */\r
- @Override\r
- public void setFocus() {\r
- fTimeGraphViewer.setFocus();\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Signal handlers\r
- // ------------------------------------------------------------------------\r
-\r
- @TmfSignalHandler\r
- public void experimentSelected(final TmfExperimentSelectedSignal<? extends TmfEvent> signal) {\r
- if (signal.getExperiment().equals(fSelectedExperiment)) {\r
- return;\r
- }\r
-\r
- final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- selectExperiment(signal.getExperiment());\r
- }\r
- };\r
- thread.start();\r
- }\r
-\r
- @TmfSignalHandler\r
- public void synchToTime(final TmfTimeSynchSignal signal) {\r
- if (signal.getSource() == this) {\r
- return;\r
- }\r
- final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphViewer.setSelectedTime(time, true);\r
- startZoomThread(fTimeGraphViewer.getTime0(), fTimeGraphViewer.getTime1());\r
- }\r
- });\r
- }\r
-\r
- @TmfSignalHandler\r
- public void synchToRange(final TmfRangeSynchSignal signal) {\r
- if (signal.getSource() == this) {\r
- return;\r
- }\r
- final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();\r
- final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();\r
- final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphViewer.setStartFinishTime(startTime, endTime);\r
- fTimeGraphViewer.setSelectedTime(time, false);\r
- startZoomThread(startTime, endTime);\r
- }\r
- });\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Internal\r
- // ------------------------------------------------------------------------\r
-\r
- @SuppressWarnings("unchecked")\r
- private void selectExperiment(TmfExperiment<?> experiment) {\r
- fStartTime = Long.MAX_VALUE;\r
- fEndTime = Long.MIN_VALUE;\r
- fSelectedExperiment = (TmfExperiment<ITmfEvent>) experiment;\r
- ArrayList<TraceEntry> entryList = new ArrayList<TraceEntry>();\r
- for (ITmfTrace<?> trace : experiment.getTraces()) {\r
- if (trace instanceof CtfKernelTrace) {\r
- CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;\r
- IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r
- long startTime = ssq.getStartTime();\r
- long endTime = ssq.getCurrentEndTime() + 1;\r
- TraceEntry groupEntry = new TraceEntry(ctfKernelTrace, trace.getName(), startTime, endTime);\r
- entryList.add(groupEntry);\r
- fStartTime = Math.min(fStartTime, startTime);\r
- fEndTime = Math.max(fEndTime, endTime);\r
- List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$\r
- ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];\r
- for (int i = 0; i < cpuQuarks.size(); i++) {\r
- int cpuQuark = cpuQuarks.get(i);\r
- int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));\r
- ResourcesEntry entry = new ResourcesEntry(cpuQuark, ctfKernelTrace, Type.CPU, cpu);\r
- groupEntry.addChild(entry);\r
- cpuEntries[i] = entry;\r
- }\r
- List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$\r
- ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];\r
- for (int i = 0; i < irqQuarks.size(); i++) {\r
- int irqQuark = irqQuarks.get(i);\r
- int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));\r
- ResourcesEntry entry = new ResourcesEntry(irqQuark, ctfKernelTrace, Type.IRQ, irq);\r
- groupEntry.addChild(entry);\r
- irqEntries[i] = entry;\r
- }\r
- List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$\r
- ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];\r
- for (int i = 0; i < softIrqQuarks.size(); i++) {\r
- int softIrqQuark = softIrqQuarks.get(i);\r
- int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));\r
- ResourcesEntry entry = new ResourcesEntry(softIrqQuark, ctfKernelTrace, Type.SOFT_IRQ, softIrq);\r
- groupEntry.addChild(entry);\r
- softIrqEntries[i] = entry;\r
- }\r
- }\r
- }\r
- fEntryList = entryList;\r
- refresh(INITIAL_WINDOW_OFFSET);\r
- for (TraceEntry traceEntry : fEntryList) {\r
- CtfKernelTrace ctfKernelTrace = ((TraceEntry) traceEntry).getTrace();\r
- IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r
- long startTime = ssq.getStartTime();\r
- long endTime = ssq.getCurrentEndTime() + 1;\r
- long resolution = (endTime - startTime) / fDisplayWidth;\r
- for (ResourcesEntry entry : traceEntry.getChildren()) {\r
- List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, false, new NullProgressMonitor());\r
- entry.setEventList(eventList);\r
- redraw();\r
- }\r
- }\r
- }\r
-\r
- private List<ITimeEvent> getEventList(ResourcesEntry entry, long startTime, long endTime, long resolution, boolean includeNull, IProgressMonitor monitor) {\r
- IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r
- startTime = Math.max(startTime, ssq.getStartTime());\r
- endTime = Math.min(endTime, ssq.getCurrentEndTime() + 1);\r
- if (endTime <= startTime) {\r
- return null;\r
- }\r
- List<ITimeEvent> eventList = null;\r
- int quark = entry.getQuark();\r
- try {\r
- if (entry.getType().equals(Type.CPU)) {\r
- int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);\r
- List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution);\r
- eventList = new ArrayList<ITimeEvent>(statusIntervals.size());\r
- long lastEndTime = -1;\r
- for (ITmfStateInterval statusInterval : statusIntervals) {\r
- if (monitor.isCanceled()) {\r
- return null;\r
- }\r
- int status = statusInterval.getStateValue().unboxInt();\r
- long time = statusInterval.getStartTime();\r
- long duration = statusInterval.getEndTime() - time + 1;\r
- if (!statusInterval.getStateValue().isNull()) {\r
- if (lastEndTime != time && lastEndTime != -1) {\r
- eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));\r
- }\r
- eventList.add(new ResourcesEvent(entry, time, duration, status));\r
- lastEndTime = time + duration;\r
- } else {\r
- if (includeNull) {\r
- eventList.add(new ResourcesEvent(entry, time, duration));\r
- }\r
- }\r
- }\r
- } else if (entry.getType().equals(Type.IRQ)) {\r
- List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution);\r
- eventList = new ArrayList<ITimeEvent>(irqIntervals.size());\r
- long lastEndTime = -1;\r
- boolean lastIsNull = true;\r
- for (ITmfStateInterval irqInterval : irqIntervals) {\r
- if (monitor.isCanceled()) {\r
- return null;\r
- }\r
- long time = irqInterval.getStartTime();\r
- long duration = irqInterval.getEndTime() - time + 1;\r
- if (!irqInterval.getStateValue().isNull()) {\r
- int cpu = irqInterval.getStateValue().unboxInt();\r
- eventList.add(new ResourcesEvent(entry, time, duration, cpu));\r
- lastIsNull = false;\r
- } else {\r
- if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {\r
- eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));\r
- }\r
- if (includeNull) {\r
- eventList.add(new ResourcesEvent(entry, time, duration));\r
- }\r
- lastIsNull = true;\r
- }\r
- lastEndTime = time + duration;\r
- }\r
- } else if (entry.getType().equals(Type.SOFT_IRQ)) {\r
- List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution);\r
- eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());\r
- long lastEndTime = -1;\r
- boolean lastIsNull = true;\r
- for (ITmfStateInterval softIrqInterval : softIrqIntervals) {\r
- if (monitor.isCanceled()) {\r
- return null;\r
- }\r
- long time = softIrqInterval.getStartTime();\r
- long duration = softIrqInterval.getEndTime() - time + 1;\r
- if (!softIrqInterval.getStateValue().isNull()) {\r
- int cpu = softIrqInterval.getStateValue().unboxInt();\r
- eventList.add(new ResourcesEvent(entry, time, duration, cpu));\r
- } else {\r
- if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {\r
- eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));\r
- }\r
- if (includeNull) {\r
- eventList.add(new ResourcesEvent(entry, time, duration));\r
- }\r
- lastIsNull = true;\r
- }\r
- lastEndTime = time + duration;\r
- }\r
- }\r
- } catch (AttributeNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (TimeRangeException e) {\r
- e.printStackTrace();\r
- } catch (StateValueTypeException e) {\r
- e.printStackTrace();\r
- }\r
- return eventList;\r
- }\r
-\r
- private void refresh(final long windowRange) {\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- ITimeGraphEntry[] entries = fEntryList.toArray(new ITimeGraphEntry[0]);\r
- Arrays.sort(entries, new TraceEntryComparator());\r
- fTimeGraphViewer.setInput(entries);\r
- fTimeGraphViewer.setTimeBounds(fStartTime, fEndTime);\r
-\r
- long endTime = fStartTime + windowRange;\r
-\r
- if (fEndTime < endTime) {\r
- endTime = fEndTime;\r
- }\r
- fTimeGraphViewer.setStartFinishTime(fStartTime, endTime);\r
-\r
- startZoomThread(fStartTime, endTime);\r
- }\r
- });\r
- }\r
-\r
-\r
- private void redraw() {\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphViewer.getControl().redraw();\r
- fTimeGraphViewer.getControl().update();\r
- }\r
- });\r
- }\r
-\r
- private void startZoomThread(long startTime, long endTime) {\r
- if (fZoomThread != null) {\r
- fZoomThread.cancel();\r
- }\r
- fZoomThread = new ZoomThread(startTime, endTime);\r
- fZoomThread.start();\r
- }\r
-\r
- private void makeActions() {\r
- fPreviousResourceAction = fTimeGraphViewer.getPreviousItemAction();\r
- fPreviousResourceAction.setText(Messages.ResourcesView_previousResourceActionNameText);\r
- fPreviousResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);\r
- fNextResourceAction = fTimeGraphViewer.getNextItemAction();\r
- fNextResourceAction.setText(Messages.ResourcesView_nextResourceActionNameText);\r
- fNextResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);\r
- }\r
-\r
- private void contributeToActionBars() {\r
- IActionBars bars = getViewSite().getActionBars();\r
- fillLocalToolBar(bars.getToolBarManager());\r
- }\r
-\r
- private void fillLocalToolBar(IToolBarManager manager) {\r
- manager.add(fTimeGraphViewer.getShowLegendAction());\r
- manager.add(new Separator());\r
- manager.add(fTimeGraphViewer.getResetScaleAction());\r
- manager.add(fTimeGraphViewer.getPreviousEventAction());\r
- manager.add(fTimeGraphViewer.getNextEventAction());\r
- manager.add(fPreviousResourceAction);\r
- manager.add(fNextResourceAction);\r
- manager.add(fTimeGraphViewer.getZoomInAction());\r
- manager.add(fTimeGraphViewer.getZoomOutAction());\r
- manager.add(new Separator());\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
+import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
+import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor;
+import org.eclipse.linuxtools.tmf.ui.views.TmfView;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;
+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.model.TimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Main implementation for the LTTng 2.0 kernel Resource view
+ *
+ * @author Patrick Tasse
+ */
+public class ResourcesView extends TmfView {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ /** View ID. */
+ public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
+
+ /**
+ * Redraw state enum
+ */
+ private enum State { IDLE, BUSY, PENDING }
+
+ // ------------------------------------------------------------------------
+ // Fields
+ // ------------------------------------------------------------------------
+
+ // The time graph viewer
+ TimeGraphViewer fTimeGraphViewer;
+
+ // The selected trace
+ private ITmfTrace fTrace;
+
+ // The time graph entry list
+ private ArrayList<TraceEntry> fEntryList;
+
+ // The trace to entry list hash map
+ final private HashMap<ITmfTrace, ArrayList<TraceEntry>> fEntryListMap = new HashMap<ITmfTrace, ArrayList<TraceEntry>>();
+
+ // The trace to build thread hash map
+ final private HashMap<ITmfTrace, BuildThread> fBuildThreadMap = new HashMap<ITmfTrace, BuildThread>();
+
+ // The start time
+ private long fStartTime;
+
+ // The end time
+ private long fEndTime;
+
+ // The display width
+ private final int fDisplayWidth;
+
+ // The next resource action
+ private Action fNextResourceAction;
+
+ // The previous resource action
+ private Action fPreviousResourceAction;
+
+ // The zoom thread
+ private ZoomThread fZoomThread;
+
+ // The redraw state used to prevent unnecessary queuing of display runnables
+ private State fRedrawState = State.IDLE;
+
+ // The redraw synchronization object
+ final private Object fSyncObj = new Object();
+
+ // ------------------------------------------------------------------------
+ // Classes
+ // ------------------------------------------------------------------------
+
+ private class TraceEntry implements ITimeGraphEntry {
+ // The Trace
+ private final CtfKernelTrace fKernelTrace;
+ // The start time
+ private final long fTraceStartTime;
+ // The end time
+ private final long fTraceEndTime;
+ // The children of the entry
+ private final ArrayList<ResourcesEntry> fChildren;
+ // The name of entry
+ private final String fName;
+
+ public TraceEntry(CtfKernelTrace trace, String name, long startTime, long endTime) {
+ fKernelTrace = trace;
+ fChildren = new ArrayList<ResourcesEntry>();
+ fName = name;
+ fTraceStartTime = startTime;
+ fTraceEndTime = endTime;
+ }
+
+ @Override
+ public ITimeGraphEntry getParent() {
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren() {
+ return fChildren != null && fChildren.size() > 0;
+ }
+
+ @Override
+ public List<ResourcesEntry> getChildren() {
+ return fChildren;
+ }
+
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ @Override
+ public long getStartTime() {
+ return fTraceStartTime;
+ }
+
+ @Override
+ public long getEndTime() {
+ return fTraceEndTime;
+ }
+
+ @Override
+ public boolean hasTimeEvents() {
+ return false;
+ }
+
+ @Override
+ public Iterator<ITimeEvent> getTimeEventsIterator() {
+ return null;
+ }
+
+ @Override
+ public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
+ return null;
+ }
+
+ public CtfKernelTrace getTrace() {
+ return fKernelTrace;
+ }
+
+ public void addChild(ResourcesEntry entry) {
+ int index;
+ for (index = 0; index < fChildren.size(); index++) {
+ ResourcesEntry other = fChildren.get(index);
+ if (entry.getType().compareTo(other.getType()) < 0) {
+ break;
+ } else if (entry.getType().equals(other.getType())) {
+ if (entry.getId() < other.getId()) {
+ break;
+ }
+ }
+ }
+ entry.setParent(this);
+ fChildren.add(index, entry);
+ }
+ }
+
+ private static class TraceEntryComparator implements Comparator<ITimeGraphEntry> {
+ @Override
+ public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
+ int result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
+ if (result == 0) {
+ result = o1.getName().compareTo(o2.getName());
+ }
+ return result;
+ }
+ }
+
+ private class BuildThread extends Thread {
+ private final ITmfTrace fBuildTrace;
+ private final IProgressMonitor fMonitor;
+
+ public BuildThread(ITmfTrace trace) {
+ super("ResourcesView build"); //$NON-NLS-1$
+ fBuildTrace = trace;
+ fMonitor = new NullProgressMonitor();
+ }
+
+ @Override
+ public void run() {
+ buildEventList(fBuildTrace, fMonitor);
+ synchronized (fBuildThreadMap) {
+ fBuildThreadMap.remove(this);
+ }
+ }
+
+ public void cancel() {
+ fMonitor.setCanceled(true);
+ }
+ }
+
+ private class ZoomThread extends Thread {
+ private final ArrayList<TraceEntry> fZoomEntryList;
+ private final long fZoomStartTime;
+ private final long fZoomEndTime;
+ private final IProgressMonitor fMonitor;
+
+ public ZoomThread(ArrayList<TraceEntry> entryList, long startTime, long endTime) {
+ super("ResourcesView zoom"); //$NON-NLS-1$
+ fZoomEntryList = entryList;
+ fZoomStartTime = startTime;
+ fZoomEndTime = endTime;
+ fMonitor = new NullProgressMonitor();
+ }
+
+ @Override
+ public void run() {
+ if (fZoomEntryList == null) {
+ return;
+ }
+ long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);
+ for (TraceEntry traceEntry : fZoomEntryList) {
+ if (!traceEntry.fKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID).waitUntilBuilt()) {
+ return;
+ }
+ for (ITimeGraphEntry child : traceEntry.getChildren()) {
+ if (fMonitor.isCanceled()) {
+ break;
+ }
+ ResourcesEntry entry = (ResourcesEntry) child;
+ if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {
+ entry.setZoomedEventList(null);
+ } else {
+ List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, resolution, true, fMonitor);
+ if (zoomedEventList != null) {
+ entry.setZoomedEventList(zoomedEventList);
+ }
+ }
+ redraw();
+ }
+ }
+ }
+
+ public void cancel() {
+ fMonitor.setCanceled(true);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Default constructor
+ */
+ public ResourcesView() {
+ super(ID);
+ fDisplayWidth = Display.getDefault().getBounds().width;
+ }
+
+ // ------------------------------------------------------------------------
+ // ViewPart
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createPartControl(Composite parent) {
+ fTimeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);
+
+ fTimeGraphViewer.setTimeGraphProvider(new ResourcesPresentationProvider(fTimeGraphViewer));
+
+ fTimeGraphViewer.setTimeFormat(TimeFormat.CALENDAR);
+
+ fTimeGraphViewer.addRangeListener(new ITimeGraphRangeListener() {
+ @Override
+ public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {
+ long startTime = event.getStartTime();
+ long endTime = event.getEndTime();
+ TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));
+ TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphViewer.getSelectedTime());
+ broadcast(new TmfRangeSynchSignal(ResourcesView.this, range, time));
+ startZoomThread(startTime, endTime);
+ }
+ });
+
+ fTimeGraphViewer.addTimeListener(new ITimeGraphTimeListener() {
+ @Override
+ public void timeSelected(TimeGraphTimeEvent event) {
+ long time = event.getTime();
+ broadcast(new TmfTimeSynchSignal(ResourcesView.this, new CtfTmfTimestamp(time)));
+ }
+ });
+
+ // View Action Handling
+ makeActions();
+ contributeToActionBars();
+
+ IEditorPart editor = getSite().getPage().getActiveEditor();
+ if (editor instanceof ITmfTraceEditor) {
+ ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
+ if (trace != null) {
+ traceSelected(new TmfTraceSelectedSignal(this, trace));
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ @Override
+ public void setFocus() {
+ fTimeGraphViewer.setFocus();
+ }
+
+ // ------------------------------------------------------------------------
+ // Signal handlers
+ // ------------------------------------------------------------------------
+
+ /**
+ * Handler for the trace selected signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void traceSelected(final TmfTraceSelectedSignal signal) {
+ if (signal.getTrace() == fTrace) {
+ return;
+ }
+ fTrace = signal.getTrace();
+
+ synchronized (fEntryListMap) {
+ fEntryList = fEntryListMap.get(fTrace);
+ if (fEntryList == null) {
+ synchronized (fBuildThreadMap) {
+ BuildThread buildThread = new BuildThread(fTrace);
+ fBuildThreadMap.put(fTrace, buildThread);
+ buildThread.start();
+ }
+ } else {
+ fStartTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ fEndTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ refresh();
+ }
+ }
+ }
+
+ /**
+ * Trace is disposed: clear the data structures and the view
+ *
+ * @param signal the signal received
+ */
+ @TmfSignalHandler
+ public void traceClosed(final TmfTraceClosedSignal signal) {
+ synchronized (fBuildThreadMap) {
+ BuildThread buildThread = fBuildThreadMap.remove(signal.getTrace());
+ if (buildThread != null) {
+ buildThread.cancel();
+ }
+ }
+ synchronized (fEntryListMap) {
+ fEntryListMap.remove(signal.getTrace());
+ }
+ if (signal.getTrace() == fTrace) {
+ fTrace = null;
+ fStartTime = 0;
+ fEndTime = 0;
+ if (fZoomThread != null) {
+ fZoomThread.cancel();
+ }
+ refresh();
+ }
+ }
+
+ /**
+ * Handler for the TimeSynch signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void synchToTime(final TmfTimeSynchSignal signal) {
+ if (signal.getSource() == this || fTrace == null) {
+ return;
+ }
+ final long time = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphViewer.getControl().isDisposed()) {
+ return;
+ }
+ fTimeGraphViewer.setSelectedTime(time, true);
+ startZoomThread(fTimeGraphViewer.getTime0(), fTimeGraphViewer.getTime1());
+ }
+ });
+ }
+
+ /**
+ * Handler for the RangeSynch signal
+ *
+ * @param signal
+ * The incoming signal
+ */
+ @TmfSignalHandler
+ public void synchToRange(final TmfRangeSynchSignal signal) {
+ if (signal.getSource() == this || fTrace == null) {
+ return;
+ }
+ if (signal.getCurrentRange().getIntersection(fTrace.getTimeRange()) == null) {
+ return;
+ }
+ final long startTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ final long endTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ final long time = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphViewer.getControl().isDisposed()) {
+ return;
+ }
+ fTimeGraphViewer.setStartFinishTime(startTime, endTime);
+ fTimeGraphViewer.setSelectedTime(time, false);
+ startZoomThread(startTime, endTime);
+ }
+ });
+ }
+
+ // ------------------------------------------------------------------------
+ // Internal
+ // ------------------------------------------------------------------------
+
+ private void buildEventList(final ITmfTrace trace, IProgressMonitor monitor) {
+ fStartTime = Long.MAX_VALUE;
+ fEndTime = Long.MIN_VALUE;
+ ITmfTrace[] traces;
+ if (trace instanceof TmfExperiment) {
+ TmfExperiment experiment = (TmfExperiment) trace;
+ traces = experiment.getTraces();
+ } else {
+ traces = new ITmfTrace[] { trace };
+ }
+ ArrayList<TraceEntry> entryList = new ArrayList<TraceEntry>();
+ for (ITmfTrace aTrace : traces) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ if (aTrace instanceof CtfKernelTrace) {
+ CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) aTrace;
+ ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID);
+ if (!ssq.waitUntilBuilt()) {
+ return;
+ }
+ long startTime = ssq.getStartTime();
+ long endTime = ssq.getCurrentEndTime() + 1;
+ TraceEntry groupEntry = new TraceEntry(ctfKernelTrace, aTrace.getName(), startTime, endTime);
+ entryList.add(groupEntry);
+ fStartTime = Math.min(fStartTime, startTime);
+ fEndTime = Math.max(fEndTime, endTime);
+ List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$
+ ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];
+ for (int i = 0; i < cpuQuarks.size(); i++) {
+ int cpuQuark = cpuQuarks.get(i);
+ int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));
+ ResourcesEntry entry = new ResourcesEntry(cpuQuark, ctfKernelTrace, Type.CPU, cpu);
+ groupEntry.addChild(entry);
+ cpuEntries[i] = entry;
+ }
+ List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
+ ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];
+ for (int i = 0; i < irqQuarks.size(); i++) {
+ int irqQuark = irqQuarks.get(i);
+ int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
+ ResourcesEntry entry = new ResourcesEntry(irqQuark, ctfKernelTrace, Type.IRQ, irq);
+ groupEntry.addChild(entry);
+ irqEntries[i] = entry;
+ }
+ List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
+ ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];
+ for (int i = 0; i < softIrqQuarks.size(); i++) {
+ int softIrqQuark = softIrqQuarks.get(i);
+ int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
+ ResourcesEntry entry = new ResourcesEntry(softIrqQuark, ctfKernelTrace, Type.SOFT_IRQ, softIrq);
+ groupEntry.addChild(entry);
+ softIrqEntries[i] = entry;
+ }
+ }
+ }
+ synchronized (fEntryListMap) {
+ fEntryListMap.put(trace, (ArrayList<TraceEntry>) entryList.clone());
+ }
+ if (trace == fTrace) {
+ refresh();
+ }
+ for (TraceEntry traceEntry : entryList) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ CtfKernelTrace ctfKernelTrace = traceEntry.getTrace();
+ ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID);
+ long startTime = ssq.getStartTime();
+ long endTime = ssq.getCurrentEndTime() + 1;
+ long resolution = (endTime - startTime) / fDisplayWidth;
+ for (ResourcesEntry entry : traceEntry.getChildren()) {
+ List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, false, monitor);
+ entry.setEventList(eventList);
+ redraw();
+ }
+ }
+ }
+
+ private static List<ITimeEvent> getEventList(ResourcesEntry entry,
+ long startTime, long endTime, long resolution, boolean includeNull,
+ IProgressMonitor monitor) {
+ ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
+ startTime = Math.max(startTime, ssq.getStartTime());
+ endTime = Math.min(endTime, ssq.getCurrentEndTime() + 1);
+ if (endTime <= startTime) {
+ return null;
+ }
+ List<ITimeEvent> eventList = null;
+ int quark = entry.getQuark();
+ try {
+ if (entry.getType().equals(Type.CPU)) {
+ int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);
+ List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);
+ eventList = new ArrayList<ITimeEvent>(statusIntervals.size());
+ long lastEndTime = -1;
+ for (ITmfStateInterval statusInterval : statusIntervals) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ int status = statusInterval.getStateValue().unboxInt();
+ long time = statusInterval.getStartTime();
+ long duration = statusInterval.getEndTime() - time + 1;
+ if (!statusInterval.getStateValue().isNull()) {
+ if (lastEndTime != time && lastEndTime != -1) {
+ eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
+ }
+ eventList.add(new ResourcesEvent(entry, time, duration, status));
+ lastEndTime = time + duration;
+ } else {
+ if (includeNull) {
+ eventList.add(new ResourcesEvent(entry, time, duration));
+ }
+ }
+ }
+ } else if (entry.getType().equals(Type.IRQ)) {
+ List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);
+ eventList = new ArrayList<ITimeEvent>(irqIntervals.size());
+ long lastEndTime = -1;
+ boolean lastIsNull = true;
+ for (ITmfStateInterval irqInterval : irqIntervals) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ long time = irqInterval.getStartTime();
+ long duration = irqInterval.getEndTime() - time + 1;
+ if (!irqInterval.getStateValue().isNull()) {
+ int cpu = irqInterval.getStateValue().unboxInt();
+ eventList.add(new ResourcesEvent(entry, time, duration, cpu));
+ lastIsNull = false;
+ } else {
+ if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
+ eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));
+ }
+ if (includeNull) {
+ eventList.add(new ResourcesEvent(entry, time, duration));
+ }
+ lastIsNull = true;
+ }
+ lastEndTime = time + duration;
+ }
+ } else if (entry.getType().equals(Type.SOFT_IRQ)) {
+ List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);
+ eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());
+ long lastEndTime = -1;
+ boolean lastIsNull = true;
+ for (ITmfStateInterval softIrqInterval : softIrqIntervals) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ long time = softIrqInterval.getStartTime();
+ long duration = softIrqInterval.getEndTime() - time + 1;
+ if (!softIrqInterval.getStateValue().isNull()) {
+ int cpu = softIrqInterval.getStateValue().unboxInt();
+ eventList.add(new ResourcesEvent(entry, time, duration, cpu));
+ } else {
+ if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
+ eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));
+ }
+ if (includeNull) {
+ eventList.add(new ResourcesEvent(entry, time, duration));
+ }
+ lastIsNull = true;
+ }
+ lastEndTime = time + duration;
+ }
+ }
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (TimeRangeException e) {
+ e.printStackTrace();
+ } catch (StateValueTypeException e) {
+ e.printStackTrace();
+ } catch (StateSystemDisposedException e) {
+ /* Ignored */
+ }
+ return eventList;
+ }
+
+ private void refresh() {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphViewer.getControl().isDisposed()) {
+ return;
+ }
+ ITimeGraphEntry[] entries = null;
+ synchronized (fEntryListMap) {
+ fEntryList = fEntryListMap.get(fTrace);
+ if (fEntryList == null) {
+ fEntryList = new ArrayList<TraceEntry>();
+ }
+ entries = fEntryList.toArray(new ITimeGraphEntry[0]);
+ }
+ if (entries != null) {
+ Arrays.sort(entries, new TraceEntryComparator());
+ fTimeGraphViewer.setInput(entries);
+ fTimeGraphViewer.setTimeBounds(fStartTime, fEndTime);
+
+ long timestamp = fTrace == null ? 0 : fTrace.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ long startTime = fTrace == null ? 0 : fTrace.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ long endTime = fTrace == null ? 0 : fTrace.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ startTime = Math.max(startTime, fStartTime);
+ endTime = Math.min(endTime, fEndTime);
+ fTimeGraphViewer.setSelectedTime(timestamp, false);
+ fTimeGraphViewer.setStartFinishTime(startTime, endTime);
+
+ startZoomThread(startTime, endTime);
+ }
+ }
+ });
+ }
+
+ private void redraw() {
+ synchronized (fSyncObj) {
+ if (fRedrawState == State.IDLE) {
+ fRedrawState = State.BUSY;
+ } else {
+ fRedrawState = State.PENDING;
+ return;
+ }
+ }
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (fTimeGraphViewer.getControl().isDisposed()) {
+ return;
+ }
+ fTimeGraphViewer.getControl().redraw();
+ fTimeGraphViewer.getControl().update();
+ synchronized (fSyncObj) {
+ if (fRedrawState == State.PENDING) {
+ fRedrawState = State.IDLE;
+ redraw();
+ } else {
+ fRedrawState = State.IDLE;
+ }
+ }
+ }
+ });
+ }
+
+ private void startZoomThread(long startTime, long endTime) {
+ if (fZoomThread != null) {
+ fZoomThread.cancel();
+ }
+ fZoomThread = new ZoomThread(fEntryList, startTime, endTime);
+ fZoomThread.start();
+ }
+
+ private void makeActions() {
+ fPreviousResourceAction = fTimeGraphViewer.getPreviousItemAction();
+ fPreviousResourceAction.setText(Messages.ResourcesView_previousResourceActionNameText);
+ fPreviousResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);
+ fNextResourceAction = fTimeGraphViewer.getNextItemAction();
+ fNextResourceAction.setText(Messages.ResourcesView_nextResourceActionNameText);
+ fNextResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);
+ }
+
+ private void contributeToActionBars() {
+ IActionBars bars = getViewSite().getActionBars();
+ fillLocalToolBar(bars.getToolBarManager());
+ }
+
+ private void fillLocalToolBar(IToolBarManager manager) {
+ manager.add(fTimeGraphViewer.getShowLegendAction());
+ manager.add(new Separator());
+ manager.add(fTimeGraphViewer.getResetScaleAction());
+ manager.add(fTimeGraphViewer.getPreviousEventAction());
+ manager.add(fTimeGraphViewer.getNextEventAction());
+ manager.add(fPreviousResourceAction);
+ manager.add(fNextResourceAction);
+ manager.add(fTimeGraphViewer.getZoomInAction());
+ manager.add(fTimeGraphViewer.getZoomOutAction());
+ manager.add(new Separator());
+ }
+}