1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.controlflow
.evProcessor
;
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
;
25 * Creates instances of specific before state update handlers, per corresponding
31 class FlowTRangeBeforeUpdateHandlers
{
34 * Handles: LTT_EVENT_SYSCALL_ENTRY
36 * Replace C function named "before_execmode_hook" in eventhooks.c
40 final IEventProcessing
getStateModesHandler() {
41 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
43 // this method is common to many events
44 private Events eventType
= Events
.LTT_EVENT_SYSCALL_ENTRY
;
47 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
49 Long cpu
= trcEvent
.getCpuId();
50 LttngProcessState stateProcess
= traceSt
.getRunning_process()
52 // TraceDebug.debug("Before handler called");
53 String traceId
= traceSt
.getTraceId();
55 if (stateProcess
!= null) {
56 // Find process within the list of registered time-range
60 // key process attributes to look for it or store it
61 // are: pid, birth, trace_num, note: cpu not relevant since
64 TimeRangeEventProcess localProcess
= procContainer
65 .findProcess(stateProcess
.getPid(), stateProcess
66 .getCreation_time().getValue(), traceId
);
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
);
77 // Do the actual drawing
78 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
79 stateProcess
, localProcess
, params
);
82 .debug("Running process is null! (getStateModesHandler)");
89 public Events
getEventHandleType() {
98 * Handles: LTT_EVENT_SCHED_SCHEDULE
100 * Replace C function named "before_schedchange_hook" in eventhooks.c
102 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE (?)
107 final IEventProcessing
getBeforeSchedChangeHandler() {
108 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
110 private Events eventType
= Events
.LTT_EVENT_SCHED_SCHEDULE
;
113 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
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
);
120 // This is useless even in Lttv !!
121 // Long state_out = getAFieldLong(trcEvent, traceSt,
122 // Fields.LTT_FIELD_PREV_STATE);
124 // We need to process information.
125 LttngProcessState process
= traceSt
.getRunning_process().get(
126 trcEvent
.getCpuId());
128 if (process
!= null) {
129 if (process
.getPid().equals(pid_out
) == false) {
131 // process = lttv_state_find_process(ts,tfs->cpu,
133 process
= lttv_state_find_process(traceSt
, trcEvent
134 .getCpuId(), pid_out
);
136 // guint trace_num = ts->parent.index;
139 if (process
!= null) {
141 // Is this call really replace these two C lines ??
142 // HashedProcessData *hashed_process_data = NULL;
143 // hashed_process_data =
144 // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
145 TimeRangeEventProcess localProcess
= procContainer
146 .findProcess(process
.getPid(), process
147 .getCreation_time().getValue(), traceSt
150 // Add process to process list if not present
152 // 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);
153 if (localProcess
== null) {
154 TmfTimeRange timeRange
= traceSt
.getInputDataRef()
155 .getTraceTimeWindow();
156 localProcess
= addLocalProcess(process
, timeRange
157 .getStartTime().getValue(), timeRange
158 .getEndTime().getValue(), traceSt
162 // Do the actual drawing
163 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
165 localProcess
, params
);
167 // Process may be null if the process started BEFORE the
169 // TraceDebug.debug("Process is null for pid_out! (getBeforeSchedChangeHandler)");
172 process
= lttv_state_find_process(traceSt
, trcEvent
173 .getCpuId(), pid_in
);
175 if (process
!= null) {
177 // Is this call really replace these two C lines ??
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
184 .getCreation_time().getValue(), traceSt
187 // Add process to process list if not present
189 // processlist_add(process_list, drawing, pid_in,
190 // process->tgid, tfs->cpu, process->ppid, &birth,
191 // trace_num, process->name, process->brand, &pl_height,
192 // &process_info, &hashed_process_data);
193 if (localProcess
== null) {
194 TmfTimeRange timeRange
= traceSt
.getInputDataRef()
195 .getTraceTimeWindow();
196 localProcess
= addLocalProcess(process
, timeRange
197 .getStartTime().getValue(), timeRange
198 .getEndTime().getValue(), traceSt
202 // Do the actual drawing
203 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
205 localProcess
, params
);
208 // Process can be null if it started AFTER the trace
209 // end. Do nothing...
210 // TraceDebug.debug("No process found for pid_in! Something is wrong? (getBeforeSchedChangeHandler)");
214 .debug("Running process is null! (getBeforeSchedChangeHandler)");
221 public Events
getEventHandleType() {
231 * Handles: LTT_EVENT_PROCESS_EXIT
233 * Replace C function named "before_process_exit_hook" in eventhooks.c
237 final IEventProcessing
getProcessExitHandler() {
238 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
240 private Events eventType
= Events
.LTT_EVENT_PROCESS_EXIT
;
243 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
245 // We need to process information.
246 LttngProcessState process
= traceSt
.getRunning_process().get(
247 trcEvent
.getCpuId());
249 if (process
!= null) {
251 // This C call does not seem to be possible, as we have no
252 // "current_process" in LttngTraceState
253 // hashed_process_data =
254 // process_list->current_hash_data[trace_num][cpu];
257 // Is this call really replace these two C lines ??
258 // HashedProcessData *hashed_process_data = NULL;
259 // hashed_process_data =
260 // processlist_get_process_data(process_list, pid,
261 // process->cpu, &birth,trace_num);
262 TimeRangeEventProcess localProcess
= procContainer
263 .findProcess(process
.getPid(), process
264 .getCreation_time().getValue(), traceSt
267 // Add process to process list if not present
269 // processlist_add(process_list, drawing, pid,
270 // process->tgid, process->cpu, process->ppid, &birth,
271 // trace_num, process->name, process->brand,&pl_height,
272 // &process_info, &hashed_process_data);
273 if (localProcess
== null) {
274 if ((process
.getPid() == 0)
275 || (process
.getPid() != process
.getPpid())) {
276 TmfTimeRange timeRange
= traceSt
.getInputDataRef()
277 .getTraceTimeWindow();
278 localProcess
= addLocalProcess(process
, timeRange
279 .getStartTime().getValue(), timeRange
280 .getEndTime().getValue(), traceSt
282 // Call the function that does the actual drawing
283 makeDraw(traceSt
, trcEvent
.getTimestamp()
284 .getValue(), process
, localProcess
, params
);
287 .debug("Pid is null or Pid == PPID! (getProcessExitHandler)");
292 .debug("Running process is null! (getProcessExitHandler)");
299 public Events
getEventHandleType() {
308 * Handles: LTT_EVENT_PROCESS_FREE
310 * Replace C function named "before_process_release_hook" in eventhooks.c
312 * Fields: LTT_FIELD_PID
317 final IEventProcessing
getProcessFreeHandler() {
318 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
320 private Events eventType
= Events
.LTT_EVENT_PROCESS_FREE
;
323 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
324 // PID of the process to release
325 Long release_pid
= getAFieldLong(trcEvent
, traceSt
,
326 Fields
.LTT_FIELD_PID
);
328 if ((release_pid
!= null)) {
329 LttngProcessState process
= lttv_state_find_process(
330 traceSt
, ANY_CPU
, release_pid
);
331 if (process
!= null) {
333 // Replace the C call :
334 // hashed_process_data =
335 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
336 TimeRangeEventProcess localProcess
= procContainer
337 .findProcess(process
.getPid(), process
338 .getCreation_time().getValue(), traceSt
341 // This is as it was in the C ... ?
342 if (localProcess
== null) {
346 // Perform the drawing
347 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
349 localProcess
, params
);
353 .debug("Release_pid is null! (getProcessFreeHandler)");
360 public Events
getEventHandleType() {
369 * Handles: LTT_EVENT_STATEDUMP_END
371 * Replace C function named "before_statedump_end" in eventhooks.c
375 final IEventProcessing
getStateDumpEndHandler() {
376 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
378 private Events eventType
= Events
.LTT_EVENT_STATEDUMP_END
;
381 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
383 // What's below should replace the following call in C :
384 // ClosureData closure_data;
385 // closure_data.events_request = events_request;
386 // closure_data.tss = tss;
387 // closure_data.end_time = evtime;
388 // convert_time_to_pixels(time_window,evtime,width,&closure_data.x_end);
389 // g_hash_table_foreach(process_list->process_hash,
390 // draw_closure,(void*)&closure_data);
392 // And the draw is always the same then...
394 LttngProcessState process
= null;
395 for (int proc_id
= 0; proc_id
< traceSt
.getProcesses().size(); proc_id
++) {
396 process
= lttv_state_find_process(traceSt
, traceSt
397 .getProcesses().get(proc_id
).getCpu(), traceSt
398 .getProcesses().get(proc_id
).getPid());
400 if (process
!= null) {
401 // Replace the C call :
402 // hashed_process_data =
403 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
404 TimeRangeEventProcess localProcess
= procContainer
405 .findProcess(process
.getPid(), process
406 .getCreation_time().getValue(), traceSt
408 if (localProcess
!= null) {
409 // Call the function that will does the actual
411 makeDraw(traceSt
, trcEvent
.getTimestamp()
412 .getValue(), process
, localProcess
, params
);
415 .debug("localProcess is null! (getStateDumpEndHandler)");
419 .debug("Process is null! (getStateDumpEndHandler)");
428 public Events
getEventHandleType() {