Remove all existing @since annotations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / callstack / CallStackPresentationProvider.java
CommitLineData
e8251298 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
e8251298
PT
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
2bdf0193 13package org.eclipse.tracecompass.tmf.ui.views.callstack;
e8251298 14
e8251298
PT
15import org.eclipse.swt.SWT;
16import org.eclipse.swt.graphics.GC;
17import org.eclipse.swt.graphics.RGB;
18import org.eclipse.swt.graphics.Rectangle;
2bdf0193
AM
19import org.eclipse.tracecompass.internal.tmf.ui.Activator;
20import org.eclipse.tracecompass.internal.tmf.ui.Messages;
e894a508
AM
21import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
22import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
23import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
24import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
25import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
2bdf0193
AM
26import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem;
27import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
28import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
29import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
30import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
31import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
e8251298
PT
32
33/**
34 * Presentation provider for the Call Stack view, based on the generic TMF
35 * presentation provider.
36 *
37 * @author Patrick Tasse
e8251298
PT
38 */
39public class CallStackPresentationProvider extends TimeGraphPresentationProvider {
40
41 /** Number of colors used for call stack events */
42 public static final int NUM_COLORS = 360;
43
5da83da5
AM
44 private final CallStackView fView;
45
0a563f93
MAL
46 private Integer fAverageCharWidth;
47
e8251298
PT
48 private enum State {
49 MULTIPLE (new RGB(100, 100, 100)),
50 EXEC (new RGB(0, 200, 0));
51
52974e38 52 private final RGB rgb;
e8251298
PT
53
54 private State (RGB rgb) {
55 this.rgb = rgb;
56 }
57 }
58
5da83da5
AM
59 /**
60 * Constructor
61 *
62 * @param view
63 * The callstack view that will contain the time events
64 */
65 public CallStackPresentationProvider(CallStackView view) {
66 fView = view;
67 }
68
e8251298
PT
69 @Override
70 public String getStateTypeName(ITimeGraphEntry entry) {
60b4d44c 71 return Messages.CallStackPresentationProvider_Thread;
e8251298
PT
72 }
73
74 @Override
75 public StateItem[] getStateTable() {
52974e38
PT
76 final float saturation = 0.6f;
77 final float brightness = 0.6f;
e8251298
PT
78 StateItem[] stateTable = new StateItem[NUM_COLORS + 1];
79 stateTable[0] = new StateItem(State.MULTIPLE.rgb, State.MULTIPLE.toString());
80 for (int i = 0; i < NUM_COLORS; i++) {
52974e38 81 RGB rgb = new RGB(i, saturation, brightness);
e8251298
PT
82 stateTable[i + 1] = new StateItem(rgb, State.EXEC.toString());
83 }
84 return stateTable;
85 }
86
87 @Override
88 public int getStateTableIndex(ITimeEvent event) {
89 if (event instanceof CallStackEvent) {
90 CallStackEvent callStackEvent = (CallStackEvent) event;
91 return callStackEvent.getValue() + 1;
92 } else if (event instanceof NullTimeEvent) {
93 return INVISIBLE;
94 }
95 return State.MULTIPLE.ordinal();
96 }
97
98 @Override
99 public String getEventName(ITimeEvent event) {
100 if (event instanceof CallStackEvent) {
101 CallStackEntry entry = (CallStackEntry) event.getEntry();
da27e43a 102 ITmfStateSystem ss = entry.getStateSystem();
e8251298 103 try {
5da83da5
AM
104 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
105 if (!value.isNull()) {
106 String address = value.toString();
107 return fView.getFunctionName(address);
e8251298
PT
108 }
109 } catch (AttributeNotFoundException e) {
52974e38 110 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298 111 } catch (TimeRangeException e) {
52974e38 112 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298
PT
113 } catch (StateSystemDisposedException e) {
114 /* Ignored */
115 }
116 return null;
117 }
118 return State.MULTIPLE.toString();
119 }
120
121 @Override
122 public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
0a563f93
MAL
123 if (fAverageCharWidth == null) {
124 fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth();
125 }
126 if (bounds.width <= fAverageCharWidth) {
e8251298
PT
127 return;
128 }
129 if (!(event instanceof CallStackEvent)) {
130 return;
131 }
132 CallStackEntry entry = (CallStackEntry) event.getEntry();
da27e43a 133 ITmfStateSystem ss = entry.getStateSystem();
e8251298 134 try {
5da83da5
AM
135 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
136 if (!value.isNull()) {
137 String address = value.toString();
138 String name = fView.getFunctionName(address);
e8251298 139 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
5da83da5 140 Utils.drawText(gc, name, bounds.x, bounds.y - 2, bounds.width, true, true);
e8251298
PT
141 }
142 } catch (AttributeNotFoundException e) {
52974e38 143 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298 144 } catch (TimeRangeException e) {
52974e38 145 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298
PT
146 } catch (StateSystemDisposedException e) {
147 /* Ignored */
148 }
149 }
150
151}
This page took 0.062921 seconds and 5 git commands to generate.