TMF: Changed the LTTng kernel analysis module to use the output extension
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesView.java
CommitLineData
6151d86c 1/*******************************************************************************
1cf25311 2 * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
6151d86c
PT
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
4999a196 11 * Geneviève Bastien - Move code to provide base classes for time graph views
6151d86c
PT
12 *******************************************************************************/
13
14package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
15
16import java.util.ArrayList;
1cf25311
PT
17import java.util.Collections;
18import java.util.HashMap;
6151d86c 19import java.util.List;
1cf25311 20import java.util.Map;
6151d86c
PT
21
22import org.eclipse.core.runtime.IProgressMonitor;
6151d86c
PT
23import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
24import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
25import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
e3366401 26import org.eclipse.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule;
6151d86c 27import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
96345c5a 28import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
6151d86c
PT
29import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
30import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
31import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
f1f86dfb 32import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
6151d86c 33import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
4999a196 34import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView;
6151d86c 35import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
1d46dc38 36import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.NullTimeEvent;
6151d86c 37import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
4999a196 38import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
6151d86c
PT
39
40/**
41 * Main implementation for the LTTng 2.0 kernel Resource view
42 *
43 * @author Patrick Tasse
44 */
4999a196 45public class ResourcesView extends AbstractTimeGraphView {
6151d86c
PT
46
47 /** View ID. */
48 public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
49
4999a196 50 private static final String[] FILTER_COLUMN_NAMES = new String[] {
747adf5c 51 Messages.ResourcesView_stateTypeName
4999a196 52 };
6151d86c 53
1cf25311
PT
54 // Timeout between updates in the build thread in ms
55 private static final long BUILD_UPDATE_TIMEOUT = 500;
56
6151d86c
PT
57 // ------------------------------------------------------------------------
58 // Constructors
59 // ------------------------------------------------------------------------
60
61 /**
62 * Default constructor
63 */
64 public ResourcesView() {
747adf5c
PT
65 super(ID, new ResourcesPresentationProvider());
66 setFilterColumns(FILTER_COLUMN_NAMES);
6151d86c
PT
67 }
68
1cf25311
PT
69 // ------------------------------------------------------------------------
70 // Internal
71 // ------------------------------------------------------------------------
72
6151d86c 73 @Override
4999a196
GB
74 protected String getNextText() {
75 return Messages.ResourcesView_nextResourceActionNameText;
6151d86c
PT
76 }
77
6151d86c 78 @Override
4999a196
GB
79 protected String getNextTooltip() {
80 return Messages.ResourcesView_nextResourceActionToolTipText;
fec1ac0b
BH
81 }
82
4999a196
GB
83 @Override
84 protected String getPrevText() {
85 return Messages.ResourcesView_previousResourceActionNameText;
6151d86c
PT
86 }
87
4999a196
GB
88 @Override
89 protected String getPrevTooltip() {
90 return Messages.ResourcesView_previousResourceActionToolTipText;
6151d86c
PT
91 }
92
4999a196 93 @Override
1cf25311 94 protected void buildEventList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
ff3f02c8 95 LttngKernelAnalysisModule module = trace.getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID);
1cf25311
PT
96 if (module == null) {
97 return;
98 }
99 module.schedule();
100 module.waitForInitialization();
101 ITmfStateSystem ssq = module.getStateSystem();
102 if (ssq == null) {
103 return;
104 }
fec1ac0b 105
1cf25311
PT
106 Map<Integer, ResourcesEntry> entryMap = new HashMap<>();
107 TimeGraphEntry traceEntry = null;
108
109 long startTime = ssq.getStartTime();
110 long start = startTime;
111 setStartTime(Math.min(getStartTime(), startTime));
112 boolean complete = false;
113 while (!complete) {
faa38350
PT
114 if (monitor.isCanceled()) {
115 return;
116 }
1cf25311
PT
117 complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
118 if (ssq.isCancelled()) {
119 return;
120 }
121 long end = ssq.getCurrentEndTime();
122 if (start == end && !complete) { // when complete execute one last time regardless of end time
123 continue;
124 }
125 long endTime = end + 1;
126 setEndTime(Math.max(getEndTime(), endTime));
127
128 if (traceEntry == null) {
129 traceEntry = new ResourcesEntry(trace, trace.getName(), startTime, endTime, 0);
130 List<TimeGraphEntry> entryList = Collections.singletonList(traceEntry);
131 addToEntryList(parentTrace, entryList);
132 } else {
133 traceEntry.updateEndTime(endTime);
134 }
135
136 List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$
137 for (Integer cpuQuark : cpuQuarks) {
138 int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));
139 ResourcesEntry entry = entryMap.get(cpuQuark);
140 if (entry == null) {
141 entry = new ResourcesEntry(cpuQuark, trace, startTime, endTime, Type.CPU, cpu);
142 entryMap.put(cpuQuark, entry);
143 traceEntry.addChild(entry);
144 } else {
145 entry.updateEndTime(endTime);
6151d86c 146 }
1cf25311
PT
147 }
148 List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
149 for (Integer irqQuark : irqQuarks) {
150 int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
151 ResourcesEntry entry = entryMap.get(irqQuark);
152 if (entry == null) {
153 entry = new ResourcesEntry(irqQuark, trace, startTime, endTime, Type.IRQ, irq);
154 entryMap.put(irqQuark, entry);
155 traceEntry.addChild(entry);
156 } else {
157 entry.updateEndTime(endTime);
6151d86c 158 }
1cf25311
PT
159 }
160 List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
161 for (Integer softIrqQuark : softIrqQuarks) {
162 int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
163 ResourcesEntry entry = entryMap.get(softIrqQuark);
164 if (entry == null) {
165 entry = new ResourcesEntry(softIrqQuark, trace, startTime, endTime, Type.SOFT_IRQ, softIrq);
166 entryMap.put(softIrqQuark, entry);
167 traceEntry.addChild(entry);
168 } else {
169 entry.updateEndTime(endTime);
6151d86c
PT
170 }
171 }
4999a196 172
1cf25311
PT
173 if (parentTrace.equals(getTrace())) {
174 refresh();
faa38350 175 }
1cf25311 176 long resolution = Math.max(1, (endTime - ssq.getStartTime()) / getDisplayWidth());
4999a196 177 for (TimeGraphEntry entry : traceEntry.getChildren()) {
1cf25311
PT
178 if (monitor.isCanceled()) {
179 return;
180 }
181 List<ITimeEvent> eventList = getEventList(entry, start, endTime, resolution, monitor);
182 if (eventList != null) {
183 for (ITimeEvent event : eventList) {
184 entry.addEvent(event);
185 }
186 }
6151d86c
PT
187 redraw();
188 }
1cf25311
PT
189
190 start = end;
6151d86c
PT
191 }
192 }
193
4999a196
GB
194 @Override
195 protected List<ITimeEvent> getEventList(TimeGraphEntry entry,
196 long startTime, long endTime, long resolution,
6151d86c 197 IProgressMonitor monitor) {
1d46dc38 198 ResourcesEntry resourcesEntry = (ResourcesEntry) entry;
ff3f02c8 199 LttngKernelAnalysisModule module = resourcesEntry.getTrace().getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID);
1cf25311
PT
200 if (module == null) {
201 return null;
202 }
4bc53929
GB
203 ITmfStateSystem ssq = module.getStateSystem();
204 if (ssq == null) {
205 return null;
206 }
41b5c37f
AM
207 final long realStart = Math.max(startTime, ssq.getStartTime());
208 final long realEnd = Math.min(endTime, ssq.getCurrentEndTime() + 1);
209 if (realEnd <= realStart) {
6151d86c
PT
210 return null;
211 }
212 List<ITimeEvent> eventList = null;
4999a196
GB
213 int quark = resourcesEntry.getQuark();
214
6151d86c 215 try {
4999a196 216 if (resourcesEntry.getType().equals(Type.CPU)) {
6151d86c 217 int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);
41b5c37f 218 List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, realStart, realEnd - 1, resolution, monitor);
e0838ca1 219 eventList = new ArrayList<>(statusIntervals.size());
6151d86c
PT
220 long lastEndTime = -1;
221 for (ITmfStateInterval statusInterval : statusIntervals) {
222 if (monitor.isCanceled()) {
223 return null;
224 }
225 int status = statusInterval.getStateValue().unboxInt();
226 long time = statusInterval.getStartTime();
227 long duration = statusInterval.getEndTime() - time + 1;
228 if (!statusInterval.getStateValue().isNull()) {
229 if (lastEndTime != time && lastEndTime != -1) {
230 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
231 }
4999a196 232 eventList.add(new TimeEvent(entry, time, duration, status));
1d46dc38
PT
233 } else if (lastEndTime == -1 || time + duration >= endTime) {
234 // add null event if it intersects the start or end time
235 eventList.add(new NullTimeEvent(entry, time, duration));
6151d86c 236 }
1d46dc38 237 lastEndTime = time + duration;
6151d86c 238 }
4999a196 239 } else if (resourcesEntry.getType().equals(Type.IRQ)) {
41b5c37f 240 List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
e0838ca1 241 eventList = new ArrayList<>(irqIntervals.size());
6151d86c
PT
242 long lastEndTime = -1;
243 boolean lastIsNull = true;
244 for (ITmfStateInterval irqInterval : irqIntervals) {
245 if (monitor.isCanceled()) {
246 return null;
247 }
248 long time = irqInterval.getStartTime();
249 long duration = irqInterval.getEndTime() - time + 1;
250 if (!irqInterval.getStateValue().isNull()) {
251 int cpu = irqInterval.getStateValue().unboxInt();
4999a196 252 eventList.add(new TimeEvent(entry, time, duration, cpu));
6151d86c
PT
253 lastIsNull = false;
254 } else {
1d46dc38
PT
255 if (lastEndTime == -1) {
256 // add null event if it intersects the start time
257 eventList.add(new NullTimeEvent(entry, time, duration));
4999a196 258 } else {
1d46dc38
PT
259 if (lastEndTime != time && lastIsNull) {
260 /* 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) */
261 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
262 }
263 if (time + duration >= endTime) {
264 // add null event if it intersects the end time
265 eventList.add(new NullTimeEvent(entry, time, duration));
266 }
6151d86c
PT
267 }
268 lastIsNull = true;
269 }
270 lastEndTime = time + duration;
271 }
4999a196 272 } else if (resourcesEntry.getType().equals(Type.SOFT_IRQ)) {
41b5c37f 273 List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
e0838ca1 274 eventList = new ArrayList<>(softIrqIntervals.size());
6151d86c
PT
275 long lastEndTime = -1;
276 boolean lastIsNull = true;
277 for (ITmfStateInterval softIrqInterval : softIrqIntervals) {
278 if (monitor.isCanceled()) {
279 return null;
280 }
281 long time = softIrqInterval.getStartTime();
282 long duration = softIrqInterval.getEndTime() - time + 1;
283 if (!softIrqInterval.getStateValue().isNull()) {
284 int cpu = softIrqInterval.getStateValue().unboxInt();
4999a196 285 eventList.add(new TimeEvent(entry, time, duration, cpu));
6151d86c 286 } else {
1d46dc38
PT
287 if (lastEndTime == -1) {
288 // add null event if it intersects the start time
289 eventList.add(new NullTimeEvent(entry, time, duration));
4999a196 290 } else {
1d46dc38
PT
291 if (lastEndTime != time && lastIsNull) {
292 /* 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) */
293 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
294 }
295 if (time + duration >= endTime) {
296 // add null event if it intersects the end time
297 eventList.add(new NullTimeEvent(entry, time, duration));
298 }
6151d86c
PT
299 }
300 lastIsNull = true;
301 }
302 lastEndTime = time + duration;
303 }
304 }
4999a196 305
1cf25311 306 } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
6151d86c 307 e.printStackTrace();
96345c5a
AM
308 } catch (StateSystemDisposedException e) {
309 /* Ignored */
6151d86c
PT
310 }
311 return eventList;
312 }
313
6151d86c 314}
This page took 0.064004 seconds and 5 git commands to generate.