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 / FlowBeforeUpdateHandlers.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 before state update handlers, per corresponding
25 * event.
26 *
27 * @author alvaro
28 *
29 */
30 class FlowBeforeUpdateHandlers {
31 /**
32 * <p>
33 * Handles: LTT_EVENT_SYSCALL_ENTRY
34 * </p>
35 * Replace C function named "before_execmode_hook" in eventhooks.c
36 *
37 * @return
38 */
39 final ILttngEventProcessor getStateModesHandler() {
40 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
41
42 // @Override
43 @Override
44 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
45
46 Long cpu = trcEvent.getCpuId();
47 LttngProcessState stateProcess = traceSt.getRunning_process()
48 .get(cpu);
49 // TraceDebug.debug("Before handler called");
50 String traceId = traceSt.getTraceId();
51
52 if (stateProcess != null) {
53 // Find process within the list of registered time-range
54 // related
55 // processes
56
57 // key process attributes to look for it or store it
58 // are: pid, birth, trace_num, note: cpu not relevant since
59 // it
60 // may change
61 TimeRangeEventProcess localProcess = procContainer
62 .findProcess(stateProcess.getPid(), stateProcess.getCpu(), traceId, stateProcess
63 .getCreation_time());
64
65 // Add process to process list if not present
66 if (localProcess == null) {
67 TmfTimeRange timeRange = traceSt.getContext()
68 .getTraceTimeWindow();
69 localProcess = addLocalProcess(stateProcess, timeRange
70 .getStartTime().getValue(), timeRange
71 .getEndTime().getValue(), traceId);
72 }
73
74 // Do the actual drawing
75 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
76 stateProcess, localProcess, params);
77 } else {
78 TraceDebug
79 .debug("Running state process is null! (getStateModesHandler)");
80 }
81
82 return false;
83 }
84 };
85 return handler;
86 }
87
88 /**
89 * <p>
90 * Handles: LTT_EVENT_SCHED_SCHEDULE
91 * </p>
92 * Replace C function named "before_schedchange_hook" in eventhooks.c
93 * <p>
94 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE (?)
95 * </p>
96 *
97 * @return
98 */
99 final ILttngEventProcessor getBeforeSchedChangeHandler() {
100 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
101
102 // @Override
103 @Override
104 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
105
106 Long pid_out = getAFieldLong(trcEvent, traceSt,
107 Fields.LTT_FIELD_PREV_PID);
108 Long pid_in = getAFieldLong(trcEvent, traceSt,
109 Fields.LTT_FIELD_NEXT_PID);
110
111 // This is useless even in Lttv !!
112 // Long state_out = getAFieldLong(trcEvent, traceSt,
113 // Fields.LTT_FIELD_PREV_STATE);
114
115 // We need to process information.
116 LttngProcessState process = traceSt.getRunning_process().get(
117 trcEvent.getCpuId());
118
119 if (process != null) {
120 if (process.getPid().equals(pid_out) == false) {
121 // To replace :
122 // process = lttv_state_find_process(ts,tfs->cpu,
123 // pid_out);
124 process = lttv_state_find_process(traceSt, trcEvent
125 .getCpuId(), pid_out);
126 // Also, removed :
127 // guint trace_num = ts->parent.index;
128 }
129
130 if (process != null) {
131 // TODO: Implement something similar to current hash in
132 // order to keep track of the current process and speed
133 // up finding the local resource.
134
135 // HashedProcessData *hashed_process_data = NULL;
136 // hashed_process_data =
137 // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
138 TimeRangeEventProcess localProcess = procContainer
139 .findProcess(process.getPid(), process.getCpu(), traceSt
140 .getTraceId(), process.getCreation_time());
141
142 // Add process to process list if not present
143 // Replace C Call :
144 // 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);
145 if (localProcess == null) {
146 TmfTimeRange timeRange = traceSt.getContext()
147 .getTraceTimeWindow();
148 localProcess = addLocalProcess(process, timeRange
149 .getStartTime().getValue(), timeRange
150 .getEndTime().getValue(), traceSt
151 .getTraceId());
152 }
153
154 // Do the actual drawing
155 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
156 process,
157 localProcess, params);
158 } else {
159 // Process may be null if the process started BEFORE the
160 // trace start
161 // TraceDebug.debug("Process is null for pid_out! (getBeforeSchedChangeHandler)");
162 }
163
164 // PID_IN section
165 process = lttv_state_find_process(traceSt, trcEvent
166 .getCpuId(), pid_in);
167
168 if (process != null) {
169 // HashedProcessData *hashed_process_data = NULL;
170 // hashed_process_data =
171 // processlist_get_process_data(process_list, pid_in,
172 // tfs->cpu, &birth, trace_num);
173 TimeRangeEventProcess localProcess = procContainer
174 .findProcess(process.getPid(), process.getCpu(), traceSt
175 .getTraceId(), process.getCreation_time());
176
177 // Add process to process list if not present
178 // Replace C Call :
179 // processlist_add(process_list, drawing, pid_in,
180 // process->tgid, tfs->cpu, process->ppid, &birth,
181 // trace_num, process->name, process->brand, &pl_height,
182 // &process_info, &hashed_process_data);
183 if (localProcess == null) {
184 TmfTimeRange timeRange = traceSt.getContext()
185 .getTraceTimeWindow();
186 localProcess = addLocalProcess(process, timeRange
187 .getStartTime().getValue(), timeRange
188 .getEndTime().getValue(), traceSt
189 .getTraceId());
190 }
191
192 // Do the actual drawing
193 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
194 process,
195 localProcess, params);
196
197 } else {
198 // Process can be null if it started AFTER the trace
199 // end. Do nothing...
200 // TraceDebug.debug("No process found for pid_in! Something is wrong? (getBeforeSchedChangeHandler)");
201 }
202 } else {
203 TraceDebug
204 .debug("Running process is null! (getBeforeSchedChangeHandler)");
205 }
206
207 return false;
208 }
209 };
210
211 return handler;
212 }
213
214 /**
215 * <p>
216 * Handles: LTT_EVENT_PROCESS_EXIT
217 * </p>
218 * Replace C function named "before_process_exit_hook" in eventhooks.c
219 *
220 * @return
221 */
222 final ILttngEventProcessor getProcessExitHandler() {
223 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
224
225 // @Override
226 @Override
227 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
228
229 // We need to process information.
230 LttngProcessState process = traceSt.getRunning_process().get(
231 trcEvent.getCpuId());
232
233 if (process != null) {
234 // TODO: Implement a similar method to track the current
235 // local process in order to speed up finding the local
236 // resource
237
238 // hashed_process_data =
239 // processlist_get_process_data(process_list, pid,
240 // process->cpu, &birth,trace_num);
241 TimeRangeEventProcess localProcess = procContainer
242 .findProcess(process.getPid(), process.getCpu(), traceSt
243 .getTraceId(), process.getCreation_time());
244
245 // Add process to process list if not present
246 // Replace C Call :
247 // processlist_add(process_list, drawing, pid,
248 // process->tgid, process->cpu, process->ppid, &birth,
249 // trace_num, process->name, process->brand,&pl_height,
250 // &process_info, &hashed_process_data);
251 if (localProcess == null) {
252 TmfTimeRange timeRange = traceSt.getContext()
253 .getTraceTimeWindow();
254 localProcess = addLocalProcess(process, timeRange
255 .getStartTime().getValue(), timeRange
256 .getEndTime().getValue(), traceSt.getTraceId());
257 }
258
259 // Call the function that does the actual drawing
260 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
261 process, localProcess, params);
262
263 } else {
264 TraceDebug
265 .debug("Running process is null! (getProcessExitHandler)");
266 }
267
268 return false;
269 }
270 };
271 return handler;
272 }
273
274 /**
275 * <p>
276 * Handles: LTT_EVENT_PROCESS_FREE
277 * </p>
278 * Replace C function named "before_process_release_hook" in eventhooks.c
279 * <p>
280 * Fields: LTT_FIELD_PID
281 * </p>
282 *
283 * @return
284 */
285 final ILttngEventProcessor getProcessFreeHandler() {
286 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
287
288 // @Override
289 @Override
290 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
291 // PID of the process to release
292 Long release_pid = getAFieldLong(trcEvent, traceSt,
293 Fields.LTT_FIELD_PID);
294
295 if ((release_pid != null)) {
296 LttngProcessState process = lttv_state_find_process(
297 traceSt, ANY_CPU, release_pid);
298 if (process != null) {
299
300 // Replace the C call :
301 // hashed_process_data =
302 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
303 TimeRangeEventProcess localProcess = procContainer
304 .findProcess(process.getPid(), process.getCpu(), traceSt
305 .getTraceId(), process
306 .getCreation_time());
307
308 // This is as it was in the C ... ?
309 if (localProcess == null) {
310 return false;
311 }
312
313 // Perform the drawing
314 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
315 process,
316 localProcess, params);
317 }
318 } else {
319 TraceDebug
320 .debug("Release_pid is null! (getProcessFreeHandler)");
321 }
322
323 return false;
324 }
325 };
326 return handler;
327 }
328
329 /**
330 * <p>
331 * Handles: LTT_EVENT_STATEDUMP_END
332 * </p>
333 * Replace C function named "before_statedump_end" in eventhooks.c
334 *
335 * @return
336 */
337 final ILttngEventProcessor getStateDumpEndHandler() {
338 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
339
340 // @Override
341 @Override
342 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
343
344 // What's below should replace the following call in C :
345 // ClosureData closure_data;
346 // closure_data.events_request = events_request;
347 // closure_data.tss = tss;
348 // closure_data.end_time = evtime;
349 // convert_time_to_pixels(time_window,evtime,width,&closure_data.x_end);
350 // g_hash_table_foreach(process_list->process_hash,
351 // draw_closure,(void*)&closure_data);
352 //
353 // And the draw is always the same then...
354
355 // The c-library loops through the local processes, search for
356 // the local processes in the state provider and then draws
357 // If it's present is the local processes why shuldn't they be
358 // present in the state provider?
359 // This seems more direct. and makes sure all processes are
360 // reflected in the control flow view.
361 LttngProcessState[] processes = traceSt.getProcesses();
362 for (int pos=0; pos < processes.length; pos++) {
363 LttngProcessState process = processes[pos];
364
365 // Replace the C call :
366 // hashed_process_data =
367 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
368 TimeRangeEventProcess localProcess = procContainer
369 .findProcess(process.getPid(), process.getCpu(), traceSt
370 .getTraceId(), process
371 .getCreation_time());
372
373 // Add process to process list if not present
374 if (localProcess == null) {
375 TmfTimeRange timeRange = traceSt.getContext()
376 .getTraceTimeWindow();
377 localProcess = addLocalProcess(process, timeRange
378 .getStartTime().getValue(), timeRange
379 .getEndTime().getValue(), traceSt.getTraceId());
380 }
381
382 // Call the function that will does the actual
383 // drawing
384 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
385 process, localProcess, params);
386 }
387
388 return false;
389 }
390 };
391
392 return handler;
393 }
394
395 }
This page took 0.039735 seconds and 6 git commands to generate.