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
.kernel
.resources2
;
12 import static java
.util
.Objects
.requireNonNull
;
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
;
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
;
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
;
30 import com
.google
.common
.annotations
.VisibleForTesting
;
31 import com
.google
.common
.primitives
.Ints
;
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.
37 * TODO This timegraph only models CPU states. States of IRQs under each CPU
38 * should be added at some point.
40 * @author Alexandre Montplaisir
42 public class ResourcesModelProvider
extends StateSystemModelProvider
{
44 private static final Supplier
<ITimeGraphModelStateProvider
> STATE_PROVIDER
= () -> {
45 return new ResourcesModelStateProvider();
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * Each "CPU" attribute has the following children:
56 * <li>Current_thread</li>
61 private static final String
[] CPUS_QUARK_PATTERN
= { Attributes
.CPUS
, "*" }; //$NON-NLS-1$
64 * Get the tree element name for every cpu.
67 public static final Function
<TreeRenderContext
, TimeGraphTreeRender
> SS_TO_TREE_RENDER_FUNCTION
= (treeContext
) -> {
68 ITmfStateSystem ss
= treeContext
.ss
;
70 List
<TimeGraphTreeElement
> treeElems
= ss
.getQuarks(CPUS_QUARK_PATTERN
).stream()
72 String cpuStr
= ss
.getAttributeName(baseQuark
);
73 Integer cpu
= Ints
.tryParse(cpuStr
);
77 return new ResourcesTreeElement(cpu
, Collections
.emptyList(), baseQuark
);
79 .filter(Objects
::nonNull
)
81 * Sort entries according to their CPU number (not just an
84 .sorted(Comparator
.comparingInt(ResourcesTreeElement
::getCpu
))
85 .collect(Collectors
.toList());
87 return new TimeGraphTreeRender(treeElems
);
93 public ResourcesModelProvider() {
94 super(requireNonNull(Messages
.resourcesProviderName
),
99 /* Parameters specific to state system render providers */
100 KernelAnalysisModule
.ID
,
101 SS_TO_TREE_RENDER_FUNCTION
);