Remove extra item.select() calls
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui / src / org / eclipse / tracecompass / internal / analysis / timing / ui / flamegraph / FlameGraphPresentationProvider.java
CommitLineData
74ccf789
SF
1/*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 *******************************************************************************/
9package org.eclipse.tracecompass.internal.analysis.timing.ui.flamegraph;
10
11import java.text.Format;
12import java.text.NumberFormat;
13import java.util.Map;
14
15import org.eclipse.swt.SWT;
16import org.eclipse.swt.graphics.GC;
17import org.eclipse.swt.graphics.RGB;
18import org.eclipse.swt.graphics.Rectangle;
19import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.SubSecondTimeWithUnitFormat;
0b06f3bc 20import org.eclipse.tracecompass.internal.analysis.timing.core.callgraph.AggregatedCalledFunctionStatistics;
74ccf789
SF
21import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
23import org.eclipse.tracecompass.tmf.ui.symbols.ISymbolProvider;
24import org.eclipse.tracecompass.tmf.ui.symbols.SymbolProviderManager;
25import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem;
26import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
27import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
28import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
29import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
30
31import com.google.common.collect.ImmutableMap;
32
33/**
34 * Presentation provider for the flame graph view, based on the generic TMF
35 * presentation provider.
36 *
37 * @author Sonia Farrah
38 */
39public class FlameGraphPresentationProvider extends TimeGraphPresentationProvider {
74ccf789
SF
40 /** Number of colors used for flameGraph events */
41 public static final int NUM_COLORS = 360;
42
43 private static final Format FORMATTER = new SubSecondTimeWithUnitFormat();
44
45 private FlameGraphView fView;
46
47 private Integer fAverageCharWidth;
48
49 private enum State {
50 MULTIPLE(new RGB(100, 100, 100)), 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
74ccf789
SF
61 */
62 public FlameGraphPresentationProvider() {
0b06f3bc 63 // Do nothing
74ccf789
SF
64 }
65
66 @Override
67 public StateItem[] getStateTable() {
68 final float saturation = 0.6f;
69 final float brightness = 0.6f;
70 StateItem[] stateTable = new StateItem[NUM_COLORS + 1];
71 stateTable[0] = new StateItem(State.MULTIPLE.rgb, State.MULTIPLE.toString());
72 for (int i = 0; i < NUM_COLORS; i++) {
73 RGB rgb = new RGB(i, saturation, brightness);
74 stateTable[i + 1] = new StateItem(rgb, State.EXEC.toString());
75 }
76 return stateTable;
77 }
78
79 @Override
80 public boolean displayTimesInTooltip() {
81 return false;
82 }
83
84 @Override
85 public String getStateTypeName() {
86 return Messages.FlameGraph_Depth;
87 }
88
89 @Override
90 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event, long hoverTime) {
0b06f3bc
SF
91 AggregatedCalledFunctionStatistics statistics = ((FlamegraphEvent) event).getStatistics();
92 ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
29f66918
SF
93 builder.put(Messages.FlameGraph_NbCalls, NumberFormat.getIntegerInstance().format(statistics.getNbSegments())); // $NON-NLS-1$
94 builder.put(String.valueOf(Messages.FlameGraph_Durations), ""); //$NON-NLS-1$
95 builder.put("\t" + Messages.FlameGraph_Duration, FORMATTER.format(event.getDuration())); //$NON-NLS-1$
96 builder.put("\t" + Messages.FlameGraph_AverageDuration, FORMATTER.format(statistics.getAverage())); // $NON-NLS-1$ //$NON-NLS-1$
97 builder.put("\t" + Messages.FlameGraph_MaxDuration, FORMATTER.format((statistics.getMax()))); // $NON-NLS-1$ //$NON-NLS-1$
98 builder.put("\t" + Messages.FlameGraph_MinDuration, FORMATTER.format(statistics.getMin())); // $NON-NLS-1$ //$NON-NLS-1$
99 builder.put("\t" + Messages.FlameGraph_Deviation, FORMATTER.format(statistics.getStdDev())); //$NON-NLS-1$
100 builder.put(Messages.FlameGraph_SelfTimes, ""); //$NON-NLS-1$
101 builder.put("\t" + Messages.FlameGraph_SelfTime, FORMATTER.format(((FlamegraphEvent) event).getSelfTime())); //$NON-NLS-1$
102 builder.put("\t" + Messages.FlameGraph_AverageSelfTime, FORMATTER.format(statistics.getAverageSelfTime())); // $NON-NLS-1$ //$NON-NLS-1$
103 builder.put("\t" + Messages.FlameGraph_MaxSelfTime, FORMATTER.format(statistics.getMaxSelfTime())); // $NON-NLS-1$ //$NON-NLS-1$
104 builder.put("\t" + Messages.FlameGraph_MinSelfTime, FORMATTER.format(statistics.getMinSelfTime())); // $NON-NLS-1$ //$NON-NLS-1$
105 builder.put("\t" + Messages.FlameGraph_SelfTimeDeviation, FORMATTER.format(statistics.getStdDevSelfTime())); //$NON-NLS-1$
0b06f3bc
SF
106 return builder.build();
107
74ccf789
SF
108 }
109
110 @Override
111 public int getStateTableIndex(ITimeEvent event) {
112 if (event instanceof FlamegraphEvent) {
113 FlamegraphEvent flameGraphEvent = (FlamegraphEvent) event;
114 return flameGraphEvent.getValue() + 1;
115 } else if (event instanceof NullTimeEvent) {
116 return INVISIBLE;
117 }
118 return State.MULTIPLE.ordinal();
119 }
120
121 /**
0b06f3bc 122 * Get the event's symbol.It could be an address or a name.
74ccf789
SF
123 *
124 * @param fGEvent
125 * An event
126 * @param symbolProvider
127 * A symbol provider
128 */
129 private static String getFuntionSymbol(FlamegraphEvent event, ISymbolProvider symbolProvider) {
130 String funcSymbol = ""; //$NON-NLS-1$
fdf2d9bb
MK
131 if (event.getSymbol() instanceof Long || event.getSymbol() instanceof Integer) {
132 long longAddress = ((Long) event.getSymbol()).longValue();
133 funcSymbol = symbolProvider.getSymbolText(longAddress);
134 if (funcSymbol == null) {
135 return "0x" + Long.toHexString(longAddress); //$NON-NLS-1$
74ccf789 136 }
fdf2d9bb
MK
137 } else {
138 return event.getSymbol().toString();
74ccf789
SF
139 }
140 return funcSymbol;
141 }
142
143 @Override
144 public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
145 if (fAverageCharWidth == null) {
146 fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth();
147 }
148 if (bounds.width <= fAverageCharWidth) {
149 return;
150 }
151 if (!(event instanceof FlamegraphEvent)) {
152 return;
153 }
154 String funcSymbol = ""; //$NON-NLS-1$
155 ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
156 if (activeTrace != null) {
157 FlamegraphEvent fgEvent = (FlamegraphEvent) event;
158 ISymbolProvider symbolProvider = SymbolProviderManager.getInstance().getSymbolProvider(activeTrace);
159 funcSymbol = getFuntionSymbol(fgEvent, symbolProvider);
160 }
161 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
162 Utils.drawText(gc, funcSymbol, bounds.x, bounds.y, bounds.width, bounds.height, true, true);
163 }
164
165 /**
166 * The flame graph view
167 *
168 * @return The flame graph view
169 */
170 public FlameGraphView getView() {
171 return fView;
172 }
173
174 /**
175 * The flame graph view
176 *
177 * @param view
178 * The flame graph view
179 */
180 public void setView(FlameGraphView view) {
181 fView = view;
182 }
183
184}
This page took 0.032968 seconds and 5 git commands to generate.