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