os.linux: Move Attributes class to internal package
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / kernel / handlers / ProcessForkHandler.java
CommitLineData
c8f45ad2
MK
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
13package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers;
14
0f7a12d3 15import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues;
c8f45ad2 16import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
f69045e2 17import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
c8f45ad2
MK
18import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
19import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
20import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
21import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
22import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
23import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
24
25/**
26 * Fork Handler
27 */
28public 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();
8a0bbebf 43 Integer cpu = KernelEventHandlerUtils.getCpu(event);
c8f45ad2
MK
44 String childProcessName = (String) content.getField(getLayout().fieldChildComm()).getValue();
45
46 Integer parentTid = ((Long) content.getField(getLayout().fieldParentTid()).getValue()).intValue();
47 Integer childTid = ((Long) content.getField(getLayout().fieldChildTid()).getValue()).intValue();
48
8a0bbebf
MJ
49 String parentThreadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(parentTid, cpu);
50 if (parentThreadAttributeName == null) {
51 return;
52 }
53
54 String childThreadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(childTid, cpu);
55 if (childThreadAttributeName == null) {
56 return;
57 }
58
6fdc59f8 59 final int threadsNode = KernelEventHandlerUtils.getNodeThreads(ss);
8a0bbebf
MJ
60 Integer parentTidNode = ss.getQuarkRelativeAndAdd(threadsNode, parentThreadAttributeName);
61 Integer childTidNode = ss.getQuarkRelativeAndAdd(threadsNode, childThreadAttributeName);
62
c8f45ad2
MK
63
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);
69
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);
74
75 /* Set the new process' status */
76 quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.STATUS);
77 value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE;
78 ss.modifyAttribute(timestamp, value, quark);
79
80 /* Set the process' syscall name, to be the same as the parent's */
81 quark = ss.getQuarkRelativeAndAdd(parentTidNode, Attributes.SYSTEM_CALL);
82 value = ss.queryOngoingState(quark);
2e3a31c4
FG
83 if (!value.isNull()) {
84 quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.SYSTEM_CALL);
85 ss.modifyAttribute(timestamp, value, quark);
c8f45ad2 86 }
2e3a31c4 87
c8f45ad2
MK
88 }
89}
This page took 0.032593 seconds and 5 git commands to generate.