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