Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.state.evProcessor.state; | |
13 | ||
14 | ||
15 | import org.eclipse.linuxtools.lttng.TraceDebug; | |
16 | import org.eclipse.linuxtools.lttng.event.LttngEvent; | |
17 | import org.eclipse.linuxtools.lttng.state.StateStrings; | |
63eecb47 | 18 | import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionMode; |
5d10d135 ASL |
19 | import org.eclipse.linuxtools.lttng.state.StateStrings.IRQMode; |
20 | import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus; | |
88144d4a | 21 | import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing; |
5d10d135 ASL |
22 | import org.eclipse.linuxtools.lttng.state.model.LTTngCPUState; |
23 | import org.eclipse.linuxtools.lttng.state.model.LttngBdevState; | |
24 | import org.eclipse.linuxtools.lttng.state.model.LttngExecutionState; | |
25 | import org.eclipse.linuxtools.lttng.state.model.LttngIRQState; | |
26 | import org.eclipse.linuxtools.lttng.state.model.LttngProcessState; | |
27 | import org.eclipse.linuxtools.lttng.state.model.LttngTraceState; | |
28 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
29 | ||
63eecb47 FC |
30 | public abstract class AbsStateUpdate extends AbsStateProcessing implements |
31 | IEventProcessing { | |
5d10d135 ASL |
32 | |
33 | // ======================================================================== | |
34 | // Data | |
35 | // ======================================================================= | |
36 | protected static final Long ANY_CPU = 0L; | |
37 | ||
38 | // ======================================================================== | |
39 | // push and pop from stack | |
40 | // ======================================================================= | |
41 | protected void push_state(Long cpu, StateStrings.ExecutionMode execMode, | |
42 | String submode, TmfTimestamp eventTime, LttngTraceState traceSt) { | |
43 | ||
44 | LttngProcessState process = traceSt.getRunning_process().get(cpu); | |
45 | LttngExecutionState exe_state = new LttngExecutionState(); | |
46 | exe_state.setExec_mode(execMode); | |
47 | exe_state.setExec_submode(submode); | |
58c60db3 FC |
48 | exe_state.setEntry_Time(eventTime); |
49 | exe_state.setChange_Time(eventTime); | |
5d10d135 | 50 | exe_state.setCum_cpu_time(0L); |
88144d4a | 51 | exe_state.setProc_status(process.getState().getProc_status()); |
5d10d135 ASL |
52 | process.pushToExecutionStack(exe_state); |
53 | } | |
54 | ||
55 | protected void pop_state(Long cpu, StateStrings.ExecutionMode execMode, | |
56 | LttngTraceState traceSt, TmfTimestamp eventTime) { | |
57 | ||
58 | LttngProcessState process = traceSt.getRunning_process().get(cpu); | |
59 | ||
60 | if (!process.getState().getExec_mode().equals(execMode)) { | |
61 | // Different execution mode | |
62 | TraceDebug.debug("Different Execution Mode type \n\tTime:" | |
63 | + eventTime.toString() + "\n\tprocess state has: \n\t" | |
64 | + process.getState().getExec_mode().toString() | |
65 | + "\n\twhen pop_int is:\n\t" + execMode.toString()); | |
66 | return; | |
67 | } | |
68 | ||
63eecb47 | 69 | //The process state is updated within the pop method |
5d10d135 | 70 | process.popFromExecutionStack(); |
58c60db3 | 71 | process.getState().setChange_Time(eventTime); |
5d10d135 ASL |
72 | } |
73 | ||
74 | protected void irq_push_mode(LttngIRQState irqst, IRQMode state) { | |
75 | irqst.pushToIrqStack(state); | |
76 | } | |
77 | ||
78 | protected void irq_set_base_mode(LttngIRQState irqst, IRQMode state) { | |
79 | irqst.clearAndSetBaseToIrqStack(state); | |
80 | } | |
81 | ||
82 | protected void irq_pop_mode(LttngIRQState irqst) { | |
83 | irqst.popFromIrqStack(); | |
84 | } | |
85 | ||
86 | protected void cpu_push_mode(LTTngCPUState cpust, StateStrings.CpuMode state) { | |
87 | // The initialization (init) creates a LttngCPUState instance per | |
88 | // available cpu in the system | |
89 | cpust.pushToCpuStack(state); | |
90 | } | |
91 | ||
92 | protected void cpu_pop_mode(LTTngCPUState cpust) { | |
93 | cpust.popFromCpuStack(); | |
94 | } | |
95 | ||
96 | /* clears the stack and sets the state passed as argument */ | |
97 | protected void cpu_set_base_mode(LTTngCPUState cpust, | |
98 | StateStrings.CpuMode state) { | |
99 | cpust.clearAndSetBaseToCpuStack(state); | |
100 | } | |
101 | ||
102 | protected void bdev_pop_mode(LttngBdevState bdevst) { | |
103 | bdevst.popFromBdevStack(); | |
104 | } | |
105 | ||
106 | /** | |
107 | * Push a new received function pointer to the user_stack | |
108 | * | |
109 | * @param traceSt | |
110 | * @param funcptr | |
111 | * @param cpu | |
112 | */ | |
113 | protected void push_function(LttngTraceState traceSt, Long funcptr, Long cpu) { | |
114 | // Get the related process | |
115 | LttngProcessState process = traceSt.getRunning_process().get(cpu); | |
116 | ||
117 | // update stack | |
118 | process.pushToUserStack(funcptr); | |
119 | ||
120 | // update the pointer to the current function on the corresponding | |
121 | // process | |
122 | process.setCurrent_function(funcptr); | |
123 | } | |
124 | ||
125 | protected void pop_function(LttngTraceState traceSt, LttngEvent trcEvent, | |
126 | Long funcptr) { | |
127 | Long cpu = trcEvent.getCpuId(); | |
128 | LttngProcessState process = traceSt.getRunning_process().get(cpu); | |
129 | Long curr_function = process.getCurrent_function(); | |
130 | ||
131 | if (curr_function != null && curr_function != funcptr) { | |
132 | TraceDebug.debug("Different functions: " + funcptr + " current: " | |
133 | + curr_function + " time stamp: " | |
134 | + trcEvent.getTimestamp().toString()); | |
135 | ||
136 | // g_info("Different functions (%lu.%09lu): ignore it\n", | |
137 | // tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); | |
138 | // g_info("process state has %" PRIu64 " when pop_function is %" | |
139 | // PRIu64 | |
140 | // "\n", | |
141 | // process->current_function, funcptr); | |
142 | // g_info("{ %u, %u, %s, %s, %s }\n", | |
143 | // process->pid, | |
144 | // process->ppid, | |
145 | // g_quark_to_string(process->name), | |
146 | // g_quark_to_string(process->brand), | |
147 | // g_quark_to_string(process->state->s)); | |
148 | return; | |
149 | } | |
150 | ||
151 | process.popFromUserStack(); | |
152 | process.setCurrent_function(process.peekFromUserStack()); | |
153 | } | |
154 | ||
155 | // ======================================================================== | |
156 | // General methods | |
157 | // ======================================================================= | |
158 | // Adaption from MKDEV macro | |
159 | protected Long mkdev(Long major, Long minor) { | |
160 | Long result = null; | |
161 | if (major != null && minor != null) { | |
162 | result = (major << 20) | minor; | |
163 | } | |
164 | return result; | |
165 | } | |
166 | ||
167 | /* | |
168 | * FIXME : this function should be called when we receive an event telling | |
169 | * that release_task has been called in the kernel. In happens generally | |
63eecb47 | 170 | * when the parent waits for its child termination, but may also happen in |
5d10d135 ASL |
171 | * special cases in the child's exit : when the parent ignores its children |
172 | * SIGCCHLD or has the flag SA_NOCLDWAIT. It can also happen when the child | |
173 | * is part of a killed thread group, but isn't the leader. | |
174 | */ | |
175 | protected boolean exit_process(LttngTraceState ts, LttngProcessState process) { | |
176 | /* | |
177 | * Wait for both schedule with exit dead and process free to happen. | |
178 | * They can happen in any order. | |
179 | */ | |
180 | process.incrementFree_events(); | |
181 | if (process.getFree_events() < 2) { | |
182 | return false; | |
183 | } | |
184 | ||
185 | process.clearExecutionStack(); | |
186 | process.clearUserStack(); | |
58c60db3 | 187 | ts.getProcesses().remove(process); |
5d10d135 ASL |
188 | |
189 | return true; | |
190 | } | |
191 | ||
192 | /** | |
193 | * @param traceSt | |
194 | * @param cpu | |
195 | * @param pid | |
196 | * @param tgid | |
197 | * @param timestamp | |
198 | * @return | |
199 | */ | |
200 | protected LttngProcessState create_process(LttngTraceState traceSt, | |
201 | Long cpu, Long pid, Long tgid, final TmfTimestamp timestamp) { | |
202 | LttngProcessState process = create_process(traceSt, cpu, pid, tgid, | |
203 | ProcessStatus.LTTV_STATE_UNNAMED.getInName(), timestamp); | |
204 | return process; | |
205 | } | |
206 | ||
207 | /** | |
208 | * @param traceSt | |
209 | * @param cpu | |
210 | * @param pid | |
211 | * @param tgid | |
212 | * @param name | |
213 | * @param timestamp | |
214 | * @return | |
215 | */ | |
216 | protected LttngProcessState create_process(LttngTraceState traceSt, | |
217 | Long cpu, Long pid, Long tgid, String name, | |
218 | final TmfTimestamp timestamp) { | |
219 | LttngProcessState process; | |
58c60db3 FC |
220 | process = new LttngProcessState(cpu, pid, tgid, name, timestamp); |
221 | traceSt.getProcesses().add(process); | |
5d10d135 ASL |
222 | return process; |
223 | } | |
224 | ||
63eecb47 FC |
225 | /** |
226 | * @param ts | |
227 | * @param cpu | |
228 | * @param pid | |
229 | * @param timestamp | |
230 | * , Used when a new process is needed | |
231 | * @return | |
232 | */ | |
233 | protected LttngProcessState lttv_state_find_process_or_create( | |
234 | LttngTraceState ts, Long cpu, Long pid, final TmfTimestamp timestamp) { | |
235 | ||
236 | LttngProcessState process = lttv_state_find_process(ts, cpu, pid); | |
237 | /* Put ltt_time_zero creation time for non existing processes */ | |
238 | if (process == null) { | |
239 | process = create_process(ts, cpu, pid, 0L, timestamp); | |
240 | // leave only one entry in the execution stack | |
241 | process.popFromExecutionStack(); | |
242 | LttngExecutionState es = process.getState(); | |
243 | es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN); | |
244 | es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED); | |
245 | } | |
246 | ||
247 | return process; | |
248 | } | |
249 | ||
5d10d135 | 250 | } |