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