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