(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / controlflow / evProcessor / FlowAfterUpdateHandlers.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 after state update handlers, per corresponding
25 * event.
26 *
27 * @author alvaro
28 *
29 */
30 class FlowAfterUpdateHandlers {
31 /**
32 * <p>
33 * Handles: LTT_EVENT_SCHED_SCHEDULE
34 * </p>
35 * Replace C function "after_schedchange_hook" in eventhooks.c
36 * <p>
37 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID
38 * </p>
39 *
40 * @return
41 */
42 final ILttngEventProcessor getSchedChangeHandler() {
43 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
44
45 // @Override
46 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
47
48 // get event time, cpu, trace_number, process, pid
49 LttngProcessState process_in = traceSt.getRunning_process().get(trcEvent.getCpuId());
50
51 // pid_out is never used, even in LTTv!
52 //Long pid_out = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PREV_PID);
53 Long pid_in = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_NEXT_PID);
54
55 if ( !(pid_in.equals(process_in.getPid())) ) {
56 TraceDebug.debug("pid_in != PID! (getSchedChangeHandler)");
57 }
58
59 //hashed_process_data = processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
60 TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCpu(), traceSt.getTraceId(),process_in.getCreation_time() );
61
62 if ( localProcess == null ) {
63 if ( (pid_in == 0) || (pid_in != process_in.getPpid()) ) {
64 TmfTimeRange timeRange = traceSt.getContext().getTraceTimeWindow();
65 localProcess = addLocalProcess(process_in, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId());
66 }
67 else {
68 TraceDebug
69 .debug("pid_in is not 0 or pid_in == PPID! (getSchedChangeHandler)");
70 }
71 }
72
73 // There is no drawing done by the C code below, only refreshing
74 // the references to the current hash data to make it ready for
75 // next event
76
77 // This current implementation does not support the use of
78 // current hashed data
79 // although an equivalent would be good in order to improve the
80 // time to find the currently running process per cpu.
81 /*
82 if(ltt_time_compare(hashed_process_data_in->next_good_time, evtime) <= 0)
83 {
84 TimeWindow time_window = lttvwindow_get_time_window(control_flow_data->tab);
85
86 #ifdef EXTRA_CHECK
87 if(ltt_time_compare(evtime, time_window.start_time) == -1 || ltt_time_compare(evtime, time_window.end_time) == 1)
88 return FALSE;
89 #endif //EXTRA_CHECK
90
91 Drawing_t *drawing = control_flow_data->drawing;
92 guint width = drawing->width;
93 guint new_x;
94
95 convert_time_to_pixels(time_window,evtime,width,&new_x);
96
97 if(hashed_process_data_in->x.middle != new_x) {
98 hashed_process_data_in->x.middle = new_x;
99 hashed_process_data_in->x.middle_used = FALSE;
100 hashed_process_data_in->x.middle_marked = FALSE;
101 }
102 }*/
103
104 return false;
105
106 }
107 };
108 return handler;
109 }
110
111 /**
112 * <p>
113 * Handles: LTT_EVENT_PROCESS_FORK
114 * </p>
115 * Replace C function "after_process_fork_hook" in eventhooks.c
116 * <p>
117 * Fields: LTT_FIELD_CHILD_PID
118 * </p>
119 *
120 * @return
121 */
122 final ILttngEventProcessor getProcessForkHandler() {
123 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
124
125 // @Override
126 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
127
128 Long child_pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_CHILD_PID);
129 LttngProcessState process_child = lttv_state_find_process(traceSt, trcEvent.getCpuId(), child_pid );
130
131 if ( process_child != null ) {
132 TimeRangeEventProcess localProcess = procContainer.findProcess(process_child.getPid(), process_child.getCpu(), traceSt.getTraceId(), process_child.getCreation_time() );
133
134 if ( localProcess == null ) {
135 if ( (child_pid == 0) || (child_pid != process_child.getPpid()) ) {
136 TmfTimeRange timeRange = traceSt.getContext().getTraceTimeWindow();
137 localProcess = addLocalProcess(process_child, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId());
138 }
139 else {
140 TraceDebug.debug("localProcess is null with child_pid not 0 or child_pid equals PPID (getProcessForkHandler)");
141 }
142 } else {
143 // If we found the process, the Ppid and the Tgid might
144 // be missing, let's add them
145 localProcess.setPpid(process_child.getPpid());
146 localProcess.setTgid(process_child.getTgid());
147 }
148 }
149 else {
150 TraceDebug.debug("process_child is null! (getProcessForkHandler)");
151 }
152
153 return false;
154 }
155 };
156 return handler;
157 }
158
159 /**
160 * <p>
161 * Handles: LTT_EVENT_PROCESS_EXIT
162 * </p>
163 * Replace C function "after_process_exit_hook" in eventhooks.c
164 *
165 * @return
166 */
167 final ILttngEventProcessor getProcessExitHandler() {
168 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
169
170 // @Override
171 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
172
173 LttngProcessState process = traceSt.getRunning_process().get(trcEvent.getCpuId());
174
175 if ( process != null ) {
176
177 // *** TODO: ***
178 // We shall look into a way to find the current process
179 // faster, see the c library
180 // (current_hash) in order to speed up the find. see c-code
181 // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){
182 // hashed_process_data = process_list->current_hash_data[trace_num][cpu];
183 // }
184 TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time());
185
186 if ( localProcess == null ) {
187 if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) {
188 TmfTimeRange timeRange = traceSt.getContext().getTraceTimeWindow();
189 localProcess = addLocalProcess(process, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId());
190 }
191 else {
192 TraceDebug.debug("process pid is not 0 or pid equals ppid! (getProcessExitHandler)");
193 }
194 }
195 }
196 else {
197 TraceDebug.debug("process is null! (getProcessExitHandler)");
198 }
199
200 return false;
201 }
202 };
203 return handler;
204 }
205
206
207 /**
208 * <p>
209 * Handles: LTT_EVENT_EXEC
210 * </p>
211 * Replace C function "after_fs_exec_hook" in eventhooks.c
212 *
213 * @return
214 */
215 final ILttngEventProcessor getProcessExecHandler() {
216 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
217
218 // @Override
219 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
220
221 LttngProcessState process = traceSt.getRunning_process().get(trcEvent.getCpuId());
222
223 if ( process != null ) {
224
225 TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time());
226
227 if ( localProcess == null ) {
228 if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) {
229 TmfTimeRange timeRange = traceSt.getContext().getTraceTimeWindow();
230 localProcess = addLocalProcess(process, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId());
231 }
232 else {
233 TraceDebug.debug("process pid is not 0 or pid equals ppid! (getProcessExecHandler)");
234 }
235 }
236 else {
237 // If we found the process, the name might be missing. Let's add it here.
238 localProcess.setName(process.getName());
239 }
240 }
241 else {
242 TraceDebug.debug("process is null! (getProcessExecHandler)");
243 }
244
245 return false;
246 }
247 };
248 return handler;
249 }
250
251 /**
252 * <p>
253 * LTT_EVENT_THREAD_BRAND
254 * </p>
255 * Replace C function "after_user_generic_thread_brand_hook" in eventhooks.c
256 *
257 * @return
258 */
259 final ILttngEventProcessor GetThreadBrandHandler() {
260 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
261
262 // @Override
263 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
264
265 LttngProcessState process = traceSt.getRunning_process().get(trcEvent.getCpuId());
266
267 if ( process != null ) {
268
269 // Similar to above comments, implement a faster way to find
270 // the local process
271 // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){
272 // hashed_process_data = process_list->current_hash_data[trace_num][cpu];
273 // }
274 TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time());
275
276 if ( localProcess == null ) {
277 if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) {
278 TmfTimeRange timeRange = traceSt.getContext().getTraceTimeWindow();
279 localProcess = addLocalProcess(process, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId());
280 }
281 else {
282 TraceDebug.debug("process pid is not 0 or pid equals ppid! (GetThreadBrandHandler)");
283 }
284 }
285 else {
286 // If we found the process, the brand might be missing
287 // on it, add it.
288 localProcess.setBrand(process.getBrand());
289 }
290 }
291 else {
292 TraceDebug.debug("process is null! (GetThreadBrandHandler)");
293 }
294
295 return false;
296
297 }
298 };
299 return handler;
300 }
301
302 /**
303 * <p>
304 * LTT_EVENT_PROCESS_STATE
305 * </p>
306 * Replace C function "after_event_enum_process_hook" in eventhooks.c
307 * <p>
308 * <p>
309 * Creates the processlist entry for the child process. Put the last
310 * position in x at the current time value.
311 * </p>
312 *
313 * <p>
314 * Fields: LTT_FIELD_PID
315 * </p>
316 *
317 * @return
318 */
319 final ILttngEventProcessor getEnumProcessStateHandler() {
320 AbsFlowTRangeUpdate handler = new AbsFlowTRangeUpdate() {
321
322 // @Override
323 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
324
325 int first_cpu;
326 int nb_cpus;
327
328 Long pid_in = getAFieldLong(trcEvent, traceSt,
329 Fields.LTT_FIELD_PID);
330
331 // Lttv assume that pid_in will NEVER be null or incoherent
332 // What if ... ? (let's add some debug)
333 if ( pid_in != null ) {
334 if(pid_in == 0L) {
335 first_cpu = 0;
336 nb_cpus = traceSt.getNumberOfCPUs();
337 }
338 else {
339 first_cpu = ANY_CPU.intValue();
340 nb_cpus = ANY_CPU.intValue() + 1;
341 }
342
343 for (int cpu = first_cpu; cpu < nb_cpus; cpu++) {
344 LttngProcessState process_in = lttv_state_find_process(traceSt, trcEvent.getCpuId(), pid_in );
345
346 if ( process_in != null ) {
347 TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCpu(), traceSt.getTraceId(), process_in.getCreation_time());
348
349 if (localProcess == null) {
350 if ( (process_in.getPid() == 0) || (process_in.getPid() != process_in.getPpid()) ) {
351 TmfTimeRange timeRange = traceSt.getContext().getTraceTimeWindow();
352 localProcess = addLocalProcess(process_in, timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue(), traceSt.getTraceId());
353 }
354 else {
355 TraceDebug.debug("process pid is not 0 or pid equals ppid! (getEnumProcessStateHandler)");
356 }
357 }
358 else {
359 // If the process was found, it might be missing informations, add it here
360 localProcess.setName(process_in.getName());
361 localProcess.setPpid(process_in.getPpid());
362 localProcess.setTgid(process_in.getTgid());
363 }
364 }
365 else {
366 TraceDebug.debug("process_in is null! This should never happen. (getEnumProcessStateHandler)");
367 }
368 }
369 }
370 else {
371 TraceDebug.debug("pid_in is null! This should never happen, really... (getEnumProcessStateHandler)");
372 }
373
374 return false;
375 }
376 };
377 return handler;
378 }
379
380 }
This page took 0.03927 seconds and 5 git commands to generate.