1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.callgraph
;
12 import java
.util
.Collection
;
13 import java
.util
.Comparator
;
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
;
26 * An aspect used to get the function name of a call stack event or to compare
27 * the duration of two events
29 * @author Sonia Farrah
31 public final class SymbolAspect
implements ISegmentAspect
{
35 public static final ISegmentAspect SYMBOL_ASPECT
= new SymbolAspect();
40 public SymbolAspect() {
44 public @NonNull String
getName() {
45 return NonNullUtils
.nullToEmptyString(Messages
.CallStack_FunctionName
);
49 public @NonNull String
getHelpText() {
50 return NonNullUtils
.nullToEmptyString(Messages
.CallStack_FunctionName
);
54 public @Nullable Comparator
<?
> getComparator() {
55 return new Comparator
<ISegment
>() {
57 public int compare(@Nullable ISegment o1
, @Nullable ISegment o2
) {
58 if (o1
== null || o2
== null) {
59 throw new IllegalArgumentException();
61 return Long
.compare(o1
.getLength(), o2
.getLength());
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();
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) {
84 if (symbolText
== null) {
85 return "0x" + Long
.toHexString(longAddress
); //$NON-NLS-1$
87 // take the start time in the query for the symbol name
88 long time
= segment
.getStart();
89 int pid
= calledFunction
.getProcessId();
91 for (ISymbolProvider provider
: providers
) {
92 String text
= provider
.getSymbolText(pid
, time
, longAddress
);
100 return String
.valueOf(symbol
);