56a25a58a2ddd0d5cc0fde5a9cd6fe185e533a61
[deliverable/tracecompass.git] / lttng / org.lttng.scope.lttng.kernel.core / src / org / lttng / scope / lttng / kernel / 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.lttng.scope.lttng.kernel.core.event.aspect;
14
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;
25
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;
32
33 /**
34 * This aspect finds the priority of the thread running from this event using
35 * the {@link KernelAnalysisModule}.
36 *
37 * @author Christian Mansky
38 */
39 public final class ThreadPriorityAspect implements ITmfEventAspect<Integer> {
40
41 /** The singleton instance */
42 public static final ThreadPriorityAspect INSTANCE = new ThreadPriorityAspect();
43
44 private ThreadPriorityAspect() {
45 }
46
47 @Override
48 public final String getName() {
49 return NonNullUtils.nullToEmptyString(Messages.ThreadPriorityAspect_Name);
50 }
51
52 @Override
53 public final String getHelpText() {
54 return NonNullUtils.nullToEmptyString(Messages.ThreadPriorityAspect_HelpText);
55 }
56
57 @Override
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) {
62 return null;
63 }
64
65 ITmfStateSystem ss = kernelAnalysis.getStateSystem();
66 if (ss == null) {
67 return null;
68 }
69
70 Integer tid = KernelTidAspect.INSTANCE.resolve(event);
71 if (tid == null) {
72 return null;
73 }
74
75 final long ts = event.getTimestamp().getValue();
76 Integer execPrio = null;
77 try {
78 Integer cpu = 0;
79 if (tid == 0) {
80 /* Find the CPU this event is run on */
81 cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TmfCpuAspect.class, event);
82 }
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) {
89 }
90 return execPrio;
91 }
92 }
This page took 0.031901 seconds and 4 git commands to generate.