1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
;
15 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.StateValues
;
16 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelAnalysisEventLayout
;
17 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.Attributes
;
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
;
27 public class SchedWakeupHandler
extends KernelEventHandler
{
31 * @param layout event layout
33 public SchedWakeupHandler(IKernelAnalysisEventLayout layout
) {
38 public void handleEvent(ITmfStateSystemBuilder ss
, ITmfEvent event
) throws AttributeNotFoundException
{
39 Integer cpu
= KernelEventHandlerUtils
.getCpu(event
);
40 final int tid
= ((Long
) event
.getContent().getField(getLayout().fieldTid()).getValue()).intValue();
41 final int prio
= ((Long
) event
.getContent().getField(getLayout().fieldPrio()).getValue()).intValue();
43 String threadAttributeName
= Attributes
.buildThreadAttributeName(tid
, cpu
);
44 if (threadAttributeName
== null) {
48 final int threadNode
= ss
.getQuarkRelativeAndAdd(KernelEventHandlerUtils
.getNodeThreads(ss
), threadAttributeName
);
51 * The process indicated in the event's payload is now ready to run.
52 * Assign it to the "wait for cpu" state, but only if it was not already
55 int status
= ss
.queryOngoingState(threadNode
).unboxInt();
56 ITmfStateValue value
= null;
57 long timestamp
= KernelEventHandlerUtils
.getTimestamp(event
);
58 if (status
!= StateValues
.PROCESS_STATUS_RUN_SYSCALL
&&
59 status
!= StateValues
.PROCESS_STATUS_RUN_USERMODE
) {
60 value
= StateValues
.PROCESS_STATUS_WAIT_FOR_CPU_VALUE
;
61 ss
.modifyAttribute(timestamp
, value
, threadNode
);
65 * When a user changes a threads prio (e.g. with pthread_setschedparam),
66 * it shows in ftrace with a sched_wakeup.
68 int quark
= ss
.getQuarkRelativeAndAdd(threadNode
, Attributes
.PRIO
);
69 value
= TmfStateValue
.newValueInt(prio
);
70 ss
.modifyAttribute(timestamp
, value
, quark
);