-
Notifications
You must be signed in to change notification settings - Fork 10
/
ThreadNameComparator.java
56 lines (49 loc) · 2.5 KB
/
ThreadNameComparator.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
/*******************************************************************************
* Copyright (c) 2016 Ericsson
*
* 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.incubator.internal.callstack.ui.flamegraph;
import java.util.Comparator;
import org.eclipse.tracecompass.incubator.internal.callstack.core.instrumented.provider.FlameChartEntryModel;
import org.eclipse.tracecompass.incubator.internal.callstack.core.instrumented.provider.FlameChartEntryModel.EntryType;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
/**
* Comparator to compare by thread name.
*
* @author Bernd Hufmann
*/
class ThreadNameComparator implements Comparator<ITimeGraphEntry> {
private static final Comparator<ITimeGraphEntry> INSTANCE = new ThreadNameComparator();
private ThreadNameComparator() {
// Nothing to do
}
public static Comparator<ITimeGraphEntry> getInstance() {
return INSTANCE;
}
@Override
public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
if (o1 instanceof TimeGraphEntry && o2 instanceof TimeGraphEntry) {
ITmfTreeDataModel entryModel1 = ((TimeGraphEntry) o1).getEntryModel();
ITmfTreeDataModel entryModel2 = ((TimeGraphEntry) o2).getEntryModel();
if (entryModel1 instanceof FlameChartEntryModel && entryModel2 instanceof FlameChartEntryModel) {
FlameChartEntryModel fcEntry1 = (FlameChartEntryModel) entryModel1;
FlameChartEntryModel fcEntry2 = (FlameChartEntryModel) entryModel2;
// If any of the entry is a function of kernel, don't compare
if (fcEntry1.getEntryType().equals(EntryType.FUNCTION) || fcEntry2.getEntryType().equals(EntryType.FUNCTION) ||
fcEntry1.getEntryType().equals(EntryType.KERNEL) || fcEntry2.getEntryType().equals(EntryType.KERNEL)) {
return 0;
}
}
}
// Fallback to entry name comparator
return o1.getName().compareTo(o2.getName());
}
}