Introduce Call Stack view and state system
[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
15import org.eclipse.linuxtools.tmf.core.callstack.CallStackStateProvider;
16import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
17import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
18import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
19import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
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
45 private enum State {
46 MULTIPLE (new RGB(100, 100, 100)),
47 EXEC (new RGB(0, 200, 0));
48
49 public final RGB rgb;
50
51 private State (RGB rgb) {
52 this.rgb = rgb;
53 }
54 }
55
56 @Override
57 public String getStateTypeName() {
58 // Empty string since no generic name
59 return ""; //$NON-NLS-1$
60 }
61
62 @Override
63 public String getStateTypeName(ITimeGraphEntry entry) {
64 return ""; //$NON-NLS-1$
65 }
66
67 @Override
68 public StateItem[] getStateTable() {
69 StateItem[] stateTable = new StateItem[NUM_COLORS + 1];
70 stateTable[0] = new StateItem(State.MULTIPLE.rgb, State.MULTIPLE.toString());
71 for (int i = 0; i < NUM_COLORS; i++) {
72 RGB rgb = new RGB((i), (float) 0.6, (float) 0.6);
73 stateTable[i + 1] = new StateItem(rgb, State.EXEC.toString());
74 }
75 return stateTable;
76 }
77
78 @Override
79 public int getStateTableIndex(ITimeEvent event) {
80 if (event instanceof CallStackEvent) {
81 CallStackEvent callStackEvent = (CallStackEvent) event;
82 return callStackEvent.getValue() + 1;
83 } else if (event instanceof NullTimeEvent) {
84 return INVISIBLE;
85 }
86 return State.MULTIPLE.ordinal();
87 }
88
89 @Override
90 public String getEventName(ITimeEvent event) {
91 if (event instanceof CallStackEvent) {
92 CallStackEntry entry = (CallStackEntry) event.getEntry();
93 ITmfStateSystem ss = entry.getTrace().getStateSystems().get(CallStackStateProvider.ID);
94 try {
95 ITmfStateInterval value = ss.querySingleState(event.getTime(), entry.getQuark());
96 if (!value.getStateValue().isNull()) {
97 ITmfStateValue state = value.getStateValue();
98 return state.toString();
99 }
100 } catch (AttributeNotFoundException e) {
101 e.printStackTrace();
102 } catch (TimeRangeException e) {
103 e.printStackTrace();
104 } catch (StateSystemDisposedException e) {
105 /* Ignored */
106 }
107 return null;
108 }
109 return State.MULTIPLE.toString();
110 }
111
112 @Override
113 public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
114 if (bounds.width <= gc.getFontMetrics().getAverageCharWidth()) {
115 return;
116 }
117 if (!(event instanceof CallStackEvent)) {
118 return;
119 }
120 CallStackEntry entry = (CallStackEntry) event.getEntry();
121 ITmfStateSystem ss = entry.getTrace().getStateSystems().get(CallStackStateProvider.ID);
122 try {
123 ITmfStateInterval value = ss.querySingleState(event.getTime(), entry.getQuark());
124 if (!value.getStateValue().isNull()) {
125 ITmfStateValue state = value.getStateValue();
126 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
127 Utils.drawText(gc, state.toString(), bounds.x, bounds.y - 2, bounds.width, true, true);
128 }
129 } catch (AttributeNotFoundException e) {
130 e.printStackTrace();
131 } catch (TimeRangeException e) {
132 e.printStackTrace();
133 } catch (StateSystemDisposedException e) {
134 /* Ignored */
135 }
136 }
137
138}
This page took 0.043988 seconds and 5 git commands to generate.