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 | ||
0f7a12d3 AM |
17 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.LinuxValues; |
18 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues; | |
c8f45ad2 | 19 | import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout; |
f69045e2 | 20 | import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes; |
c8f45ad2 MK |
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(); | |
8a0bbebf | 46 | Integer cpu = KernelEventHandlerUtils.getCpu(event); |
c8f45ad2 MK |
47 | int tid = ((Long) content.getField("tid").getValue()).intValue(); //$NON-NLS-1$ |
48 | int pid = ((Long) content.getField("pid").getValue()).intValue(); //$NON-NLS-1$ | |
49 | int ppid = ((Long) content.getField("ppid").getValue()).intValue(); //$NON-NLS-1$ | |
50 | int status = ((Long) content.getField("status").getValue()).intValue(); //$NON-NLS-1$ | |
51 | String name = checkNotNull((String) content.getField("name").getValue()); //$NON-NLS-1$ | |
52 | /* | |
53 | * "mode" could be interesting too, but it doesn't seem to be populated | |
54 | * with anything relevant for now. | |
55 | */ | |
56 | ||
642b4947 | 57 | String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu); |
8a0bbebf MJ |
58 | if (threadAttributeName == null) { |
59 | return; | |
60 | } | |
61 | ||
62 | int curThreadNode = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeThreads(ss), threadAttributeName); | |
c8f45ad2 MK |
63 | long timestamp = KernelEventHandlerUtils.getTimestamp(event); |
64 | /* Set the process' name */ | |
65 | setProcessName(ss, name, curThreadNode, timestamp); | |
66 | ||
67 | /* Set the process' PPID */ | |
68 | setPpid(ss, tid, pid, ppid, curThreadNode, timestamp); | |
69 | ||
70 | /* Set the process' status */ | |
71 | setStatus(ss, status, curThreadNode, timestamp); | |
72 | } | |
73 | ||
5ae5a500 | 74 | private static void setStatus(ITmfStateSystemBuilder ss, int status, int curThreadNode, long timestamp) { |
c8f45ad2 | 75 | ITmfStateValue value; |
d3cc952f | 76 | if (ss.queryOngoingState(curThreadNode).isNull()) { |
c8f45ad2 MK |
77 | switch (status) { |
78 | case LinuxValues.STATEDUMP_PROCESS_STATUS_WAIT_CPU: | |
79 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; | |
80 | break; | |
81 | case LinuxValues.STATEDUMP_PROCESS_STATUS_WAIT: | |
82 | /* | |
83 | * We have no information on what the process is waiting on | |
84 | * (unlike a sched_switch for example), so we will use the | |
85 | * WAIT_UNKNOWN state instead of the "normal" WAIT_BLOCKED | |
86 | * state. | |
87 | */ | |
88 | value = StateValues.PROCESS_STATUS_WAIT_UNKNOWN_VALUE; | |
89 | break; | |
90 | default: | |
91 | value = StateValues.PROCESS_STATUS_UNKNOWN_VALUE; | |
92 | } | |
d3cc952f | 93 | ss.modifyAttribute(timestamp, value, curThreadNode); |
c8f45ad2 MK |
94 | } |
95 | } | |
96 | ||
5ae5a500 | 97 | private static void setPpid(ITmfStateSystemBuilder ss, int tid, int pid, int ppid, int curThreadNode, long timestamp) { |
c8f45ad2 MK |
98 | ITmfStateValue value; |
99 | int quark; | |
100 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.PPID); | |
101 | if (ss.queryOngoingState(quark).isNull()) { | |
102 | if (pid == tid) { | |
103 | /* We have a process. Use the 'PPID' field. */ | |
104 | value = TmfStateValue.newValueInt(ppid); | |
105 | } else { | |
106 | /* We have a thread, use the 'PID' field for the parent. */ | |
107 | value = TmfStateValue.newValueInt(pid); | |
108 | } | |
109 | ss.modifyAttribute(timestamp, value, quark); | |
110 | } | |
111 | } | |
112 | ||
5ae5a500 | 113 | private static void setProcessName(ITmfStateSystemBuilder ss, String name, int curThreadNode, long timestamp) { |
c8f45ad2 MK |
114 | ITmfStateValue value; |
115 | int quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.EXEC_NAME); | |
116 | if (ss.queryOngoingState(quark).isNull()) { | |
117 | /* If the value didn't exist previously, set it */ | |
118 | value = TmfStateValue.newValueString(name); | |
119 | ss.modifyAttribute(timestamp, value, quark); | |
120 | } | |
121 | } | |
122 | } |