Adapt new kernel.core plugins to TMF
[deliverable/tracecompass.git] / lttng / org.lttng.scope.lttng.kernel.core / src / org / lttng / scope / lttng / kernel / core / views / timegraph / resources / ResourcesModelStateProvider.java
CommitLineData
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
10package org.lttng.scope.lttng.kernel.core.views.timegraph.resources;
11
12import java.util.Collections;
13import java.util.List;
14import java.util.Map;
15import java.util.function.Function;
16
17import org.eclipse.jdt.annotation.Nullable;
deecbf8e
AM
18import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
19import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues;
20import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
21import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
af3275f8
AM
22import org.lttng.scope.lttng.kernel.core.views.timegraph.KernelAnalysisStateDefinitions;
23import org.lttng.scope.tmf2.views.core.config.ConfigOption;
24import org.lttng.scope.tmf2.views.core.timegraph.model.provider.statesystem.StateSystemModelStateProvider;
25import org.lttng.scope.tmf2.views.core.timegraph.model.render.ColorDefinition;
26import org.lttng.scope.tmf2.views.core.timegraph.model.render.LineThickness;
27import org.lttng.scope.tmf2.views.core.timegraph.model.render.StateDefinition;
28
29import com.google.common.annotations.VisibleForTesting;
30import com.google.common.collect.ImmutableList;
31
af3275f8
AM
32/**
33 * State provider of the Resources time graph.
34 *
35 * @author Alexandre Montplaisir
36 */
37public class ResourcesModelStateProvider extends StateSystemModelStateProvider {
38
39 // ------------------------------------------------------------------------
40 // Label mapping
41 // ------------------------------------------------------------------------
42
43 private static final Function<StateIntervalContext, @Nullable String> LABEL_MAPPING_FUNCTION = ssCtx -> null;
44
45 // ------------------------------------------------------------------------
46 // Color mapping, line thickness
47 // ------------------------------------------------------------------------
48
49 /**
50 * State definitions used in this provider.
51 */
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);
59
60 private static final Function<StateIntervalContext, StateDefinition> STATE_DEF_MAPPING_FUNCTION = ssCtx -> {
61 ITmfStateValue val = ssCtx.sourceInterval.getStateValue();
62 return stateValueToStateDef(val);
63 };
64
65 @VisibleForTesting
66 static final StateDefinition stateValueToStateDef(ITmfStateValue val) {
67 if (val.isNull()) {
68 return KernelAnalysisStateDefinitions.NO_STATE;
69 }
70
71 try {
72 int status = val.unboxInt();
73 switch (status) {
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;
86 default:
87 return KernelAnalysisStateDefinitions.CPU_STATE_UNKNOWN;
88 }
89
90 } catch (StateValueTypeException e) {
91 return KernelAnalysisStateDefinitions.CPU_STATE_UNKNOWN;
92 }
93 }
94
95 private static final Function<StateIntervalContext, String> STATE_NAME_MAPPING_FUNCTION = ssCtx -> STATE_DEF_MAPPING_FUNCTION.apply(ssCtx).getName();
96
97 private static final Function<StateIntervalContext, ConfigOption<ColorDefinition>> COLOR_MAPPING_FUNCTION = ssCtx -> STATE_DEF_MAPPING_FUNCTION.apply(ssCtx).getColor();
98
99 private static final Function<StateIntervalContext, ConfigOption<LineThickness>> LINE_THICKNESS_MAPPING_FUNCTION = ssCtx -> STATE_DEF_MAPPING_FUNCTION.apply(ssCtx).getLineThickness();
100
101 // ------------------------------------------------------------------------
102 // Properties
103 // ------------------------------------------------------------------------
104
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();
108 };
109
110 /**
111 * Constructor
112 */
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);
121 }
122}
This page took 0.028388 seconds and 5 git commands to generate.