Commit | Line | Data |
---|---|---|
af3275f8 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013, 2015 École Polytechnique de Montréal | |
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 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | * Mathieu Rail - Provide the requirements of the analysis | |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.lttng.scope.lttng.kernel.core.analysis.os; | |
15 | ||
16 | import static java.util.Objects.requireNonNull; | |
17 | import static org.lttng.scope.common.core.NonNullUtils.nullToEmptyString; | |
18 | ||
19 | import java.util.List; | |
20 | import java.util.Objects; | |
21 | import java.util.Set; | |
22 | import java.util.stream.Collectors; | |
23 | ||
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; | |
32 | ||
33 | import com.google.common.primitives.Ints; | |
34 | ||
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; | |
39 | ||
40 | /** | |
41 | * State System Module for lttng kernel traces | |
42 | * | |
43 | * @author Geneviève Bastien | |
44 | */ | |
45 | public class KernelAnalysisModule extends TmfStateSystemAnalysisModule { | |
46 | ||
47 | /** The ID of this analysis module */ | |
48 | public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.kernel"; //$NON-NLS-1$ | |
49 | ||
50 | @Override | |
51 | protected @NonNull ITmfStateProvider createStateProvider() { | |
52 | ITmfTrace trace = requireNonNull(getTrace()); | |
53 | ILttngKernelEventLayout layout; | |
54 | ||
55 | if (trace instanceof IKernelTrace) { | |
56 | layout = ((IKernelTrace) trace).getKernelEventLayout(); | |
57 | } else { | |
58 | /* Fall-back to the base LttngEventLayout */ | |
59 | layout = LttngEventLayout.getInstance(); | |
60 | } | |
61 | ||
62 | return new KernelStateProvider(trace, layout); | |
63 | } | |
64 | ||
65 | @Override | |
66 | protected String getFullHelpText() { | |
67 | return nullToEmptyString(Messages.LttngKernelAnalysisModule_Help); | |
68 | } | |
69 | ||
70 | @Override | |
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); | |
75 | ||
76 | Set<Integer> irqNumbers = cpuQuarks.stream() | |
77 | .flatMap(quark -> { | |
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); | |
84 | }) | |
85 | .collect(Collectors.toSet()); | |
86 | ||
87 | Set<Integer> softIrqNumbers = cpuQuarks.stream() | |
88 | .flatMap(quark -> { | |
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); | |
95 | }) | |
96 | .collect(Collectors.toSet()); | |
97 | ||
98 | int irqsQuark = ss.getQuarkAbsoluteAndAdd(Attributes.IRQS); | |
99 | if (irqsQuark == ss.getNbAttributes()) { | |
100 | /* | |
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 | |
103 | * system library. | |
104 | */ | |
105 | ss.modifyAttribute(ss.getStartTime(), TmfStateValue.nullValue(), irqsQuark); | |
106 | } | |
107 | for (int irqNumber : irqNumbers) { | |
108 | int irqQuark = ss.getQuarkRelativeAndAdd(irqsQuark, String.valueOf(irqNumber)); | |
109 | List<String[]> irqPaths = cpuQuarks.stream() | |
110 | .map(quark -> { | |
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; | |
118 | }) | |
119 | .collect(Collectors.toList()); | |
120 | ||
121 | IStateAggregationRule rule = new AttributePriorityAggregationRule(ss, irqQuark, irqPaths); | |
122 | ss.addAggregationRule(rule); | |
123 | } | |
124 | ||
125 | int softIrqsQuark = ss.getQuarkAbsoluteAndAdd(Attributes.SOFT_IRQS); | |
126 | if (softIrqsQuark == ss.getNbAttributes()) { | |
127 | /* | |
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 | |
130 | * system library. | |
131 | */ | |
132 | ss.modifyAttribute(ss.getStartTime(), TmfStateValue.nullValue(), softIrqsQuark); | |
133 | } | |
134 | for (int softIrqNumber : softIrqNumbers) { | |
135 | int softIrqQuark = ss.getQuarkRelativeAndAdd(softIrqsQuark, String.valueOf(softIrqNumber)); | |
136 | List<String[]> softIrqPaths = cpuQuarks.stream() | |
137 | .map(quark -> { | |
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; | |
145 | }) | |
146 | .collect(Collectors.toList()); | |
147 | ||
148 | ss.addAggregationRule(new AttributePriorityAggregationRule(ss, softIrqQuark, softIrqPaths)); | |
149 | } | |
150 | ||
151 | } | |
152 | } |