Commit | Line | Data |
---|---|---|
905218ff SF |
1 | /******************************************************************************* |
2 | * Copyright (c) 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 | ||
37c87032 | 10 | package org.eclipse.tracecompass.internal.analysis.timing.core.callgraph; |
905218ff | 11 | |
6db1aec6 | 12 | import java.util.Collection; |
905218ff SF |
13 | import java.util.Comparator; |
14 | ||
15 | import org.eclipse.jdt.annotation.NonNull; | |
16 | import org.eclipse.jdt.annotation.Nullable; | |
17 | import org.eclipse.tracecompass.common.core.NonNullUtils; | |
905218ff SF |
18 | import org.eclipse.tracecompass.segmentstore.core.ISegment; |
19 | import org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect; | |
37c87032 MK |
20 | import org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider; |
21 | import org.eclipse.tracecompass.tmf.core.symbols.SymbolProviderManager; | |
905218ff SF |
22 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
23 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | |
905218ff SF |
24 | |
25 | /** | |
26 | * An aspect used to get the function name of a call stack event or to compare | |
27 | * the duration of two events | |
28 | * | |
29 | * @author Sonia Farrah | |
30 | */ | |
31 | public final class SymbolAspect implements ISegmentAspect { | |
32 | /** | |
33 | * A symbol aspect | |
34 | */ | |
37c87032 | 35 | public static final ISegmentAspect SYMBOL_ASPECT = new SymbolAspect(); |
905218ff SF |
36 | |
37 | /** | |
38 | * Constructor | |
39 | */ | |
40 | public SymbolAspect() { | |
41 | } | |
42 | ||
43 | @Override | |
44 | public @NonNull String getName() { | |
45 | return NonNullUtils.nullToEmptyString(Messages.CallStack_FunctionName); | |
46 | } | |
47 | ||
48 | @Override | |
49 | public @NonNull String getHelpText() { | |
50 | return NonNullUtils.nullToEmptyString(Messages.CallStack_FunctionName); | |
51 | } | |
52 | ||
53 | @Override | |
54 | public @Nullable Comparator<?> getComparator() { | |
2d8d933f | 55 | return new Comparator<ISegment>() { |
905218ff | 56 | @Override |
2d8d933f | 57 | public int compare(@Nullable ISegment o1, @Nullable ISegment o2) { |
905218ff SF |
58 | if (o1 == null || o2 == null) { |
59 | throw new IllegalArgumentException(); | |
60 | } | |
61 | return Long.compare(o1.getLength(), o2.getLength()); | |
62 | } | |
63 | }; | |
64 | } | |
65 | ||
66 | @Override | |
67 | public @Nullable Object resolve(@NonNull ISegment segment) { | |
2d8d933f SF |
68 | if (segment instanceof ICalledFunction) { |
69 | ICalledFunction calledFunction = (ICalledFunction) segment; | |
37c87032 | 70 | // FIXME work around this trace |
905218ff SF |
71 | ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace(); |
72 | if (trace != null) { | |
6db1aec6 | 73 | String symbolText = null; |
2d8d933f SF |
74 | Object symbol = calledFunction.getSymbol(); |
75 | if (symbol instanceof Long) { | |
76 | Long longAddress = (Long) symbol; | |
6db1aec6 GB |
77 | Collection<ISymbolProvider> providers = SymbolProviderManager.getInstance().getSymbolProviders(trace); |
78 | for (ISymbolProvider provider: providers) { | |
79 | symbolText = provider.getSymbolText(longAddress); | |
80 | if (symbolText != null) { | |
81 | break; | |
82 | } | |
83 | } | |
2d8d933f SF |
84 | if (symbolText == null) { |
85 | return "0x" + Long.toHexString(longAddress); //$NON-NLS-1$ | |
86 | } | |
c2845a63 BH |
87 | // take the start time in the query for the symbol name |
88 | long time = segment.getStart(); | |
89 | int pid = calledFunction.getProcessId(); | |
90 | if (pid > 0) { | |
6db1aec6 GB |
91 | for (ISymbolProvider provider: providers) { |
92 | String text = provider.getSymbolText(pid, time, longAddress); | |
93 | if (text != null) { | |
94 | return text; | |
95 | } | |
c2845a63 BH |
96 | } |
97 | } | |
2d8d933f SF |
98 | return symbolText; |
99 | } | |
100 | return String.valueOf(symbol); | |
905218ff SF |
101 | } |
102 | } | |
103 | return null; | |
104 | } | |
105 | } |