ss: Replace AttributeNotFoundException with IOOBE for quark parameters
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / callstack / CallStackPresentationProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2016 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.StateSystemDisposedException;
23 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
24 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
25 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem;
26 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
27 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
28 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
29 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
30 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
31
32 /**
33 * Presentation provider for the Call Stack view, based on the generic TMF
34 * presentation provider.
35 *
36 * @author Patrick Tasse
37 */
38 public class CallStackPresentationProvider extends TimeGraphPresentationProvider {
39
40 /** Number of colors used for call stack events */
41 public static final int NUM_COLORS = 360;
42
43 private CallStackView fView;
44
45 private Integer fAverageCharWidth;
46
47 private enum State {
48 MULTIPLE (new RGB(100, 100, 100)),
49 EXEC (new RGB(0, 200, 0));
50
51 private final RGB rgb;
52
53 private State (RGB rgb) {
54 this.rgb = rgb;
55 }
56 }
57
58 /**
59 * Constructor
60 *
61 * @since 1.2
62 */
63 public CallStackPresentationProvider() {
64 }
65
66 /**
67 * Sets the call stack view
68 *
69 * @param view
70 * The call stack view that will contain the time events
71 * @since 1.2
72 */
73 public void setCallStackView(CallStackView view) {
74 fView = view;
75 }
76
77 @Override
78 public String getStateTypeName(ITimeGraphEntry entry) {
79 return Messages.CallStackPresentationProvider_Thread;
80 }
81
82 @Override
83 public StateItem[] getStateTable() {
84 final float saturation = 0.6f;
85 final float brightness = 0.6f;
86 StateItem[] stateTable = new StateItem[NUM_COLORS + 1];
87 stateTable[0] = new StateItem(State.MULTIPLE.rgb, State.MULTIPLE.toString());
88 for (int i = 0; i < NUM_COLORS; i++) {
89 RGB rgb = new RGB(i, saturation, brightness);
90 stateTable[i + 1] = new StateItem(rgb, State.EXEC.toString());
91 }
92 return stateTable;
93 }
94
95 @Override
96 public int getStateTableIndex(ITimeEvent event) {
97 if (event instanceof CallStackEvent) {
98 CallStackEvent callStackEvent = (CallStackEvent) event;
99 return callStackEvent.getValue() + 1;
100 } else if (event instanceof NullTimeEvent) {
101 return INVISIBLE;
102 }
103 return State.MULTIPLE.ordinal();
104 }
105
106 @Override
107 public String getEventName(ITimeEvent event) {
108 if (event instanceof CallStackEvent) {
109 CallStackEntry entry = (CallStackEntry) event.getEntry();
110 ITmfStateSystem ss = entry.getStateSystem();
111 try {
112 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
113 if (!value.isNull()) {
114 return fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
115 }
116 } catch (TimeRangeException e) {
117 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
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 (fAverageCharWidth == null) {
129 fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth();
130 }
131 if (bounds.width <= fAverageCharWidth) {
132 return;
133 }
134 if (!(event instanceof CallStackEvent)) {
135 return;
136 }
137 CallStackEntry entry = (CallStackEntry) event.getEntry();
138 ITmfStateSystem ss = entry.getStateSystem();
139 try {
140 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
141 if (!value.isNull()) {
142 String name = fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
143 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
144 Utils.drawText(gc, name, bounds.x, bounds.y, bounds.width, bounds.height, true, true);
145 }
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.044058 seconds and 5 git commands to generate.