1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
.tracecompass
.tmf
.ui
.views
.callstack
;
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
;
19 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
20 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.StateItem
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
30 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
34 * Presentation provider for the Call Stack view, based on the generic TMF
35 * presentation provider.
37 * @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 CallStackView fView
;
46 private Integer fAverageCharWidth
;
49 MULTIPLE (new RGB(100, 100, 100)),
50 EXEC (new RGB(0, 200, 0));
52 private final RGB rgb
;
54 private State (RGB rgb
) {
64 public CallStackPresentationProvider() {
68 * Sets the call stack view
71 * The call stack view that will contain the time events
74 public void setCallStackView(CallStackView view
) {
79 public String
getStateTypeName(ITimeGraphEntry entry
) {
80 return Messages
.CallStackPresentationProvider_Thread
;
84 public StateItem
[] getStateTable() {
85 final float saturation
= 0.6f
;
86 final float brightness
= 0.6f
;
87 StateItem
[] stateTable
= new StateItem
[NUM_COLORS
+ 1];
88 stateTable
[0] = new StateItem(State
.MULTIPLE
.rgb
, State
.MULTIPLE
.toString());
89 for (int i
= 0; i
< NUM_COLORS
; i
++) {
90 RGB rgb
= new RGB(i
, saturation
, brightness
);
91 stateTable
[i
+ 1] = new StateItem(rgb
, State
.EXEC
.toString());
97 public int getStateTableIndex(ITimeEvent event
) {
98 if (event
instanceof CallStackEvent
) {
99 CallStackEvent callStackEvent
= (CallStackEvent
) event
;
100 return callStackEvent
.getValue() + 1;
101 } else if (event
instanceof NullTimeEvent
) {
104 return State
.MULTIPLE
.ordinal();
108 public String
getEventName(ITimeEvent event
) {
109 if (event
instanceof CallStackEvent
) {
110 CallStackEntry entry
= (CallStackEntry
) event
.getEntry();
111 ITmfStateSystem ss
= entry
.getStateSystem();
113 ITmfStateValue value
= ss
.querySingleState(event
.getTime(), entry
.getQuark()).getStateValue();
114 if (!value
.isNull()) {
115 String address
= value
.toString();
116 return fView
.getFunctionName(address
);
118 } catch (AttributeNotFoundException e
) {
119 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
120 } catch (TimeRangeException e
) {
121 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
122 } catch (StateSystemDisposedException e
) {
127 return State
.MULTIPLE
.toString();
131 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
132 if (fAverageCharWidth
== null) {
133 fAverageCharWidth
= gc
.getFontMetrics().getAverageCharWidth();
135 if (bounds
.width
<= fAverageCharWidth
) {
138 if (!(event
instanceof CallStackEvent
)) {
141 CallStackEntry entry
= (CallStackEntry
) event
.getEntry();
142 ITmfStateSystem ss
= entry
.getStateSystem();
144 ITmfStateValue value
= ss
.querySingleState(event
.getTime(), entry
.getQuark()).getStateValue();
145 if (!value
.isNull()) {
146 String address
= value
.toString();
147 String name
= fView
.getFunctionName(address
);
148 gc
.setForeground(gc
.getDevice().getSystemColor(SWT
.COLOR_WHITE
));
149 Utils
.drawText(gc
, name
, bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
, true, true);
151 } catch (AttributeNotFoundException e
) {
152 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
153 } catch (TimeRangeException e
) {
154 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
155 } catch (StateSystemDisposedException e
) {