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
.kernelanalysis
.Attributes
;
16 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.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
;
28 public class ProcessForkHandler
extends KernelEventHandler
{
36 public ProcessForkHandler(IKernelAnalysisEventLayout layout
) {
41 public void handleEvent(ITmfStateSystemBuilder ss
, ITmfEvent event
) throws AttributeNotFoundException
{
42 ITmfEventField content
= event
.getContent();
43 String childProcessName
= (String
) content
.getField(getLayout().fieldChildComm()).getValue();
45 Integer parentTid
= ((Long
) content
.getField(getLayout().fieldParentTid()).getValue()).intValue();
46 Integer childTid
= ((Long
) content
.getField(getLayout().fieldChildTid()).getValue()).intValue();
48 Integer parentTidNode
= ss
.getQuarkRelativeAndAdd(KernelEventHandlerUtils
.getNodeThreads(ss
), parentTid
.toString());
49 Integer childTidNode
= ss
.getQuarkRelativeAndAdd(KernelEventHandlerUtils
.getNodeThreads(ss
), childTid
.toString());
51 /* Assign the PPID to the new process */
52 int quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.PPID
);
53 ITmfStateValue value
= TmfStateValue
.newValueInt(parentTid
);
54 long timestamp
= KernelEventHandlerUtils
.getTimestamp(event
);
55 ss
.modifyAttribute(timestamp
, value
, quark
);
57 /* Set the new process' exec_name */
58 quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.EXEC_NAME
);
59 value
= TmfStateValue
.newValueString(childProcessName
);
60 ss
.modifyAttribute(timestamp
, value
, quark
);
62 /* Set the new process' status */
63 quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.STATUS
);
64 value
= StateValues
.PROCESS_STATUS_WAIT_FOR_CPU_VALUE
;
65 ss
.modifyAttribute(timestamp
, value
, quark
);
67 /* Set the process' syscall name, to be the same as the parent's */
68 quark
= ss
.getQuarkRelativeAndAdd(parentTidNode
, Attributes
.SYSTEM_CALL
);
69 value
= ss
.queryOngoingState(quark
);
70 if (!value
.isNull()) {
71 quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.SYSTEM_CALL
);
72 ss
.modifyAttribute(timestamp
, value
, quark
);