/
CallStackElement.java
188 lines (163 loc) · 5.78 KB
/
CallStackElement.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*******************************************************************************
* Copyright (c) 2017 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.internal.analysis.callstack.core.callstack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.analysis.callstack.core.base.ICallStackElement;
import org.eclipse.tracecompass.internal.analysis.callstack.core.tree.ITree;
import org.eclipse.tracecompass.internal.analysis.callstack.core.tree.IWeightedTreeGroupDescriptor;
/**
* A basic callstack element implementing the methods of the interface.
*
* @author Geneviève Bastien
*/
public class CallStackElement implements ICallStackElement {
/**
* The default key to use for symbol resolution if none is available
*/
public static final int DEFAULT_SYMBOL_KEY = -1;
private final String fName;
private final IWeightedTreeGroupDescriptor fDescriptor;
private final @Nullable IWeightedTreeGroupDescriptor fNextDescriptor;
private final Collection<ICallStackElement> fChildren = new ArrayList<>();
private @Nullable ICallStackElement fParent;
private @Nullable ICallStackElement fSymbolKeyElement = null;
/**
* Constructor
*
* @param name
* The name of this element
* @param descriptor
* The corresponding group descriptor
*/
public CallStackElement(String name, IWeightedTreeGroupDescriptor descriptor) {
this(name, descriptor, null, null);
}
/**
* Constructor
*
* @param name
* The name of this element
* @param descriptor
* The corresponding group descriptor
* @param nextGroup
* The next group descriptor
* @param parent
* The parent element
*/
public CallStackElement(String name, IWeightedTreeGroupDescriptor descriptor, @Nullable IWeightedTreeGroupDescriptor nextGroup, @Nullable ICallStackElement parent) {
fName = name;
fDescriptor = descriptor;
fParent = parent;
fNextDescriptor = nextGroup;
if (parent instanceof CallStackElement) {
fSymbolKeyElement = ((CallStackElement) parent).fSymbolKeyElement;
}
}
@Override
public Collection<ICallStackElement> getChildrenElements() {
return fChildren;
}
@Override
public void addChild(ITree child) {
if (!(child instanceof ICallStackElement)) {
throw new IllegalArgumentException("The CallStackElement hierarchy does not support children of type " + child.getClass().getName()); //$NON-NLS-1$
}
fChildren.add((ICallStackElement) child);
child.setParent(this);
}
@Override
public void setParent(@Nullable ITree parent) {
if (parent != null && !(parent instanceof ICallStackElement)) {
throw new IllegalArgumentException("The CallStackElement hierarchy does not support parent of type " + parent.getClass().getName()); //$NON-NLS-1$
}
fParent = (ICallStackElement) parent;
}
@Override
public IWeightedTreeGroupDescriptor getGroup() {
return fDescriptor;
}
@Override
public String getName() {
return fName;
}
@Override
public boolean isLeaf() {
return fNextDescriptor == null;
}
@Override
public boolean isCallStack() {
return isLeaf();
}
@Override
public @Nullable IWeightedTreeGroupDescriptor getNextGroup() {
return fNextDescriptor;
}
@Override
public void setSymbolKeyElement(ICallStackElement element) {
fSymbolKeyElement = element;
}
@Override
public boolean isSymbolKeyElement() {
return fSymbolKeyElement == this;
}
@Override
public final int getSymbolKeyAt(long startTime) {
int processId = DEFAULT_SYMBOL_KEY;
if (isSymbolKeyElement()) {
return retrieveSymbolKeyAt(startTime);
}
ICallStackElement symbolKeyElement = fSymbolKeyElement;
// if there is no symbol key element, return the default value
if (symbolKeyElement == null) {
return processId;
}
return symbolKeyElement.getSymbolKeyAt(startTime);
}
/**
* Retrieve the symbol key for this element. This method is called by
* {@link #getSymbolKeyAt(long)} when the current element is the symbol key.
* So this method should assume the current is the symbol key provider and
* use its own values to retrieve what the key to resolve symbols should be
* at the time of the query.
*
* @param time
* The time at which to resolve the symbol
* @return The symbol key at the requested time
*/
protected int retrieveSymbolKeyAt(long time) {
return DEFAULT_SYMBOL_KEY;
}
@Override
public @Nullable ICallStackElement getParentElement() {
return fParent;
}
@Override
public String toString() {
return getName();
}
@Override
public @Nullable ITree getParent() {
return getParentElement();
}
@Override
public Collection<ITree> getChildren() {
List<ITree> list = new ArrayList<>();
list.addAll(fChildren);
return list;
}
@Override
public CallStackElement copyElement() {
return new CallStackElement(fName, fDescriptor, fNextDescriptor, null);
}
}