Commit | Line | Data |
---|---|---|
c8f45ad2 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers; | |
14 | ||
0f7a12d3 AM |
15 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.Attributes; |
16 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues; | |
c8f45ad2 MK |
17 | import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout; |
18 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; | |
19 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; | |
20 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; | |
21 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; | |
22 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
23 | ||
24 | /** | |
25 | * Wakeup handler | |
26 | */ | |
27 | public class SchedWakeupHandler extends KernelEventHandler { | |
28 | ||
29 | /** | |
30 | * Constructor | |
31 | * @param layout event layout | |
32 | */ | |
33 | public SchedWakeupHandler(IKernelAnalysisEventLayout layout) { | |
34 | super(layout); | |
35 | } | |
36 | ||
37 | @Override | |
38 | public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) throws AttributeNotFoundException { | |
39 | final int tid = ((Long) event.getContent().getField(getLayout().fieldTid()).getValue()).intValue(); | |
40 | final int prio = ((Long) event.getContent().getField(getLayout().fieldPrio()).getValue()).intValue(); | |
41 | final int threadNode = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeThreads(ss), String.valueOf(tid)); | |
42 | ||
43 | /* | |
44 | * The process indicated in the event's payload is now ready to run. | |
45 | * Assign it to the "wait for cpu" state, but only if it was not already | |
46 | * running. | |
47 | */ | |
48 | int quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.STATUS); | |
49 | int status = ss.queryOngoingState(quark).unboxInt(); | |
50 | ITmfStateValue value = null; | |
51 | long timestamp = KernelEventHandlerUtils.getTimestamp(event); | |
52 | if (status != StateValues.PROCESS_STATUS_RUN_SYSCALL && | |
53 | status != StateValues.PROCESS_STATUS_RUN_USERMODE) { | |
54 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; | |
55 | ss.modifyAttribute(timestamp, value, quark); | |
56 | } | |
57 | ||
58 | /* | |
59 | * When a user changes a threads prio (e.g. with pthread_setschedparam), | |
60 | * it shows in ftrace with a sched_wakeup. | |
61 | */ | |
62 | quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.PRIO); | |
63 | value = TmfStateValue.newValueInt(prio); | |
64 | ss.modifyAttribute(timestamp, value, quark); | |
65 | } | |
66 | } |