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