tmf: Update API for multiple symbol providers
[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;
87262dc1 21import org.eclipse.tracecompass.internal.analysis.timing.core.callgraph.ICalledFunction;
37c87032 22import org.eclipse.tracecompass.internal.analysis.timing.core.callgraph.SymbolAspect;
74ccf789
SF
23import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
24import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
74ccf789
SF
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<>();
87262dc1 93 builder.put(Messages.FlameGraph_NbCalls, NumberFormat.getIntegerInstance().format(statistics.getDurationStatistics().getNbElements())); // $NON-NLS-1$
29f66918
SF
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$
87262dc1
GB
96 builder.put("\t" + Messages.FlameGraph_AverageDuration, FORMATTER.format(statistics.getDurationStatistics().getMean())); // $NON-NLS-1$ //$NON-NLS-1$
97 builder.put("\t" + Messages.FlameGraph_MaxDuration, FORMATTER.format((statistics.getDurationStatistics().getMax()))); // $NON-NLS-1$ //$NON-NLS-1$
98 builder.put("\t" + Messages.FlameGraph_MinDuration, FORMATTER.format(statistics.getDurationStatistics().getMin())); // $NON-NLS-1$ //$NON-NLS-1$
99 builder.put("\t" + Messages.FlameGraph_Deviation, FORMATTER.format(statistics.getDurationStatistics().getStdDev())); //$NON-NLS-1$
29f66918
SF
100 builder.put(Messages.FlameGraph_SelfTimes, ""); //$NON-NLS-1$
101 builder.put("\t" + Messages.FlameGraph_SelfTime, FORMATTER.format(((FlamegraphEvent) event).getSelfTime())); //$NON-NLS-1$
87262dc1
GB
102 builder.put("\t" + Messages.FlameGraph_AverageSelfTime, FORMATTER.format(statistics.getSelfTimeStatistics().getMean())); // $NON-NLS-1$ //$NON-NLS-1$
103 builder.put("\t" + Messages.FlameGraph_MaxSelfTime, FORMATTER.format(statistics.getSelfTimeStatistics().getMax())); // $NON-NLS-1$ //$NON-NLS-1$
104 builder.put("\t" + Messages.FlameGraph_MinSelfTime, FORMATTER.format(statistics.getSelfTimeStatistics().getMin())); // $NON-NLS-1$ //$NON-NLS-1$
105 builder.put("\t" + Messages.FlameGraph_SelfTimeDeviation, FORMATTER.format(statistics.getSelfTimeStatistics().getStdDev())); //$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
74ccf789 126 */
6db1aec6 127 private static String getFunctionSymbol(FlamegraphEvent event) {
74ccf789 128 String funcSymbol = ""; //$NON-NLS-1$
fdf2d9bb 129 if (event.getSymbol() instanceof Long || event.getSymbol() instanceof Integer) {
37c87032
MK
130
131 ICalledFunction segment = event.getStatistics().getDurationStatistics().getMinObject();
132 if (segment == null) {
133 long longAddress = ((Long) event.getSymbol()).longValue();
87262dc1
GB
134 return "0x" + Long.toHexString(longAddress); //$NON-NLS-1$
135 }
37c87032
MK
136 Object symbol = SymbolAspect.SYMBOL_ASPECT.resolve(segment);
137 if (symbol != null) {
138 return symbol.toString();
c2845a63 139 }
fdf2d9bb
MK
140 } else {
141 return event.getSymbol().toString();
74ccf789
SF
142 }
143 return funcSymbol;
144 }
145
146 @Override
147 public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
148 if (fAverageCharWidth == null) {
149 fAverageCharWidth = gc.getFontMetrics().getAverageCharWidth();
150 }
151 if (bounds.width <= fAverageCharWidth) {
152 return;
153 }
154 if (!(event instanceof FlamegraphEvent)) {
155 return;
156 }
157 String funcSymbol = ""; //$NON-NLS-1$
158 ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
159 if (activeTrace != null) {
160 FlamegraphEvent fgEvent = (FlamegraphEvent) event;
6db1aec6 161 funcSymbol = getFunctionSymbol(fgEvent);
74ccf789
SF
162 }
163 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
164 Utils.drawText(gc, funcSymbol, bounds.x, bounds.y, bounds.width, bounds.height, true, true);
165 }
166
167 /**
168 * The flame graph view
169 *
170 * @return The flame graph view
171 */
172 public FlameGraphView getView() {
173 return fView;
174 }
175
176 /**
177 * The flame graph view
178 *
179 * @param view
180 * The flame graph view
181 */
182 public void setView(FlameGraphView view) {
183 fView = view;
184 }
185
186}
This page took 0.037568 seconds and 5 git commands to generate.