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
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
13 package org.eclipse.tracecompass.tmf.ui.views.callstack;
14
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;
32
33 /**
34 * Presentation provider for the Call Stack view, based on the generic TMF
35 * presentation provider.
36 *
37 * @author Patrick Tasse
38 */
39 public class CallStackPresentationProvider extends TimeGraphPresentationProvider {
40
41 /** Number of colors used for call stack events */
42 public static final int NUM_COLORS = 360;
43
44 private CallStackView fView;
45
46 private Integer fAverageCharWidth;
47
48 private enum State {
49 MULTIPLE (new RGB(100, 100, 100)),
50 EXEC (new RGB(0, 200, 0));
51
52 private final RGB rgb;
53
54 private State (RGB rgb) {
55 this.rgb = rgb;
56 }
57 }
58
59 /**
60 * Constructor
61 *
62 * @since 2.0
63 */
64 public CallStackPresentationProvider() {
65 }
66
67 /**
68 * Sets the call stack view
69 *
70 * @param view
71 * The call stack view that will contain the time events
72 * @since 2.0
73 */
74 public void setCallStackView(CallStackView view) {
75 fView = view;
76 }
77
78 @Override
79 public String getStateTypeName(ITimeGraphEntry entry) {
80 return Messages.CallStackPresentationProvider_Thread;
81 }
82
83 @Override
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());
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();
111 ITmfStateSystem ss = entry.getStateSystem();
112 try {
113 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
114 if (!value.isNull()) {
115 return fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
116 }
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) {
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) {
131 if (fAverageCharWidth == null) {
132 fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth();
133 }
134 if (bounds.width <= fAverageCharWidth) {
135 return;
136 }
137 if (!(event instanceof CallStackEvent)) {
138 return;
139 }
140 CallStackEntry entry = (CallStackEntry) event.getEntry();
141 ITmfStateSystem ss = entry.getStateSystem();
142 try {
143 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
144 if (!value.isNull()) {
145 String name = fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
146 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
147 Utils.drawText(gc, name, bounds.x, bounds.y, bounds.width, bounds.height, true, true);
148 }
149 } catch (AttributeNotFoundException e) {
150 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
151 } catch (TimeRangeException e) {
152 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
153 } catch (StateSystemDisposedException e) {
154 /* Ignored */
155 }
156 }
157
158 }
This page took 0.045697 seconds and 5 git commands to generate.