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
.lttng
.scope
.lttng
.kernel
.core
.event
.aspect
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfCpuAspect
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
22 import org
.lttng
.scope
.common
.core
.NonNullUtils
;
23 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.Attributes
;
24 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.KernelAnalysisModule
;
26 import ca
.polymtl
.dorsal
.libdelorean
.ITmfStateSystem
;
27 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.AttributeNotFoundException
;
28 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.StateSystemDisposedException
;
29 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.TimeRangeException
;
30 import ca
.polymtl
.dorsal
.libdelorean
.interval
.ITmfStateInterval
;
31 import ca
.polymtl
.dorsal
.libdelorean
.statevalue
.ITmfStateValue
;
34 * This aspect finds the priority of the thread running from this event using
35 * the {@link KernelAnalysisModule}.
37 * @author Christian Mansky
39 public final class ThreadPriorityAspect
implements ITmfEventAspect
<Integer
> {
41 /** The singleton instance */
42 public static final ThreadPriorityAspect INSTANCE
= new ThreadPriorityAspect();
44 private ThreadPriorityAspect() {
48 public final String
getName() {
49 return NonNullUtils
.nullToEmptyString(Messages
.ThreadPriorityAspect_Name
);
53 public final String
getHelpText() {
54 return NonNullUtils
.nullToEmptyString(Messages
.ThreadPriorityAspect_HelpText
);
58 public @Nullable Integer
resolve(ITmfEvent event
) {
59 final @NonNull ITmfTrace trace
= event
.getTrace();
60 KernelAnalysisModule kernelAnalysis
= TmfTraceUtils
.getAnalysisModuleOfClass(trace
, KernelAnalysisModule
.class, KernelAnalysisModule
.ID
);
61 if (kernelAnalysis
== null) {
65 ITmfStateSystem ss
= kernelAnalysis
.getStateSystem();
70 Integer tid
= KernelTidAspect
.INSTANCE
.resolve(event
);
75 final long ts
= event
.getTimestamp().getValue();
76 Integer execPrio
= null;
80 /* Find the CPU this event is run on */
81 cpu
= TmfTraceUtils
.resolveIntEventAspectOfClassForEvent(trace
, TmfCpuAspect
.class, event
);
83 int execPrioQuark
= ss
.getQuarkAbsolute(Attributes
.THREADS
, Attributes
.buildThreadAttributeName(tid
, cpu
), Attributes
.PRIO
);
84 ITmfStateInterval interval
= ss
.querySingleState(ts
, execPrioQuark
);
85 ITmfStateValue prioValue
= interval
.getStateValue();
86 /* We know the prio must be an Integer */
87 execPrio
= prioValue
.unboxInt();
88 } catch (AttributeNotFoundException
| StateSystemDisposedException
| TimeRangeException e
) {