/******************************************************************************* * Copyright (c) 2015 Ericsson * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Matthew Khouzam - Initial API and implementation *******************************************************************************/ package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers; import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues; import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout; import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes; import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; /** * Fork Handler */ public class ProcessForkHandler extends KernelEventHandler { /** * Constructor * * @param layout * event layout */ public ProcessForkHandler(IKernelAnalysisEventLayout layout) { super(layout); } @Override public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) throws AttributeNotFoundException { ITmfEventField content = event.getContent(); Integer cpu = KernelEventHandlerUtils.getCpu(event); String childProcessName = (String) content.getField(getLayout().fieldChildComm()).getValue(); Integer parentTid = ((Long) content.getField(getLayout().fieldParentTid()).getValue()).intValue(); Integer childTid = ((Long) content.getField(getLayout().fieldChildTid()).getValue()).intValue(); String parentThreadAttributeName = Attributes.buildThreadAttributeName(parentTid, cpu); if (parentThreadAttributeName == null) { return; } String childThreadAttributeName = Attributes.buildThreadAttributeName(childTid, cpu); if (childThreadAttributeName == null) { return; } final int threadsNode = KernelEventHandlerUtils.getNodeThreads(ss); Integer parentTidNode = ss.getQuarkRelativeAndAdd(threadsNode, parentThreadAttributeName); Integer childTidNode = ss.getQuarkRelativeAndAdd(threadsNode, childThreadAttributeName); /* Assign the PPID to the new process */ int quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.PPID); ITmfStateValue value = TmfStateValue.newValueInt(parentTid); long timestamp = KernelEventHandlerUtils.getTimestamp(event); ss.modifyAttribute(timestamp, value, quark); /* Set the new process' exec_name */ quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.EXEC_NAME); value = TmfStateValue.newValueString(childProcessName); ss.modifyAttribute(timestamp, value, quark); /* Set the new process' status */ value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; ss.modifyAttribute(timestamp, value, childTidNode); /* Set the process' syscall name, to be the same as the parent's */ quark = ss.getQuarkRelativeAndAdd(parentTidNode, Attributes.SYSTEM_CALL); value = ss.queryOngoingState(quark); if (!value.isNull()) { quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.SYSTEM_CALL); ss.modifyAttribute(timestamp, value, quark); } } }