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
.ui
.callgraph
;
12 import java
.util
.Comparator
;
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
.CalledFunction
;
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
;
27 * An aspect used to get the function name of a call stack event or to compare
28 * the duration of two events
30 * @author Sonia Farrah
32 public final class SymbolAspect
implements ISegmentAspect
{
36 public static final @NonNull ISegmentAspect SYMBOL_ASPECT
= new SymbolAspect();
41 public SymbolAspect() {
45 public @NonNull String
getName() {
46 return NonNullUtils
.nullToEmptyString(Messages
.CallStack_FunctionName
);
50 public @NonNull String
getHelpText() {
51 return NonNullUtils
.nullToEmptyString(Messages
.CallStack_FunctionName
);
55 public @Nullable Comparator
<?
> getComparator() {
56 return new Comparator
<CalledFunction
>() {
58 public int compare(@Nullable CalledFunction o1
, @Nullable CalledFunction o2
) {
59 if (o1
== null || o2
== null) {
60 throw new IllegalArgumentException();
62 return Long
.compare(o1
.getLength(), o2
.getLength());
68 public @Nullable Object
resolve(@NonNull ISegment segment
) {
69 if (segment
instanceof CalledFunction
) {
70 CalledFunction calledFunction
= (CalledFunction
) segment
;
71 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
73 ISymbolProvider provider
= SymbolProviderManager
.getInstance().getSymbolProvider(trace
);
74 String symbolText
= provider
.getSymbolText(calledFunction
.getAddr());
75 return symbolText
== null ?
"0x" + calledFunction
.getAddr() : symbolText
; //$NON-NLS-1$