[290968] Contribution
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / controlflow / evProcessor / FlowTRangeBeforeUpdateHandlers.java
CommitLineData
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 *******************************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor;
13
14import org.eclipse.linuxtools.lttng.event.LttngEvent;
15import org.eclipse.linuxtools.lttng.state.StateStrings.Events;
16import org.eclipse.linuxtools.lttng.state.StateStrings.Fields;
17import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing;
18import org.eclipse.linuxtools.lttng.state.model.LttngProcessState;
19import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
20import org.eclipse.linuxtools.lttng.ui.TraceDebug;
21import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess;
22import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
23
24/**
25 * Creates instances of specific before state update handlers, per corresponding
26 * event.
27 *
28 * @author alvaro
29 *
30 */
31class FlowTRangeBeforeUpdateHandlers {
32 /**
33 * <p>
34 * Handles: LTT_EVENT_SYSCALL_ENTRY
35 * </p>
36 * Replace C function named "before_execmode_hook" in eventhooks.c
37 *
38 * @return
39 */
40 final IEventProcessing getStateModesHandler() {
41 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
42
43 // this method is common to many events
44 private Events eventType = Events.LTT_EVENT_SYSCALL_ENTRY;
45
46 // @Override
47 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
48
49 Long cpu = trcEvent.getCpuId();
50 LttngProcessState stateProcess = traceSt.getRunning_process()
51 .get(cpu);
52 // TraceDebug.debug("Before handler called");
53 String traceId = traceSt.getTraceId();
54
55 if (stateProcess != null) {
56 // Find process within the list of registered time-range
57 // related
58 // processes
59
60 // key process attributes to look for it or store it
61 // are: pid, birth, trace_num, note: cpu not relevant since
62 // it
63 // may change
64 TimeRangeEventProcess localProcess = procContainer
dfaf8391
FC
65 .findProcess(stateProcess.getPid(), stateProcess
66 .getCreation_time().getValue(), traceId);
8035003b
ASL
67
68 // Add process to process list if not present
69 if (localProcess == null) {
70 TmfTimeRange timeRange = traceSt.getInputDataRef()
71 .getTraceTimeWindow();
72 localProcess = addLocalProcess(stateProcess, timeRange
73 .getStartTime().getValue(), timeRange
74 .getEndTime().getValue(), traceId);
75 }
76
77 // Do the actual drawing
41dc35d0
FC
78 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
79 stateProcess, localProcess, params);
8035003b
ASL
80 } else {
81 TraceDebug
dfaf8391 82 .debug("Running process is null! (getStateModesHandler)");
8035003b
ASL
83 }
84
85 return false;
86 }
87
88 // @Override
89 public Events getEventHandleType() {
90 return eventType;
91 }
92 };
93 return handler;
94 }
95
96 /**
97 * <p>
98 * Handles: LTT_EVENT_SCHED_SCHEDULE
99 * </p>
100 * Replace C function named "before_schedchange_hook" in eventhooks.c
101 * <p>
102 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE (?)
103 * </p>
104 *
105 * @return
106 */
107 final IEventProcessing getBeforeSchedChangeHandler() {
108 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
109
110 private Events eventType = Events.LTT_EVENT_SCHED_SCHEDULE;
111
112 // @Override
113 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
114
115 Long pid_out = getAFieldLong(trcEvent, traceSt,
116 Fields.LTT_FIELD_PREV_PID);
117 Long pid_in = getAFieldLong(trcEvent, traceSt,
118 Fields.LTT_FIELD_NEXT_PID);
119
120 // This is useless even in Lttv !!
121 // Long state_out = getAFieldLong(trcEvent, traceSt,
122 // Fields.LTT_FIELD_PREV_STATE);
123
124 // We need to process information.
125 LttngProcessState process = traceSt.getRunning_process().get(
126 trcEvent.getCpuId());
127
128 if (process != null) {
129 if (process.getPid().equals(pid_out) == false) {
130 // To replace :
131 // process = lttv_state_find_process(ts,tfs->cpu,
132 // pid_out);
133 process = lttv_state_find_process(traceSt, trcEvent
134 .getCpuId(), pid_out);
135 // Also, removed :
136 // guint trace_num = ts->parent.index;
137 }
138
139 if (process != null) {
dfaf8391
FC
140 // ***VERIFY***
141 // Is this call really replace these two C lines ??
8035003b
ASL
142 // HashedProcessData *hashed_process_data = NULL;
143 // hashed_process_data =
144 // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
145 TimeRangeEventProcess localProcess = procContainer
dfaf8391
FC
146 .findProcess(process.getPid(), process
147 .getCreation_time().getValue(), traceSt
148 .getTraceId());
8035003b
ASL
149
150 // Add process to process list if not present
151 // Replace C Call :
152 // processlist_add(process_list,drawing,pid_out,process->tgid,process->cpu,process->ppid,&birth,trace_num,process->name,process->brand,&pl_height,&process_info,&hashed_process_data);
153 if (localProcess == null) {
154 TmfTimeRange timeRange = traceSt.getInputDataRef()
155 .getTraceTimeWindow();
156 localProcess = addLocalProcess(process, timeRange
157 .getStartTime().getValue(), timeRange
158 .getEndTime().getValue(), traceSt
159 .getTraceId());
160 }
161
162 // Do the actual drawing
41dc35d0
FC
163 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
164 process,
8035003b
ASL
165 localProcess, params);
166 } else {
167 // Process may be null if the process started BEFORE the
168 // trace start
169 // TraceDebug.debug("Process is null for pid_out! (getBeforeSchedChangeHandler)");
170 }
171
8035003b
ASL
172 process = lttv_state_find_process(traceSt, trcEvent
173 .getCpuId(), pid_in);
174
175 if (process != null) {
dfaf8391
FC
176 // ***VERIFY***
177 // Is this call really replace these two C lines ??
8035003b
ASL
178 // HashedProcessData *hashed_process_data = NULL;
179 // hashed_process_data =
180 // processlist_get_process_data(process_list, pid_in,
181 // tfs->cpu, &birth, trace_num);
182 TimeRangeEventProcess localProcess = procContainer
dfaf8391
FC
183 .findProcess(process.getPid(), process
184 .getCreation_time().getValue(), traceSt
185 .getTraceId());
8035003b
ASL
186
187 // Add process to process list if not present
188 // Replace C Call :
189 // processlist_add(process_list, drawing, pid_in,
190 // process->tgid, tfs->cpu, process->ppid, &birth,
191 // trace_num, process->name, process->brand, &pl_height,
192 // &process_info, &hashed_process_data);
193 if (localProcess == null) {
194 TmfTimeRange timeRange = traceSt.getInputDataRef()
195 .getTraceTimeWindow();
196 localProcess = addLocalProcess(process, timeRange
197 .getStartTime().getValue(), timeRange
198 .getEndTime().getValue(), traceSt
199 .getTraceId());
200 }
201
202 // Do the actual drawing
41dc35d0
FC
203 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
204 process,
8035003b
ASL
205 localProcess, params);
206
207 } else {
208 // Process can be null if it started AFTER the trace
209 // end. Do nothing...
210 // TraceDebug.debug("No process found for pid_in! Something is wrong? (getBeforeSchedChangeHandler)");
211 }
212 } else {
213 TraceDebug
214 .debug("Running process is null! (getBeforeSchedChangeHandler)");
215 }
216
217 return false;
218 }
219
220 // @Override
221 public Events getEventHandleType() {
222 return eventType;
223 }
224 };
225
226 return handler;
227 }
228
229 /**
230 * <p>
231 * Handles: LTT_EVENT_PROCESS_EXIT
232 * </p>
233 * Replace C function named "before_process_exit_hook" in eventhooks.c
234 *
235 * @return
236 */
237 final IEventProcessing getProcessExitHandler() {
238 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
239
240 private Events eventType = Events.LTT_EVENT_PROCESS_EXIT;
241
242 // @Override
243 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
244
245 // We need to process information.
246 LttngProcessState process = traceSt.getRunning_process().get(
247 trcEvent.getCpuId());
248
249 if (process != null) {
dfaf8391
FC
250 // *** FIXME ***
251 // This C call does not seem to be possible, as we have no
252 // "current_process" in LttngTraceState
253 // hashed_process_data =
254 // process_list->current_hash_data[trace_num][cpu];
8035003b 255
dfaf8391
FC
256 // ***VERIFY***
257 // Is this call really replace these two C lines ??
258 // HashedProcessData *hashed_process_data = NULL;
8035003b
ASL
259 // hashed_process_data =
260 // processlist_get_process_data(process_list, pid,
261 // process->cpu, &birth,trace_num);
262 TimeRangeEventProcess localProcess = procContainer
dfaf8391
FC
263 .findProcess(process.getPid(), process
264 .getCreation_time().getValue(), traceSt
265 .getTraceId());
8035003b
ASL
266
267 // Add process to process list if not present
268 // Replace C Call :
269 // processlist_add(process_list, drawing, pid,
270 // process->tgid, process->cpu, process->ppid, &birth,
271 // trace_num, process->name, process->brand,&pl_height,
272 // &process_info, &hashed_process_data);
273 if (localProcess == null) {
dfaf8391
FC
274 if ((process.getPid() == 0)
275 || (process.getPid() != process.getPpid())) {
276 TmfTimeRange timeRange = traceSt.getInputDataRef()
277 .getTraceTimeWindow();
278 localProcess = addLocalProcess(process, timeRange
279 .getStartTime().getValue(), timeRange
280 .getEndTime().getValue(), traceSt
281 .getTraceId());
282 // Call the function that does the actual drawing
41dc35d0
FC
283 makeDraw(traceSt, trcEvent.getTimestamp()
284 .getValue(), process, localProcess, params);
dfaf8391
FC
285 } else {
286 TraceDebug
287 .debug("Pid is null or Pid == PPID! (getProcessExitHandler)");
288 }
8035003b 289 }
8035003b
ASL
290 } else {
291 TraceDebug
41dc35d0 292 .debug("Running process is null! (getProcessExitHandler)");
8035003b
ASL
293 }
294
295 return false;
296 }
297
298 // @Override
299 public Events getEventHandleType() {
300 return eventType;
301 }
302 };
303 return handler;
304 }
305
306 /**
307 * <p>
308 * Handles: LTT_EVENT_PROCESS_FREE
309 * </p>
310 * Replace C function named "before_process_release_hook" in eventhooks.c
311 * <p>
312 * Fields: LTT_FIELD_PID
313 * </p>
314 *
315 * @return
316 */
317 final IEventProcessing getProcessFreeHandler() {
318 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
319
320 private Events eventType = Events.LTT_EVENT_PROCESS_FREE;
321
322 // @Override
323 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
324 // PID of the process to release
325 Long release_pid = getAFieldLong(trcEvent, traceSt,
326 Fields.LTT_FIELD_PID);
327
328 if ((release_pid != null)) {
329 LttngProcessState process = lttv_state_find_process(
330 traceSt, ANY_CPU, release_pid);
331 if (process != null) {
332
333 // Replace the C call :
334 // hashed_process_data =
335 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
336 TimeRangeEventProcess localProcess = procContainer
dfaf8391
FC
337 .findProcess(process.getPid(), process
338 .getCreation_time().getValue(), traceSt
339 .getTraceId());
8035003b
ASL
340
341 // This is as it was in the C ... ?
342 if (localProcess == null) {
343 return false;
344 }
345
346 // Perform the drawing
41dc35d0
FC
347 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
348 process,
8035003b
ASL
349 localProcess, params);
350 }
351 } else {
352 TraceDebug
353 .debug("Release_pid is null! (getProcessFreeHandler)");
354 }
355
356 return false;
357 }
358
359 // @Override
360 public Events getEventHandleType() {
361 return eventType;
362 }
363 };
364 return handler;
365 }
366
367 /**
368 * <p>
369 * Handles: LTT_EVENT_STATEDUMP_END
370 * </p>
371 * Replace C function named "before_statedump_end" in eventhooks.c
372 *
373 * @return
374 */
375 final IEventProcessing getStateDumpEndHandler() {
376 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
377
378 private Events eventType = Events.LTT_EVENT_STATEDUMP_END;
379
380 // @Override
381 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
382
383 // What's below should replace the following call in C :
384 // ClosureData closure_data;
385 // closure_data.events_request = events_request;
386 // closure_data.tss = tss;
387 // closure_data.end_time = evtime;
388 // convert_time_to_pixels(time_window,evtime,width,&closure_data.x_end);
389 // g_hash_table_foreach(process_list->process_hash,
390 // draw_closure,(void*)&closure_data);
391 //
392 // And the draw is always the same then...
393
dfaf8391
FC
394 LttngProcessState process = null;
395 for (int proc_id = 0; proc_id < traceSt.getProcesses().size(); proc_id++) {
396 process = lttv_state_find_process(traceSt, traceSt
397 .getProcesses().get(proc_id).getCpu(), traceSt
398 .getProcesses().get(proc_id).getPid());
8035003b 399
dfaf8391
FC
400 if (process != null) {
401 // Replace the C call :
402 // hashed_process_data =
403 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
404 TimeRangeEventProcess localProcess = procContainer
405 .findProcess(process.getPid(), process
406 .getCreation_time().getValue(), traceSt
407 .getTraceId());
408 if (localProcess != null) {
409 // Call the function that will does the actual
410 // drawing
41dc35d0
FC
411 makeDraw(traceSt, trcEvent.getTimestamp()
412 .getValue(), process, localProcess, params);
dfaf8391
FC
413 } else {
414 TraceDebug
415 .debug("localProcess is null! (getStateDumpEndHandler)");
416 }
417 } else {
418 TraceDebug
419 .debug("Process is null! (getStateDumpEndHandler)");
8035003b 420 }
8035003b
ASL
421 }
422
423 return false;
dfaf8391 424
8035003b
ASL
425 }
426
427 // @Override
428 public Events getEventHandleType() {
429 return eventType;
430 }
431 };
432
433 return handler;
434 }
435
436}
This page took 0.04238 seconds and 5 git commands to generate.