os.linux: Move Attributes class to internal package
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / analysis / os / linux / core / event / aspect / ThreadPriorityAspect.java
CommitLineData
2531b10a
CM
1/*******************************************************************************
2 * Copyright (c) 2015 Keba AG
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 * Christian Mansky - Initial implementation
11 *******************************************************************************/
12
6070a6bc 13package org.eclipse.tracecompass.analysis.os.linux.core.event.aspect;
2531b10a 14
8097abda 15import org.eclipse.jdt.annotation.NonNull;
2531b10a 16import org.eclipse.jdt.annotation.Nullable;
6070a6bc
AM
17import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
18import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelTidAspect;
2531b10a 19import org.eclipse.tracecompass.common.core.NonNullUtils;
f69045e2 20import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
8097abda 21import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers.KernelEventHandlerUtils;
6070a6bc
AM
22import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
23import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
24import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
25import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
26import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
27import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
2531b10a
CM
28import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
29import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
8097abda
MK
30import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
31import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
2531b10a
CM
32import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
33
34/**
35 * This aspect finds the priority of the thread running from this event using
6d16f5a9 36 * the {@link KernelAnalysisModule}.
2531b10a
CM
37 *
38 * @author Christian Mansky
0f7a12d3 39 * @since 2.0
2531b10a
CM
40 */
41public final class ThreadPriorityAspect implements ITmfEventAspect {
42
43 /** The singleton instance */
44 public static final ThreadPriorityAspect INSTANCE = new ThreadPriorityAspect();
45
46 private ThreadPriorityAspect() {
47 }
48
49 @Override
50 public final String getName() {
51 return NonNullUtils.nullToEmptyString(Messages.AspectName_Prio);
52 }
53
54 @Override
55 public final String getHelpText() {
56 return NonNullUtils.nullToEmptyString(Messages.AspectHelpText_Prio);
57 }
58
59 @Override
60 public @Nullable Integer resolve(ITmfEvent event) {
8097abda
MK
61 final @NonNull ITmfTrace trace = event.getTrace();
62 KernelAnalysisModule kernelAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID);
2531b10a
CM
63 if (kernelAnalysis == null) {
64 return null;
65 }
66
6070a6bc
AM
67 ITmfStateSystem ss = kernelAnalysis.getStateSystem();
68 if (ss == null) {
69 return null;
70 }
71
2531b10a
CM
72 Integer tid = KernelTidAspect.INSTANCE.resolve(event);
73 if (tid == null) {
74 return null;
75 }
76
6070a6bc
AM
77 final long ts = event.getTimestamp().getValue();
78 Integer execPrio = null;
79 try {
8097abda
MK
80 Integer cpu = 0;
81 if (tid == 0) {
82 /* Find the CPU this event is run on */
83 cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TmfCpuAspect.class, event);
84 }
85 int execPrioQuark = ss.getQuarkAbsolute(Attributes.THREADS, KernelEventHandlerUtils.buildThreadAttributeName(tid, cpu), Attributes.PRIO);
6070a6bc
AM
86 ITmfStateInterval interval = ss.querySingleState(ts, execPrioQuark);
87 ITmfStateValue prioValue = interval.getStateValue();
88 /* We know the prio must be an Integer */
89 execPrio = prioValue.unboxInt();
90 } catch (AttributeNotFoundException | StateSystemDisposedException | TimeRangeException e) {
91 }
92 return execPrio;
2531b10a 93 }
2531b10a 94}
This page took 0.051631 seconds and 5 git commands to generate.