Import lttng.kernel.core plugins from Scope
[deliverable/tracecompass.git] / lttng / org.lttng.scope.lttng.kernel.core / src / org / lttng / scope / lttng / kernel / core / views / timegraph / resources / ResourcesIrqModelProvider.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.LinkedList;
16 import java.util.List;
17 import java.util.function.Function;
18
19 import org.lttng.scope.lttng.kernel.core.analysis.os.Attributes;
20 import org.lttng.scope.lttng.kernel.core.views.timegraph.resources.elements.ResourcesIrqTreeElement;
21 import org.lttng.scope.lttng.kernel.core.views.timegraph.resources.elements.ResourcesIrqTreeElement.IrqType;
22 import org.lttng.scope.tmf2.views.core.timegraph.model.render.tree.TimeGraphTreeElement;
23 import org.lttng.scope.tmf2.views.core.timegraph.model.render.tree.TimeGraphTreeRender;
24
25 import com.google.common.annotations.VisibleForTesting;
26 import com.google.common.primitives.Ints;
27
28 import ca.polymtl.dorsal.libdelorean.ITmfStateSystem;
29
30 /**
31 * View model for a Resources view showing IRQs and SoftIRQs.
32 *
33 * @author Alexandre Montplaisir
34 */
35 public class ResourcesIrqModelProvider extends ResourcesBaseModelProvider {
36
37 private static final String[] IRQS_QUARK_PATTERN = { Attributes.IRQS, "*" }; //$NON-NLS-1$
38 private static final String[] SOFT_IRQS_QUARK_PATTERN = { Attributes.SOFT_IRQS, "*" }; //$NON-NLS-1$
39
40 /**
41 * Get the tree element name for every cpu.
42 */
43 @VisibleForTesting
44 public static final Function<TreeRenderContext, TimeGraphTreeRender> SS_TO_TREE_RENDER_FUNCTION = (treeContext) -> {
45 ITmfStateSystem ss = treeContext.ss;
46
47 List<ResourcesIrqTreeElement> treeElems = new LinkedList<>();
48 /* Create "IRQ *" children */
49 ss.getQuarks(IRQS_QUARK_PATTERN).forEach(irqQuark -> {
50 String name = ss.getAttributeName(irqQuark);
51 Integer irqNumber = Ints.tryParse(name);
52 if (irqNumber != null) {
53 treeElems.add(new ResourcesIrqTreeElement(IrqType.IRQ, irqNumber, irqQuark));
54 }
55 });
56
57 /* Create "SoftIRQ *" children */
58 ss.getQuarks(SOFT_IRQS_QUARK_PATTERN).forEach(irqQuark -> {
59 String name = ss.getAttributeName(irqQuark);
60 Integer irqNumber = Ints.tryParse(name);
61 if (irqNumber != null) {
62 treeElems.add(new ResourcesIrqTreeElement(IrqType.SOFTIRQ, irqNumber, irqQuark));
63 }
64 });
65
66 Collections.sort(treeElems, IRQ_SORTER);
67 @SuppressWarnings("rawtypes")
68 List treeElems2 = treeElems;
69 TimeGraphTreeElement rootElement = new TimeGraphTreeElement(treeContext.traceName, treeElems2);
70 return new TimeGraphTreeRender(rootElement);
71 };
72
73 /**
74 * Constructor
75 */
76 public ResourcesIrqModelProvider() {
77 super(requireNonNull(Messages.resourcesIrqProviderName), SS_TO_TREE_RENDER_FUNCTION);
78 }
79
80 }
This page took 0.031844 seconds and 5 git commands to generate.