tmf: Make Callstack View pass timestamps and PIDs to symbol provider
[deliverable/tracecompass.git] / tmf / 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
ade0a3c5 44 private CallStackView fView;
5da83da5 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 *
ade0a3c5
PT
62 * @since 2.0
63 */
64 public CallStackPresentationProvider() {
65 }
66
67 /**
68 * Sets the call stack view
69 *
5da83da5 70 * @param view
ade0a3c5
PT
71 * The call stack view that will contain the time events
72 * @since 2.0
5da83da5 73 */
ade0a3c5 74 public void setCallStackView(CallStackView view) {
5da83da5
AM
75 fView = view;
76 }
77
e8251298
PT
78 @Override
79 public String getStateTypeName(ITimeGraphEntry entry) {
60b4d44c 80 return Messages.CallStackPresentationProvider_Thread;
e8251298
PT
81 }
82
83 @Override
84 public StateItem[] getStateTable() {
52974e38
PT
85 final float saturation = 0.6f;
86 final float brightness = 0.6f;
e8251298
PT
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++) {
52974e38 90 RGB rgb = new RGB(i, saturation, brightness);
e8251298
PT
91 stateTable[i + 1] = new StateItem(rgb, State.EXEC.toString());
92 }
93 return stateTable;
94 }
95
96 @Override
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) {
102 return INVISIBLE;
103 }
104 return State.MULTIPLE.ordinal();
105 }
106
107 @Override
108 public String getEventName(ITimeEvent event) {
109 if (event instanceof CallStackEvent) {
110 CallStackEntry entry = (CallStackEntry) event.getEntry();
da27e43a 111 ITmfStateSystem ss = entry.getStateSystem();
e8251298 112 try {
5da83da5
AM
113 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
114 if (!value.isNull()) {
4ce4d8af 115 return fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
e8251298
PT
116 }
117 } catch (AttributeNotFoundException e) {
52974e38 118 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298 119 } catch (TimeRangeException e) {
52974e38 120 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298
PT
121 } catch (StateSystemDisposedException e) {
122 /* Ignored */
123 }
124 return null;
125 }
126 return State.MULTIPLE.toString();
127 }
128
129 @Override
130 public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
0a563f93
MAL
131 if (fAverageCharWidth == null) {
132 fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth();
133 }
134 if (bounds.width <= fAverageCharWidth) {
e8251298
PT
135 return;
136 }
137 if (!(event instanceof CallStackEvent)) {
138 return;
139 }
140 CallStackEntry entry = (CallStackEntry) event.getEntry();
da27e43a 141 ITmfStateSystem ss = entry.getStateSystem();
e8251298 142 try {
5da83da5
AM
143 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
144 if (!value.isNull()) {
4ce4d8af 145 String name = fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
e8251298 146 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
3bd20aa6 147 Utils.drawText(gc, name, bounds.x, bounds.y, bounds.width, bounds.height, true, true);
e8251298
PT
148 }
149 } catch (AttributeNotFoundException e) {
52974e38 150 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298 151 } catch (TimeRangeException e) {
52974e38 152 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298
PT
153 } catch (StateSystemDisposedException e) {
154 /* Ignored */
155 }
156 }
157
158}
This page took 0.097234 seconds and 5 git commands to generate.