Commit | Line | Data |
---|---|---|
af3275f8 AM |
1 | /* |
2 | * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> | |
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 | ||
10 | package org.lttng.scope.lttng.kernel.core.views.timegraph.resources; | |
11 | ||
12 | import static java.util.Objects.requireNonNull; | |
13 | ||
14 | import java.util.Collections; | |
15 | import java.util.Comparator; | |
16 | import java.util.LinkedList; | |
17 | import java.util.List; | |
18 | import java.util.Objects; | |
19 | import java.util.function.Function; | |
20 | import java.util.stream.Collectors; | |
21 | ||
deecbf8e AM |
22 | import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes; |
23 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; | |
af3275f8 AM |
24 | import org.lttng.scope.lttng.kernel.core.views.timegraph.resources.elements.ResourcesCpuTreeElement; |
25 | import org.lttng.scope.lttng.kernel.core.views.timegraph.resources.elements.ResourcesIrqTreeElement; | |
26 | import org.lttng.scope.lttng.kernel.core.views.timegraph.resources.elements.ResourcesIrqTreeElement.IrqType; | |
27 | import org.lttng.scope.tmf2.views.core.timegraph.model.render.tree.TimeGraphTreeElement; | |
28 | import org.lttng.scope.tmf2.views.core.timegraph.model.render.tree.TimeGraphTreeRender; | |
29 | ||
30 | import com.google.common.annotations.VisibleForTesting; | |
31 | import com.google.common.primitives.Ints; | |
32 | ||
af3275f8 AM |
33 | /** |
34 | * View model for a Resources view, showing CPUs as the first level, then | |
35 | * per-cpu IRQs as the second level. | |
36 | * | |
37 | * @author Alexandre Montplaisir | |
38 | */ | |
39 | public class ResourcesCpuIrqModelProvider extends ResourcesBaseModelProvider { | |
40 | ||
41 | /** | |
42 | * Each "CPU" attribute has the following children: | |
43 | * | |
44 | * <ul> | |
45 | * <li>Current_thread</li> | |
46 | * <li>Soft_IRQs</li> | |
47 | * <li>IRQs</li> | |
48 | * </ul> | |
49 | */ | |
50 | private static final String[] CPUS_QUARK_PATTERN = { Attributes.CPUS, "*" }; //$NON-NLS-1$ | |
51 | ||
52 | /** | |
53 | * Get the tree element name for every cpu. | |
54 | */ | |
55 | @VisibleForTesting | |
56 | public static final Function<TreeRenderContext, TimeGraphTreeRender> SS_TO_TREE_RENDER_FUNCTION = (treeContext) -> { | |
57 | ITmfStateSystem ss = treeContext.ss; | |
58 | ||
59 | List<TimeGraphTreeElement> treeElems = ss.getQuarks(CPUS_QUARK_PATTERN).stream() | |
60 | .map(cpuQuark -> { | |
61 | String cpuStr = ss.getAttributeName(cpuQuark); | |
62 | Integer cpu = Ints.tryParse(cpuStr); | |
63 | if (cpu == null) { | |
64 | return null; | |
65 | } | |
66 | ||
67 | List<ResourcesIrqTreeElement> children = new LinkedList<>(); | |
68 | ||
69 | /* Add the "IRQ" children. */ | |
deecbf8e | 70 | int irqsQuark = ss.optQuarkRelative(cpuQuark, Attributes.IRQS); |
af3275f8 AM |
71 | for (int irqQuark : ss.getSubAttributes(irqsQuark, false)) { |
72 | int irqNumber = Ints.tryParse(ss.getAttributeName(irqQuark)); | |
73 | children.add(new ResourcesIrqTreeElement(IrqType.IRQ, irqNumber, irqQuark)); | |
74 | } | |
75 | ||
76 | /* Add the "SoftIRQ" children. */ | |
deecbf8e | 77 | int softIrqsQuark = ss.optQuarkRelative(cpuQuark, Attributes.SOFT_IRQS); |
af3275f8 AM |
78 | for (int softIrqQuark : ss.getSubAttributes(softIrqsQuark, false)) { |
79 | int irqNumber = Ints.tryParse(ss.getAttributeName(softIrqQuark)); | |
80 | children.add(new ResourcesIrqTreeElement(IrqType.SOFTIRQ, irqNumber, softIrqQuark)); | |
81 | } | |
82 | ||
83 | Collections.sort(children, IRQ_SORTER); | |
84 | /* Generic types are not covariant :/ Use a raw type instead... */ | |
85 | @SuppressWarnings("rawtypes") | |
86 | List children2 = children; | |
87 | return new ResourcesCpuTreeElement(cpu, children2, cpuQuark); | |
88 | }) | |
89 | .filter(Objects::nonNull) | |
90 | /* | |
91 | * Sort entries according to their CPU number (not just an | |
92 | * alphabetical sort!) | |
93 | */ | |
94 | .sorted(Comparator.comparingInt(ResourcesCpuTreeElement::getCpu)) | |
95 | .collect(Collectors.toList()); | |
96 | ||
97 | TimeGraphTreeElement rootElement = new TimeGraphTreeElement(treeContext.traceName, treeElems); | |
98 | return new TimeGraphTreeRender(rootElement); | |
99 | }; | |
100 | ||
101 | /** | |
102 | * Constructor | |
103 | */ | |
104 | public ResourcesCpuIrqModelProvider() { | |
105 | super(requireNonNull(Messages.resourcesCpuIrqProviderName), SS_TO_TREE_RENDER_FUNCTION); | |
106 | } | |
107 | ||
108 | } |