ss: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / callstack / CallStackPresentationProvider.java
CommitLineData
e8251298 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
e8251298
PT
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
2bdf0193 13package org.eclipse.tracecompass.tmf.ui.views.callstack;
e8251298 14
e8251298
PT
15import org.eclipse.swt.SWT;
16import org.eclipse.swt.graphics.GC;
17import org.eclipse.swt.graphics.RGB;
18import org.eclipse.swt.graphics.Rectangle;
2bdf0193
AM
19import org.eclipse.tracecompass.internal.tmf.ui.Activator;
20import org.eclipse.tracecompass.internal.tmf.ui.Messages;
e894a508
AM
21import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
22import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
23import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
24import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
25import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
2bdf0193
AM
26import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem;
27import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
28import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
29import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
30import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
31import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
e8251298
PT
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
0a563f93
MAL
47 private Integer fAverageCharWidth;
48
e8251298
PT
49 private enum State {
50 MULTIPLE (new RGB(100, 100, 100)),
51 EXEC (new RGB(0, 200, 0));
52
52974e38 53 private final RGB rgb;
e8251298
PT
54
55 private State (RGB rgb) {
56 this.rgb = rgb;
57 }
58 }
59
5da83da5
AM
60 /**
61 * Constructor
62 *
63 * @param view
64 * The callstack view that will contain the time events
c4767854 65 * @since 3.0
5da83da5
AM
66 */
67 public CallStackPresentationProvider(CallStackView view) {
68 fView = view;
69 }
70
e8251298
PT
71 @Override
72 public String getStateTypeName(ITimeGraphEntry entry) {
60b4d44c 73 return Messages.CallStackPresentationProvider_Thread;
e8251298
PT
74 }
75
76 @Override
77 public StateItem[] getStateTable() {
52974e38
PT
78 final float saturation = 0.6f;
79 final float brightness = 0.6f;
e8251298
PT
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++) {
52974e38 83 RGB rgb = new RGB(i, saturation, brightness);
e8251298
PT
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();
da27e43a 104 ITmfStateSystem ss = entry.getStateSystem();
e8251298 105 try {
5da83da5
AM
106 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
107 if (!value.isNull()) {
108 String address = value.toString();
109 return fView.getFunctionName(address);
e8251298
PT
110 }
111 } catch (AttributeNotFoundException e) {
52974e38 112 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298 113 } catch (TimeRangeException e) {
52974e38 114 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298
PT
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) {
0a563f93
MAL
125 if (fAverageCharWidth == null) {
126 fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth();
127 }
128 if (bounds.width <= fAverageCharWidth) {
e8251298
PT
129 return;
130 }
131 if (!(event instanceof CallStackEvent)) {
132 return;
133 }
134 CallStackEntry entry = (CallStackEntry) event.getEntry();
da27e43a 135 ITmfStateSystem ss = entry.getStateSystem();
e8251298 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.057157 seconds and 5 git commands to generate.