tmf: Move plugins to their own sub-directory
[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 final 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 * @param view
63 * The callstack view that will contain the time events
64 */
65 public CallStackPresentationProvider(CallStackView view) {
66 fView = view;
67 }
68
69 @Override
70 public String getStateTypeName(ITimeGraphEntry entry) {
71 return Messages.CallStackPresentationProvider_Thread;
72 }
73
74 @Override
75 public StateItem[] getStateTable() {
76 final float saturation = 0.6f;
77 final float brightness = 0.6f;
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++) {
81 RGB rgb = new RGB(i, saturation, brightness);
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();
102 ITmfStateSystem ss = entry.getStateSystem();
103 try {
104 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
105 if (!value.isNull()) {
106 String address = value.toString();
107 return fView.getFunctionName(address);
108 }
109 } catch (AttributeNotFoundException e) {
110 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
111 } catch (TimeRangeException e) {
112 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
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) {
123 if (fAverageCharWidth == null) {
124 fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth();
125 }
126 if (bounds.width <= fAverageCharWidth) {
127 return;
128 }
129 if (!(event instanceof CallStackEvent)) {
130 return;
131 }
132 CallStackEntry entry = (CallStackEntry) event.getEntry();
133 ITmfStateSystem ss = entry.getStateSystem();
134 try {
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);
139 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
140 Utils.drawText(gc, name, bounds.x, bounds.y - 2, bounds.width, true, true);
141 }
142 } catch (AttributeNotFoundException e) {
143 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
144 } catch (TimeRangeException e) {
145 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
146 } catch (StateSystemDisposedException e) {
147 /* Ignored */
148 }
149 }
150
151 }
This page took 0.036515 seconds and 6 git commands to generate.