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 static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.Attributes
;
18 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.LinuxValues
;
19 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.StateValues
;
20 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelAnalysisEventLayout
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
29 * LTTng Specific state dump event handler
31 public class StateDumpHandler
extends KernelEventHandler
{
39 public StateDumpHandler(IKernelAnalysisEventLayout layout
) {
44 public void handleEvent(ITmfStateSystemBuilder ss
, ITmfEvent event
) throws AttributeNotFoundException
{
45 ITmfEventField content
= event
.getContent();
46 int tid
= ((Long
) content
.getField("tid").getValue()).intValue(); //$NON-NLS-1$
47 int pid
= ((Long
) content
.getField("pid").getValue()).intValue(); //$NON-NLS-1$
48 int ppid
= ((Long
) content
.getField("ppid").getValue()).intValue(); //$NON-NLS-1$
49 int status
= ((Long
) content
.getField("status").getValue()).intValue(); //$NON-NLS-1$
50 String name
= checkNotNull((String
) content
.getField("name").getValue()); //$NON-NLS-1$
52 * "mode" could be interesting too, but it doesn't seem to be populated
53 * with anything relevant for now.
56 int curThreadNode
= ss
.getQuarkRelativeAndAdd(KernelEventHandlerUtils
.getNodeThreads(ss
), String
.valueOf(tid
));
57 long timestamp
= KernelEventHandlerUtils
.getTimestamp(event
);
58 /* Set the process' name */
59 setProcessName(ss
, name
, curThreadNode
, timestamp
);
61 /* Set the process' PPID */
62 setPpid(ss
, tid
, pid
, ppid
, curThreadNode
, timestamp
);
64 /* Set the process' status */
65 setStatus(ss
, status
, curThreadNode
, timestamp
);
68 private static void setStatus(ITmfStateSystemBuilder ss
, int status
, int curThreadNode
, long timestamp
) throws AttributeNotFoundException
{
71 quark
= ss
.getQuarkRelativeAndAdd(curThreadNode
, Attributes
.STATUS
);
72 if (ss
.queryOngoingState(quark
).isNull()) {
74 case LinuxValues
.STATEDUMP_PROCESS_STATUS_WAIT_CPU
:
75 value
= StateValues
.PROCESS_STATUS_WAIT_FOR_CPU_VALUE
;
77 case LinuxValues
.STATEDUMP_PROCESS_STATUS_WAIT
:
79 * We have no information on what the process is waiting on
80 * (unlike a sched_switch for example), so we will use the
81 * WAIT_UNKNOWN state instead of the "normal" WAIT_BLOCKED
84 value
= StateValues
.PROCESS_STATUS_WAIT_UNKNOWN_VALUE
;
87 value
= StateValues
.PROCESS_STATUS_UNKNOWN_VALUE
;
89 ss
.modifyAttribute(timestamp
, value
, quark
);
93 private static void setPpid(ITmfStateSystemBuilder ss
, int tid
, int pid
, int ppid
, int curThreadNode
, long timestamp
) throws AttributeNotFoundException
{
96 quark
= ss
.getQuarkRelativeAndAdd(curThreadNode
, Attributes
.PPID
);
97 if (ss
.queryOngoingState(quark
).isNull()) {
99 /* We have a process. Use the 'PPID' field. */
100 value
= TmfStateValue
.newValueInt(ppid
);
102 /* We have a thread, use the 'PID' field for the parent. */
103 value
= TmfStateValue
.newValueInt(pid
);
105 ss
.modifyAttribute(timestamp
, value
, quark
);
109 private static void setProcessName(ITmfStateSystemBuilder ss
, String name
, int curThreadNode
, long timestamp
) throws AttributeNotFoundException
{
110 ITmfStateValue value
;
111 int quark
= ss
.getQuarkRelativeAndAdd(curThreadNode
, Attributes
.EXEC_NAME
);
112 if (ss
.queryOngoingState(quark
).isNull()) {
113 /* If the value didn't exist previously, set it */
114 value
= TmfStateValue
.newValueString(name
);
115 ss
.modifyAttribute(timestamp
, value
, quark
);