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
.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
.statesystem
.ITmfStateSystem
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.graphics
.GC
;
29 import org
.eclipse
.swt
.graphics
.RGB
;
30 import org
.eclipse
.swt
.graphics
.Rectangle
;
33 * Presentation provider for the Call Stack view, based on the generic TMF
34 * presentation provider.
36 * @author Patrick Tasse
39 public class CallStackPresentationProvider
extends TimeGraphPresentationProvider
{
41 /** Number of colors used for call stack events */
42 public static final int NUM_COLORS
= 360;
44 private final CallStackView fView
;
47 MULTIPLE (new RGB(100, 100, 100)),
48 EXEC (new RGB(0, 200, 0));
50 private final RGB rgb
;
52 private State (RGB rgb
) {
61 * 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
= CallStackView
.getCallStackStateSystem(entry
.getTrace());
112 ITmfStateValue value
= ss
.querySingleState(event
.getTime(), entry
.getQuark()).getStateValue();
113 if (!value
.isNull()) {
114 String address
= value
.toString();
115 return fView
.getFunctionName(address
);
117 } catch (AttributeNotFoundException e
) {
118 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
119 } catch (TimeRangeException e
) {
120 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
121 } catch (StateSystemDisposedException e
) {
126 return State
.MULTIPLE
.toString();
130 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
131 if (bounds
.width
<= gc
.getFontMetrics().getAverageCharWidth()) {
134 if (!(event
instanceof CallStackEvent
)) {
137 CallStackEntry entry
= (CallStackEntry
) event
.getEntry();
138 ITmfStateSystem ss
= CallStackView
.getCallStackStateSystem(entry
.getTrace());
143 ITmfStateValue value
= ss
.querySingleState(event
.getTime(), entry
.getQuark()).getStateValue();
144 if (!value
.isNull()) {
145 String address
= value
.toString();
146 String name
= fView
.getFunctionName(address
);
147 gc
.setForeground(gc
.getDevice().getSystemColor(SWT
.COLOR_WHITE
));
148 Utils
.drawText(gc
, name
, bounds
.x
, bounds
.y
- 2, bounds
.width
, true, true);
150 } catch (AttributeNotFoundException e
) {
151 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
152 } catch (TimeRangeException e
) {
153 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
154 } catch (StateSystemDisposedException e
) {