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