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
;
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 Integer cpu
= KernelEventHandlerUtils
.getCpu(event
);
44 String childProcessName
= (String
) content
.getField(getLayout().fieldChildComm()).getValue();
46 Integer parentTid
= ((Long
) content
.getField(getLayout().fieldParentTid()).getValue()).intValue();
47 Integer childTid
= ((Long
) content
.getField(getLayout().fieldChildTid()).getValue()).intValue();
49 String parentThreadAttributeName
= Attributes
.buildThreadAttributeName(parentTid
, cpu
);
50 if (parentThreadAttributeName
== null) {
54 String childThreadAttributeName
= Attributes
.buildThreadAttributeName(childTid
, cpu
);
55 if (childThreadAttributeName
== null) {
59 final int threadsNode
= KernelEventHandlerUtils
.getNodeThreads(ss
);
60 Integer parentTidNode
= ss
.getQuarkRelativeAndAdd(threadsNode
, parentThreadAttributeName
);
61 Integer childTidNode
= ss
.getQuarkRelativeAndAdd(threadsNode
, childThreadAttributeName
);
64 /* Assign the PPID to the new process */
65 int quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.PPID
);
66 ITmfStateValue value
= TmfStateValue
.newValueInt(parentTid
);
67 long timestamp
= KernelEventHandlerUtils
.getTimestamp(event
);
68 ss
.modifyAttribute(timestamp
, value
, quark
);
70 /* Set the new process' exec_name */
71 quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.EXEC_NAME
);
72 value
= TmfStateValue
.newValueString(childProcessName
);
73 ss
.modifyAttribute(timestamp
, value
, quark
);
75 /* Set the new process' status */
76 value
= StateValues
.PROCESS_STATUS_WAIT_FOR_CPU_VALUE
;
77 ss
.modifyAttribute(timestamp
, value
, childTidNode
);
79 /* Set the process's run queue, to be the same as the parent's */
80 quark
= ss
.getQuarkRelativeAndAdd(parentTidNode
, Attributes
.CURRENT_CPU_RQ
);
81 value
= ss
.queryOngoingState(quark
);
82 quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.CURRENT_CPU_RQ
);
83 ss
.modifyAttribute(timestamp
, value
, quark
);
85 /* Set the process' syscall name, to be the same as the parent's */
86 quark
= ss
.getQuarkRelativeAndAdd(parentTidNode
, Attributes
.SYSTEM_CALL
);
87 value
= ss
.queryOngoingState(quark
);
88 if (!value
.isNull()) {
89 quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.SYSTEM_CALL
);
90 ss
.modifyAttribute(timestamp
, value
, quark
);