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