tmf: Update API for multiple symbol providers
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.core / src / org / eclipse / tracecompass / internal / analysis / timing / core / callgraph / SymbolAspect.java
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
10 package org.eclipse.tracecompass.internal.analysis.timing.core.callgraph;
11
12 import java.util.Collection;
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;
18 import org.eclipse.tracecompass.segmentstore.core.ISegment;
19 import org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect;
20 import org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider;
21 import org.eclipse.tracecompass.tmf.core.symbols.SymbolProviderManager;
22 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
23 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
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 */
35 public static final ISegmentAspect SYMBOL_ASPECT = new SymbolAspect();
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() {
55 return new Comparator<ISegment>() {
56 @Override
57 public int compare(@Nullable ISegment o1, @Nullable ISegment o2) {
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) {
68 if (segment instanceof ICalledFunction) {
69 ICalledFunction calledFunction = (ICalledFunction) segment;
70 // FIXME work around this trace
71 ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
72 if (trace != null) {
73 String symbolText = null;
74 Object symbol = calledFunction.getSymbol();
75 if (symbol instanceof Long) {
76 Long longAddress = (Long) symbol;
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 }
84 if (symbolText == null) {
85 return "0x" + Long.toHexString(longAddress); //$NON-NLS-1$
86 }
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) {
91 for (ISymbolProvider provider: providers) {
92 String text = provider.getSymbolText(pid, time, longAddress);
93 if (text != null) {
94 return text;
95 }
96 }
97 }
98 return symbolText;
99 }
100 return String.valueOf(symbol);
101 }
102 }
103 return null;
104 }
105 }
This page took 0.035744 seconds and 6 git commands to generate.