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