Commit | Line | Data |
---|---|---|
e8251298 | 1 | /******************************************************************************* |
ed48dc75 | 2 | * Copyright (c) 2013, 2016 Ericsson |
e8251298 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 | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.views.callstack; |
e8251298 | 14 | |
e8251298 PT |
15 | import org.eclipse.swt.SWT; |
16 | import org.eclipse.swt.graphics.GC; | |
17 | import org.eclipse.swt.graphics.RGB; | |
18 | import org.eclipse.swt.graphics.Rectangle; | |
2bdf0193 AM |
19 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
20 | import org.eclipse.tracecompass.internal.tmf.ui.Messages; | |
e894a508 | 21 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
e894a508 AM |
22 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; |
23 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
24 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; | |
2bdf0193 AM |
25 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem; |
26 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; | |
27 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
28 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
29 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent; | |
30 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils; | |
e8251298 PT |
31 | |
32 | /** | |
33 | * Presentation provider for the Call Stack view, based on the generic TMF | |
34 | * presentation provider. | |
35 | * | |
36 | * @author Patrick Tasse | |
e8251298 PT |
37 | */ |
38 | public class CallStackPresentationProvider extends TimeGraphPresentationProvider { | |
39 | ||
40 | /** Number of colors used for call stack events */ | |
41 | public static final int NUM_COLORS = 360; | |
42 | ||
ade0a3c5 | 43 | private CallStackView fView; |
5da83da5 | 44 | |
0a563f93 MAL |
45 | private Integer fAverageCharWidth; |
46 | ||
e8251298 PT |
47 | private enum State { |
48 | MULTIPLE (new RGB(100, 100, 100)), | |
49 | EXEC (new RGB(0, 200, 0)); | |
50 | ||
52974e38 | 51 | private final RGB rgb; |
e8251298 PT |
52 | |
53 | private State (RGB rgb) { | |
54 | this.rgb = rgb; | |
55 | } | |
56 | } | |
57 | ||
5da83da5 AM |
58 | /** |
59 | * Constructor | |
60 | * | |
066b02aa | 61 | * @since 1.2 |
ade0a3c5 PT |
62 | */ |
63 | public CallStackPresentationProvider() { | |
64 | } | |
65 | ||
66 | /** | |
67 | * Sets the call stack view | |
68 | * | |
5da83da5 | 69 | * @param view |
ade0a3c5 | 70 | * The call stack view that will contain the time events |
066b02aa | 71 | * @since 1.2 |
5da83da5 | 72 | */ |
ade0a3c5 | 73 | public void setCallStackView(CallStackView view) { |
5da83da5 AM |
74 | fView = view; |
75 | } | |
76 | ||
e8251298 PT |
77 | @Override |
78 | public String getStateTypeName(ITimeGraphEntry entry) { | |
60b4d44c | 79 | return Messages.CallStackPresentationProvider_Thread; |
e8251298 PT |
80 | } |
81 | ||
82 | @Override | |
83 | public StateItem[] getStateTable() { | |
52974e38 PT |
84 | final float saturation = 0.6f; |
85 | final float brightness = 0.6f; | |
e8251298 PT |
86 | StateItem[] stateTable = new StateItem[NUM_COLORS + 1]; |
87 | stateTable[0] = new StateItem(State.MULTIPLE.rgb, State.MULTIPLE.toString()); | |
88 | for (int i = 0; i < NUM_COLORS; i++) { | |
52974e38 | 89 | RGB rgb = new RGB(i, saturation, brightness); |
e8251298 PT |
90 | stateTable[i + 1] = new StateItem(rgb, State.EXEC.toString()); |
91 | } | |
92 | return stateTable; | |
93 | } | |
94 | ||
95 | @Override | |
96 | public int getStateTableIndex(ITimeEvent event) { | |
97 | if (event instanceof CallStackEvent) { | |
98 | CallStackEvent callStackEvent = (CallStackEvent) event; | |
99 | return callStackEvent.getValue() + 1; | |
100 | } else if (event instanceof NullTimeEvent) { | |
101 | return INVISIBLE; | |
102 | } | |
103 | return State.MULTIPLE.ordinal(); | |
104 | } | |
105 | ||
106 | @Override | |
107 | public String getEventName(ITimeEvent event) { | |
108 | if (event instanceof CallStackEvent) { | |
109 | CallStackEntry entry = (CallStackEntry) event.getEntry(); | |
da27e43a | 110 | ITmfStateSystem ss = entry.getStateSystem(); |
e8251298 | 111 | try { |
5da83da5 AM |
112 | ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue(); |
113 | if (!value.isNull()) { | |
4ce4d8af | 114 | return fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value); |
e8251298 | 115 | } |
e8251298 | 116 | } catch (TimeRangeException e) { |
52974e38 | 117 | Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$ |
e8251298 PT |
118 | } catch (StateSystemDisposedException e) { |
119 | /* Ignored */ | |
120 | } | |
121 | return null; | |
122 | } | |
123 | return State.MULTIPLE.toString(); | |
124 | } | |
125 | ||
126 | @Override | |
127 | public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) { | |
0a563f93 MAL |
128 | if (fAverageCharWidth == null) { |
129 | fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth(); | |
130 | } | |
131 | if (bounds.width <= fAverageCharWidth) { | |
e8251298 PT |
132 | return; |
133 | } | |
134 | if (!(event instanceof CallStackEvent)) { | |
135 | return; | |
136 | } | |
137 | CallStackEntry entry = (CallStackEntry) event.getEntry(); | |
da27e43a | 138 | ITmfStateSystem ss = entry.getStateSystem(); |
e8251298 | 139 | try { |
5da83da5 AM |
140 | ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue(); |
141 | if (!value.isNull()) { | |
4ce4d8af | 142 | String name = fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value); |
e8251298 | 143 | gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); |
3bd20aa6 | 144 | Utils.drawText(gc, name, bounds.x, bounds.y, bounds.width, bounds.height, true, true); |
e8251298 | 145 | } |
e8251298 | 146 | } catch (TimeRangeException e) { |
52974e38 | 147 | Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$ |
e8251298 PT |
148 | } catch (StateSystemDisposedException e) { |
149 | /* Ignored */ | |
150 | } | |
151 | } | |
152 | ||
153 | } |