Commit | Line | Data |
---|---|---|
2531b10a CM |
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 | ||
6070a6bc | 13 | package org.eclipse.tracecompass.analysis.os.linux.core.event.aspect; |
2531b10a | 14 | |
8097abda | 15 | import org.eclipse.jdt.annotation.NonNull; |
2531b10a | 16 | import org.eclipse.jdt.annotation.Nullable; |
6070a6bc AM |
17 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule; |
18 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelTidAspect; | |
2531b10a | 19 | import org.eclipse.tracecompass.common.core.NonNullUtils; |
f69045e2 | 20 | import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes; |
6070a6bc AM |
21 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
22 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; | |
23 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; | |
24 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
25 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; | |
26 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; | |
2531b10a CM |
27 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
28 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; | |
8097abda MK |
29 | import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect; |
30 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
2531b10a CM |
31 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; |
32 | ||
33 | /** | |
34 | * This aspect finds the priority of the thread running from this event using | |
6d16f5a9 | 35 | * the {@link KernelAnalysisModule}. |
2531b10a CM |
36 | * |
37 | * @author Christian Mansky | |
0f7a12d3 | 38 | * @since 2.0 |
2531b10a | 39 | */ |
ec48d248 | 40 | public final class ThreadPriorityAspect implements ITmfEventAspect<Integer> { |
2531b10a CM |
41 | |
42 | /** The singleton instance */ | |
43 | public static final ThreadPriorityAspect INSTANCE = new ThreadPriorityAspect(); | |
44 | ||
45 | private ThreadPriorityAspect() { | |
46 | } | |
47 | ||
48 | @Override | |
49 | public final String getName() { | |
50 | return NonNullUtils.nullToEmptyString(Messages.AspectName_Prio); | |
51 | } | |
52 | ||
53 | @Override | |
54 | public final String getHelpText() { | |
55 | return NonNullUtils.nullToEmptyString(Messages.AspectHelpText_Prio); | |
56 | } | |
57 | ||
58 | @Override | |
59 | public @Nullable Integer resolve(ITmfEvent event) { | |
8097abda MK |
60 | final @NonNull ITmfTrace trace = event.getTrace(); |
61 | KernelAnalysisModule kernelAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID); | |
2531b10a CM |
62 | if (kernelAnalysis == null) { |
63 | return null; | |
64 | } | |
65 | ||
6070a6bc AM |
66 | ITmfStateSystem ss = kernelAnalysis.getStateSystem(); |
67 | if (ss == null) { | |
68 | return null; | |
69 | } | |
70 | ||
2531b10a CM |
71 | Integer tid = KernelTidAspect.INSTANCE.resolve(event); |
72 | if (tid == null) { | |
73 | return null; | |
74 | } | |
75 | ||
6070a6bc AM |
76 | final long ts = event.getTimestamp().getValue(); |
77 | Integer execPrio = null; | |
78 | try { | |
8097abda MK |
79 | Integer cpu = 0; |
80 | if (tid == 0) { | |
81 | /* Find the CPU this event is run on */ | |
82 | cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TmfCpuAspect.class, event); | |
83 | } | |
642b4947 | 84 | int execPrioQuark = ss.getQuarkAbsolute(Attributes.THREADS, Attributes.buildThreadAttributeName(tid, cpu), Attributes.PRIO); |
6070a6bc AM |
85 | ITmfStateInterval interval = ss.querySingleState(ts, execPrioQuark); |
86 | ITmfStateValue prioValue = interval.getStateValue(); | |
87 | /* We know the prio must be an Integer */ | |
88 | execPrio = prioValue.unboxInt(); | |
89 | } catch (AttributeNotFoundException | StateSystemDisposedException | TimeRangeException e) { | |
90 | } | |
91 | return execPrio; | |
2531b10a | 92 | } |
2531b10a | 93 | } |