Commit | Line | Data |
---|---|---|
44d8e2f1 | 1 | /******************************************************************************* |
f8f46a52 | 2 | * Copyright (c) 2015, 2016 École Polytechnique de Montréal |
44d8e2f1 FG |
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 | ||
10 | package org.eclipse.tracecompass.internal.analysis.graph.ui.criticalpath.view; | |
11 | ||
94411c58 AM |
12 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
13 | ||
44d8e2f1 FG |
14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | import java.util.Comparator; | |
17 | import java.util.HashMap; | |
44d8e2f1 FG |
18 | import java.util.List; |
19 | import java.util.Map; | |
585f9916 GB |
20 | import java.util.concurrent.locks.Lock; |
21 | import java.util.concurrent.locks.ReentrantLock; | |
44d8e2f1 FG |
22 | |
23 | import org.eclipse.core.runtime.IProgressMonitor; | |
585f9916 | 24 | import org.eclipse.core.runtime.NullProgressMonitor; |
44d8e2f1 FG |
25 | import org.eclipse.jdt.annotation.NonNull; |
26 | import org.eclipse.jdt.annotation.Nullable; | |
27 | import org.eclipse.jface.viewers.Viewer; | |
28 | import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker; | |
29 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge; | |
30 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge.EdgeType; | |
31 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph; | |
32 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex; | |
2244d4af | 33 | import org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule; |
44d8e2f1 FG |
34 | import org.eclipse.tracecompass.analysis.graph.core.criticalpath.CriticalPathModule; |
35 | import org.eclipse.tracecompass.common.core.NonNullUtils; | |
36 | import org.eclipse.tracecompass.internal.analysis.graph.core.base.TmfGraphStatistics; | |
37 | import org.eclipse.tracecompass.internal.analysis.graph.core.base.TmfGraphVisitor; | |
38 | import org.eclipse.tracecompass.internal.analysis.graph.ui.criticalpath.view.CriticalPathPresentationProvider.State; | |
39 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; | |
40 | import org.eclipse.tracecompass.tmf.core.signal.TmfStartAnalysisSignal; | |
41 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
42 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; | |
43 | import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView; | |
44 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphContentProvider; | |
45 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent; | |
46 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
47 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
48 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent; | |
49 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry; | |
50 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent; | |
51 | ||
52 | import com.google.common.collect.HashBasedTable; | |
53 | import com.google.common.collect.Iterables; | |
54 | import com.google.common.collect.Table; | |
55 | ||
56 | /** | |
57 | * The Critical Path view | |
58 | * | |
59 | * @author Geneviève Bastien | |
60 | * @author Francis Giraldeau | |
61 | */ | |
62 | public class CriticalPathView extends AbstractTimeGraphView { | |
63 | ||
64 | // ------------------------------------------------------------------------ | |
65 | // Constants | |
66 | // ------------------------------------------------------------------------ | |
67 | ||
68 | /** View ID */ | |
69 | public static final String ID = "org.eclipse.linuxtools.tmf.analysis.graph.ui.criticalpath.view.criticalpathview"; //$NON-NLS-1$ | |
70 | ||
71 | private static final double NANOINV = 0.000000001; | |
72 | ||
73 | private static final String COLUMN_PROCESS = Messages.getMessage(Messages.CriticalFlowView_columnProcess); | |
74 | private static final String COLUMN_ELAPSED = Messages.getMessage(Messages.CriticalFlowView_columnElapsed); | |
75 | private static final String COLUMN_PERCENT = Messages.getMessage(Messages.CriticalFlowView_columnPercent); | |
76 | ||
77 | private static final String[] COLUMN_NAMES = new String[] { | |
78 | COLUMN_PROCESS, | |
79 | COLUMN_ELAPSED, | |
80 | COLUMN_PERCENT | |
81 | }; | |
82 | ||
83 | private static final String[] FILTER_COLUMN_NAMES = new String[] { | |
84 | COLUMN_PROCESS | |
85 | }; | |
86 | ||
dc303fab | 87 | private final Table<ITmfTrace, Object, List<ILinkEvent>> fLinks = HashBasedTable.create(); |
44d8e2f1 | 88 | /** The trace to entry list hash map */ |
dc303fab | 89 | private final Table<ITmfTrace, Object, TmfGraphStatistics> fObjectStatistics = HashBasedTable.create(); |
44d8e2f1 FG |
90 | |
91 | private final CriticalPathContentProvider fContentProvider = new CriticalPathContentProvider(); | |
92 | ||
93 | private TmfGraphStatistics fStats = new TmfGraphStatistics(); | |
94 | ||
95 | private static final IGraphWorker DEFAULT_WORKER = new IGraphWorker() { | |
96 | @Override | |
97 | public String getHostId() { | |
98 | return "default"; //$NON-NLS-1$ | |
99 | } | |
100 | }; | |
101 | ||
102 | private class CriticalPathContentProvider implements ITimeGraphContentProvider { | |
103 | ||
104 | private final class HorizontalLinksVisitor extends TmfGraphVisitor { | |
105 | private final CriticalPathEntry fDefaultParent; | |
106 | private final Map<String, CriticalPathEntry> fHostEntries; | |
107 | private final TmfGraph fGraph; | |
108 | private final ITmfTrace fTrace; | |
109 | private final HashMap<Object, CriticalPathEntry> fRootList; | |
110 | ||
111 | private HorizontalLinksVisitor(CriticalPathEntry defaultParent, Map<String, CriticalPathEntry> hostEntries, TmfGraph graph, ITmfTrace trace, HashMap<Object, CriticalPathEntry> rootList) { | |
112 | fDefaultParent = defaultParent; | |
113 | fHostEntries = hostEntries; | |
114 | fGraph = graph; | |
115 | fTrace = trace; | |
116 | fRootList = rootList; | |
117 | } | |
118 | ||
119 | @Override | |
120 | public void visitHead(TmfVertex node) { | |
121 | /* TODO possible null pointer ? */ | |
122 | IGraphWorker owner = fGraph.getParentOf(node); | |
123 | if (owner == null) { | |
124 | return; | |
125 | } | |
126 | if (fRootList.containsKey(owner)) { | |
127 | return; | |
128 | } | |
129 | TmfVertex first = fGraph.getHead(owner); | |
130 | TmfVertex last = fGraph.getTail(owner); | |
131 | if (first == null || last == null) { | |
132 | return; | |
133 | } | |
134 | setStartTime(Math.min(getStartTime(), first.getTs())); | |
135 | setEndTime(Math.max(getEndTime(), last.getTs())); | |
136 | // create host entry | |
137 | CriticalPathEntry parent = fDefaultParent; | |
138 | String host = owner.getHostId(); | |
139 | if (!fHostEntries.containsKey(host)) { | |
140 | fHostEntries.put(host, new CriticalPathEntry(host, fTrace, getStartTime(), getEndTime(), owner)); | |
141 | } | |
94411c58 | 142 | parent = checkNotNull(fHostEntries.get(host)); |
44d8e2f1 FG |
143 | CriticalPathEntry entry = new CriticalPathEntry(NonNullUtils.nullToEmptyString(owner), fTrace, getStartTime(), getEndTime(), owner); |
144 | parent.addChild(entry); | |
145 | ||
146 | fRootList.put(owner, entry); | |
147 | } | |
148 | ||
44d8e2f1 FG |
149 | @Override |
150 | public void visit(TmfEdge link, boolean horizontal) { | |
151 | if (horizontal) { | |
152 | Object parent = fGraph.getParentOf(link.getVertexFrom()); | |
0e4f957e | 153 | CriticalPathEntry entry = fRootList.get(parent); |
44d8e2f1 FG |
154 | TimeEvent ev = new TimeEvent(entry, link.getVertexFrom().getTs(), link.getDuration(), |
155 | getMatchingState(link.getType()).ordinal()); | |
156 | entry.addEvent(ev); | |
157 | } | |
158 | } | |
159 | } | |
160 | ||
161 | private final class VerticalLinksVisitor extends TmfGraphVisitor { | |
162 | private final TmfGraph fGraph; | |
163 | private final List<ILinkEvent> fGraphLinks; | |
164 | private final Map<Object, CriticalPathEntry> fEntryMap; | |
165 | ||
166 | private VerticalLinksVisitor(TmfGraph graph, List<ILinkEvent> graphLinks, Map<Object, CriticalPathEntry> entryMap) { | |
167 | fGraph = graph; | |
168 | fGraphLinks = graphLinks; | |
169 | fEntryMap = entryMap; | |
170 | } | |
171 | ||
172 | @Override | |
173 | public void visitHead(TmfVertex node) { | |
174 | ||
175 | } | |
176 | ||
177 | @Override | |
178 | public void visit(TmfVertex node) { | |
179 | ||
180 | } | |
181 | ||
182 | @Override | |
183 | public void visit(TmfEdge link, boolean horizontal) { | |
184 | if (!horizontal) { | |
185 | Object parentFrom = fGraph.getParentOf(link.getVertexFrom()); | |
186 | Object parentTo = fGraph.getParentOf(link.getVertexTo()); | |
187 | CriticalPathEntry entryFrom = fEntryMap.get(parentFrom); | |
188 | CriticalPathEntry entryTo = fEntryMap.get(parentTo); | |
189 | TimeLinkEvent lk = new TimeLinkEvent(entryFrom, entryTo, link.getVertexFrom().getTs(), | |
190 | link.getVertexTo().getTs() - link.getVertexFrom().getTs(), getMatchingState(link.getType()).ordinal()); | |
191 | fGraphLinks.add(lk); | |
192 | } | |
193 | } | |
194 | } | |
195 | ||
585f9916 GB |
196 | private class BuildThread extends Thread { |
197 | private final ITmfTrace fBuildTrace; | |
198 | private final IProgressMonitor fMonitor; | |
199 | ||
200 | public BuildThread(final ITmfTrace trace) { | |
201 | super("Critical path view build"); //$NON-NLS-1$ | |
202 | fBuildTrace = trace; | |
203 | fMonitor = new NullProgressMonitor(); | |
204 | } | |
205 | ||
206 | @Override | |
207 | public void run() { | |
208 | try { | |
209 | CriticalPathModule module = Iterables.<@Nullable CriticalPathModule> getFirst( | |
210 | TmfTraceUtils.getAnalysisModulesOfClass(fBuildTrace, CriticalPathModule.class), | |
211 | null); | |
212 | if (module == null) { | |
213 | return; | |
214 | } | |
215 | module.schedule(); | |
216 | if (module.waitForCompletion(fMonitor)) { | |
2244d4af GB |
217 | // Module is completed, set the start and end time of |
218 | // this view | |
219 | setStartEndTime(module); | |
585f9916 GB |
220 | refresh(); |
221 | } | |
222 | ||
223 | } finally { | |
224 | fSyncLock.lock(); | |
225 | fBuildThread = null; | |
226 | fSyncLock.unlock(); | |
227 | } | |
228 | } | |
229 | ||
230 | public void cancel() { | |
231 | fMonitor.setCanceled(true); | |
232 | } | |
233 | } | |
234 | ||
235 | private final Lock fSyncLock = new ReentrantLock(); | |
236 | private final Map<Object, Map<Object, CriticalPathEntry>> workerMaps = new HashMap<>(); | |
237 | private final Map<Object, List<TimeGraphEntry>> workerEntries = new HashMap<>(); | |
238 | private final Map<Object, List<ILinkEvent>> linkMap = new HashMap<>(); | |
44d8e2f1 | 239 | private @Nullable Object fCurrentObject; |
585f9916 | 240 | private @Nullable BuildThread fBuildThread = null; |
44d8e2f1 FG |
241 | |
242 | @Override | |
df2597e0 | 243 | public ITimeGraphEntry[] getElements(@Nullable Object inputElement) { |
44d8e2f1 FG |
244 | ITimeGraphEntry[] ret = new ITimeGraphEntry[0]; |
245 | if (inputElement instanceof List) { | |
246 | List<?> list = (List<?>) inputElement; | |
247 | if (!list.isEmpty()) { | |
248 | Object first = list.get(0); | |
249 | if (first instanceof CriticalPathBaseEntry) { | |
250 | IGraphWorker worker = ((CriticalPathBaseEntry) first).getWorker(); | |
251 | ret = getWorkerEntries(worker); | |
252 | } | |
253 | } | |
254 | } | |
255 | return ret; | |
256 | } | |
257 | ||
258 | private ITimeGraphEntry[] getWorkerEntries(IGraphWorker worker) { | |
259 | fCurrentObject = worker; | |
260 | List<TimeGraphEntry> entries = workerEntries.get(worker); | |
2244d4af | 261 | ITmfTrace trace = getTrace(); |
44d8e2f1 FG |
262 | if (entries == null) { |
263 | buildEntryList(worker); | |
264 | entries = workerEntries.get(worker); | |
2244d4af GB |
265 | } else if (trace != null) { |
266 | // Get the statistics object for this worker | |
267 | TmfGraphStatistics stats = fObjectStatistics.get(trace, worker); | |
268 | if (stats == null) { | |
269 | stats = new TmfGraphStatistics(); | |
270 | } | |
271 | fStats = stats; | |
44d8e2f1 | 272 | } |
df2597e0 | 273 | |
44d8e2f1 FG |
274 | return (entries == null) ? |
275 | new ITimeGraphEntry[0] : | |
367e2932 | 276 | entries.toArray(new @NonNull ITimeGraphEntry[entries.size()]); |
44d8e2f1 FG |
277 | } |
278 | ||
279 | private void buildEntryList(IGraphWorker worker) { | |
280 | final ITmfTrace trace = getTrace(); | |
281 | if (trace == null) { | |
282 | return; | |
283 | } | |
284 | final TmfGraph graph = getGraph(trace); | |
285 | if (graph == null) { | |
286 | return; | |
287 | } | |
44d8e2f1 FG |
288 | |
289 | final HashMap<Object, CriticalPathEntry> rootList = new HashMap<>(); | |
290 | fLinks.remove(trace, worker); | |
291 | ||
292 | TmfVertex vertex = graph.getHead(); | |
293 | ||
294 | /* Calculate statistics */ | |
295 | fStats = new TmfGraphStatistics(); | |
296 | fStats.computeGraphStatistics(graph, worker); | |
297 | fObjectStatistics.put(trace, worker, fStats); | |
298 | ||
299 | // Hosts entries are parent of each worker entries | |
300 | final Map<String, CriticalPathEntry> hostEntries = new HashMap<>(); | |
301 | ||
302 | /* create all interval entries and horizontal links */ | |
303 | ||
304 | final CriticalPathEntry defaultParent = new CriticalPathEntry("default", trace, getStartTime(), getEndTime(), DEFAULT_WORKER); //$NON-NLS-1$ | |
305 | graph.scanLineTraverse(vertex, new HorizontalLinksVisitor(defaultParent, hostEntries, graph, trace, rootList)); | |
306 | ||
307 | workerMaps.put(worker, rootList); | |
308 | ||
309 | List<TimeGraphEntry> list = new ArrayList<>(); | |
310 | list.addAll(hostEntries.values()); | |
311 | if (defaultParent.hasChildren()) { | |
312 | list.add(defaultParent); | |
313 | } | |
314 | ||
44d8e2f1 FG |
315 | workerEntries.put(worker, list); |
316 | } | |
317 | ||
318 | private @Nullable TmfGraph getGraph(final ITmfTrace trace) { | |
df2597e0 AM |
319 | CriticalPathModule module = Iterables.<@Nullable CriticalPathModule> getFirst( |
320 | TmfTraceUtils.getAnalysisModulesOfClass(trace, CriticalPathModule.class), | |
321 | null); | |
44d8e2f1 | 322 | if (module == null) { |
9ee366e2 | 323 | throw new IllegalStateException("View requires an analysis module"); //$NON-NLS-1$ |
44d8e2f1 | 324 | } |
df2597e0 | 325 | |
44d8e2f1 FG |
326 | final TmfGraph graph = module.getCriticalPath(); |
327 | return graph; | |
328 | } | |
329 | ||
330 | public @Nullable List<ILinkEvent> getLinkList(long startTime, long endTime) { | |
331 | Object current = fCurrentObject; | |
332 | if (current == null) { | |
333 | return null; | |
334 | } | |
335 | /* | |
336 | * Critical path typically has relatively few links, so we calculate | |
337 | * and save them all, but just return those in range | |
338 | */ | |
339 | List<ILinkEvent> links = linkMap.get(current); | |
340 | if (links != null) { | |
341 | return links; | |
342 | } | |
343 | final ITmfTrace trace = getTrace(); | |
344 | if (trace == null) { | |
345 | return null; | |
346 | } | |
df2597e0 AM |
347 | CriticalPathModule module = Iterables.<@Nullable CriticalPathModule> getFirst( |
348 | TmfTraceUtils.getAnalysisModulesOfClass(trace, CriticalPathModule.class), null); | |
44d8e2f1 | 349 | if (module == null) { |
9ee366e2 | 350 | throw new IllegalStateException("View requires an analysis module"); //$NON-NLS-1$ |
44d8e2f1 | 351 | } |
df2597e0 | 352 | |
44d8e2f1 FG |
353 | final TmfGraph graph = module.getCriticalPath(); |
354 | if (graph == null) { | |
355 | return null; | |
356 | } | |
357 | final Map<Object, CriticalPathEntry> entryMap = workerMaps.get(current); | |
358 | if (entryMap == null) { | |
359 | return null; | |
360 | } | |
361 | ||
362 | TmfVertex vertex = graph.getHead(); | |
363 | ||
364 | final List<ILinkEvent> graphLinks = new ArrayList<>(); | |
365 | ||
366 | /* find vertical links */ | |
367 | graph.scanLineTraverse(vertex, new VerticalLinksVisitor(graph, graphLinks, entryMap)); | |
4c4e2816 | 368 | fLinks.put(trace, checkNotNull(fCurrentObject), graphLinks); |
44d8e2f1 FG |
369 | links = graphLinks; |
370 | ||
371 | List<ILinkEvent> linksInRange = new ArrayList<>(); | |
372 | for (ILinkEvent link : links) { | |
373 | if (((link.getTime() >= startTime) && (link.getTime() <= endTime)) || | |
374 | ((link.getTime() + link.getDuration() >= startTime) && (link.getTime() + link.getDuration() <= endTime))) { | |
375 | linksInRange.add(link); | |
376 | } | |
377 | } | |
378 | return linksInRange; | |
379 | } | |
380 | ||
381 | @Override | |
382 | public void dispose() { | |
585f9916 GB |
383 | fSyncLock.lock(); |
384 | try { | |
385 | BuildThread buildThread = fBuildThread; | |
386 | if (buildThread != null) { | |
387 | buildThread.cancel(); | |
388 | } | |
389 | } finally { | |
390 | fSyncLock.unlock(); | |
391 | } | |
44d8e2f1 FG |
392 | } |
393 | ||
394 | @Override | |
395 | public void inputChanged(@Nullable Viewer viewer, @Nullable Object oldInput, @Nullable Object newInput) { | |
585f9916 GB |
396 | // The input has changed, the critical path will be re-computed, |
397 | // wait for the analysis to be finished, then call the refresh | |
398 | // method of the view | |
399 | if (!(newInput instanceof List)) { | |
400 | return; | |
401 | } | |
402 | List<?> list = (List<?>) newInput; | |
403 | if (list.isEmpty()) { | |
404 | return; | |
405 | } | |
406 | final ITmfTrace trace = getTrace(); | |
407 | if (trace == null) { | |
408 | return; | |
409 | } | |
410 | ||
411 | fSyncLock.lock(); | |
412 | try { | |
413 | BuildThread buildThread = fBuildThread; | |
414 | if (buildThread != null) { | |
415 | buildThread.cancel(); | |
416 | } | |
417 | buildThread = new BuildThread(trace); | |
418 | buildThread.start(); | |
419 | fBuildThread = buildThread; | |
420 | } finally { | |
421 | fSyncLock.unlock(); | |
422 | } | |
44d8e2f1 FG |
423 | } |
424 | ||
425 | @Override | |
4c4e2816 | 426 | public ITimeGraphEntry @Nullable [] getChildren(@Nullable Object parentElement) { |
44d8e2f1 FG |
427 | if (parentElement instanceof CriticalPathEntry) { |
428 | List<? extends ITimeGraphEntry> children = ((CriticalPathEntry) parentElement).getChildren(); | |
429 | return children.toArray(new TimeGraphEntry[children.size()]); | |
430 | } | |
431 | return null; | |
432 | } | |
433 | ||
434 | @Override | |
435 | public @Nullable ITimeGraphEntry getParent(@Nullable Object element) { | |
436 | if (element instanceof CriticalPathEntry) { | |
437 | return ((CriticalPathEntry) element).getParent(); | |
438 | } | |
439 | return null; | |
440 | } | |
441 | ||
442 | @Override | |
443 | public boolean hasChildren(@Nullable Object element) { | |
444 | if (element instanceof CriticalPathEntry) { | |
445 | return ((CriticalPathEntry) element).hasChildren(); | |
446 | } | |
447 | return false; | |
448 | } | |
449 | ||
450 | } | |
451 | ||
452 | private class CriticalPathTreeLabelProvider extends TreeLabelProvider { | |
453 | ||
454 | @Override | |
455 | public String getColumnText(@Nullable Object element, int columnIndex) { | |
456 | if (element == null) { | |
457 | return ""; //$NON-NLS-1$ | |
458 | } | |
459 | CriticalPathEntry entry = (CriticalPathEntry) element; | |
460 | if (columnIndex == 0) { | |
461 | return NonNullUtils.nullToEmptyString(entry.getName()); | |
462 | } else if (columnIndex == 1) { | |
463 | Long sum = fStats.getSum(entry.getWorker()); | |
464 | String value = String.format("%.9f", sum * NANOINV); //$NON-NLS-1$ | |
465 | return NonNullUtils.nullToEmptyString(value); | |
466 | } else if (columnIndex == 2) { | |
467 | Double percent = fStats.getPercent(entry.getWorker()); | |
468 | String value = String.format("%.2f", percent * 100); //$NON-NLS-1$ | |
469 | return NonNullUtils.nullToEmptyString(value); | |
470 | } | |
471 | return ""; //$NON-NLS-1$ | |
472 | } | |
473 | ||
474 | } | |
475 | ||
476 | private class CriticalPathEntryComparator implements Comparator<ITimeGraphEntry> { | |
477 | ||
478 | @Override | |
479 | public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) { | |
480 | ||
481 | int result = 0; | |
482 | ||
483 | if ((o1 instanceof CriticalPathEntry) && (o2 instanceof CriticalPathEntry)) { | |
484 | CriticalPathEntry entry1 = (CriticalPathEntry) o1; | |
485 | CriticalPathEntry entry2 = (CriticalPathEntry) o2; | |
486 | result = -1 * fStats.getSum(entry1.getWorker()).compareTo(fStats.getSum(entry2.getWorker())); | |
487 | } | |
488 | return result; | |
489 | } | |
490 | } | |
491 | ||
492 | /** | |
493 | * Constructor | |
494 | */ | |
495 | public CriticalPathView() { | |
496 | super(ID, new CriticalPathPresentationProvider()); | |
497 | setTreeColumns(COLUMN_NAMES); | |
498 | setFilterColumns(FILTER_COLUMN_NAMES); | |
499 | setTreeLabelProvider(new CriticalPathTreeLabelProvider()); | |
500 | setTimeGraphContentProvider(fContentProvider); | |
501 | setEntryComparator(new CriticalPathEntryComparator()); | |
502 | } | |
503 | ||
504 | // ------------------------------------------------------------------------ | |
505 | // Internal | |
506 | // ------------------------------------------------------------------------ | |
507 | ||
508 | private static State getMatchingState(EdgeType type) { | |
509 | State state = State.UNKNOWN; | |
510 | switch (type) { | |
511 | case RUNNING: | |
512 | state = State.RUNNING; | |
513 | break; | |
514 | case PREEMPTED: | |
515 | state = State.PREEMPTED; | |
516 | break; | |
517 | case TIMER: | |
518 | state = State.TIMER; | |
519 | break; | |
520 | case BLOCK_DEVICE: | |
521 | state = State.BLOCK_DEVICE; | |
522 | break; | |
523 | case INTERRUPTED: | |
524 | state = State.INTERRUPTED; | |
525 | break; | |
526 | case NETWORK: | |
527 | state = State.NETWORK; | |
528 | break; | |
529 | case USER_INPUT: | |
530 | state = State.USER_INPUT; | |
531 | break; | |
5aa7fe19 FG |
532 | case IPI: |
533 | state = State.IPI; | |
534 | break; | |
44d8e2f1 FG |
535 | case EPS: |
536 | case UNKNOWN: | |
537 | case DEFAULT: | |
538 | case BLOCKED: | |
539 | break; | |
540 | default: | |
541 | break; | |
542 | } | |
543 | return state; | |
544 | } | |
545 | ||
44d8e2f1 | 546 | @Override |
f8f46a52 | 547 | protected void buildEntryList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor) { |
44d8e2f1 FG |
548 | /* This class uses a content provider instead */ |
549 | } | |
550 | ||
551 | @Override | |
552 | protected @Nullable List<ITimeEvent> getEventList(TimeGraphEntry entry, | |
553 | long startTime, long endTime, long resolution, | |
554 | IProgressMonitor monitor) { | |
32ba3b09 PT |
555 | /* |
556 | * The event list is built in the HorizontalLinksVisitor. This is called | |
557 | * only from the zoom thread and only for the CriticalPathBaseEntry. | |
558 | */ | |
559 | return null; | |
44d8e2f1 FG |
560 | } |
561 | ||
562 | @Override | |
563 | protected @Nullable List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) { | |
564 | return fContentProvider.getLinkList(startTime, endTime); | |
565 | } | |
566 | ||
567 | /** | |
568 | * Signal handler for analysis started | |
569 | * | |
570 | * @param signal | |
571 | * The signal | |
572 | */ | |
573 | @TmfSignalHandler | |
574 | public void analysisStarted(TmfStartAnalysisSignal signal) { | |
575 | if (!(signal.getAnalysisModule() instanceof CriticalPathModule)) { | |
576 | return; | |
577 | } | |
578 | CriticalPathModule module = (CriticalPathModule) signal.getAnalysisModule(); | |
579 | Object obj = module.getParameter(CriticalPathModule.PARAM_WORKER); | |
580 | if (obj == null) { | |
581 | return; | |
582 | } | |
583 | if (!(obj instanceof IGraphWorker)) { | |
584 | throw new IllegalStateException("Wrong type for critical path module parameter " + //$NON-NLS-1$ | |
585 | CriticalPathModule.PARAM_WORKER + | |
586 | " expected IGraphWorker got " + //$NON-NLS-1$ | |
587 | obj.getClass().getSimpleName()); | |
588 | } | |
589 | ITmfTrace trace = getTrace(); | |
590 | if (trace == null) { | |
591 | throw new IllegalStateException("Trace is null"); //$NON-NLS-1$ | |
592 | } | |
593 | IGraphWorker worker = (IGraphWorker) obj; | |
44d8e2f1 FG |
594 | |
595 | TimeGraphEntry tge = new CriticalPathBaseEntry(worker); | |
596 | List<TimeGraphEntry> list = Collections.singletonList(tge); | |
597 | putEntryList(trace, list); | |
598 | refresh(); | |
599 | } | |
600 | ||
2244d4af GB |
601 | private void setStartEndTime(CriticalPathModule module) { |
602 | // Initialize the start/end time of the view to trace's times | |
603 | ITmfTrace trace = getTrace(); | |
604 | if (trace == null) { | |
605 | throw new IllegalStateException("The trace should not be null when we have a critical path to display"); //$NON-NLS-1$ | |
606 | } | |
607 | long start = trace.getStartTime().toNanos(); | |
608 | long end = trace.getEndTime().toNanos(); | |
609 | ||
610 | // Set the start/end time of the view | |
611 | Object paramGraph = module.getParameter(CriticalPathModule.PARAM_GRAPH); | |
612 | if (paramGraph instanceof TmfGraphBuilderModule) { | |
613 | TmfGraphBuilderModule graphModule = (TmfGraphBuilderModule) paramGraph; | |
614 | TmfGraph graph = graphModule.getGraph(); | |
615 | if (graph == null) { | |
616 | return; | |
617 | } | |
618 | TmfVertex head = graph.getHead(); | |
619 | if (head != null) { | |
620 | start = Math.min(start, head.getTs()); | |
621 | for (IGraphWorker w : graph.getWorkers()) { | |
622 | TmfVertex tail = graph.getTail(w); | |
623 | if (tail != null) { | |
624 | end = Math.max(end, tail.getTs()); | |
625 | } | |
626 | } | |
627 | } | |
628 | } | |
629 | setStartTime(start); | |
630 | setEndTime(end); | |
631 | } | |
632 | ||
44d8e2f1 | 633 | } |