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
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.Attributes
;
23 import org
.lttng
.scope
.lttng
.kernel
.core
.views
.timegraph
.resources
.elements
.ResourcesCpuTreeElement
;
24 import org
.lttng
.scope
.lttng
.kernel
.core
.views
.timegraph
.resources
.elements
.ResourcesIrqTreeElement
;
25 import org
.lttng
.scope
.lttng
.kernel
.core
.views
.timegraph
.resources
.elements
.ResourcesIrqTreeElement
.IrqType
;
26 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.render
.tree
.TimeGraphTreeElement
;
27 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.render
.tree
.TimeGraphTreeRender
;
29 import com
.google
.common
.annotations
.VisibleForTesting
;
30 import com
.google
.common
.primitives
.Ints
;
32 import ca
.polymtl
.dorsal
.libdelorean
.ITmfStateSystem
;
35 * View model for a Resources view, showing CPUs as the first level, then
36 * per-cpu IRQs as the second level.
38 * @author Alexandre Montplaisir
40 public class ResourcesCpuIrqModelProvider
extends ResourcesBaseModelProvider
{
43 * Each "CPU" attribute has the following children:
46 * <li>Current_thread</li>
51 private static final String
[] CPUS_QUARK_PATTERN
= { Attributes
.CPUS
, "*" }; //$NON-NLS-1$
54 * Get the tree element name for every cpu.
57 public static final Function
<TreeRenderContext
, TimeGraphTreeRender
> SS_TO_TREE_RENDER_FUNCTION
= (treeContext
) -> {
58 ITmfStateSystem ss
= treeContext
.ss
;
60 List
<TimeGraphTreeElement
> treeElems
= ss
.getQuarks(CPUS_QUARK_PATTERN
).stream()
62 String cpuStr
= ss
.getAttributeName(cpuQuark
);
63 Integer cpu
= Ints
.tryParse(cpuStr
);
68 List
<ResourcesIrqTreeElement
> children
= new LinkedList
<>();
70 /* Add the "IRQ" children. */
71 int irqsQuark
= ss
.getQuarkRelative(cpuQuark
, Attributes
.IRQS
);
72 for (int irqQuark
: ss
.getSubAttributes(irqsQuark
, false)) {
73 int irqNumber
= Ints
.tryParse(ss
.getAttributeName(irqQuark
));
74 children
.add(new ResourcesIrqTreeElement(IrqType
.IRQ
, irqNumber
, irqQuark
));
77 /* Add the "SoftIRQ" children. */
78 int softIrqsQuark
= ss
.getQuarkRelative(cpuQuark
, Attributes
.SOFT_IRQS
);
79 for (int softIrqQuark
: ss
.getSubAttributes(softIrqsQuark
, false)) {
80 int irqNumber
= Ints
.tryParse(ss
.getAttributeName(softIrqQuark
));
81 children
.add(new ResourcesIrqTreeElement(IrqType
.SOFTIRQ
, irqNumber
, softIrqQuark
));
84 Collections
.sort(children
, IRQ_SORTER
);
85 /* Generic types are not covariant :/ Use a raw type instead... */
86 @SuppressWarnings("rawtypes")
87 List children2
= children
;
88 return new ResourcesCpuTreeElement(cpu
, children2
, cpuQuark
);
90 .filter(Objects
::nonNull
)
92 * Sort entries according to their CPU number (not just an
95 .sorted(Comparator
.comparingInt(ResourcesCpuTreeElement
::getCpu
))
96 .collect(Collectors
.toList());
98 TimeGraphTreeElement rootElement
= new TimeGraphTreeElement(treeContext
.traceName
, treeElems
);
99 return new TimeGraphTreeRender(rootElement
);
105 public ResourcesCpuIrqModelProvider() {
106 super(requireNonNull(Messages
.resourcesCpuIrqProviderName
), SS_TO_TREE_RENDER_FUNCTION
);