Import lttng.kernel.core plugins from Scope
[deliverable/tracecompass.git] / lttng / org.lttng.scope.lttng.kernel.core / src / org / lttng / scope / lttng / kernel / core / analysis / os / handlers / internal / 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.lttng.scope.lttng.kernel.core.analysis.os.handlers.internal;
14
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;
20
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;
25
26 /**
27 * Fork Handler
28 */
29 public class ProcessForkHandler extends KernelEventHandler {
30
31 /**
32 * Constructor
33 *
34 * @param layout
35 * event layout
36 */
37 public ProcessForkHandler(ILttngKernelEventLayout layout) {
38 super(layout);
39 }
40
41 @Override
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();
46
47 Integer parentTid = ((Long) content.getField(getLayout().fieldParentTid()).getValue()).intValue();
48 Integer childTid = ((Long) content.getField(getLayout().fieldChildTid()).getValue()).intValue();
49
50 String parentThreadAttributeName = Attributes.buildThreadAttributeName(parentTid, cpu);
51 if (parentThreadAttributeName == null) {
52 return;
53 }
54
55 String childThreadAttributeName = Attributes.buildThreadAttributeName(childTid, cpu);
56 if (childThreadAttributeName == null) {
57 return;
58 }
59
60 final int threadsNode = KernelEventHandlerUtils.getNodeThreads(ss);
61 Integer parentTidNode = ss.getQuarkRelativeAndAdd(threadsNode, parentThreadAttributeName);
62 Integer childTidNode = ss.getQuarkRelativeAndAdd(threadsNode, childThreadAttributeName);
63
64
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);
70
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);
75
76 /*
77 * Set the new process' status, it is initially in a blocked state. A
78 * subsequent sched_wakeup_new will schedule it.
79 */
80 value = StateValues.PROCESS_STATUS_WAIT_BLOCKED_VALUE;
81 ss.modifyAttribute(timestamp, value, childTidNode);
82
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);
89 }
90
91 }
92 }
This page took 0.033908 seconds and 5 git commands to generate.