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
.timegraph
.resources
;
12 import java
.util
.Collections
;
13 import java
.util
.List
;
15 import java
.util
.function
.Function
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.KernelAnalysisModule
;
19 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.StateValues
;
20 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
22 import org
.lttng
.scope
.lttng
.kernel
.core
.views
.timegraph
.KernelAnalysisStateDefinitions
;
23 import org
.lttng
.scope
.tmf2
.views
.core
.config
.ConfigOption
;
24 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.provider
.statesystem
.StateSystemModelStateProvider
;
25 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.render
.ColorDefinition
;
26 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.render
.LineThickness
;
27 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.render
.StateDefinition
;
29 import com
.google
.common
.annotations
.VisibleForTesting
;
30 import com
.google
.common
.collect
.ImmutableList
;
33 * State provider of the Resources time graph.
35 * @author Alexandre Montplaisir
37 public class ResourcesModelStateProvider
extends StateSystemModelStateProvider
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 private static final Function
<StateIntervalContext
, @Nullable String
> LABEL_MAPPING_FUNCTION
= ssCtx
-> null;
45 // ------------------------------------------------------------------------
46 // Color mapping, line thickness
47 // ------------------------------------------------------------------------
50 * State definitions used in this provider.
52 private static final List
<StateDefinition
> STATE_DEFINITIONS
= ImmutableList
.of(
53 KernelAnalysisStateDefinitions
.CPU_STATE_IDLE
,
54 KernelAnalysisStateDefinitions
.THREAD_STATE_SYSCALL
,
55 KernelAnalysisStateDefinitions
.THREAD_STATE_USERMODE
,
56 KernelAnalysisStateDefinitions
.CPU_STATE_IRQ_ACTIVE
,
57 KernelAnalysisStateDefinitions
.CPU_STATE_SOFTIRQ_ACTIVE
,
58 KernelAnalysisStateDefinitions
.CPU_STATE_SOFTIRQ_RAISED
);
60 private static final Function
<StateIntervalContext
, StateDefinition
> STATE_DEF_MAPPING_FUNCTION
= ssCtx
-> {
61 ITmfStateValue val
= ssCtx
.sourceInterval
.getStateValue();
62 return stateValueToStateDef(val
);
66 static final StateDefinition
stateValueToStateDef(ITmfStateValue val
) {
68 return KernelAnalysisStateDefinitions
.NO_STATE
;
72 int status
= val
.unboxInt();
74 case StateValues
.CPU_STATUS_IDLE
:
75 return KernelAnalysisStateDefinitions
.CPU_STATE_IDLE
;
76 case StateValues
.CPU_STATUS_RUN_SYSCALL
:
77 return KernelAnalysisStateDefinitions
.THREAD_STATE_SYSCALL
;
78 case StateValues
.CPU_STATUS_RUN_USERMODE
:
79 return KernelAnalysisStateDefinitions
.THREAD_STATE_USERMODE
;
80 case StateValues
.CPU_STATUS_IRQ
:
81 return KernelAnalysisStateDefinitions
.CPU_STATE_IRQ_ACTIVE
;
82 case StateValues
.CPU_STATUS_SOFTIRQ
:
83 return KernelAnalysisStateDefinitions
.CPU_STATE_SOFTIRQ_ACTIVE
;
84 case StateValues
.CPU_STATUS_SOFT_IRQ_RAISED
:
85 return KernelAnalysisStateDefinitions
.CPU_STATE_SOFTIRQ_RAISED
;
87 return KernelAnalysisStateDefinitions
.CPU_STATE_UNKNOWN
;
90 } catch (StateValueTypeException e
) {
91 return KernelAnalysisStateDefinitions
.CPU_STATE_UNKNOWN
;
95 private static final Function
<StateIntervalContext
, String
> STATE_NAME_MAPPING_FUNCTION
= ssCtx
-> STATE_DEF_MAPPING_FUNCTION
.apply(ssCtx
).getName();
97 private static final Function
<StateIntervalContext
, ConfigOption
<ColorDefinition
>> COLOR_MAPPING_FUNCTION
= ssCtx
-> STATE_DEF_MAPPING_FUNCTION
.apply(ssCtx
).getColor();
99 private static final Function
<StateIntervalContext
, ConfigOption
<LineThickness
>> LINE_THICKNESS_MAPPING_FUNCTION
= ssCtx
-> STATE_DEF_MAPPING_FUNCTION
.apply(ssCtx
).getLineThickness();
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
105 private static final Function
<StateIntervalContext
, Map
<String
, String
>> PROPERTIES_MAPPING_FUNCTION
= ssCtx
-> {
106 // TODO Add current thread on this CPU
107 return Collections
.emptyMap();
113 public ResourcesModelStateProvider() {
114 super(STATE_DEFINITIONS
,
115 KernelAnalysisModule
.ID
,
116 STATE_NAME_MAPPING_FUNCTION
,
117 LABEL_MAPPING_FUNCTION
,
118 COLOR_MAPPING_FUNCTION
,
119 LINE_THICKNESS_MAPPING_FUNCTION
,
120 PROPERTIES_MAPPING_FUNCTION
);