1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.callstack
;
15 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
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
.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
;
34 * Presentation provider for the Call Stack view, based on the generic TMF
35 * presentation provider.
37 * @author Patrick Tasse
40 public class CallStackPresentationProvider
extends TimeGraphPresentationProvider
{
42 /** Number of colors used for call stack events */
43 public static final int NUM_COLORS
= 360;
45 private final CallStackView fView
;
48 MULTIPLE (new RGB(100, 100, 100)),
49 EXEC (new RGB(0, 200, 0));
51 private final RGB rgb
;
53 private State (RGB rgb
) {
62 * The callstack view that will contain the time events
64 public CallStackPresentationProvider(CallStackView view
) {
69 public String
getStateTypeName() {
70 // Empty string since no generic name
71 return ""; //$NON-NLS-1$
75 public String
getStateTypeName(ITimeGraphEntry entry
) {
76 return ""; //$NON-NLS-1$
80 public StateItem
[] getStateTable() {
81 final float saturation
= 0.6f
;
82 final float brightness
= 0.6f
;
83 StateItem
[] stateTable
= new StateItem
[NUM_COLORS
+ 1];
84 stateTable
[0] = new StateItem(State
.MULTIPLE
.rgb
, State
.MULTIPLE
.toString());
85 for (int i
= 0; i
< NUM_COLORS
; i
++) {
86 RGB rgb
= new RGB(i
, saturation
, brightness
);
87 stateTable
[i
+ 1] = new StateItem(rgb
, State
.EXEC
.toString());
93 public int getStateTableIndex(ITimeEvent event
) {
94 if (event
instanceof CallStackEvent
) {
95 CallStackEvent callStackEvent
= (CallStackEvent
) event
;
96 return callStackEvent
.getValue() + 1;
97 } else if (event
instanceof NullTimeEvent
) {
100 return State
.MULTIPLE
.ordinal();
104 public String
getEventName(ITimeEvent event
) {
105 if (event
instanceof CallStackEvent
) {
106 CallStackEntry entry
= (CallStackEntry
) event
.getEntry();
107 ITmfStateSystem ss
= entry
.getTrace().getStateSystems().get(CallStackStateProvider
.ID
);
109 ITmfStateValue value
= ss
.querySingleState(event
.getTime(), entry
.getQuark()).getStateValue();
110 if (!value
.isNull()) {
111 String address
= value
.toString();
112 return fView
.getFunctionName(address
);
114 } catch (AttributeNotFoundException e
) {
115 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
116 } catch (TimeRangeException e
) {
117 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
118 } catch (StateSystemDisposedException e
) {
123 return State
.MULTIPLE
.toString();
127 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
128 if (bounds
.width
<= gc
.getFontMetrics().getAverageCharWidth()) {
131 if (!(event
instanceof CallStackEvent
)) {
134 CallStackEntry entry
= (CallStackEntry
) event
.getEntry();
135 ITmfStateSystem ss
= entry
.getTrace().getStateSystems().get(CallStackStateProvider
.ID
);
137 ITmfStateValue value
= ss
.querySingleState(event
.getTime(), entry
.getQuark()).getStateValue();
138 if (!value
.isNull()) {
139 String address
= value
.toString();
140 String name
= fView
.getFunctionName(address
);
141 gc
.setForeground(gc
.getDevice().getSystemColor(SWT
.COLOR_WHITE
));
142 Utils
.drawText(gc
, name
, bounds
.x
, bounds
.y
- 2, bounds
.width
, true, true);
144 } catch (AttributeNotFoundException e
) {
145 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
146 } catch (TimeRangeException e
) {
147 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
148 } catch (StateSystemDisposedException e
) {