1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.tid
;
13 import java
.util
.TreeMap
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelAnalysisEventLayout
;
17 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
18 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.Activator
;
19 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
20 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfCpuAspect
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfStateProvider
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
30 * Active TID state provider, this only does one thing: figure out the active
31 * TID on any given CPU. This state provider is designed to do one thing and do
34 * Note: this state provider exists as a way to accelerate the TID aspect, but
35 * also to start splitting up the kernel analysis into smaller sections.
37 * Note 2: this is deliberately only package visible.
39 * @author Matthew Khouzam
41 class ActiveTidStateProvider
extends AbstractTmfStateProvider
{
43 private static final @NonNull String PROVIDER_ID
= "activeTidAnalysis.provider"; //$NON-NLS-1$
44 private static final int VERSION
= 0;
46 private final Map
<Integer
, Integer
> fCpuNumToQuark
= new TreeMap
<>();
47 private final @NonNull String fSchedSwitch
;
48 private final @NonNull String fNextTid
;
49 private final @NonNull IKernelAnalysisEventLayout fLayout
;
51 public ActiveTidStateProvider(@NonNull ITmfTrace trace
, @NonNull IKernelAnalysisEventLayout layout
) {
52 super(trace
, PROVIDER_ID
);
53 fSchedSwitch
= layout
.eventSchedSwitch();
54 fNextTid
= layout
.fieldNextTid();
59 public int getVersion() {
64 public @NonNull ITmfStateProvider
getNewInstance() {
65 return new ActiveTidStateProvider(getTrace(), fLayout
);
69 protected void eventHandle(@NonNull ITmfEvent event
) {
70 Integer cpu
= TmfTraceUtils
.resolveIntEventAspectOfClassForEvent(event
.getTrace(), TmfCpuAspect
.class, event
);
74 ITmfStateSystemBuilder ssb
= getStateSystemBuilder();
78 Integer cpuQuark
= fCpuNumToQuark
.get(cpu
);
79 if (cpuQuark
== null) {
80 // this will only happen once
81 String cpuAttributeName
= NonNullUtils
.nullToEmptyString(cpu
);
82 cpuQuark
= ssb
.getQuarkAbsoluteAndAdd(cpuAttributeName
);
83 fCpuNumToQuark
.put(cpu
, cpuQuark
);
85 if (!event
.getName().equals(fSchedSwitch
)) {
89 int nextTid
= ((Long
) event
.getContent().getField(fNextTid
).getValue()).intValue();
90 final TmfStateValue value
= TmfStateValue
.newValueInt(nextTid
);
91 ssb
.modifyAttribute(event
.getTimestamp().toNanos(), value
, cpuQuark
);
92 } catch (StateValueTypeException e
) {
93 Activator
.getDefault().logError(NonNullUtils
.nullToEmptyString(e
.getMessage()), e
);