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