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
.getCpu(), traceId
, stateProcess
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 state 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) {
140 // TODO: Implement something similar to current hash in
141 // order to keep track of the current process and speed
142 // up finding the local resource.
144 // HashedProcessData *hashed_process_data = NULL;
145 // hashed_process_data =
146 // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
147 TimeRangeEventProcess localProcess
= procContainer
148 .findProcess(process
.getPid(), process
.getCpu(), traceSt
149 .getTraceId(), process
.getCreation_time());
151 // Add process to process list if not present
153 // 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);
154 if (localProcess
== null) {
155 TmfTimeRange timeRange
= traceSt
.getInputDataRef()
156 .getTraceTimeWindow();
157 localProcess
= addLocalProcess(process
, timeRange
158 .getStartTime().getValue(), timeRange
159 .getEndTime().getValue(), traceSt
163 // Do the actual drawing
164 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
166 localProcess
, params
);
168 // Process may be null if the process started BEFORE the
170 // TraceDebug.debug("Process is null for pid_out! (getBeforeSchedChangeHandler)");
174 process
= lttv_state_find_process(traceSt
, trcEvent
175 .getCpuId(), pid_in
);
177 if (process
!= null) {
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
.getCpu(), traceSt
184 .getTraceId(), process
.getCreation_time());
186 // Add process to process list if not present
188 // processlist_add(process_list, drawing, pid_in,
189 // process->tgid, tfs->cpu, process->ppid, &birth,
190 // trace_num, process->name, process->brand, &pl_height,
191 // &process_info, &hashed_process_data);
192 if (localProcess
== null) {
193 TmfTimeRange timeRange
= traceSt
.getInputDataRef()
194 .getTraceTimeWindow();
195 localProcess
= addLocalProcess(process
, timeRange
196 .getStartTime().getValue(), timeRange
197 .getEndTime().getValue(), traceSt
201 // Do the actual drawing
202 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
204 localProcess
, params
);
207 // Process can be null if it started AFTER the trace
208 // end. Do nothing...
209 // TraceDebug.debug("No process found for pid_in! Something is wrong? (getBeforeSchedChangeHandler)");
213 .debug("Running process is null! (getBeforeSchedChangeHandler)");
220 public Events
getEventHandleType() {
230 * Handles: LTT_EVENT_PROCESS_EXIT
232 * Replace C function named "before_process_exit_hook" in eventhooks.c
236 final IEventProcessing
getProcessExitHandler() {
237 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
239 private Events eventType
= Events
.LTT_EVENT_PROCESS_EXIT
;
242 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
244 // We need to process information.
245 LttngProcessState process
= traceSt
.getRunning_process().get(
246 trcEvent
.getCpuId());
248 if (process
!= null) {
249 // TODO: Implement a similar method to track the current
250 // local process in order to speed up finding the local
253 // hashed_process_data =
254 // processlist_get_process_data(process_list, pid,
255 // process->cpu, &birth,trace_num);
256 TimeRangeEventProcess localProcess
= procContainer
257 .findProcess(process
.getPid(), process
.getCpu(), traceSt
258 .getTraceId(), process
.getCreation_time());
260 // Add process to process list if not present
262 // processlist_add(process_list, drawing, pid,
263 // process->tgid, process->cpu, process->ppid, &birth,
264 // trace_num, process->name, process->brand,&pl_height,
265 // &process_info, &hashed_process_data);
266 if (localProcess
== null) {
267 TmfTimeRange timeRange
= traceSt
.getInputDataRef()
268 .getTraceTimeWindow();
269 localProcess
= addLocalProcess(process
, timeRange
270 .getStartTime().getValue(), timeRange
271 .getEndTime().getValue(), traceSt
.getTraceId());
274 // Call the function that does the actual drawing
275 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
276 process
, localProcess
, params
);
280 .debug("Running process is null! (getProcessExitHandler)");
287 public Events
getEventHandleType() {
296 * Handles: LTT_EVENT_PROCESS_FREE
298 * Replace C function named "before_process_release_hook" in eventhooks.c
300 * Fields: LTT_FIELD_PID
305 final IEventProcessing
getProcessFreeHandler() {
306 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
308 private Events eventType
= Events
.LTT_EVENT_PROCESS_FREE
;
311 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
312 // PID of the process to release
313 Long release_pid
= getAFieldLong(trcEvent
, traceSt
,
314 Fields
.LTT_FIELD_PID
);
316 if ((release_pid
!= null)) {
317 LttngProcessState process
= lttv_state_find_process(
318 traceSt
, ANY_CPU
, release_pid
);
319 if (process
!= null) {
321 // Replace the C call :
322 // hashed_process_data =
323 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
324 TimeRangeEventProcess localProcess
= procContainer
325 .findProcess(process
.getPid(), process
.getCpu(), traceSt
326 .getTraceId(), process
327 .getCreation_time());
329 // This is as it was in the C ... ?
330 if (localProcess
== null) {
334 // Perform the drawing
335 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
337 localProcess
, params
);
341 .debug("Release_pid is null! (getProcessFreeHandler)");
348 public Events
getEventHandleType() {
357 * Handles: LTT_EVENT_STATEDUMP_END
359 * Replace C function named "before_statedump_end" in eventhooks.c
363 final IEventProcessing
getStateDumpEndHandler() {
364 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
366 private Events eventType
= Events
.LTT_EVENT_STATEDUMP_END
;
369 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
371 // What's below should replace the following call in C :
372 // ClosureData closure_data;
373 // closure_data.events_request = events_request;
374 // closure_data.tss = tss;
375 // closure_data.end_time = evtime;
376 // convert_time_to_pixels(time_window,evtime,width,&closure_data.x_end);
377 // g_hash_table_foreach(process_list->process_hash,
378 // draw_closure,(void*)&closure_data);
380 // And the draw is always the same then...
382 // The c-library loops through the local processes, search for
383 // the local processes in the state provider and then draws
384 // If it's present is the local processes why shuldn't they be
385 // present in the state provider?
386 // This seems more direct. and makes sure all processes are
387 // reflected in the control flow view.
388 LttngProcessState
[] processes
= traceSt
.getProcesses();
389 for (int pos
=0; pos
< processes
.length
; pos
++) {
390 LttngProcessState process
= processes
[pos
];
392 // Replace the C call :
393 // hashed_process_data =
394 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
395 TimeRangeEventProcess localProcess
= procContainer
396 .findProcess(process
.getPid(), process
.getCpu(), traceSt
397 .getTraceId(), process
398 .getCreation_time());
400 // Add process to process list if not present
401 if (localProcess
== null) {
402 TmfTimeRange timeRange
= traceSt
.getInputDataRef()
403 .getTraceTimeWindow();
404 localProcess
= addLocalProcess(process
, timeRange
405 .getStartTime().getValue(), timeRange
406 .getEndTime().getValue(), traceSt
.getTraceId());
409 // Call the function that will does the actual
411 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
412 process
, localProcess
, params
);
419 public Events
getEventHandleType() {