1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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 * Alexis Cabana-Loriaux - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.contextswitch
;
15 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.Attributes
;
18 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelAnalysisEventLayout
;
19 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
20 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.Activator
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.StateSystemBuilderUtils
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfCpuAspect
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfStateProvider
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
33 * Class used to build a state system of the context switches of a trace
35 * @author Alexis Cabana-Loriaux
39 public class KernelContextSwitchStateProvider
extends AbstractTmfStateProvider
{
41 private static final String ID
= "org.eclipse.tracecompass.analysis.os.linux.contextswitch.stateprovider"; //$NON-NLS-1$
42 private static final int STARTING_QUARK
= -1;
43 private int fCpuAttributeQuark
= STARTING_QUARK
;
44 private @Nullable ITmfStateSystemBuilder fStateSystemBuilder
;
45 private IKernelAnalysisEventLayout fLayout
;
53 * the associated layout
55 public KernelContextSwitchStateProvider(ITmfTrace trace
, IKernelAnalysisEventLayout layout
) {
61 public int getVersion() {
66 public ITmfStateProvider
getNewInstance() {
67 return new KernelContextSwitchStateProvider(getTrace(), fLayout
);
71 * Classify sched_switch events for every CPU
74 protected void eventHandle(ITmfEvent event
) {
75 ITmfStateSystemBuilder stateSystemBuilder
= fStateSystemBuilder
;
76 if (stateSystemBuilder
== null) {
77 stateSystemBuilder
= (ITmfStateSystemBuilder
) getAssignedStateSystem();
78 fStateSystemBuilder
= stateSystemBuilder
;
80 if (stateSystemBuilder
== null) {
83 if (fCpuAttributeQuark
== STARTING_QUARK
) {
84 fCpuAttributeQuark
= stateSystemBuilder
.getQuarkAbsoluteAndAdd(Attributes
.CPUS
);
86 if (event
.getName().equals(fLayout
.eventSchedSwitch())) {
87 Object cpuObj
= TmfTraceUtils
.resolveEventAspectOfClassForEvent(event
.getTrace(), TmfCpuAspect
.class, event
);
89 /* We couldn't find any CPU information, ignore this event */
92 int cpuQuark
= stateSystemBuilder
.getQuarkRelativeAndAdd(fCpuAttributeQuark
, cpuObj
.toString());
94 StateSystemBuilderUtils
.incrementAttributeInt(stateSystemBuilder
, event
.getTimestamp().getValue(), cpuQuark
, 1);
95 } catch (StateValueTypeException
| AttributeNotFoundException e
) {
96 Activator
.getDefault().logError(NonNullUtils
.nullToEmptyString(e
.getMessage()), e
);