40bed11921b893fc5e951b78bb660c7facacdaea
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / kernel / handlers / SchedWakeupHandler.java
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
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;
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 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();
42
43 String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu);
44 if (threadAttributeName == null) {
45 return;
46 }
47
48 final int threadNode = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeThreads(ss), threadAttributeName);
49
50 /*
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
53 * running.
54 */
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);
62 }
63
64 /*
65 * When a user changes a threads prio (e.g. with pthread_setschedparam),
66 * it shows in ftrace with a sched_wakeup.
67 */
68 int quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.PRIO);
69 value = TmfStateValue.newValueInt(prio);
70 ss.modifyAttribute(timestamp, value, quark);
71 }
72 }
This page took 0.031437 seconds and 4 git commands to generate.