1 /*******************************************************************************
2 * Copyright (c) 2015 Keba AG
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 * Christian Mansky - Initial implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.event
.aspect
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.KernelAnalysisModule
;
18 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.KernelTidAspect
;
19 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
20 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.Attributes
;
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
;
35 * This aspect finds the priority of the thread running from this event using
36 * the {@link KernelAnalysisModule}.
38 * @author Christian Mansky
41 public final class ThreadPriorityAspect
implements ITmfEventAspect
{
43 /** The singleton instance */
44 public static final ThreadPriorityAspect INSTANCE
= new ThreadPriorityAspect();
46 private ThreadPriorityAspect() {
50 public final String
getName() {
51 return NonNullUtils
.nullToEmptyString(Messages
.AspectName_Prio
);
55 public final String
getHelpText() {
56 return NonNullUtils
.nullToEmptyString(Messages
.AspectHelpText_Prio
);
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) {
67 ITmfStateSystem ss
= kernelAnalysis
.getStateSystem();
72 Integer tid
= KernelTidAspect
.INSTANCE
.resolve(event
);
77 final long ts
= event
.getTimestamp().getValue();
78 Integer execPrio
= null;
82 /* Find the CPU this event is run on */
83 cpu
= TmfTraceUtils
.resolveIntEventAspectOfClassForEvent(trace
, TmfCpuAspect
.class, event
);
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
) {