a9f870b7d7d03742fad81d93b1644406931acd2f
[deliverable/tracecompass.git] / lttng / org.lttng.scope.lttng.kernel.core / src / org / lttng / scope / lttng / kernel / core / views / timegraph / resources / ResourcesCpuIrqModelProvider.java
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
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;
28
29 import com.google.common.annotations.VisibleForTesting;
30 import com.google.common.primitives.Ints;
31
32 import ca.polymtl.dorsal.libdelorean.ITmfStateSystem;
33
34 /**
35 * View model for a Resources view, showing CPUs as the first level, then
36 * per-cpu IRQs as the second level.
37 *
38 * @author Alexandre Montplaisir
39 */
40 public class ResourcesCpuIrqModelProvider extends ResourcesBaseModelProvider {
41
42 /**
43 * Each "CPU" attribute has the following children:
44 *
45 * <ul>
46 * <li>Current_thread</li>
47 * <li>Soft_IRQs</li>
48 * <li>IRQs</li>
49 * </ul>
50 */
51 private static final String[] CPUS_QUARK_PATTERN = { Attributes.CPUS, "*" }; //$NON-NLS-1$
52
53 /**
54 * Get the tree element name for every cpu.
55 */
56 @VisibleForTesting
57 public static final Function<TreeRenderContext, TimeGraphTreeRender> SS_TO_TREE_RENDER_FUNCTION = (treeContext) -> {
58 ITmfStateSystem ss = treeContext.ss;
59
60 List<TimeGraphTreeElement> treeElems = ss.getQuarks(CPUS_QUARK_PATTERN).stream()
61 .map(cpuQuark -> {
62 String cpuStr = ss.getAttributeName(cpuQuark);
63 Integer cpu = Ints.tryParse(cpuStr);
64 if (cpu == null) {
65 return null;
66 }
67
68 List<ResourcesIrqTreeElement> children = new LinkedList<>();
69
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));
75 }
76
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));
82 }
83
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);
89 })
90 .filter(Objects::nonNull)
91 /*
92 * Sort entries according to their CPU number (not just an
93 * alphabetical sort!)
94 */
95 .sorted(Comparator.comparingInt(ResourcesCpuTreeElement::getCpu))
96 .collect(Collectors.toList());
97
98 TimeGraphTreeElement rootElement = new TimeGraphTreeElement(treeContext.traceName, treeElems);
99 return new TimeGraphTreeRender(rootElement);
100 };
101
102 /**
103 * Constructor
104 */
105 public ResourcesCpuIrqModelProvider() {
106 super(requireNonNull(Messages.resourcesCpuIrqProviderName), SS_TO_TREE_RENDER_FUNCTION);
107 }
108
109 }
This page took 0.032715 seconds and 4 git commands to generate.