c34b52fd2a9ee8b82d24451dd20aea89a5b2843b
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / kernel / handlers / ProcessForkHandler.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.Attributes;
16 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues;
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 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
24
25 /**
26 * Fork Handler
27 */
28 public class ProcessForkHandler extends KernelEventHandler {
29
30 /**
31 * Constructor
32 *
33 * @param layout
34 * event layout
35 */
36 public ProcessForkHandler(IKernelAnalysisEventLayout layout) {
37 super(layout);
38 }
39
40 @Override
41 public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) throws AttributeNotFoundException {
42 ITmfEventField content = event.getContent();
43 String childProcessName = (String) content.getField(getLayout().fieldChildComm()).getValue();
44
45 Integer parentTid = ((Long) content.getField(getLayout().fieldParentTid()).getValue()).intValue();
46 Integer childTid = ((Long) content.getField(getLayout().fieldChildTid()).getValue()).intValue();
47
48 final int threadsNode = KernelEventHandlerUtils.getNodeThreads(ss);
49 Integer parentTidNode = ss.getQuarkRelativeAndAdd(threadsNode, parentTid.toString());
50 Integer childTidNode = ss.getQuarkRelativeAndAdd(threadsNode, childTid.toString());
51
52 /* Assign the PPID to the new process */
53 int quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.PPID);
54 ITmfStateValue value = TmfStateValue.newValueInt(parentTid);
55 long timestamp = KernelEventHandlerUtils.getTimestamp(event);
56 ss.modifyAttribute(timestamp, value, quark);
57
58 /* Set the new process' exec_name */
59 quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.EXEC_NAME);
60 value = TmfStateValue.newValueString(childProcessName);
61 ss.modifyAttribute(timestamp, value, quark);
62
63 /* Set the new process' status */
64 quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.STATUS);
65 value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE;
66 ss.modifyAttribute(timestamp, value, quark);
67
68 /* Set the process' syscall name, to be the same as the parent's */
69 quark = ss.getQuarkRelativeAndAdd(parentTidNode, Attributes.SYSTEM_CALL);
70 value = ss.queryOngoingState(quark);
71 if (!value.isNull()) {
72 quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.SYSTEM_CALL);
73 ss.modifyAttribute(timestamp, value, quark);
74 }
75
76 }
77 }
This page took 0.038384 seconds and 4 git commands to generate.