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
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
;
15 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
16 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
17 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.Attributes
;
18 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.StateValues
;
19 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.layout
.ILttngKernelEventLayout
;
21 import ca
.polymtl
.dorsal
.libdelorean
.ITmfStateSystemBuilder
;
22 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.AttributeNotFoundException
;
23 import ca
.polymtl
.dorsal
.libdelorean
.statevalue
.ITmfStateValue
;
24 import ca
.polymtl
.dorsal
.libdelorean
.statevalue
.TmfStateValue
;
29 public class ProcessForkHandler
extends KernelEventHandler
{
37 public ProcessForkHandler(ILttngKernelEventLayout layout
) {
42 public void handleEvent(ITmfStateSystemBuilder ss
, ITmfEvent event
) throws AttributeNotFoundException
{
43 ITmfEventField content
= event
.getContent();
44 Integer cpu
= KernelEventHandlerUtils
.getCpu(event
);
45 String childProcessName
= (String
) content
.getField(getLayout().fieldChildComm()).getValue();
47 Integer parentTid
= ((Long
) content
.getField(getLayout().fieldParentTid()).getValue()).intValue();
48 Integer childTid
= ((Long
) content
.getField(getLayout().fieldChildTid()).getValue()).intValue();
50 String parentThreadAttributeName
= Attributes
.buildThreadAttributeName(parentTid
, cpu
);
51 if (parentThreadAttributeName
== null) {
55 String childThreadAttributeName
= Attributes
.buildThreadAttributeName(childTid
, cpu
);
56 if (childThreadAttributeName
== null) {
60 final int threadsNode
= KernelEventHandlerUtils
.getNodeThreads(ss
);
61 Integer parentTidNode
= ss
.getQuarkRelativeAndAdd(threadsNode
, parentThreadAttributeName
);
62 Integer childTidNode
= ss
.getQuarkRelativeAndAdd(threadsNode
, childThreadAttributeName
);
65 /* Assign the PPID to the new process */
66 int quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.PPID
);
67 ITmfStateValue value
= TmfStateValue
.newValueInt(parentTid
);
68 long timestamp
= KernelEventHandlerUtils
.getTimestamp(event
);
69 ss
.modifyAttribute(timestamp
, value
, quark
);
71 /* Set the new process' exec_name */
72 quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.EXEC_NAME
);
73 value
= TmfStateValue
.newValueString(childProcessName
);
74 ss
.modifyAttribute(timestamp
, value
, quark
);
77 * Set the new process' status, it is initially in a blocked state. A
78 * subsequent sched_wakeup_new will schedule it.
80 value
= StateValues
.PROCESS_STATUS_WAIT_BLOCKED_VALUE
;
81 ss
.modifyAttribute(timestamp
, value
, childTidNode
);
83 /* Set the process' syscall name, to be the same as the parent's */
84 quark
= ss
.getQuarkRelativeAndAdd(parentTidNode
, Attributes
.SYSTEM_CALL
);
85 value
= ss
.queryOngoingState(quark
);
86 if (!value
.isNull()) {
87 quark
= ss
.getQuarkRelativeAndAdd(childTidNode
, Attributes
.SYSTEM_CALL
);
88 ss
.modifyAttribute(timestamp
, value
, quark
);