Merge branch 'master' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesView.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal
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
11 * Geneviève Bastien - Move code to provide base classes for time graph views
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
21 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
22 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
23 import org.eclipse.linuxtools.lttng2.kernel.core.trace.LttngKernelTrace;
24 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
25 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
26 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
27 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
28 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
29 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
30 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
31 import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView;
32 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
33 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
34 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
35
36 /**
37 * Main implementation for the LTTng 2.0 kernel Resource view
38 *
39 * @author Patrick Tasse
40 */
41 public class ResourcesView extends AbstractTimeGraphView {
42
43 /** View ID. */
44 public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
45
46 /**
47 * Default value for events with no other value. Since value in this case is
48 * often a CPU number, this constant should be <0
49 */
50 public static final int NO_VALUE_EVENT = -999;
51
52 private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn;
53
54 private static final String[] COLUMN_NAMES = new String[] {
55 PROCESS_COLUMN
56 };
57
58 private static final String[] FILTER_COLUMN_NAMES = new String[] {
59 PROCESS_COLUMN
60 };
61
62 private static final int[] WEIGHTS = { 15, 85 };
63
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
68 /**
69 * Default constructor
70 */
71 public ResourcesView() {
72 super(ID, COLUMN_NAMES, FILTER_COLUMN_NAMES, new ResourcesPresentationProvider());
73 setWeight(WEIGHTS);
74 }
75
76 @Override
77 protected String getNextText() {
78 return Messages.ResourcesView_nextResourceActionNameText;
79 }
80
81 @Override
82 protected String getNextTooltip() {
83 return Messages.ResourcesView_nextResourceActionToolTipText;
84 }
85
86 @Override
87 protected String getPrevText() {
88 return Messages.ResourcesView_previousResourceActionNameText;
89 }
90
91 @Override
92 protected String getPrevTooltip() {
93 return Messages.ResourcesView_previousResourceActionToolTipText;
94 }
95
96 // ------------------------------------------------------------------------
97 // Internal
98 // ------------------------------------------------------------------------
99
100 @Override
101 protected void buildEventList(ITmfTrace trace, IProgressMonitor monitor) {
102 setStartTime(Long.MAX_VALUE);
103 setEndTime(Long.MIN_VALUE);
104
105 ArrayList<ResourcesEntry> entryList = new ArrayList<ResourcesEntry>();
106 for (ITmfTrace aTrace : fTraceManager.getActiveTraceSet()) {
107 if (monitor.isCanceled()) {
108 return;
109 }
110 if (aTrace instanceof LttngKernelTrace) {
111 LttngKernelTrace lttngKernelTrace = (LttngKernelTrace) aTrace;
112 ITmfStateSystem ssq = lttngKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID);
113 if (!ssq.waitUntilBuilt()) {
114 return;
115 }
116 long startTime = ssq.getStartTime();
117 long endTime = ssq.getCurrentEndTime() + 1;
118 ResourcesEntry groupEntry = new ResourcesEntry(lttngKernelTrace, aTrace.getName(), startTime, endTime, 0);
119 entryList.add(groupEntry);
120 setStartTime(Math.min(getStartTime(), startTime));
121 setEndTime(Math.max(getEndTime(), endTime));
122 List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$
123 ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];
124 for (int i = 0; i < cpuQuarks.size(); i++) {
125 int cpuQuark = cpuQuarks.get(i);
126 int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));
127 ResourcesEntry entry = new ResourcesEntry(cpuQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.CPU, cpu);
128 groupEntry.addChild(entry);
129 cpuEntries[i] = entry;
130 }
131 List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
132 ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];
133 for (int i = 0; i < irqQuarks.size(); i++) {
134 int irqQuark = irqQuarks.get(i);
135 int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
136 ResourcesEntry entry = new ResourcesEntry(irqQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.IRQ, irq);
137 groupEntry.addChild(entry);
138 irqEntries[i] = entry;
139 }
140 List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
141 ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];
142 for (int i = 0; i < softIrqQuarks.size(); i++) {
143 int softIrqQuark = softIrqQuarks.get(i);
144 int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
145 ResourcesEntry entry = new ResourcesEntry(softIrqQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.SOFT_IRQ, softIrq);
146 groupEntry.addChild(entry);
147 softIrqEntries[i] = entry;
148 }
149 }
150 }
151 putEntryList(trace, (ArrayList<TimeGraphEntry>) entryList.clone());
152
153 if (trace.equals(getTrace())) {
154 refresh();
155 }
156 for (ResourcesEntry traceEntry : entryList) {
157 if (monitor.isCanceled()) {
158 return;
159 }
160 LttngKernelTrace lttngKernelTrace = traceEntry.getTrace();
161 ITmfStateSystem ssq = lttngKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID);
162 long startTime = ssq.getStartTime();
163 long endTime = ssq.getCurrentEndTime() + 1;
164 long resolution = (endTime - startTime) / getDisplayWidth();
165 for (TimeGraphEntry entry : traceEntry.getChildren()) {
166 List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, monitor);
167 entry.setEventList(eventList);
168 redraw();
169 }
170 }
171 }
172
173 @Override
174 protected List<ITimeEvent> getEventList(TimeGraphEntry entry,
175 long startTime, long endTime, long resolution,
176 IProgressMonitor monitor) {
177 ITmfStateSystem ssq = entry.getTrace().getStateSystems().get(LttngKernelTrace.STATE_ID);
178 final long realStart = Math.max(startTime, ssq.getStartTime());
179 final long realEnd = Math.min(endTime, ssq.getCurrentEndTime() + 1);
180 if (realEnd <= realStart) {
181 return null;
182 }
183 List<ITimeEvent> eventList = null;
184
185 if (!(entry instanceof ResourcesEntry)) {
186 return eventList;
187 }
188 ResourcesEntry resourcesEntry = (ResourcesEntry) entry;
189 int quark = resourcesEntry.getQuark();
190
191 try {
192 if (resourcesEntry.getType().equals(Type.CPU)) {
193 int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);
194 List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, realStart, realEnd - 1, resolution, monitor);
195 eventList = new ArrayList<ITimeEvent>(statusIntervals.size());
196 long lastEndTime = -1;
197 for (ITmfStateInterval statusInterval : statusIntervals) {
198 if (monitor.isCanceled()) {
199 return null;
200 }
201 int status = statusInterval.getStateValue().unboxInt();
202 long time = statusInterval.getStartTime();
203 long duration = statusInterval.getEndTime() - time + 1;
204 if (!statusInterval.getStateValue().isNull()) {
205 if (lastEndTime != time && lastEndTime != -1) {
206 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
207 }
208 eventList.add(new TimeEvent(entry, time, duration, status));
209 lastEndTime = time + duration;
210 } else {
211 if (true) {// includeNull) {
212 eventList.add(new TimeEvent(entry, time, duration, NO_VALUE_EVENT));
213 }
214 }
215 }
216 } else if (resourcesEntry.getType().equals(Type.IRQ)) {
217 List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
218 eventList = new ArrayList<ITimeEvent>(irqIntervals.size());
219 long lastEndTime = -1;
220 boolean lastIsNull = true;
221 for (ITmfStateInterval irqInterval : irqIntervals) {
222 if (monitor.isCanceled()) {
223 return null;
224 }
225 long time = irqInterval.getStartTime();
226 long duration = irqInterval.getEndTime() - time + 1;
227 if (!irqInterval.getStateValue().isNull()) {
228 int cpu = irqInterval.getStateValue().unboxInt();
229 eventList.add(new TimeEvent(entry, time, duration, cpu));
230 lastIsNull = false;
231 } else {
232 if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
233 /* 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) */
234 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
235 } else {
236 eventList.add(new TimeEvent(entry, time, duration, NO_VALUE_EVENT));
237 }
238 lastIsNull = true;
239 }
240 lastEndTime = time + duration;
241 }
242 } else if (resourcesEntry.getType().equals(Type.SOFT_IRQ)) {
243 List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
244 eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());
245 long lastEndTime = -1;
246 boolean lastIsNull = true;
247 for (ITmfStateInterval softIrqInterval : softIrqIntervals) {
248 if (monitor.isCanceled()) {
249 return null;
250 }
251 long time = softIrqInterval.getStartTime();
252 long duration = softIrqInterval.getEndTime() - time + 1;
253 if (!softIrqInterval.getStateValue().isNull()) {
254 int cpu = softIrqInterval.getStateValue().unboxInt();
255 eventList.add(new TimeEvent(entry, time, duration, cpu));
256 } else {
257 if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
258 /* 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) */
259 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
260 } else {
261 eventList.add(new TimeEvent(entry, time, duration, NO_VALUE_EVENT));
262 }
263 lastIsNull = true;
264 }
265 lastEndTime = time + duration;
266 }
267 }
268
269 } catch (AttributeNotFoundException e) {
270 e.printStackTrace();
271 } catch (TimeRangeException e) {
272 e.printStackTrace();
273 } catch (StateValueTypeException e) {
274 e.printStackTrace();
275 } catch (StateSystemDisposedException e) {
276 /* Ignored */
277 }
278 return eventList;
279 }
280
281 }
This page took 0.037962 seconds and 6 git commands to generate.