ss: Replace AttributeNotFoundException with IOOBE for quark parameters
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / analysis / os / linux / core / tid / ActiveTidStateProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.analysis.os.linux.core.tid;
11
12 import java.util.Map;
13 import java.util.TreeMap;
14
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;
28
29 /**
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
32 * it fast.
33 *
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.
36 *
37 * Note 2: this is deliberately only package visible.
38 *
39 * @author Matthew Khouzam
40 */
41 class ActiveTidStateProvider extends AbstractTmfStateProvider {
42
43 private static final @NonNull String PROVIDER_ID = "activeTidAnalysis.provider"; //$NON-NLS-1$
44 private static final int VERSION = 0;
45
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;
50
51 public ActiveTidStateProvider(@NonNull ITmfTrace trace, @NonNull IKernelAnalysisEventLayout layout) {
52 super(trace, PROVIDER_ID);
53 fSchedSwitch = layout.eventSchedSwitch();
54 fNextTid = layout.fieldNextTid();
55 fLayout = layout;
56 }
57
58 @Override
59 public int getVersion() {
60 return VERSION;
61 }
62
63 @Override
64 public @NonNull ITmfStateProvider getNewInstance() {
65 return new ActiveTidStateProvider(getTrace(), fLayout);
66 }
67
68 @Override
69 protected void eventHandle(@NonNull ITmfEvent event) {
70 Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), TmfCpuAspect.class, event);
71 if (cpu == null) {
72 return;
73 }
74 ITmfStateSystemBuilder ssb = getStateSystemBuilder();
75 if (ssb == null) {
76 return;
77 }
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);
84 }
85 if (!event.getName().equals(fSchedSwitch)) {
86 return;
87 }
88 try {
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);
94 }
95 }
96 }
This page took 0.033406 seconds and 5 git commands to generate.