-/*******************************************************************************\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.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.Attributes;\r
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;\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.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.TmfSignalHandler;\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.TimeGraphProvider;\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
-\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
- // 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<ITimeGraphEntry> 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
- // ------------------------------------------------------------------------\r
- // Classes\r
- // ------------------------------------------------------------------------\r
-\r
- private class GroupEntry implements ITimeGraphEntry {\r
- public ITimeGraphEntry fParent;\r
- public ArrayList<ITimeGraphEntry> fChildren;\r
- public String fName;\r
-\r
- public GroupEntry(ITimeGraphEntry parent, String name) {\r
- fParent = parent;\r
- fChildren = new ArrayList<ITimeGraphEntry>();\r
- fName = name;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getParent() {\r
- return fParent;\r
- }\r
-\r
- @Override\r
- public boolean hasChildren() {\r
- return fChildren != null && fChildren.size() > 0;\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry[] getChildren() {\r
- return fChildren.toArray(new ITimeGraphEntry[0]);\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return fName;\r
- }\r
-\r
- @Override\r
- public long getStartTime() {\r
- return -1;\r
- }\r
-\r
- @Override\r
- public long getStopTime() {\r
- return -1;\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 void addChild(ITimeGraphEntry entry) {\r
- fChildren.add(entry);\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 TimeGraphProvider() {\r
- @Override\r
- public String getTraceClassName(ITimeGraphEntry trace) {\r
- return "trace class"; //$NON-NLS-1$\r
- }\r
- \r
- @Override\r
- public String getStateName(StateColor color) {\r
- return "state name"; //$NON-NLS-1$\r
- }\r
- \r
- @Override\r
- public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) {\r
- return "event name"; //$NON-NLS-1$\r
- }\r
- \r
- @Override\r
- public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {\r
- return new HashMap<String, String>();\r
- }\r
- \r
- @Override\r
- public StateColor getEventColor(ITimeEvent event) {\r
- if (event.getTime() % 2 == 0) {\r
- return StateColor.BLACK;\r
- } else {\r
- return StateColor.GRAY;\r
- }\r
- }\r
- });\r
-\r
- final Thread thread = new Thread() {\r
- @Override\r
- public void run() {\r
- if (TmfExperiment.getCurrentExperiment() != null) {\r
- selectExperiment(TmfExperiment.getCurrentExperiment());\r
- }\r
- }\r
- };\r
- thread.start();\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() {\r
- @Override\r
- public void run() {\r
- selectExperiment(signal.getExperiment());\r
- }};\r
- thread.start();\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
- fEntryList = new ArrayList<ITimeGraphEntry>();\r
- for (ITmfTrace<?> trace : experiment.getTraces()) {\r
- GroupEntry groupEntry = new GroupEntry(null, trace.getPath());\r
- fEntryList.add(groupEntry);\r
- refresh();\r
- if (trace instanceof CtfKernelTrace) {\r
- CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;\r
- IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r
- long start = ssq.getStartTime();\r
- long end = ssq.getCurrentEndTime();\r
- fStartTime = Math.min(fStartTime, start);\r
- fEndTime = Math.max(fEndTime, end);\r
- List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$\r
- for (int cpuQuark : cpuQuarks) {\r
- String cpuName = "CPU " + ssq.getAttributeName(cpuQuark);\r
- ResourcesEntry entry = new ResourcesEntry(groupEntry, ctfKernelTrace, cpuName);\r
- try {\r
- int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD);\r
- long resolution = (end - start) / fDisplayWidth;\r
- List<ITmfStateInterval> currentThreadIntervals = ssq.queryHistoryRange(currentThreadQuark, start, end, resolution);\r
- for (ITmfStateInterval currentThreadInterval : currentThreadIntervals) {\r
- if (!currentThreadInterval.getStateValue().isNull() && currentThreadInterval.getStateValue().getType() == 0) {\r
- int currentThread = currentThreadInterval.getStateValue().unboxInt();\r
- long startTime = currentThreadInterval.getStartTime();\r
- long endTime = currentThreadInterval.getEndTime();\r
- entry.addTraceEvent(new TimeEvent(entry, startTime, endTime - startTime));\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
- groupEntry.addChild(entry);\r
- refresh();\r
- }\r
- }\r
- }\r
- }\r
-\r
- private void refresh() {\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- if (fTimeGraphViewer.getControl().isDisposed()) {\r
- return;\r
- }\r
- fTimeGraphViewer.setInput(fEntryList.toArray(new ITimeGraphEntry[0]));\r
- fTimeGraphViewer.setTimeBounds(fStartTime, fEndTime);\r
- fTimeGraphViewer.setStartFinishTime(fStartTime, fEndTime);\r
- }\r
- });\r
- }\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;
+ }
+
+}