/
CallStackSeries.java
707 lines (643 loc) · 27.8 KB
/
CallStackSeries.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
/*******************************************************************************
* Copyright (c) 2016 É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.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread;
import org.eclipse.tracecompass.internal.analysis.callstack.core.Activator;
import org.eclipse.tracecompass.internal.analysis.callstack.core.base.ICallStackElement;
import org.eclipse.tracecompass.internal.analysis.callstack.core.base.ICallStackGroupDescriptor;
import org.eclipse.tracecompass.internal.analysis.callstack.core.callgraph.CalledFunctionFactory;
import org.eclipse.tracecompass.internal.analysis.callstack.core.callgraph.ICalledFunction;
import org.eclipse.tracecompass.internal.analysis.callstack.core.callstack.CallStackHostUtils.IHostIdProvider;
import org.eclipse.tracecompass.internal.analysis.callstack.core.callstack.CallStackHostUtils.IHostIdResolver;
import org.eclipse.tracecompass.internal.analysis.callstack.core.instrumented.InstrumentedCallStackElement;
import org.eclipse.tracecompass.internal.analysis.callstack.core.instrumented.InstrumentedGroupDescriptor;
import org.eclipse.tracecompass.internal.analysis.callstack.core.model.IHostModel;
import org.eclipse.tracecompass.internal.analysis.callstack.core.model.ModelManager;
import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
import com.google.common.base.Function;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
/**
* A callstack series contain the information necessary to build all the
* different callstacks from a same pattern.
*
* Example: Let's take a trace that registers function entry and exit for
* threads and where events also provide information on some other stackable
* application component:
*
* The structure of this callstack in the state system could be as follows:
*
* <pre>
* Per PID
* [pid]
* [tid]
* callstack
* 1 {@literal ->} function name
* 2 {@literal ->} function name
* 3 {@literal ->} function name
* Per component
* [application component]
* [tid]
* callstack
* 1 {@literal ->} some string
* 2 {@literal ->} some string
* </pre>
*
* There are 2 {@link CallStackSeries} in this example, one starting by "Per
* PID" and another "Per component". For the first series, there could be 3
* {@link ICallStackGroupDescriptor}: "Per PID/*", "*", "callstack".
*
* If the function names happen to be addresses in an executable and the PID is
* the key to map those symbols to actual function names, then the first group
* "Per PID/*" would be the symbol key group.
*
* Each group descriptor can get the corresponding {@link ICallStackElement}s,
* ie, for the first group, it would be all the individual pids in the state
* system, and for the second group, it would be the application components.
* Each element that is not a leaf element (check with
* {@link ICallStackElement#isLeaf()}) will have a next group descriptor that
* can fetch the elements under it. The last group will resolve to leaf elements
* and each leaf elements has one {@link CallStack} object.
*
* @author Geneviève Bastien
*/
public class CallStackSeries implements ISegmentStore<ISegment> {
/**
* Interface for classes that provide a thread ID at time t for a callstack.
* The thread ID can be used to calculate extra statistics per thread, for
* example, the CPU time of each call site.
*/
public interface IThreadIdProvider {
/**
* Get the ID of callstack thread at a given time
*
* @param time
* The time of request
* @return The ID of the thread, or {@link IHostModel#UNKNOWN_TID} if
* unavailable
*/
int getThreadId(long time);
/**
* Return whether the value returned by this provider is variable
* through time (ie, each function of a stack may have a different
* thread ID), or is fixed (ie, all functions in a stack have the same
* thread ID)
*
* @return If <code>true</code>, the thread ID will be identical for a
* stack all throughout its life, it can be therefore be used to
* provider other thread-related information on stack even when
* there are no function calls.
*/
boolean variesInTime();
}
/**
* This class uses the value of an attribute as a thread ID.
*/
private static final class AttributeValueThreadProvider implements IThreadIdProvider {
private final ITmfStateSystem fSs;
private final int fQuark;
private @Nullable ITmfStateInterval fInterval;
private int fLastThreadId = IHostModel.UNKNOWN_TID;
private boolean fVariesInTime = true;
public AttributeValueThreadProvider(ITmfStateSystem ss, int quark) {
fSs = ss;
fQuark = quark;
// Try to get the tid at the start and set the fVariesInTime value
getThreadId(fSs.getStartTime());
}
@Override
public int getThreadId(long time) {
ITmfStateInterval interval = fInterval;
int tid = fLastThreadId;
// If interval is not null and either the tid does not vary in time
// or the interval intersects the requested time
if (interval != null && (!fVariesInTime || interval.intersects(time))) {
return tid;
}
try {
interval = fSs.querySingleState(time, fQuark);
switch (interval.getStateValue().getType()) {
case INTEGER:
tid = interval.getStateValue().unboxInt();
break;
case LONG:
tid = (int) interval.getStateValue().unboxLong();
break;
case STRING:
try {
tid = Integer.valueOf(interval.getStateValue().unboxStr());
} catch (NumberFormatException e) {
tid = IHostModel.UNKNOWN_TID;
}
break;
case NULL:
case DOUBLE:
case CUSTOM:
default:
break;
}
// If the interval spans the whole state system, the tid does
// not vary in time
if (fSs.waitUntilBuilt(0)) {
if (interval.intersects(fSs.getStartTime()) && interval.intersects(fSs.getCurrentEndTime() - 1)) {
fVariesInTime = false;
}
}
} catch (StateSystemDisposedException e) {
interval = null;
tid = IHostModel.UNKNOWN_TID;
}
fInterval = interval;
fLastThreadId = tid;
return tid;
}
@Override
public boolean variesInTime() {
return fVariesInTime;
}
}
/**
* This class uses the value of an attribute as a thread ID.
*/
private static final class AttributeNameThreadProvider implements IThreadIdProvider {
private final int fTid;
public AttributeNameThreadProvider(ITmfStateSystem ss, int quark) {
int tid = IHostModel.UNKNOWN_TID;
try {
String attributeName = ss.getAttributeName(quark);
tid = Integer.valueOf(attributeName);
} catch (IndexOutOfBoundsException | NumberFormatException e) {
tid = IHostModel.UNKNOWN_TID;
}
fTid = tid;
}
@Override
public int getThreadId(long time) {
return fTid;
}
@Override
public boolean variesInTime() {
return false;
}
}
/**
* This class will retrieve the thread ID
*/
private static final class CpuThreadProvider implements IThreadIdProvider {
private final ITmfStateSystem fSs;
private final int fCpuQuark;
private final IHostIdProvider fHostProvider;
public CpuThreadProvider(IHostIdProvider hostProvider, ITmfStateSystem ss, int quark, String[] path) {
fSs = ss;
fHostProvider = hostProvider;
// Get the cpu quark
List<Integer> quarks = ss.getQuarks(quark, path);
fCpuQuark = quarks.isEmpty() ? ITmfStateSystem.INVALID_ATTRIBUTE : quarks.get(0);
}
@Override
public int getThreadId(long time) {
if (fCpuQuark == ITmfStateSystem.INVALID_ATTRIBUTE) {
return IHostModel.UNKNOWN_TID;
}
// Get the CPU
try {
ITmfStateInterval querySingleState = fSs.querySingleState(time, fCpuQuark);
if (querySingleState.getStateValue().isNull()) {
return IHostModel.UNKNOWN_TID;
}
int cpu = querySingleState.getStateValue().unboxInt();
// The thread running is the one on the CPU at the beginning of
// this interval
long startTime = querySingleState.getStartTime();
IHostModel model = ModelManager.getModelFor(fHostProvider.apply(startTime));
return model.getThreadOnCpu(cpu, startTime);
} catch (StateSystemDisposedException e) {
// Nothing done
}
return IHostModel.UNKNOWN_TID;
}
@Override
public boolean variesInTime() {
return true;
}
}
/**
* Interface for describing how a callstack will get the thread ID
*/
public interface IThreadIdResolver {
/**
* Get the actual thread ID provider from this resolver
*
* @param hostProvider
* The provider of the host ID for the callstack
* @param element
* The leaf element of the callstack
* @return The thread ID provider
*/
@Nullable IThreadIdProvider resolve(IHostIdProvider hostProvider, ICallStackElement element);
}
/**
* This class will resolve the thread ID provider by the value of a
* attribute at a given depth
*/
public static final class AttributeValueThreadResolver implements IThreadIdResolver {
private int fLevel;
/**
* Constructor
*
* @param level
* The depth of the element whose value will be used to
* retrieve the thread ID
*/
public AttributeValueThreadResolver(int level) {
fLevel = level;
}
@Override
public @Nullable IThreadIdProvider resolve(IHostIdProvider hostProvider, ICallStackElement element) {
if (!(element instanceof InstrumentedCallStackElement)) {
throw new IllegalArgumentException();
}
InstrumentedCallStackElement insElement = (InstrumentedCallStackElement) element;
List<InstrumentedCallStackElement> elements = new ArrayList<>();
InstrumentedCallStackElement el = insElement;
while (el != null) {
elements.add(el);
el = el.getParentElement();
}
Collections.reverse(elements);
if (elements.size() <= fLevel) {
return null;
}
InstrumentedCallStackElement stackElement = elements.get(fLevel);
return new AttributeValueThreadProvider(stackElement.getStateSystem(), stackElement.getQuark());
}
}
/**
* This class will resolve the thread ID provider by the value of a
* attribute at a given depth
*/
public static final class AttributeNameThreadResolver implements IThreadIdResolver {
private int fLevel;
/**
* Constructor
*
* @param level
* The depth of the element whose value will be used to
* retrieve the thread ID
*/
public AttributeNameThreadResolver(int level) {
fLevel = level;
}
@Override
public @Nullable IThreadIdProvider resolve(IHostIdProvider hostProvider, ICallStackElement element) {
if (!(element instanceof InstrumentedCallStackElement)) {
throw new IllegalArgumentException();
}
InstrumentedCallStackElement insElement = (InstrumentedCallStackElement) element;
List<InstrumentedCallStackElement> elements = new ArrayList<>();
InstrumentedCallStackElement el = insElement;
while (el != null) {
elements.add(el);
el = el.getParentElement();
}
Collections.reverse(elements);
if (elements.size() <= fLevel) {
return null;
}
InstrumentedCallStackElement stackElement = elements.get(fLevel);
return new AttributeNameThreadProvider(stackElement.getStateSystem(), stackElement.getQuark());
}
}
/**
* This class will resolve the thread ID from the CPU on which the callstack
* was running at a given time
*/
public static final class CpuResolver implements IThreadIdResolver {
private String[] fPath;
/**
* Constructor
*
* @param path
* The path relative to the leaf element that will contain
* the CPU ID
*/
public CpuResolver(String[] path) {
fPath = path;
}
@Override
public @Nullable IThreadIdProvider resolve(IHostIdProvider hostProvider, ICallStackElement element) {
if (!(element instanceof InstrumentedCallStackElement)) {
throw new IllegalArgumentException();
}
InstrumentedCallStackElement insElement = (InstrumentedCallStackElement) element;
return new CpuThreadProvider(hostProvider, insElement.getStateSystem(), insElement.getQuark(), fPath);
}
}
private InstrumentedGroupDescriptor fRootGroup;
private final String fName;
private final @Nullable IThreadIdResolver fResolver;
private final IHostIdResolver fHostResolver;
private final ITmfStateSystem fStateSystem;
private final Map<Integer, ICallStackElement> fRootElements = new HashMap<>();
/**
* Constructor
*
* @param ss
* The state system containing this call stack
* @param patternPaths
* The patterns for the different levels of the callstack in the
* state system. Any further level path is relative to the
* previous one.
* @param symbolKeyLevelIndex
* The index in the list of the list to be used as a key to the
* symbol provider. The data at this level must be an integer,
* for instance a process ID
* @param name
* A name for this callstack
* @param hostResolver
* The host ID resolver for this callstack
* @param threadResolver
* The thread resolver
*/
public CallStackSeries(ITmfStateSystem ss, List<String[]> patternPaths, int symbolKeyLevelIndex, String name, IHostIdResolver hostResolver, @Nullable IThreadIdResolver threadResolver) {
fStateSystem = ss;
fName = name;
fResolver = threadResolver;
fHostResolver = hostResolver;
fRootGroup = createRootGroup(patternPaths, symbolKeyLevelIndex);
}
/**
* Get the root elements of this callstack series
*
* @return The root elements of the callstack series
*/
public Collection<ICallStackElement> getRootElements() {
return InstrumentedCallStackElement.getRootElements(fRootGroup, fHostResolver, fResolver, fRootElements);
}
/**
* Get the root group of the callstack series
*
* @return The root group descriptor
*/
public ICallStackGroupDescriptor getRootGroup() {
return fRootGroup;
}
/**
* @param patternPaths
* The patterns for the different levels of the callstack in the
* state system. Any further level path is relative to the
* previous one.
* @param symbolKeyLevelIndex
* The index in the list of the list to be used as a key to the
* symbol provider. The data at this level must be an integer,
* for instance a process ID
*/
public void updateRootGroup(List<String[]> patternPaths, int symbolKeyLevelIndex) {
fRootGroup = createRootGroup(patternPaths, symbolKeyLevelIndex);
}
private InstrumentedGroupDescriptor createRootGroup(List<String[]> patternPaths, int symbolKeyLevelIndex) {
// Build the groups from the state system and pattern paths
if (patternPaths.isEmpty()) {
throw new IllegalArgumentException("State system callstack: the list of paths should not be empty"); //$NON-NLS-1$
}
int startIndex = patternPaths.size() - 1;
InstrumentedGroupDescriptor prevLevel = new InstrumentedGroupDescriptor(fStateSystem, patternPaths.get(startIndex), null, symbolKeyLevelIndex == startIndex);
for (int i = startIndex - 1; i >= 0; i--) {
InstrumentedGroupDescriptor level = new InstrumentedGroupDescriptor(fStateSystem, patternPaths.get(i), prevLevel, symbolKeyLevelIndex == i);
prevLevel = level;
}
return prevLevel;
}
/**
* Get the name of this callstack series
*
* @return The name of the callstack series
*/
public String getName() {
return fName;
}
/**
* Query the requested callstacks and return the segments for the sampled
* times. The returned segments will be simply {@link ISegment} when there
* is no function at a given depth, or {@link ICalledFunction} when there is
* an actual function.
*
* @param callstacks
* The callstack entries to query
* @param times
* The complete list of times to query, they may not all be
* within this series's range
* @return A map of callstack depths to a list of segments.
*/
public Multimap<CallStackDepth, ISegment> queryCallStacks(Collection<CallStackDepth> callstacks, Collection<Long> times) {
Map<Integer, CallStackDepth> quarks = Maps.uniqueIndex(callstacks, cs -> cs.getQuark());
Multimap<CallStackDepth, ISegment> map = Objects.requireNonNull(ArrayListMultimap.create());
Collection<Long> queryTimes = getTimes(fStateSystem, times);
try {
@SuppressWarnings("null")
Iterable<ITmfStateInterval> query2d = fStateSystem.query2D(quarks.keySet(), queryTimes);
for (ITmfStateInterval callInterval : query2d) {
CallStackDepth callStackDepth = Objects.requireNonNull(quarks.get(callInterval.getAttribute()));
if (callInterval.getValue() != null) {
map.put(callStackDepth, callStackDepth.getCallStack().getFunctionFromInterval(callInterval));
} else {
map.put(callStackDepth, new BasicSegment(callInterval.getStartTime(), callInterval.getEndTime() + 1));
}
}
} catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
Activator.getInstance().logError("Error while querying callstacks", e); //$NON-NLS-1$
}
return map;
}
private static Collection<Long> getTimes(ITmfStateSystem ss, Collection<Long> times) {
// Filter and deduplicate the time stamps for the statesystem
long start = ss.getStartTime();
long end = ss.getCurrentEndTime();
// use a HashSet to deduplicate time stamps
Collection<Long> queryTimes = new HashSet<>();
for (long t : times) {
if (t >= start && t <= end) {
queryTimes.add(t);
}
}
return queryTimes;
}
// ---------------------------------------------------
// Segment store methods
// ---------------------------------------------------
private static Collection<ICallStackElement> getCallStacks(ICallStackElement element) {
if (element.isLeaf()) {
return Collections.singleton(element);
}
List<ICallStackElement> list = new ArrayList<>();
if (element.isCallStack()) {
list.add(element);
}
element.getChildrenElements().forEach(e -> list.addAll(getCallStacks(e)));
return list;
}
@Override
public int size() {
return Iterators.size(iterator());
}
@Override
public boolean isEmpty() {
return !iterator().hasNext();
}
@Override
public boolean contains(@Nullable Object o) {
// narrow down search when object is a segment
if (o instanceof ICalledFunction) {
ICalledFunction seg = (ICalledFunction) o;
Iterable<ISegment> iterable = getIntersectingElements(seg.getStart());
return Iterables.contains(iterable, seg);
}
return false;
}
@SuppressWarnings("null")
@Override
public Iterator<ISegment> iterator() {
ITmfStateSystem stateSystem = fRootGroup.getStateSystem();
long start = stateSystem.getStartTime();
long end = stateSystem.getCurrentEndTime();
return getIntersectingElements(start, end).iterator();
}
@Override
public Object[] toArray() {
throw new UnsupportedOperationException("This segment store can potentially cause OutOfMemoryExceptions"); //$NON-NLS-1$
}
@Override
public <T> T[] toArray(T[] a) {
throw new UnsupportedOperationException("This segment store can potentially cause OutOfMemoryExceptions"); //$NON-NLS-1$
}
@Override
public boolean add(ISegment e) {
throw new UnsupportedOperationException("This segment store does not support adding new segments"); //$NON-NLS-1$
}
@Override
public boolean containsAll(@Nullable Collection<?> c) {
if (c == null) {
return false;
}
/*
* Check that all elements in the collection are indeed ISegments, and
* find their min end and max start time
*/
long minEnd = Long.MAX_VALUE;
long maxStart = Long.MIN_VALUE;
for (Object o : c) {
if (o instanceof ICalledFunction) {
ICalledFunction seg = (ICalledFunction) o;
minEnd = Math.min(minEnd, seg.getEnd());
maxStart = Math.max(maxStart, seg.getStart());
} else {
return false;
}
}
if (minEnd > maxStart) {
/*
* all segments intersect a common range, we just need to intersect
* a time stamp in that range
*/
minEnd = maxStart;
}
/* Iterate through possible segments until we have found them all */
Iterator<ISegment> iterator = getIntersectingElements(minEnd, maxStart).iterator();
int unFound = c.size();
while (iterator.hasNext() && unFound > 0) {
ISegment seg = iterator.next();
for (Object o : c) {
if (Objects.equals(o, seg)) {
unFound--;
}
}
}
return unFound == 0;
}
@Override
public boolean addAll(@Nullable Collection<? extends ISegment> c) {
throw new UnsupportedOperationException("This segment store does not support adding new segments"); //$NON-NLS-1$
}
@Override
public void clear() {
throw new UnsupportedOperationException("This segment store does not support clearing the data"); //$NON-NLS-1$
}
private Map<Integer, CallStack> getCallStackQuarks() {
Map<Integer, CallStack> quarkToElement = new HashMap<>();
// Get the leaf elements and their callstacks
getRootElements().stream().flatMap(e -> getCallStacks(e).stream())
.filter(InstrumentedCallStackElement.class::isInstance)
.map(e -> (InstrumentedCallStackElement) e)
.forEach(e -> e.getStackQuarks().forEach(c -> quarkToElement.put(c, e.getCallStack())));
return quarkToElement;
}
@SuppressWarnings("null")
@Override
public Iterable<ISegment> getIntersectingElements(long start, long end) {
ITmfStateSystem stateSystem = fRootGroup.getStateSystem();
// Start can be Long.MIN_VALUE, we need to avoid underflow
long startTime = Math.max(Math.max(1, start) - 1, stateSystem.getStartTime());
long endTime = Math.min(end, stateSystem.getCurrentEndTime());
if (startTime > endTime) {
return Collections.emptyList();
}
Map<Integer, CallStack> quarksToElement = getCallStackQuarks();
try {
Iterable<ITmfStateInterval> query2d = stateSystem.query2D(quarksToElement.keySet(), startTime, endTime);
query2d = Iterables.filter(query2d, interval -> !interval.getStateValue().isNull());
Function<ITmfStateInterval, ICalledFunction> fct = interval -> {
CallStack callstack = quarksToElement.get(interval.getAttribute());
if (callstack == null) {
throw new IllegalArgumentException("The quark was in that map in the first place, there must be a callstack to go with it!"); //$NON-NLS-1$
}
HostThread hostThread = callstack.getHostThread(interval.getStartTime());
int pid = callstack.getSymbolKeyAt(interval.getStartTime());
if (pid == CallStackElement.DEFAULT_SYMBOL_KEY && hostThread != null) {
// Try to find the pid from the tid
pid = ModelManager.getModelFor(hostThread.getHost()).getProcessId(hostThread.getTid(), interval.getStartTime());
}
if (hostThread == null) {
hostThread = new HostThread(StringUtils.EMPTY, IHostModel.UNKNOWN_TID);
}
return CalledFunctionFactory.create(interval.getStartTime(), interval.getEndTime() + 1, interval.getValue(), pid, hostThread.getTid(),
null, ModelManager.getModelFor(hostThread.getHost()));
};
return Iterables.transform(query2d, fct);
} catch (StateSystemDisposedException e) {
Activator.getInstance().logError("Error getting intersecting elements: StateSystemDisposed"); //$NON-NLS-1$
}
return Collections.emptyList();
}
@Override
public void dispose() {
// Nothing to do
}
}