-/*******************************************************************************\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.TmfStateSystemBuildCompleted;\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
-/**\r
- * Main implementation for the LTTng 2.0 kernel Resource view\r
- *\r
- * @author Patrick Tasse\r
- */\r
-public class ResourcesView extends TmfView {\r
-\r
- // ------------------------------------------------------------------------\r
- // Constants\r
- // ------------------------------------------------------------------------\r
-\r
- /** View ID. */\r
- public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$\r
-\r
- /** Initial time range */\r
- private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec\r
-\r
- /**\r
- * Redraw state enum\r
- */\r
- private enum State { IDLE, BUSY, PENDING };\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 time graph entry list synchronization object\r
- final private Object fEntryListSyncObj = new Object();\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 final 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
- // The redraw state used to prevent unnecessary queuing of display runnables\r
- private State fRedrawState = State.IDLE;\r
-\r
- // The redraw synchronization object\r
- final private Object fSyncObj = new Object();\r
-\r
- // ------------------------------------------------------------------------\r
- // Classes\r
- // ------------------------------------------------------------------------\r
-\r
- private class TraceEntry implements ITimeGraphEntry {\r
- // The Trace\r
- private final CtfKernelTrace fTrace;\r
- // The start time\r
- private final long fTraceStartTime;\r
- // The end time\r
- private final long fTraceEndTime;\r
- // The children of the entry\r
- private final ArrayList<ResourcesEntry> fChildren;\r
- // The name of entry\r
- private final 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 final long fZoomStartTime;\r
- private final long fZoomEndTime;\r
- private final 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 = null;\r
- synchronized (fEntryListSyncObj) {\r
- entryList = fEntryList;\r
- }\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
- if (fMonitor.isCanceled()) {\r
- break;\r
- }\r
- ResourcesEntry entry = (ResourcesEntry) child;\r
- if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {\r
- entry.setZoomedEventList(null);\r
- } else {\r
- List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, resolution, true, fMonitor);\r
- if (zoomedEventList != null) {\r
- entry.setZoomedEventList(zoomedEventList);\r
- }\r
- }\r
- redraw();\r
- }\r
- }\r
- }\r
-\r
- public void cancel() {\r
- fMonitor.setCanceled(true);\r
- }\r
- }\r
-\r
- // ------------------------------------------------------------------------\r
- // Constructors\r
- // ------------------------------------------------------------------------\r
-\r
- /**\r
- * Default constructor\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
- /**\r
- * Handler for the ExperimentSelected signal\r
- *\r
- * @param signal\r
- * The incoming signal\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
- /**\r
- * Handler for the TimeSynch signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void synchToTime(final TmfTimeSynchSignal signal) {\r
- if (signal.getSource() == this || fSelectedExperiment == null) {\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
- /**\r
- * Handler for the RangeSynch signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void synchToRange(final TmfRangeSynchSignal signal) {\r
- if (signal.getSource() == this || fSelectedExperiment == null) {\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
- * Handler for the StatesystemBuildCompleted signal\r
- *\r
- * @param signal\r
- * The incoming signal\r
- */\r
- @TmfSignalHandler\r
- public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {\r
- final TmfExperiment<?> selectedExperiment = fSelectedExperiment;\r
- if (selectedExperiment == null) {\r
- return;\r
- }\r
- for (ITmfTrace<?> trace : selectedExperiment.getTraces()) {\r
- if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {\r
- final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r
- @Override\r
- public void run() {\r
- // rebuild the model\r
- selectExperiment(selectedExperiment);\r
- }\r
- };\r
- thread.start();\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
- synchronized (fEntryListSyncObj) {\r
- fEntryList = (ArrayList<TraceEntry>) entryList.clone();\r
- }\r
- refresh(INITIAL_WINDOW_OFFSET);\r
- for (TraceEntry traceEntry : entryList) {\r
- CtfKernelTrace ctfKernelTrace = 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 static List<ITimeEvent> getEventList(ResourcesEntry entry,\r
- long startTime, long endTime, long resolution, boolean includeNull,\r
- 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, monitor);\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, monitor);\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, monitor);\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 = null;\r
- synchronized (fEntryListSyncObj) {\r
- entries = fEntryList.toArray(new ITimeGraphEntry[0]);\r
- }\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
- synchronized (fSyncObj) {\r
- if (fRedrawState == State.IDLE) {\r
- fRedrawState = State.BUSY;\r
- } else {\r
- fRedrawState = State.PENDING;\r
- return;\r
- }\r
- }\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
- synchronized (fSyncObj) {\r
- if (fRedrawState == State.PENDING) {\r
- fRedrawState = State.IDLE;\r
- redraw();\r
- } else {\r
- fRedrawState = State.IDLE;\r
- }\r
- }\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, 2014 Ericsson, École Polytechnique de Montréal
+ *
+ * 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
+ * Geneviève Bastien - Move code to provide base classes for time graph views
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+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.analysis.LttngKernelAnalysisModule;
+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.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.NullTimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
+
+/**
+ * Main implementation for the LTTng 2.0 kernel Resource view
+ *
+ * @author Patrick Tasse
+ */
+public class ResourcesView extends AbstractTimeGraphView {
+
+ /** View ID. */
+ public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
+
+ private static final String[] FILTER_COLUMN_NAMES = new String[] {
+ Messages.ResourcesView_stateTypeName
+ };
+
+ // Timeout between updates in the build thread in ms
+ private static final long BUILD_UPDATE_TIMEOUT = 500;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Default constructor
+ */
+ public ResourcesView() {
+ super(ID, new ResourcesPresentationProvider());
+ setFilterColumns(FILTER_COLUMN_NAMES);
+ }
+
+ // ------------------------------------------------------------------------
+ // Internal
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected String getNextText() {
+ return Messages.ResourcesView_nextResourceActionNameText;
+ }
+
+ @Override
+ protected String getNextTooltip() {
+ return Messages.ResourcesView_nextResourceActionToolTipText;
+ }
+
+ @Override
+ protected String getPrevText() {
+ return Messages.ResourcesView_previousResourceActionNameText;
+ }
+
+ @Override
+ protected String getPrevTooltip() {
+ return Messages.ResourcesView_previousResourceActionToolTipText;
+ }
+
+ @Override
+ protected void buildEventList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
+ LttngKernelAnalysisModule module = trace.getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID);
+ if (module == null) {
+ return;
+ }
+ module.schedule();
+ module.waitForInitialization();
+ ITmfStateSystem ssq = module.getStateSystem();
+ if (ssq == null) {
+ return;
+ }
+
+ Map<Integer, ResourcesEntry> entryMap = new HashMap<>();
+ TimeGraphEntry traceEntry = null;
+
+ long startTime = ssq.getStartTime();
+ long start = startTime;
+ setStartTime(Math.min(getStartTime(), startTime));
+ boolean complete = false;
+ while (!complete) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
+ if (ssq.isCancelled()) {
+ return;
+ }
+ long end = ssq.getCurrentEndTime();
+ if (start == end && !complete) { // when complete execute one last time regardless of end time
+ continue;
+ }
+ long endTime = end + 1;
+ setEndTime(Math.max(getEndTime(), endTime));
+
+ if (traceEntry == null) {
+ traceEntry = new ResourcesEntry(trace, trace.getName(), startTime, endTime, 0);
+ List<TimeGraphEntry> entryList = Collections.singletonList(traceEntry);
+ addToEntryList(parentTrace, entryList);
+ } else {
+ traceEntry.updateEndTime(endTime);
+ }
+
+ List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$
+ for (Integer cpuQuark : cpuQuarks) {
+ int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));
+ ResourcesEntry entry = entryMap.get(cpuQuark);
+ if (entry == null) {
+ entry = new ResourcesEntry(cpuQuark, trace, startTime, endTime, Type.CPU, cpu);
+ entryMap.put(cpuQuark, entry);
+ traceEntry.addChild(entry);
+ } else {
+ entry.updateEndTime(endTime);
+ }
+ }
+ List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
+ for (Integer irqQuark : irqQuarks) {
+ int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
+ ResourcesEntry entry = entryMap.get(irqQuark);
+ if (entry == null) {
+ entry = new ResourcesEntry(irqQuark, trace, startTime, endTime, Type.IRQ, irq);
+ entryMap.put(irqQuark, entry);
+ traceEntry.addChild(entry);
+ } else {
+ entry.updateEndTime(endTime);
+ }
+ }
+ List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
+ for (Integer softIrqQuark : softIrqQuarks) {
+ int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
+ ResourcesEntry entry = entryMap.get(softIrqQuark);
+ if (entry == null) {
+ entry = new ResourcesEntry(softIrqQuark, trace, startTime, endTime, Type.SOFT_IRQ, softIrq);
+ entryMap.put(softIrqQuark, entry);
+ traceEntry.addChild(entry);
+ } else {
+ entry.updateEndTime(endTime);
+ }
+ }
+
+ if (parentTrace.equals(getTrace())) {
+ refresh();
+ }
+ long resolution = Math.max(1, (endTime - ssq.getStartTime()) / getDisplayWidth());
+ for (TimeGraphEntry entry : traceEntry.getChildren()) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ List<ITimeEvent> eventList = getEventList(entry, start, endTime, resolution, monitor);
+ if (eventList != null) {
+ for (ITimeEvent event : eventList) {
+ entry.addEvent(event);
+ }
+ }
+ redraw();
+ }
+
+ start = end;
+ }
+ }
+
+ @Override
+ protected List<ITimeEvent> getEventList(TimeGraphEntry entry,
+ long startTime, long endTime, long resolution,
+ IProgressMonitor monitor) {
+ ResourcesEntry resourcesEntry = (ResourcesEntry) entry;
+ LttngKernelAnalysisModule module = resourcesEntry.getTrace().getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID);
+ if (module == null) {
+ return null;
+ }
+ ITmfStateSystem ssq = module.getStateSystem();
+ if (ssq == null) {
+ return null;
+ }
+ final long realStart = Math.max(startTime, ssq.getStartTime());
+ final long realEnd = Math.min(endTime, ssq.getCurrentEndTime() + 1);
+ if (realEnd <= realStart) {
+ return null;
+ }
+ List<ITimeEvent> eventList = null;
+ int quark = resourcesEntry.getQuark();
+
+ try {
+ if (resourcesEntry.getType().equals(Type.CPU)) {
+ int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);
+ List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, realStart, realEnd - 1, resolution, monitor);
+ eventList = new ArrayList<>(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 TimeEvent(entry, time, duration, status));
+ } else if (lastEndTime == -1 || time + duration >= endTime) {
+ // add null event if it intersects the start or end time
+ eventList.add(new NullTimeEvent(entry, time, duration));
+ }
+ lastEndTime = time + duration;
+ }
+ } else if (resourcesEntry.getType().equals(Type.IRQ)) {
+ List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
+ eventList = new ArrayList<>(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 TimeEvent(entry, time, duration, cpu));
+ lastIsNull = false;
+ } else {
+ if (lastEndTime == -1) {
+ // add null event if it intersects the start time
+ eventList.add(new NullTimeEvent(entry, time, duration));
+ } else {
+ if (lastEndTime != time && lastIsNull) {
+ /* This is a special case where we want to show IRQ_ACTIVE state but we don't know the CPU (it is between two null samples) */
+ eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
+ }
+ if (time + duration >= endTime) {
+ // add null event if it intersects the end time
+ eventList.add(new NullTimeEvent(entry, time, duration));
+ }
+ }
+ lastIsNull = true;
+ }
+ lastEndTime = time + duration;
+ }
+ } else if (resourcesEntry.getType().equals(Type.SOFT_IRQ)) {
+ List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
+ eventList = new ArrayList<>(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 TimeEvent(entry, time, duration, cpu));
+ } else {
+ if (lastEndTime == -1) {
+ // add null event if it intersects the start time
+ eventList.add(new NullTimeEvent(entry, time, duration));
+ } else {
+ if (lastEndTime != time && lastIsNull) {
+ /* This is a special case where we want to show IRQ_ACTIVE state but we don't know the CPU (it is between two null samples) */
+ eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
+ }
+ if (time + duration >= endTime) {
+ // add null event if it intersects the end time
+ eventList.add(new NullTimeEvent(entry, time, duration));
+ }
+ }
+ lastIsNull = true;
+ }
+ lastEndTime = time + duration;
+ }
+ }
+
+ } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
+ e.printStackTrace();
+ } catch (StateSystemDisposedException e) {
+ /* Ignored */
+ }
+ return eventList;
+ }
+
+}