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