Commit | Line | Data |
---|---|---|
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 | ||
13 | package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers; | |
14 | ||
15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; | |
16 | ||
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; | |
27 | ||
28 | /** | |
29 | * LTTng Specific state dump event handler | |
30 | */ | |
31 | public class StateDumpHandler extends KernelEventHandler { | |
32 | ||
33 | /** | |
34 | * Constructor | |
35 | * | |
36 | * @param layout | |
37 | * event layout | |
38 | */ | |
39 | public StateDumpHandler(IKernelAnalysisEventLayout layout) { | |
40 | super(layout); | |
41 | } | |
42 | ||
43 | @Override | |
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$ | |
51 | /* | |
52 | * "mode" could be interesting too, but it doesn't seem to be populated | |
53 | * with anything relevant for now. | |
54 | */ | |
55 | ||
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); | |
60 | ||
61 | /* Set the process' PPID */ | |
62 | setPpid(ss, tid, pid, ppid, curThreadNode, timestamp); | |
63 | ||
64 | /* Set the process' status */ | |
65 | setStatus(ss, status, curThreadNode, timestamp); | |
66 | } | |
67 | ||
68 | private static void setStatus(ITmfStateSystemBuilder ss, int status, int curThreadNode, long timestamp) throws AttributeNotFoundException { | |
69 | ITmfStateValue value; | |
70 | int quark; | |
71 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.STATUS); | |
72 | if (ss.queryOngoingState(quark).isNull()) { | |
73 | switch (status) { | |
74 | case LinuxValues.STATEDUMP_PROCESS_STATUS_WAIT_CPU: | |
75 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; | |
76 | break; | |
77 | case LinuxValues.STATEDUMP_PROCESS_STATUS_WAIT: | |
78 | /* | |
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 | |
82 | * state. | |
83 | */ | |
84 | value = StateValues.PROCESS_STATUS_WAIT_UNKNOWN_VALUE; | |
85 | break; | |
86 | default: | |
87 | value = StateValues.PROCESS_STATUS_UNKNOWN_VALUE; | |
88 | } | |
89 | ss.modifyAttribute(timestamp, value, quark); | |
90 | } | |
91 | } | |
92 | ||
93 | private static void setPpid(ITmfStateSystemBuilder ss, int tid, int pid, int ppid, int curThreadNode, long timestamp) throws AttributeNotFoundException { | |
94 | ITmfStateValue value; | |
95 | int quark; | |
96 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.PPID); | |
97 | if (ss.queryOngoingState(quark).isNull()) { | |
98 | if (pid == tid) { | |
99 | /* We have a process. Use the 'PPID' field. */ | |
100 | value = TmfStateValue.newValueInt(ppid); | |
101 | } else { | |
102 | /* We have a thread, use the 'PID' field for the parent. */ | |
103 | value = TmfStateValue.newValueInt(pid); | |
104 | } | |
105 | ss.modifyAttribute(timestamp, value, quark); | |
106 | } | |
107 | } | |
108 | ||
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); | |
116 | } | |
117 | } | |
118 | } |