20362e3f8a2efaa4806196c51ce09de4a901b4d0
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / controlflow / evProcessor / FlowTRangeBeforeUpdateHandlers.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.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 before state update handlers, per corresponding
26 * event.
27 *
28 * @author alvaro
29 *
30 */
31 class 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
65 .findProcess(stateProcess.getPid(), stateProcess.getCpu(), traceId, stateProcess
66 .getCreation_time().getValue());
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
78 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
79 stateProcess, localProcess, params);
80 } else {
81 TraceDebug
82 .debug("Running state process is null! (getStateModesHandler)");
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) {
140 // TODO: Implement something similar to current hash in
141 // order to keep track of the current process and speed
142 // up finding the local resource.
143
144 // HashedProcessData *hashed_process_data = NULL;
145 // hashed_process_data =
146 // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
147 TimeRangeEventProcess localProcess = procContainer
148 .findProcess(process.getPid(), process.getCpu(), traceSt
149 .getTraceId(), process.getCreation_time().getValue());
150
151 // Add process to process list if not present
152 // Replace C Call :
153 // 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);
154 if (localProcess == null) {
155 TmfTimeRange timeRange = traceSt.getInputDataRef()
156 .getTraceTimeWindow();
157 localProcess = addLocalProcess(process, timeRange
158 .getStartTime().getValue(), timeRange
159 .getEndTime().getValue(), traceSt
160 .getTraceId());
161 }
162
163 // Do the actual drawing
164 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
165 process,
166 localProcess, params);
167 } else {
168 // Process may be null if the process started BEFORE the
169 // trace start
170 // TraceDebug.debug("Process is null for pid_out! (getBeforeSchedChangeHandler)");
171 }
172
173 // PID_IN section
174 process = lttv_state_find_process(traceSt, trcEvent
175 .getCpuId(), pid_in);
176
177 if (process != null) {
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
183 .findProcess(process.getPid(), process.getCpu(), traceSt
184 .getTraceId(), process.getCreation_time().getValue());
185
186 // Add process to process list if not present
187 // Replace C Call :
188 // processlist_add(process_list, drawing, pid_in,
189 // process->tgid, tfs->cpu, process->ppid, &birth,
190 // trace_num, process->name, process->brand, &pl_height,
191 // &process_info, &hashed_process_data);
192 if (localProcess == null) {
193 TmfTimeRange timeRange = traceSt.getInputDataRef()
194 .getTraceTimeWindow();
195 localProcess = addLocalProcess(process, timeRange
196 .getStartTime().getValue(), timeRange
197 .getEndTime().getValue(), traceSt
198 .getTraceId());
199 }
200
201 // Do the actual drawing
202 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
203 process,
204 localProcess, params);
205
206 } else {
207 // Process can be null if it started AFTER the trace
208 // end. Do nothing...
209 // TraceDebug.debug("No process found for pid_in! Something is wrong? (getBeforeSchedChangeHandler)");
210 }
211 } else {
212 TraceDebug
213 .debug("Running process is null! (getBeforeSchedChangeHandler)");
214 }
215
216 return false;
217 }
218
219 // @Override
220 public Events getEventHandleType() {
221 return eventType;
222 }
223 };
224
225 return handler;
226 }
227
228 /**
229 * <p>
230 * Handles: LTT_EVENT_PROCESS_EXIT
231 * </p>
232 * Replace C function named "before_process_exit_hook" in eventhooks.c
233 *
234 * @return
235 */
236 final IEventProcessing getProcessExitHandler() {
237 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
238
239 private Events eventType = Events.LTT_EVENT_PROCESS_EXIT;
240
241 // @Override
242 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
243
244 // We need to process information.
245 LttngProcessState process = traceSt.getRunning_process().get(
246 trcEvent.getCpuId());
247
248 if (process != null) {
249 // TODO: Implement a similar method to track the current
250 // local process in order to speed up finding the local
251 // resource
252
253 // hashed_process_data =
254 // processlist_get_process_data(process_list, pid,
255 // process->cpu, &birth,trace_num);
256 TimeRangeEventProcess localProcess = procContainer
257 .findProcess(process.getPid(), process.getCpu(), traceSt
258 .getTraceId(), process.getCreation_time().getValue());
259
260 // Add process to process list if not present
261 // Replace C Call :
262 // processlist_add(process_list, drawing, pid,
263 // process->tgid, process->cpu, process->ppid, &birth,
264 // trace_num, process->name, process->brand,&pl_height,
265 // &process_info, &hashed_process_data);
266 if (localProcess == null) {
267 TmfTimeRange timeRange = traceSt.getInputDataRef()
268 .getTraceTimeWindow();
269 localProcess = addLocalProcess(process, timeRange
270 .getStartTime().getValue(), timeRange
271 .getEndTime().getValue(), traceSt.getTraceId());
272 }
273
274 // Call the function that does the actual drawing
275 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
276 process, localProcess, params);
277
278 } else {
279 TraceDebug
280 .debug("Running process is null! (getProcessExitHandler)");
281 }
282
283 return false;
284 }
285
286 // @Override
287 public Events getEventHandleType() {
288 return eventType;
289 }
290 };
291 return handler;
292 }
293
294 /**
295 * <p>
296 * Handles: LTT_EVENT_PROCESS_FREE
297 * </p>
298 * Replace C function named "before_process_release_hook" in eventhooks.c
299 * <p>
300 * Fields: LTT_FIELD_PID
301 * </p>
302 *
303 * @return
304 */
305 final IEventProcessing getProcessFreeHandler() {
306 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
307
308 private Events eventType = Events.LTT_EVENT_PROCESS_FREE;
309
310 // @Override
311 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
312 // PID of the process to release
313 Long release_pid = getAFieldLong(trcEvent, traceSt,
314 Fields.LTT_FIELD_PID);
315
316 if ((release_pid != null)) {
317 LttngProcessState process = lttv_state_find_process(
318 traceSt, ANY_CPU, release_pid);
319 if (process != null) {
320
321 // Replace the C call :
322 // hashed_process_data =
323 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
324 TimeRangeEventProcess localProcess = procContainer
325 .findProcess(process.getPid(), process.getCpu(), traceSt
326 .getTraceId(), process
327 .getCreation_time().getValue());
328
329 // This is as it was in the C ... ?
330 if (localProcess == null) {
331 return false;
332 }
333
334 // Perform the drawing
335 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
336 process,
337 localProcess, params);
338 }
339 } else {
340 TraceDebug
341 .debug("Release_pid is null! (getProcessFreeHandler)");
342 }
343
344 return false;
345 }
346
347 // @Override
348 public Events getEventHandleType() {
349 return eventType;
350 }
351 };
352 return handler;
353 }
354
355 /**
356 * <p>
357 * Handles: LTT_EVENT_STATEDUMP_END
358 * </p>
359 * Replace C function named "before_statedump_end" in eventhooks.c
360 *
361 * @return
362 */
363 final IEventProcessing getStateDumpEndHandler() {
364 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
365
366 private Events eventType = Events.LTT_EVENT_STATEDUMP_END;
367
368 // @Override
369 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
370
371 // What's below should replace the following call in C :
372 // ClosureData closure_data;
373 // closure_data.events_request = events_request;
374 // closure_data.tss = tss;
375 // closure_data.end_time = evtime;
376 // convert_time_to_pixels(time_window,evtime,width,&closure_data.x_end);
377 // g_hash_table_foreach(process_list->process_hash,
378 // draw_closure,(void*)&closure_data);
379 //
380 // And the draw is always the same then...
381
382 // The c-library loops through the local processes, search for
383 // the local processes in the state provider and then draws
384 // If it's present is the local processes why shuldn't they be
385 // present in the state provider?
386 // This seems more direct. and makes sure all processes are
387 // reflected in the control flow view.
388 LttngProcessState[] processes = traceSt.getProcesses();
389 for (int pos=0; pos < processes.length; pos++) {
390 LttngProcessState process = processes[pos];
391
392 // Replace the C call :
393 // hashed_process_data =
394 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
395 TimeRangeEventProcess localProcess = procContainer
396 .findProcess(process.getPid(), process.getCpu(), traceSt
397 .getTraceId(), process
398 .getCreation_time().getValue());
399
400 // Add process to process list if not present
401 if (localProcess == null) {
402 TmfTimeRange timeRange = traceSt.getInputDataRef()
403 .getTraceTimeWindow();
404 localProcess = addLocalProcess(process, timeRange
405 .getStartTime().getValue(), timeRange
406 .getEndTime().getValue(), traceSt.getTraceId());
407 }
408
409 // Call the function that will does the actual
410 // drawing
411 makeDraw(traceSt, trcEvent.getTimestamp().getValue(),
412 process, localProcess, params);
413 }
414
415 return false;
416 }
417
418 // @Override
419 public Events getEventHandleType() {
420 return eventType;
421 }
422 };
423
424 return handler;
425 }
426
427 }
This page took 0.0403 seconds and 4 git commands to generate.