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