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