Commit | Line | Data |
---|---|---|
451ba2f7 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.kernel.resources2; | |
11 | ||
12 | import static java.util.Objects.requireNonNull; | |
13 | ||
14 | import java.util.Collections; | |
15 | import java.util.Comparator; | |
16 | import java.util.List; | |
17 | import java.util.Objects; | |
18 | import java.util.function.Function; | |
19 | import java.util.function.Supplier; | |
20 | import java.util.stream.Collectors; | |
21 | ||
d8ab28e3 AM |
22 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule; |
23 | import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes; | |
24 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; | |
451ba2f7 AM |
25 | import org.lttng.scope.tmf2.views.core.timegraph.model.provider.states.ITimeGraphModelStateProvider; |
26 | import org.lttng.scope.tmf2.views.core.timegraph.model.provider.statesystem.StateSystemModelProvider; | |
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; | |
29 | ||
30 | import com.google.common.annotations.VisibleForTesting; | |
31 | import com.google.common.primitives.Ints; | |
32 | ||
451ba2f7 AM |
33 | /** |
34 | * Base model provider for the "Resources" time graph. It displays the states of | |
35 | * CPUs, as well as the state of IRQs of each CPU. | |
36 | * | |
37 | * TODO This timegraph only models CPU states. States of IRQs under each CPU | |
38 | * should be added at some point. | |
39 | * | |
40 | * @author Alexandre Montplaisir | |
41 | */ | |
42 | public class ResourcesModelProvider extends StateSystemModelProvider { | |
43 | ||
44 | private static final Supplier<ITimeGraphModelStateProvider> STATE_PROVIDER = () -> { | |
45 | return new ResourcesModelStateProvider(); | |
46 | }; | |
47 | ||
48 | // ------------------------------------------------------------------------ | |
49 | // Tree render | |
50 | // ------------------------------------------------------------------------ | |
51 | ||
52 | /** | |
53 | * Each "CPU" attribute has the following children: | |
54 | * | |
55 | * <ul> | |
56 | * <li>Current_thread</li> | |
57 | * <li>Soft_IRQs</li> | |
58 | * <li>IRQs</li> | |
59 | * </ul> | |
60 | */ | |
61 | private static final String[] CPUS_QUARK_PATTERN = { Attributes.CPUS, "*" }; //$NON-NLS-1$ | |
62 | ||
63 | /** | |
64 | * Get the tree element name for every cpu. | |
65 | */ | |
66 | @VisibleForTesting | |
67 | public static final Function<TreeRenderContext, TimeGraphTreeRender> SS_TO_TREE_RENDER_FUNCTION = (treeContext) -> { | |
68 | ITmfStateSystem ss = treeContext.ss; | |
69 | ||
70 | List<TimeGraphTreeElement> treeElems = ss.getQuarks(CPUS_QUARK_PATTERN).stream() | |
71 | .map(baseQuark -> { | |
72 | String cpuStr = ss.getAttributeName(baseQuark); | |
73 | Integer cpu = Ints.tryParse(cpuStr); | |
74 | if (cpu == null) { | |
75 | return null; | |
76 | } | |
77 | return new ResourcesTreeElement(cpu, Collections.emptyList(), baseQuark); | |
78 | }) | |
79 | .filter(Objects::nonNull) | |
80 | /* | |
81 | * Sort entries according to their CPU number (not just an | |
82 | * alphabetical sort!) | |
83 | */ | |
84 | .sorted(Comparator.comparingInt(ResourcesTreeElement::getCpu)) | |
85 | .collect(Collectors.toList()); | |
86 | ||
87 | return new TimeGraphTreeRender(treeElems); | |
88 | }; | |
89 | ||
90 | /** | |
91 | * Constructor | |
92 | */ | |
93 | public ResourcesModelProvider() { | |
94 | super(requireNonNull(Messages.resourcesProviderName), | |
95 | null, | |
96 | null, | |
97 | STATE_PROVIDER.get(), | |
98 | null, | |
99 | /* Parameters specific to state system render providers */ | |
100 | KernelAnalysisModule.ID, | |
101 | SS_TO_TREE_RENDER_FUNCTION); | |
102 | } | |
103 | ||
104 | } |