1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 École Polytechnique de Montréal
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 * Geneviève Bastien - Initial API and implementation
11 * Mathieu Rail - Provide the requirements of the analysis
12 *******************************************************************************/
14 package org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
;
16 import static java
.util
.Objects
.requireNonNull
;
17 import static org
.lttng
.scope
.common
.core
.NonNullUtils
.nullToEmptyString
;
19 import java
.util
.List
;
20 import java
.util
.Objects
;
22 import java
.util
.stream
.Collectors
;
24 import org
.eclipse
.jdt
.annotation
.NonNull
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfStateProvider
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
28 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.internal
.KernelStateProvider
;
29 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.IKernelTrace
;
30 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.layout
.ILttngKernelEventLayout
;
31 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.layout
.internal
.LttngEventLayout
;
33 import com
.google
.common
.primitives
.Ints
;
35 import ca
.polymtl
.dorsal
.libdelorean
.ITmfStateSystemBuilder
;
36 import ca
.polymtl
.dorsal
.libdelorean
.aggregation
.AttributePriorityAggregationRule
;
37 import ca
.polymtl
.dorsal
.libdelorean
.aggregation
.IStateAggregationRule
;
38 import ca
.polymtl
.dorsal
.libdelorean
.statevalue
.TmfStateValue
;
41 * State System Module for lttng kernel traces
43 * @author Geneviève Bastien
45 public class KernelAnalysisModule
extends TmfStateSystemAnalysisModule
{
47 /** The ID of this analysis module */
48 public static final String ID
= "org.eclipse.tracecompass.analysis.os.linux.kernel"; //$NON-NLS-1$
51 protected @NonNull ITmfStateProvider
createStateProvider() {
52 ITmfTrace trace
= requireNonNull(getTrace());
53 ILttngKernelEventLayout layout
;
55 if (trace
instanceof IKernelTrace
) {
56 layout
= ((IKernelTrace
) trace
).getKernelEventLayout();
58 /* Fall-back to the base LttngEventLayout */
59 layout
= LttngEventLayout
.getInstance();
62 return new KernelStateProvider(trace
, layout
);
66 protected String
getFullHelpText() {
67 return nullToEmptyString(Messages
.LttngKernelAnalysisModule_Help
);
71 protected void setupAggregationRules(ITmfStateSystemBuilder ss
) {
72 /* Set up the virtual "IRQs" and "SoftIRQs" sub-trees */
73 final int cpusQuark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.CPUS
);
74 final List
<Integer
> cpuQuarks
= ss
.getSubAttributes(cpusQuark
, false);
76 Set
<Integer
> irqNumbers
= cpuQuarks
.stream()
78 int irqsQuark
= ss
.getQuarkRelative(quark
, Attributes
.IRQS
);
79 List
<Integer
> irqQuarks
= ss
.getSubAttributes(irqsQuark
, false);
80 return irqQuarks
.stream()
81 .map(irqQuark
-> ss
.getAttributeName(irqQuark
))
82 .map(name
-> Ints
.tryParse(name
))
83 .filter(Objects
::nonNull
);
85 .collect(Collectors
.toSet());
87 Set
<Integer
> softIrqNumbers
= cpuQuarks
.stream()
89 int irqsQuark
= ss
.getQuarkRelative(quark
, Attributes
.SOFT_IRQS
);
90 List
<Integer
> irqQuarks
= ss
.getSubAttributes(irqsQuark
, false);
91 return irqQuarks
.stream()
92 .map(irqQuark
-> ss
.getAttributeName(irqQuark
))
93 .map(name
-> Ints
.tryParse(name
))
94 .filter(Objects
::nonNull
);
96 .collect(Collectors
.toSet());
98 int irqsQuark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.IRQS
);
99 if (irqsQuark
== ss
.getNbAttributes()) {
101 * FIXME If we just created this attribute, make sure we put a null value into
102 * it so that upcoming queries return something. Should be fixed in the state
105 ss
.modifyAttribute(ss
.getStartTime(), TmfStateValue
.nullValue(), irqsQuark
);
107 for (int irqNumber
: irqNumbers
) {
108 int irqQuark
= ss
.getQuarkRelativeAndAdd(irqsQuark
, String
.valueOf(irqNumber
));
109 List
<String
[]> irqPaths
= cpuQuarks
.stream()
111 String
[] cpuQuarkPath
= ss
.getFullAttributePathArray(quark
);
112 String
[] irqAttributePath
= new String
[4];
113 irqAttributePath
[0] = cpuQuarkPath
[0];
114 irqAttributePath
[1] = cpuQuarkPath
[1];
115 irqAttributePath
[2] = Attributes
.IRQS
;
116 irqAttributePath
[3] = String
.valueOf(irqNumber
);
117 return irqAttributePath
;
119 .collect(Collectors
.toList());
121 IStateAggregationRule rule
= new AttributePriorityAggregationRule(ss
, irqQuark
, irqPaths
);
122 ss
.addAggregationRule(rule
);
125 int softIrqsQuark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.SOFT_IRQS
);
126 if (softIrqsQuark
== ss
.getNbAttributes()) {
128 * FIXME If we just created this attribute, make sure we put a null value into
129 * it so that upcoming queries return something. Should be fixed in the state
132 ss
.modifyAttribute(ss
.getStartTime(), TmfStateValue
.nullValue(), softIrqsQuark
);
134 for (int softIrqNumber
: softIrqNumbers
) {
135 int softIrqQuark
= ss
.getQuarkRelativeAndAdd(softIrqsQuark
, String
.valueOf(softIrqNumber
));
136 List
<String
[]> softIrqPaths
= cpuQuarks
.stream()
138 String
[] cpuQuarkPath
= ss
.getFullAttributePathArray(quark
);
139 String
[] irqAttributePath
= new String
[4];
140 irqAttributePath
[0] = cpuQuarkPath
[0];
141 irqAttributePath
[1] = cpuQuarkPath
[1];
142 irqAttributePath
[2] = Attributes
.SOFT_IRQS
;
143 irqAttributePath
[3] = String
.valueOf(softIrqNumber
);
144 return irqAttributePath
;
146 .collect(Collectors
.toList());
148 ss
.addAggregationRule(new AttributePriorityAggregationRule(ss
, softIrqQuark
, softIrqPaths
));