Commit | Line | Data |
---|---|---|
44d8e2f1 FG |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 É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 | ||
10 | package org.eclipse.tracecompass.internal.analysis.graph.ui.criticalpath.view; | |
11 | ||
446638fc GB |
12 | import java.util.LinkedHashMap; |
13 | import java.util.Map; | |
14 | ||
15 | import org.eclipse.jdt.annotation.NonNullByDefault; | |
44d8e2f1 FG |
16 | import org.eclipse.jdt.annotation.Nullable; |
17 | import org.eclipse.swt.graphics.RGB; | |
18 | import org.eclipse.tracecompass.common.core.NonNullUtils; | |
19 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem; | |
20 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; | |
21 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
446638fc | 22 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; |
44d8e2f1 FG |
23 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent; |
24 | ||
25 | /** | |
26 | * Presentation provider for the critical path view | |
27 | * | |
28 | * @author Geneviève Bastien | |
29 | */ | |
30 | public class CriticalPathPresentationProvider extends TimeGraphPresentationProvider { | |
31 | ||
32 | /** | |
33 | * The enumeration of possible states for the view | |
34 | */ | |
35 | public static enum State { | |
36 | /** Worker is running */ | |
446638fc | 37 | RUNNING(new RGB(0x33, 0x99, 0x00)), |
44d8e2f1 | 38 | /** Worker is interrupted */ |
446638fc | 39 | INTERRUPTED(new RGB(0xff, 0xdc, 0x00)), |
44d8e2f1 | 40 | /** Worker has been preempted */ |
446638fc | 41 | PREEMPTED(new RGB(0xc8, 0x64, 0x00)), |
44d8e2f1 | 42 | /** Worker waiting on a timer */ |
446638fc | 43 | TIMER(new RGB(0x33, 0x66, 0x99)), |
44d8e2f1 | 44 | /** Worker is blocked, waiting on a device */ |
446638fc | 45 | BLOCK_DEVICE(new RGB(0x66, 0x00, 0xcc)), |
44d8e2f1 | 46 | /** Worker is waiting for user input */ |
446638fc | 47 | USER_INPUT(new RGB(0x5a, 0x01, 0x01)), |
44d8e2f1 | 48 | /** Worker is waiting on network */ |
446638fc | 49 | NETWORK(new RGB(0xff, 0x9b, 0xff)), |
5aa7fe19 | 50 | /** Worker is waiting for an IPI */ |
446638fc | 51 | IPI(new RGB(0x66, 0x66, 0xcc)), |
44d8e2f1 | 52 | /** Any other reason */ |
446638fc | 53 | UNKNOWN(new RGB(0x40, 0x3b, 0x33)); |
44d8e2f1 FG |
54 | |
55 | /** RGB color associated with a state */ | |
56 | public final RGB rgb; | |
57 | ||
446638fc | 58 | private State(RGB rgb) { |
44d8e2f1 FG |
59 | this.rgb = rgb; |
60 | } | |
61 | } | |
62 | ||
63 | @Override | |
64 | public String getStateTypeName() { | |
65 | return Messages.getMessage(Messages.CriticalFlowView_stateTypeName); | |
66 | } | |
67 | ||
68 | @Override | |
69 | public StateItem[] getStateTable() { | |
70 | StateItem[] stateTable = new StateItem[State.values().length]; | |
71 | for (int i = 0; i < stateTable.length; i++) { | |
72 | State state = State.values()[i]; | |
73 | stateTable[i] = new StateItem(state.rgb, state.toString()); | |
74 | } | |
75 | return stateTable; | |
76 | } | |
77 | ||
78 | @Override | |
79 | public int getStateTableIndex(@Nullable ITimeEvent event) { | |
80 | if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) { | |
81 | return ((TimeEvent) event).getValue(); | |
82 | } | |
83 | return TRANSPARENT; | |
84 | } | |
85 | ||
86 | private static State getMatchingState(int status) { | |
87 | switch (status) { | |
88 | case 0: | |
89 | return State.RUNNING; | |
90 | case 1: | |
91 | return State.INTERRUPTED; | |
92 | case 2: | |
93 | return State.PREEMPTED; | |
94 | case 3: | |
95 | return State.TIMER; | |
96 | case 4: | |
97 | return State.BLOCK_DEVICE; | |
98 | case 5: | |
99 | return State.USER_INPUT; | |
100 | case 6: | |
101 | return State.NETWORK; | |
5aa7fe19 FG |
102 | case 7: |
103 | return State.IPI; | |
44d8e2f1 FG |
104 | default: |
105 | return State.UNKNOWN; | |
106 | } | |
107 | } | |
108 | ||
109 | @Override | |
110 | public String getEventName(@Nullable ITimeEvent event) { | |
111 | if (event instanceof TimeEvent) { | |
112 | TimeEvent ev = (TimeEvent) event; | |
113 | if (ev.hasValue()) { | |
114 | return NonNullUtils.nullToEmptyString(getMatchingState(ev.getValue())); | |
115 | } | |
116 | } | |
117 | return Messages.getMessage(Messages.CriticalFlowView_multipleStates); | |
118 | } | |
44d8e2f1 | 119 | |
446638fc GB |
120 | @Override |
121 | @NonNullByDefault({}) | |
122 | public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event, long hoverTime) { | |
123 | Map<String, String> eventHoverToolTipInfo = super.getEventHoverToolTipInfo(event, hoverTime); | |
124 | if (eventHoverToolTipInfo == null) { | |
125 | eventHoverToolTipInfo = new LinkedHashMap<>(); | |
126 | } | |
127 | ITimeGraphEntry entry = event.getEntry(); | |
128 | if (entry instanceof CriticalPathEntry) { | |
129 | CriticalPathEntry criticalPathEntry = (CriticalPathEntry) entry; | |
130 | Map<String, String> info = criticalPathEntry.getWorker().getWorkerInformation(hoverTime); | |
131 | eventHoverToolTipInfo.putAll(info); | |
132 | } | |
133 | return eventHoverToolTipInfo; | |
134 | } | |
135 | } |