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
.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
;
24 * Creates instances of specific before state update handlers, per corresponding
30 class FlowBeforeUpdateHandlers
{
33 * Handles: LTT_EVENT_SYSCALL_ENTRY
35 * Replace C function named "before_execmode_hook" in eventhooks.c
39 final ILttngEventProcessor
getStateModesHandler() {
40 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
44 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
46 Long cpu
= trcEvent
.getCpuId();
47 LttngProcessState stateProcess
= traceSt
.getRunning_process()
49 // TraceDebug.debug("Before handler called");
50 String traceId
= traceSt
.getTraceId();
52 if (stateProcess
!= null) {
53 // Find process within the list of registered time-range
57 // key process attributes to look for it or store it
58 // are: pid, birth, trace_num, note: cpu not relevant since
61 TimeRangeEventProcess localProcess
= procContainer
62 .findProcess(stateProcess
.getPid(), stateProcess
.getCpu(), traceId
, stateProcess
65 // Add process to process list if not present
66 if (localProcess
== null) {
67 TmfTimeRange timeRange
= traceSt
.getContext()
68 .getTraceTimeWindow();
69 localProcess
= addLocalProcess(stateProcess
, timeRange
70 .getStartTime().getValue(), timeRange
71 .getEndTime().getValue(), traceId
);
74 // Do the actual drawing
75 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
76 stateProcess
, localProcess
, params
);
79 .debug("Running state process is null! (getStateModesHandler)");
90 * Handles: LTT_EVENT_SCHED_SCHEDULE
92 * Replace C function named "before_schedchange_hook" in eventhooks.c
94 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE (?)
99 final ILttngEventProcessor
getBeforeSchedChangeHandler() {
100 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
104 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
106 Long pid_out
= getAFieldLong(trcEvent
, traceSt
,
107 Fields
.LTT_FIELD_PREV_PID
);
108 Long pid_in
= getAFieldLong(trcEvent
, traceSt
,
109 Fields
.LTT_FIELD_NEXT_PID
);
111 // This is useless even in Lttv !!
112 // Long state_out = getAFieldLong(trcEvent, traceSt,
113 // Fields.LTT_FIELD_PREV_STATE);
115 // We need to process information.
116 LttngProcessState process
= traceSt
.getRunning_process().get(
117 trcEvent
.getCpuId());
119 if (process
!= null) {
120 if (process
.getPid().equals(pid_out
) == false) {
122 // process = lttv_state_find_process(ts,tfs->cpu,
124 process
= lttv_state_find_process(traceSt
, trcEvent
125 .getCpuId(), pid_out
);
127 // guint trace_num = ts->parent.index;
130 if (process
!= null) {
131 // TODO: Implement something similar to current hash in
132 // order to keep track of the current process and speed
133 // up finding the local resource.
135 // HashedProcessData *hashed_process_data = NULL;
136 // hashed_process_data =
137 // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
138 TimeRangeEventProcess localProcess
= procContainer
139 .findProcess(process
.getPid(), process
.getCpu(), traceSt
140 .getTraceId(), process
.getCreation_time());
142 // Add process to process list if not present
144 // 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);
145 if (localProcess
== null) {
146 TmfTimeRange timeRange
= traceSt
.getContext()
147 .getTraceTimeWindow();
148 localProcess
= addLocalProcess(process
, timeRange
149 .getStartTime().getValue(), timeRange
150 .getEndTime().getValue(), traceSt
154 // Do the actual drawing
155 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
157 localProcess
, params
);
159 // Process may be null if the process started BEFORE the
161 // TraceDebug.debug("Process is null for pid_out! (getBeforeSchedChangeHandler)");
165 process
= lttv_state_find_process(traceSt
, trcEvent
166 .getCpuId(), pid_in
);
168 if (process
!= null) {
169 // HashedProcessData *hashed_process_data = NULL;
170 // hashed_process_data =
171 // processlist_get_process_data(process_list, pid_in,
172 // tfs->cpu, &birth, trace_num);
173 TimeRangeEventProcess localProcess
= procContainer
174 .findProcess(process
.getPid(), process
.getCpu(), traceSt
175 .getTraceId(), process
.getCreation_time());
177 // Add process to process list if not present
179 // processlist_add(process_list, drawing, pid_in,
180 // process->tgid, tfs->cpu, process->ppid, &birth,
181 // trace_num, process->name, process->brand, &pl_height,
182 // &process_info, &hashed_process_data);
183 if (localProcess
== null) {
184 TmfTimeRange timeRange
= traceSt
.getContext()
185 .getTraceTimeWindow();
186 localProcess
= addLocalProcess(process
, timeRange
187 .getStartTime().getValue(), timeRange
188 .getEndTime().getValue(), traceSt
192 // Do the actual drawing
193 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
195 localProcess
, params
);
198 // Process can be null if it started AFTER the trace
199 // end. Do nothing...
200 // TraceDebug.debug("No process found for pid_in! Something is wrong? (getBeforeSchedChangeHandler)");
204 .debug("Running process is null! (getBeforeSchedChangeHandler)");
216 * Handles: LTT_EVENT_PROCESS_EXIT
218 * Replace C function named "before_process_exit_hook" in eventhooks.c
222 final ILttngEventProcessor
getProcessExitHandler() {
223 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
227 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
229 // We need to process information.
230 LttngProcessState process
= traceSt
.getRunning_process().get(
231 trcEvent
.getCpuId());
233 if (process
!= null) {
234 // TODO: Implement a similar method to track the current
235 // local process in order to speed up finding the local
238 // hashed_process_data =
239 // processlist_get_process_data(process_list, pid,
240 // process->cpu, &birth,trace_num);
241 TimeRangeEventProcess localProcess
= procContainer
242 .findProcess(process
.getPid(), process
.getCpu(), traceSt
243 .getTraceId(), process
.getCreation_time());
245 // Add process to process list if not present
247 // processlist_add(process_list, drawing, pid,
248 // process->tgid, process->cpu, process->ppid, &birth,
249 // trace_num, process->name, process->brand,&pl_height,
250 // &process_info, &hashed_process_data);
251 if (localProcess
== null) {
252 TmfTimeRange timeRange
= traceSt
.getContext()
253 .getTraceTimeWindow();
254 localProcess
= addLocalProcess(process
, timeRange
255 .getStartTime().getValue(), timeRange
256 .getEndTime().getValue(), traceSt
.getTraceId());
259 // Call the function that does the actual drawing
260 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
261 process
, localProcess
, params
);
265 .debug("Running process is null! (getProcessExitHandler)");
276 * Handles: LTT_EVENT_PROCESS_FREE
278 * Replace C function named "before_process_release_hook" in eventhooks.c
280 * Fields: LTT_FIELD_PID
285 final ILttngEventProcessor
getProcessFreeHandler() {
286 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
290 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
291 // PID of the process to release
292 Long release_pid
= getAFieldLong(trcEvent
, traceSt
,
293 Fields
.LTT_FIELD_PID
);
295 if ((release_pid
!= null)) {
296 LttngProcessState process
= lttv_state_find_process(
297 traceSt
, ANY_CPU
, release_pid
);
298 if (process
!= null) {
300 // Replace the C call :
301 // hashed_process_data =
302 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
303 TimeRangeEventProcess localProcess
= procContainer
304 .findProcess(process
.getPid(), process
.getCpu(), traceSt
305 .getTraceId(), process
306 .getCreation_time());
308 // This is as it was in the C ... ?
309 if (localProcess
== null) {
313 // Perform the drawing
314 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
316 localProcess
, params
);
320 .debug("Release_pid is null! (getProcessFreeHandler)");
331 * Handles: LTT_EVENT_STATEDUMP_END
333 * Replace C function named "before_statedump_end" in eventhooks.c
337 final ILttngEventProcessor
getStateDumpEndHandler() {
338 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
342 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
344 // What's below should replace the following call in C :
345 // ClosureData closure_data;
346 // closure_data.events_request = events_request;
347 // closure_data.tss = tss;
348 // closure_data.end_time = evtime;
349 // convert_time_to_pixels(time_window,evtime,width,&closure_data.x_end);
350 // g_hash_table_foreach(process_list->process_hash,
351 // draw_closure,(void*)&closure_data);
353 // And the draw is always the same then...
355 // The c-library loops through the local processes, search for
356 // the local processes in the state provider and then draws
357 // If it's present is the local processes why shuldn't they be
358 // present in the state provider?
359 // This seems more direct. and makes sure all processes are
360 // reflected in the control flow view.
361 LttngProcessState
[] processes
= traceSt
.getProcesses();
362 for (int pos
=0; pos
< processes
.length
; pos
++) {
363 LttngProcessState process
= processes
[pos
];
365 // Replace the C call :
366 // hashed_process_data =
367 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
368 TimeRangeEventProcess localProcess
= procContainer
369 .findProcess(process
.getPid(), process
.getCpu(), traceSt
370 .getTraceId(), process
371 .getCreation_time());
373 // Add process to process list if not present
374 if (localProcess
== null) {
375 TmfTimeRange timeRange
= traceSt
.getContext()
376 .getTraceTimeWindow();
377 localProcess
= addLocalProcess(process
, timeRange
378 .getStartTime().getValue(), timeRange
379 .getEndTime().getValue(), traceSt
.getTraceId());
382 // Call the function that will does the actual
384 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
385 process
, localProcess
, params
);