Commit | Line | Data |
---|---|---|
8035003b 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.ui.views.controlflow.evProcessor; | |
13 | ||
14 | import org.eclipse.linuxtools.lttng.event.LttngEvent; | |
15 | import org.eclipse.linuxtools.lttng.state.StateStrings.Events; | |
16 | import org.eclipse.linuxtools.lttng.state.StateStrings.Fields; | |
17 | import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing; | |
18 | import org.eclipse.linuxtools.lttng.state.model.LttngProcessState; | |
19 | import org.eclipse.linuxtools.lttng.state.model.LttngTraceState; | |
20 | import org.eclipse.linuxtools.lttng.ui.TraceDebug; | |
21 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess; | |
22 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
23 | ||
24 | /** | |
25 | * Creates instances of specific after state update handlers, per corresponding | |
26 | * event. | |
27 | * | |
28 | * @author alvaro | |
29 | * | |
30 | */ | |
31 | class FlowTRangeAfterUpdateHandlers { | |
32 | /** | |
33 | * <p> | |
34 | * Handles: LTT_EVENT_SCHED_SCHEDULE | |
35 | * </p> | |
36 | * Replace C function "after_schedchange_hook" in eventhooks.c | |
37 | * <p> | |
38 | * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID | |
39 | * </p> | |
40 | * | |
41 | * @return | |
42 | */ | |
43 | final IEventProcessing getSchedChangeHandler() { | |
44 | AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() { | |
45 | ||
46 | private Events eventType = Events.LTT_EVENT_SCHED_SCHEDULE; | |
47 | ||
48 | // @Override | |
49 | public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) { | |
50 | ||
51 | // get event time, cpu, trace_number, process, pid | |
52 | LttngProcessState process_in = traceSt.getRunning_process().get(trcEvent.getCpuId()); | |
53 | ||
54 | // pid_out is never used, even in LTTv! | |
55 | //Long pid_out = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PREV_PID); | |
56 | Long pid_in = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_NEXT_PID); | |
57 | ||
58 | if ( !(pid_in.equals(process_in.getPid())) ) { | |
59 | TraceDebug.debug("pid_in != PID! (getSchedChangeHandler)"); | |
60 | } | |
61 | ||
62 | //hashed_process_data = processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num); | |
dfaf8391 | 63 | TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCreation_time().getValue(), traceSt.getTraceId() ); |
8035003b ASL |
64 | |
65 | if ( localProcess == null ) { | |
66 | if ( (pid_in == 0) || (pid_in != process_in.getPpid()) ) { | |
67 | TmfTimeRange timeRange = traceSt.getInputDataRef().getTraceTimeWindow(); | |
68 | localProcess = addLocalProcess(process_in, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId()); | |
69 | } | |
70 | else { | |
63eecb47 FC |
71 | TraceDebug |
72 | .debug("pid_in is not 0 or pid_in == PPID! (getSchedChangeHandler)"); | |
8035003b ASL |
73 | } |
74 | } | |
63eecb47 FC |
75 | |
76 | // There is no drawing done by the C code below, only refreshing | |
77 | // the references to the current hash data to make it ready for | |
78 | // next event | |
79 | ||
80 | // This current implementation does not support the use of | |
81 | // current hashed data | |
82 | // although an equivalent would be good in order to improve the | |
83 | // time to find the currently running process per cpu. | |
8035003b ASL |
84 | /* |
85 | if(ltt_time_compare(hashed_process_data_in->next_good_time, evtime) <= 0) | |
86 | { | |
87 | TimeWindow time_window = lttvwindow_get_time_window(control_flow_data->tab); | |
88 | ||
89 | #ifdef EXTRA_CHECK | |
90 | if(ltt_time_compare(evtime, time_window.start_time) == -1 || ltt_time_compare(evtime, time_window.end_time) == 1) | |
91 | return FALSE; | |
92 | #endif //EXTRA_CHECK | |
93 | ||
94 | Drawing_t *drawing = control_flow_data->drawing; | |
95 | guint width = drawing->width; | |
96 | guint new_x; | |
97 | ||
98 | convert_time_to_pixels(time_window,evtime,width,&new_x); | |
99 | ||
100 | if(hashed_process_data_in->x.middle != new_x) { | |
101 | hashed_process_data_in->x.middle = new_x; | |
102 | hashed_process_data_in->x.middle_used = FALSE; | |
103 | hashed_process_data_in->x.middle_marked = FALSE; | |
104 | } | |
105 | }*/ | |
106 | ||
107 | return false; | |
108 | ||
109 | } | |
110 | ||
111 | // @Override | |
112 | public Events getEventHandleType() { | |
113 | return eventType; | |
114 | } | |
115 | }; | |
116 | return handler; | |
117 | } | |
118 | ||
119 | /** | |
120 | * <p> | |
121 | * Handles: LTT_EVENT_PROCESS_FORK | |
122 | * </p> | |
123 | * Replace C function "after_process_fork_hook" in eventhooks.c | |
124 | * <p> | |
125 | * Fields: LTT_FIELD_CHILD_PID | |
126 | * </p> | |
127 | * | |
128 | * @return | |
129 | */ | |
130 | final IEventProcessing getProcessForkHandler() { | |
131 | AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() { | |
132 | ||
133 | private Events eventType = Events.LTT_EVENT_PROCESS_FORK; | |
134 | ||
135 | // @Override | |
136 | public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) { | |
137 | ||
138 | Long child_pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_CHILD_PID); | |
139 | LttngProcessState process_child = lttv_state_find_process(traceSt, trcEvent.getCpuId(), child_pid ); | |
140 | ||
141 | if ( process_child != null ) { | |
dfaf8391 | 142 | TimeRangeEventProcess localProcess = procContainer.findProcess(process_child.getPid(), process_child.getCreation_time().getValue(), traceSt.getTraceId() ); |
8035003b ASL |
143 | |
144 | if ( localProcess == null ) { | |
145 | if ( (child_pid == 0) || (child_pid != process_child.getPpid()) ) { | |
146 | TmfTimeRange timeRange = traceSt.getInputDataRef().getTraceTimeWindow(); | |
147 | localProcess = addLocalProcess(process_child, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId()); | |
148 | } | |
149 | else { | |
150 | TraceDebug.debug("localProcess is null with child_pid not 0 or child_pid equals PPID (getProcessForkHandler)"); | |
151 | } | |
63eecb47 FC |
152 | } else { |
153 | // If we found the process, the Ppid and the Tgid might | |
154 | // be missing, let's add them | |
155 | localProcess.setPpid(process_child.getPpid()); | |
156 | localProcess.setTgid(process_child.getTgid()); | |
8035003b ASL |
157 | } |
158 | } | |
159 | else { | |
160 | TraceDebug.debug("process_child is null! (getProcessForkHandler)"); | |
161 | } | |
162 | ||
163 | return false; | |
164 | } | |
165 | ||
166 | // @Override | |
167 | public Events getEventHandleType() { | |
168 | return eventType; | |
169 | } | |
170 | }; | |
171 | return handler; | |
172 | } | |
173 | ||
174 | /** | |
175 | * <p> | |
176 | * Handles: LTT_EVENT_PROCESS_EXIT | |
177 | * </p> | |
178 | * Replace C function "after_process_exit_hook" in eventhooks.c | |
179 | * | |
180 | * @return | |
181 | */ | |
182 | final IEventProcessing getProcessExitHandler() { | |
183 | AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() { | |
184 | ||
185 | private Events eventType = Events.LTT_EVENT_PROCESS_EXIT; | |
186 | ||
187 | // @Override | |
188 | public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) { | |
189 | ||
190 | LttngProcessState process = traceSt.getRunning_process().get(trcEvent.getCpuId()); | |
191 | ||
192 | if ( process != null ) { | |
193 | ||
194 | // *** TODO: *** | |
195 | // We shall look into a way to find the current process | |
63eecb47 | 196 | // faster, see the c library |
8035003b ASL |
197 | // (current_hash) in order to speed up the find. see c-code |
198 | // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){ | |
199 | // hashed_process_data = process_list->current_hash_data[trace_num][cpu]; | |
200 | // } | |
dfaf8391 | 201 | TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCreation_time().getValue(), traceSt.getTraceId()); |
8035003b ASL |
202 | |
203 | if ( localProcess == null ) { | |
204 | if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) { | |
205 | TmfTimeRange timeRange = traceSt.getInputDataRef().getTraceTimeWindow(); | |
206 | localProcess = addLocalProcess(process, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId()); | |
207 | } | |
208 | else { | |
209 | TraceDebug.debug("process pid is not 0 or pid equals ppid! (getProcessExitHandler)"); | |
210 | } | |
63eecb47 | 211 | } |
8035003b ASL |
212 | } |
213 | else { | |
214 | TraceDebug.debug("process is null! (getProcessExitHandler)"); | |
215 | } | |
216 | ||
217 | return false; | |
218 | } | |
219 | ||
220 | // @Override | |
221 | public Events getEventHandleType() { | |
222 | return eventType; | |
223 | } | |
224 | }; | |
225 | return handler; | |
226 | } | |
227 | ||
228 | ||
229 | /** | |
230 | * <p> | |
231 | * Handles: LTT_EVENT_EXEC | |
232 | * </p> | |
233 | * Replace C function "after_fs_exec_hook" in eventhooks.c | |
234 | * | |
235 | * @return | |
236 | */ | |
237 | final IEventProcessing getProcessExecHandler() { | |
238 | AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() { | |
239 | ||
240 | private Events eventType = Events.LTT_EVENT_EXEC; | |
241 | ||
242 | // @Override | |
243 | public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) { | |
244 | ||
245 | LttngProcessState process = traceSt.getRunning_process().get(trcEvent.getCpuId()); | |
246 | ||
247 | if ( process != null ) { | |
248 | ||
dfaf8391 | 249 | TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCreation_time().getValue(), traceSt.getTraceId()); |
8035003b ASL |
250 | |
251 | if ( localProcess == null ) { | |
252 | if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) { | |
253 | TmfTimeRange timeRange = traceSt.getInputDataRef().getTraceTimeWindow(); | |
254 | localProcess = addLocalProcess(process, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId()); | |
255 | } | |
256 | else { | |
257 | TraceDebug.debug("process pid is not 0 or pid equals ppid! (getProcessExecHandler)"); | |
258 | } | |
259 | } | |
260 | else { | |
261 | // If we found the process, the name might be missing. Let's add it here. | |
262 | localProcess.setName(process.getName()); | |
263 | } | |
264 | } | |
265 | else { | |
266 | TraceDebug.debug("process is null! (getProcessExecHandler)"); | |
267 | } | |
268 | ||
269 | return false; | |
270 | } | |
271 | ||
272 | // @Override | |
273 | public Events getEventHandleType() { | |
274 | return eventType; | |
275 | } | |
276 | }; | |
277 | return handler; | |
278 | } | |
279 | ||
280 | /** | |
281 | * <p> | |
282 | * LTT_EVENT_THREAD_BRAND | |
283 | * </p> | |
284 | * Replace C function "after_user_generic_thread_brand_hook" in eventhooks.c | |
285 | * | |
286 | * @return | |
287 | */ | |
288 | final IEventProcessing GetThreadBrandHandler() { | |
289 | AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() { | |
290 | ||
291 | private Events eventType = Events.LTT_EVENT_THREAD_BRAND; | |
292 | ||
293 | // @Override | |
294 | public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) { | |
295 | ||
296 | LttngProcessState process = traceSt.getRunning_process().get(trcEvent.getCpuId()); | |
297 | ||
298 | if ( process != null ) { | |
299 | ||
63eecb47 FC |
300 | // Similar to above comments, implement a faster way to find |
301 | // the local process | |
8035003b ASL |
302 | // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){ |
303 | // hashed_process_data = process_list->current_hash_data[trace_num][cpu]; | |
304 | // } | |
dfaf8391 | 305 | TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCreation_time().getValue(), traceSt.getTraceId()); |
8035003b ASL |
306 | |
307 | if ( localProcess == null ) { | |
308 | if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) { | |
309 | TmfTimeRange timeRange = traceSt.getInputDataRef().getTraceTimeWindow(); | |
310 | localProcess = addLocalProcess(process, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId()); | |
311 | } | |
312 | else { | |
313 | TraceDebug.debug("process pid is not 0 or pid equals ppid! (GetThreadBrandHandler)"); | |
314 | } | |
315 | } | |
316 | else { | |
63eecb47 FC |
317 | // If we found the process, the brand might be missing |
318 | // on it, add it. | |
8035003b ASL |
319 | localProcess.setBrand(process.getBrand()); |
320 | } | |
321 | } | |
322 | else { | |
323 | TraceDebug.debug("process is null! (GetThreadBrandHandler)"); | |
324 | } | |
325 | ||
326 | return false; | |
327 | ||
328 | } | |
329 | ||
330 | // @Override | |
331 | public Events getEventHandleType() { | |
332 | return eventType; | |
333 | } | |
334 | }; | |
335 | return handler; | |
336 | } | |
337 | ||
338 | /** | |
339 | * <p> | |
340 | * LTT_EVENT_PROCESS_STATE | |
341 | * </p> | |
342 | * Replace C function "after_event_enum_process_hook" in eventhooks.c | |
343 | * <p> | |
63eecb47 FC |
344 | * <p> |
345 | * Creates the processlist entry for the child process. Put the last | |
346 | * position in x at the current time value. | |
347 | * </p> | |
348 | * | |
349 | * <p> | |
350 | * Fields: LTT_FIELD_PID | |
351 | * </p> | |
352 | * | |
8035003b ASL |
353 | * @return |
354 | */ | |
355 | final IEventProcessing getEnumProcessStateHandler() { | |
356 | AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() { | |
357 | ||
358 | private Events eventType = Events.LTT_EVENT_PROCESS_STATE; | |
359 | ||
360 | // @Override | |
361 | public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) { | |
362 | ||
363 | int first_cpu; | |
364 | int nb_cpus; | |
365 | ||
63eecb47 FC |
366 | Long pid_in = getAFieldLong(trcEvent, traceSt, |
367 | Fields.LTT_FIELD_PID); | |
8035003b ASL |
368 | |
369 | // Lttv assume that pid_in will NEVER be null or incoherent | |
370 | // What if ... ? (let's add some debug) | |
371 | if ( pid_in != null ) { | |
372 | if(pid_in == 0L) { | |
373 | first_cpu = 0; | |
374 | nb_cpus = traceSt.getNumberOfCPUs(); | |
375 | } | |
376 | else { | |
377 | first_cpu = ANY_CPU.intValue(); | |
378 | nb_cpus = ANY_CPU.intValue() + 1; | |
379 | } | |
380 | ||
381 | for (int cpu = first_cpu; cpu < nb_cpus; cpu++) { | |
382 | LttngProcessState process_in = lttv_state_find_process(traceSt, trcEvent.getCpuId(), pid_in ); | |
383 | ||
384 | if ( process_in != null ) { | |
dfaf8391 | 385 | TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCreation_time().getValue(), traceSt.getTraceId()); |
8035003b ASL |
386 | |
387 | if (localProcess == null) { | |
388 | if ( (process_in.getPid() == 0) || (process_in.getPid() != process_in.getPpid()) ) { | |
389 | TmfTimeRange timeRange = traceSt.getInputDataRef().getTraceTimeWindow(); | |
390 | localProcess = addLocalProcess(process_in, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId()); | |
391 | } | |
392 | else { | |
393 | TraceDebug.debug("process pid is not 0 or pid equals ppid! (getEnumProcessStateHandler)"); | |
394 | } | |
395 | } | |
396 | else { | |
397 | // If the process was found, it might be missing informations, add it here | |
398 | localProcess.setName(process_in.getName()); | |
399 | localProcess.setPpid(process_in.getPpid()); | |
400 | localProcess.setTgid(process_in.getTgid()); | |
401 | } | |
402 | } | |
403 | else { | |
404 | TraceDebug.debug("process_in is null! This should never happen. (getEnumProcessStateHandler)"); | |
405 | } | |
406 | } | |
407 | } | |
408 | else { | |
409 | TraceDebug.debug("pid_in is null! This should never happen, really... (getEnumProcessStateHandler)"); | |
410 | } | |
411 | ||
412 | return false; | |
413 | } | |
414 | ||
415 | // @Override | |
416 | public Events getEventHandleType() { | |
417 | return eventType; | |
418 | } | |
419 | }; | |
420 | return handler; | |
421 | } | |
422 | ||
423 | } |