/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal
+ * 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
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.trace.LttngKernelTrace;
+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.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;
/** View ID. */
public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
- /**
- * Default value for events with no other value. Since value in this case is
- * often a CPU number, this constant should be <0
- */
- public static final int NO_VALUE_EVENT = -999;
-
- private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn;
-
- private static final String[] COLUMN_NAMES = new String[] {
- PROCESS_COLUMN
- };
-
private static final String[] FILTER_COLUMN_NAMES = new String[] {
- PROCESS_COLUMN
+ Messages.ResourcesView_stateTypeName
};
- private static final int[] WEIGHTS = { 15, 85 };
+ // Timeout between updates in the build thread in ms
+ private static final long BUILD_UPDATE_TIMEOUT = 500;
// ------------------------------------------------------------------------
// Constructors
* Default constructor
*/
public ResourcesView() {
- super(ID, COLUMN_NAMES, FILTER_COLUMN_NAMES, new ResourcesPresentationProvider());
- setWeight(WEIGHTS);
+ super(ID, new ResourcesPresentationProvider());
+ setFilterColumns(FILTER_COLUMN_NAMES);
}
+ // ------------------------------------------------------------------------
+ // Internal
+ // ------------------------------------------------------------------------
+
@Override
protected String getNextText() {
return Messages.ResourcesView_nextResourceActionNameText;
return Messages.ResourcesView_previousResourceActionToolTipText;
}
- // ------------------------------------------------------------------------
- // Internal
- // ------------------------------------------------------------------------
-
@Override
- protected void buildEventList(ITmfTrace trace, IProgressMonitor monitor) {
- setStartTime(Long.MAX_VALUE);
- setEndTime(Long.MIN_VALUE);
+ 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;
+ }
- ArrayList<ResourcesEntry> entryList = new ArrayList<ResourcesEntry>();
- for (ITmfTrace aTrace : fTraceManager.getActiveTraceSet()) {
+ 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;
}
- if (aTrace instanceof LttngKernelTrace) {
- LttngKernelTrace lttngKernelTrace = (LttngKernelTrace) aTrace;
- ITmfStateSystem ssq = lttngKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID);
- if (!ssq.waitUntilBuilt()) {
- return;
- }
- long startTime = ssq.getStartTime();
- long endTime = ssq.getCurrentEndTime() + 1;
- ResourcesEntry groupEntry = new ResourcesEntry(lttngKernelTrace, aTrace.getName(), startTime, endTime, 0);
- entryList.add(groupEntry);
- setStartTime(Math.min(getStartTime(), startTime));
- setEndTime(Math.max(getEndTime(), 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, lttngKernelTrace, getStartTime(), getEndTime(), Type.CPU, cpu);
- groupEntry.addChild(entry);
- cpuEntries[i] = entry;
+ 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$
- 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, lttngKernelTrace, getStartTime(), getEndTime(), Type.IRQ, irq);
- groupEntry.addChild(entry);
- irqEntries[i] = entry;
+ }
+ 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$
- 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, lttngKernelTrace, getStartTime(), getEndTime(), Type.SOFT_IRQ, softIrq);
- groupEntry.addChild(entry);
- softIrqEntries[i] = entry;
+ }
+ 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);
}
}
- }
- putEntryList(trace, (ArrayList<TimeGraphEntry>) entryList.clone());
- if (trace.equals(getTrace())) {
- refresh();
- }
- for (ResourcesEntry traceEntry : entryList) {
- if (monitor.isCanceled()) {
- return;
+ if (parentTrace.equals(getTrace())) {
+ refresh();
}
- LttngKernelTrace lttngKernelTrace = traceEntry.getTrace();
- ITmfStateSystem ssq = lttngKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID);
- long startTime = ssq.getStartTime();
- long endTime = ssq.getCurrentEndTime() + 1;
- long resolution = (endTime - startTime) / getDisplayWidth();
+ long resolution = Math.max(1, (endTime - ssq.getStartTime()) / getDisplayWidth());
for (TimeGraphEntry entry : traceEntry.getChildren()) {
- List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, monitor);
- entry.setEventList(eventList);
+ 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;
}
}
protected List<ITimeEvent> getEventList(TimeGraphEntry entry,
long startTime, long endTime, long resolution,
IProgressMonitor monitor) {
- ITmfStateSystem ssq = entry.getTrace().getStateSystems().get(LttngKernelTrace.STATE_ID);
+ 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;
-
- if (!(entry instanceof ResourcesEntry)) {
- return eventList;
- }
- ResourcesEntry resourcesEntry = (ResourcesEntry) entry;
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<ITimeEvent>(statusIntervals.size());
+ eventList = new ArrayList<>(statusIntervals.size());
long lastEndTime = -1;
for (ITmfStateInterval statusInterval : statusIntervals) {
if (monitor.isCanceled()) {
eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
}
eventList.add(new TimeEvent(entry, time, duration, status));
- lastEndTime = time + duration;
- } else {
- if (true) {// includeNull) {
- eventList.add(new TimeEvent(entry, time, duration, NO_VALUE_EVENT));
- }
+ } 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<ITimeEvent>(irqIntervals.size());
+ eventList = new ArrayList<>(irqIntervals.size());
long lastEndTime = -1;
boolean lastIsNull = true;
for (ITmfStateInterval irqInterval : irqIntervals) {
eventList.add(new TimeEvent(entry, time, duration, cpu));
lastIsNull = false;
} else {
- if (lastEndTime != time && lastEndTime != -1 && 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 (lastEndTime == -1) {
+ // add null event if it intersects the start time
+ eventList.add(new NullTimeEvent(entry, time, duration));
} else {
- eventList.add(new TimeEvent(entry, time, duration, NO_VALUE_EVENT));
+ 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;
}
}
} else if (resourcesEntry.getType().equals(Type.SOFT_IRQ)) {
List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
- eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());
+ eventList = new ArrayList<>(softIrqIntervals.size());
long lastEndTime = -1;
boolean lastIsNull = true;
for (ITmfStateInterval softIrqInterval : softIrqIntervals) {
int cpu = softIrqInterval.getStateValue().unboxInt();
eventList.add(new TimeEvent(entry, time, duration, cpu));
} else {
- if (lastEndTime != time && lastEndTime != -1 && 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 (lastEndTime == -1) {
+ // add null event if it intersects the start time
+ eventList.add(new NullTimeEvent(entry, time, duration));
} else {
- eventList.add(new TimeEvent(entry, time, duration, NO_VALUE_EVENT));
+ 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;
}
}
}
- } catch (AttributeNotFoundException e) {
- e.printStackTrace();
- } catch (TimeRangeException e) {
- e.printStackTrace();
- } catch (StateValueTypeException e) {
+ } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
e.printStackTrace();
} catch (StateSystemDisposedException e) {
/* Ignored */