1 /*******************************************************************************
2 * Copyright (c) 2013, 2016 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
.StateSystemDisposedException
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.StateItem
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
30 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
33 * Presentation provider for the Call Stack view, based on the generic TMF
34 * presentation provider.
36 * @author Patrick Tasse
38 public class CallStackPresentationProvider
extends TimeGraphPresentationProvider
{
40 /** Number of colors used for call stack events */
41 public static final int NUM_COLORS
= 360;
43 private CallStackView fView
;
45 private Integer fAverageCharWidth
;
48 MULTIPLE (new RGB(100, 100, 100)),
49 EXEC (new RGB(0, 200, 0));
51 private final RGB rgb
;
53 private State (RGB rgb
) {
63 public CallStackPresentationProvider() {
67 * Sets the call stack view
70 * The call stack view that will contain the time events
73 public void setCallStackView(CallStackView view
) {
78 public String
getStateTypeName(ITimeGraphEntry entry
) {
79 return Messages
.CallStackPresentationProvider_Thread
;
83 public StateItem
[] getStateTable() {
84 final float saturation
= 0.6f
;
85 final float brightness
= 0.6f
;
86 StateItem
[] stateTable
= new StateItem
[NUM_COLORS
+ 1];
87 stateTable
[0] = new StateItem(State
.MULTIPLE
.rgb
, State
.MULTIPLE
.toString());
88 for (int i
= 0; i
< NUM_COLORS
; i
++) {
89 RGB rgb
= new RGB(i
, saturation
, brightness
);
90 stateTable
[i
+ 1] = new StateItem(rgb
, State
.EXEC
.toString());
96 public int getStateTableIndex(ITimeEvent event
) {
97 if (event
instanceof CallStackEvent
) {
98 CallStackEvent callStackEvent
= (CallStackEvent
) event
;
99 return callStackEvent
.getValue() + 1;
100 } else if (event
instanceof NullTimeEvent
) {
103 return State
.MULTIPLE
.ordinal();
107 public String
getEventName(ITimeEvent event
) {
108 if (event
instanceof CallStackEvent
) {
109 CallStackEntry entry
= (CallStackEntry
) event
.getEntry();
110 ITmfStateSystem ss
= entry
.getStateSystem();
112 ITmfStateValue value
= ss
.querySingleState(event
.getTime(), entry
.getQuark()).getStateValue();
113 if (!value
.isNull()) {
114 return fView
.getFunctionName(entry
.getTrace(), entry
.getProcessId(), event
.getTime(), value
);
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 (fAverageCharWidth
== null) {
129 fAverageCharWidth
= gc
.getFontMetrics().getAverageCharWidth();
131 if (bounds
.width
<= fAverageCharWidth
) {
134 if (!(event
instanceof CallStackEvent
)) {
137 CallStackEntry entry
= (CallStackEntry
) event
.getEntry();
138 ITmfStateSystem ss
= entry
.getStateSystem();
140 ITmfStateValue value
= ss
.querySingleState(event
.getTime(), entry
.getQuark()).getStateValue();
141 if (!value
.isNull()) {
142 String name
= fView
.getFunctionName(entry
.getTrace(), entry
.getProcessId(), event
.getTime(), value
);
143 gc
.setForeground(gc
.getDevice().getSystemColor(SWT
.COLOR_WHITE
));
144 Utils
.drawText(gc
, name
, bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
, true, true);
146 } catch (TimeRangeException e
) {
147 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
148 } catch (StateSystemDisposedException e
) {