8f8b78c66d947552b87194911666ac847480c33f
[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.Nullable;
16 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.Attributes;
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.statesystem.core.ITmfStateSystem;
21 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
22 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
23 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
24 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
25 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
26 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
27 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
28 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
29
30 /**
31 * This aspect finds the priority of the thread running from this event using
32 * the {@link KernelAnalysisModule}.
33 *
34 * @author Christian Mansky
35 * @since 2.0
36 */
37 public final class ThreadPriorityAspect implements ITmfEventAspect {
38
39 /** The singleton instance */
40 public static final ThreadPriorityAspect INSTANCE = new ThreadPriorityAspect();
41
42 private ThreadPriorityAspect() {
43 }
44
45 @Override
46 public final String getName() {
47 return NonNullUtils.nullToEmptyString(Messages.AspectName_Prio);
48 }
49
50 @Override
51 public final String getHelpText() {
52 return NonNullUtils.nullToEmptyString(Messages.AspectHelpText_Prio);
53 }
54
55 @Override
56 public @Nullable Integer resolve(ITmfEvent event) {
57 KernelAnalysisModule kernelAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(event.getTrace(), KernelAnalysisModule.class, KernelAnalysisModule.ID);
58 if (kernelAnalysis == null) {
59 return null;
60 }
61
62 ITmfStateSystem ss = kernelAnalysis.getStateSystem();
63 if (ss == null) {
64 return null;
65 }
66
67 Integer tid = KernelTidAspect.INSTANCE.resolve(event);
68 if (tid == null) {
69 return null;
70 }
71
72 final long ts = event.getTimestamp().getValue();
73 Integer execPrio = null;
74 try {
75 int execPrioQuark = ss.getQuarkAbsolute(Attributes.THREADS, tid.toString(), Attributes.PRIO);
76 ITmfStateInterval interval = ss.querySingleState(ts, execPrioQuark);
77 ITmfStateValue prioValue = interval.getStateValue();
78 /* We know the prio must be an Integer */
79 execPrio = prioValue.unboxInt();
80 } catch (AttributeNotFoundException | StateSystemDisposedException | TimeRangeException e) {
81 }
82 return execPrio;
83 }
84 }
This page took 0.033761 seconds and 4 git commands to generate.