e8284d101d7c885627004500d4788d94cfeed609
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / analysis / os / linux / core / event / aspect / ThreadPriorityAspect.java
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
13 package org.eclipse.tracecompass.analysis.os.linux.core.event.aspect;
14
15 import org.eclipse.jdt.annotation.NonNull;
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.kernel.KernelAnalysisModule;
19 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelTidAspect;
20 import org.eclipse.tracecompass.common.core.NonNullUtils;
21 import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers.KernelEventHandlerUtils;
22 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
23 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
24 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
25 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
26 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
27 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
28 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
29 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
30 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
31 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
32 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
33
34 /**
35 * This aspect finds the priority of the thread running from this event using
36 * the {@link KernelAnalysisModule}.
37 *
38 * @author Christian Mansky
39 * @since 2.0
40 */
41 public 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) {
61 final @NonNull ITmfTrace trace = event.getTrace();
62 KernelAnalysisModule kernelAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID);
63 if (kernelAnalysis == null) {
64 return null;
65 }
66
67 ITmfStateSystem ss = kernelAnalysis.getStateSystem();
68 if (ss == null) {
69 return null;
70 }
71
72 Integer tid = KernelTidAspect.INSTANCE.resolve(event);
73 if (tid == null) {
74 return null;
75 }
76
77 final long ts = event.getTimestamp().getValue();
78 Integer execPrio = null;
79 try {
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);
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;
93 }
94 }
This page took 0.033586 seconds and 4 git commands to generate.