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