timing: show callStack segments in a density view
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui / src / org / eclipse / tracecompass / internal / analysis / timing / ui / callgraph / SymbolAspect.java
CommitLineData
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
10package org.eclipse.tracecompass.internal.analysis.timing.ui.callgraph;
11
12import java.util.Comparator;
13
14import org.eclipse.jdt.annotation.NonNull;
15import org.eclipse.jdt.annotation.Nullable;
16import org.eclipse.tracecompass.common.core.NonNullUtils;
17import org.eclipse.tracecompass.internal.analysis.timing.core.callgraph.CalledFunction;
18import org.eclipse.tracecompass.internal.analysis.timing.core.callgraph.Messages;
19import org.eclipse.tracecompass.segmentstore.core.ISegment;
20import org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect;
21import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
23import org.eclipse.tracecompass.tmf.ui.symbols.ISymbolProvider;
24import 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 */
32public 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<CalledFunction>() {
57 @Override
58 public int compare(@Nullable CalledFunction o1, @Nullable CalledFunction 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 CalledFunction) {
70 CalledFunction calledFunction = (CalledFunction) segment;
71 ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
72 if (trace != null) {
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$
76 }
77 }
78 return null;
79 }
80}
This page took 0.036522 seconds and 5 git commands to generate.