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