2 * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
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
10 package org
.lttng
.scope
.lttng
.kernel
.core
.views
.timegraph
.resources
;
12 import static java
.util
.Objects
.requireNonNull
;
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
;
22 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.Attributes
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
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
;
30 import com
.google
.common
.annotations
.VisibleForTesting
;
31 import com
.google
.common
.primitives
.Ints
;
34 * View model for a Resources view, showing CPUs as the first level, then
35 * per-cpu IRQs as the second level.
37 * @author Alexandre Montplaisir
39 public class ResourcesCpuIrqModelProvider
extends ResourcesBaseModelProvider
{
42 * Each "CPU" attribute has the following children:
45 * <li>Current_thread</li>
50 private static final String
[] CPUS_QUARK_PATTERN
= { Attributes
.CPUS
, "*" }; //$NON-NLS-1$
53 * Get the tree element name for every cpu.
56 public static final Function
<TreeRenderContext
, TimeGraphTreeRender
> SS_TO_TREE_RENDER_FUNCTION
= (treeContext
) -> {
57 ITmfStateSystem ss
= treeContext
.ss
;
59 List
<TimeGraphTreeElement
> treeElems
= ss
.getQuarks(CPUS_QUARK_PATTERN
).stream()
61 String cpuStr
= ss
.getAttributeName(cpuQuark
);
62 Integer cpu
= Ints
.tryParse(cpuStr
);
67 List
<ResourcesIrqTreeElement
> children
= new LinkedList
<>();
69 /* Add the "IRQ" children. */
70 int irqsQuark
= ss
.optQuarkRelative(cpuQuark
, Attributes
.IRQS
);
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
));
76 /* Add the "SoftIRQ" children. */
77 int softIrqsQuark
= ss
.optQuarkRelative(cpuQuark
, Attributes
.SOFT_IRQS
);
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
));
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
);
89 .filter(Objects
::nonNull
)
91 * Sort entries according to their CPU number (not just an
94 .sorted(Comparator
.comparingInt(ResourcesCpuTreeElement
::getCpu
))
95 .collect(Collectors
.toList());
97 TimeGraphTreeElement rootElement
= new TimeGraphTreeElement(treeContext
.traceName
, treeElems
);
98 return new TimeGraphTreeRender(rootElement
);
104 public ResourcesCpuIrqModelProvider() {
105 super(requireNonNull(Messages
.resourcesCpuIrqProviderName
), SS_TO_TREE_RENDER_FUNCTION
);