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() {
43 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
45 Long cpu
= trcEvent
.getCpuId();
46 LttngProcessState stateProcess
= traceSt
.getRunning_process()
48 // TraceDebug.debug("Before handler called");
49 String traceId
= traceSt
.getTraceId();
51 if (stateProcess
!= null) {
52 // Find process within the list of registered time-range
56 // key process attributes to look for it or store it
57 // are: pid, birth, trace_num, note: cpu not relevant since
60 TimeRangeEventProcess localProcess
= procContainer
61 .findProcess(stateProcess
.getPid(), stateProcess
.getCpu(), traceId
, stateProcess
64 // Add process to process list if not present
65 if (localProcess
== null) {
66 TmfTimeRange timeRange
= traceSt
.getContext()
67 .getTraceTimeWindow();
68 localProcess
= addLocalProcess(stateProcess
, timeRange
69 .getStartTime().getValue(), timeRange
70 .getEndTime().getValue(), traceId
);
73 // Do the actual drawing
74 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
75 stateProcess
, localProcess
, params
);
78 .debug("Running state process is null! (getStateModesHandler)");
89 * Handles: LTT_EVENT_SCHED_SCHEDULE
91 * Replace C function named "before_schedchange_hook" in eventhooks.c
93 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE (?)
98 final ILttngEventProcessor
getBeforeSchedChangeHandler() {
99 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
102 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
104 Long pid_out
= getAFieldLong(trcEvent
, traceSt
,
105 Fields
.LTT_FIELD_PREV_PID
);
106 Long pid_in
= getAFieldLong(trcEvent
, traceSt
,
107 Fields
.LTT_FIELD_NEXT_PID
);
109 // This is useless even in Lttv !!
110 // Long state_out = getAFieldLong(trcEvent, traceSt,
111 // Fields.LTT_FIELD_PREV_STATE);
113 // We need to process information.
114 LttngProcessState process
= traceSt
.getRunning_process().get(
115 trcEvent
.getCpuId());
117 if (process
!= null) {
118 if (process
.getPid().equals(pid_out
) == false) {
120 // process = lttv_state_find_process(ts,tfs->cpu,
122 process
= lttv_state_find_process(traceSt
, trcEvent
123 .getCpuId(), pid_out
);
125 // guint trace_num = ts->parent.index;
128 if (process
!= null) {
129 // TODO: Implement something similar to current hash in
130 // order to keep track of the current process and speed
131 // up finding the local resource.
133 // HashedProcessData *hashed_process_data = NULL;
134 // hashed_process_data =
135 // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
136 TimeRangeEventProcess localProcess
= procContainer
137 .findProcess(process
.getPid(), process
.getCpu(), traceSt
138 .getTraceId(), process
.getCreation_time());
140 // Add process to process list if not present
142 // 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);
143 if (localProcess
== null) {
144 TmfTimeRange timeRange
= traceSt
.getContext()
145 .getTraceTimeWindow();
146 localProcess
= addLocalProcess(process
, timeRange
147 .getStartTime().getValue(), timeRange
148 .getEndTime().getValue(), traceSt
152 // Do the actual drawing
153 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
155 localProcess
, params
);
157 // Process may be null if the process started BEFORE the
159 // TraceDebug.debug("Process is null for pid_out! (getBeforeSchedChangeHandler)");
163 process
= lttv_state_find_process(traceSt
, trcEvent
164 .getCpuId(), pid_in
);
166 if (process
!= null) {
167 // HashedProcessData *hashed_process_data = NULL;
168 // hashed_process_data =
169 // processlist_get_process_data(process_list, pid_in,
170 // tfs->cpu, &birth, trace_num);
171 TimeRangeEventProcess localProcess
= procContainer
172 .findProcess(process
.getPid(), process
.getCpu(), traceSt
173 .getTraceId(), process
.getCreation_time());
175 // Add process to process list if not present
177 // processlist_add(process_list, drawing, pid_in,
178 // process->tgid, tfs->cpu, process->ppid, &birth,
179 // trace_num, process->name, process->brand, &pl_height,
180 // &process_info, &hashed_process_data);
181 if (localProcess
== null) {
182 TmfTimeRange timeRange
= traceSt
.getContext()
183 .getTraceTimeWindow();
184 localProcess
= addLocalProcess(process
, timeRange
185 .getStartTime().getValue(), timeRange
186 .getEndTime().getValue(), traceSt
190 // Do the actual drawing
191 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
193 localProcess
, params
);
196 // Process can be null if it started AFTER the trace
197 // end. Do nothing...
198 // TraceDebug.debug("No process found for pid_in! Something is wrong? (getBeforeSchedChangeHandler)");
202 .debug("Running process is null! (getBeforeSchedChangeHandler)");
214 * Handles: LTT_EVENT_PROCESS_EXIT
216 * Replace C function named "before_process_exit_hook" in eventhooks.c
220 final ILttngEventProcessor
getProcessExitHandler() {
221 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
224 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
226 // We need to process information.
227 LttngProcessState process
= traceSt
.getRunning_process().get(
228 trcEvent
.getCpuId());
230 if (process
!= null) {
231 // TODO: Implement a similar method to track the current
232 // local process in order to speed up finding the local
235 // hashed_process_data =
236 // processlist_get_process_data(process_list, pid,
237 // process->cpu, &birth,trace_num);
238 TimeRangeEventProcess localProcess
= procContainer
239 .findProcess(process
.getPid(), process
.getCpu(), traceSt
240 .getTraceId(), process
.getCreation_time());
242 // Add process to process list if not present
244 // processlist_add(process_list, drawing, pid,
245 // process->tgid, process->cpu, process->ppid, &birth,
246 // trace_num, process->name, process->brand,&pl_height,
247 // &process_info, &hashed_process_data);
248 if (localProcess
== null) {
249 TmfTimeRange timeRange
= traceSt
.getContext()
250 .getTraceTimeWindow();
251 localProcess
= addLocalProcess(process
, timeRange
252 .getStartTime().getValue(), timeRange
253 .getEndTime().getValue(), traceSt
.getTraceId());
256 // Call the function that does the actual drawing
257 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
258 process
, localProcess
, params
);
262 .debug("Running process is null! (getProcessExitHandler)");
273 * Handles: LTT_EVENT_PROCESS_FREE
275 * Replace C function named "before_process_release_hook" in eventhooks.c
277 * Fields: LTT_FIELD_PID
282 final ILttngEventProcessor
getProcessFreeHandler() {
283 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
286 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
287 // PID of the process to release
288 Long release_pid
= getAFieldLong(trcEvent
, traceSt
,
289 Fields
.LTT_FIELD_PID
);
291 if ((release_pid
!= null)) {
292 LttngProcessState process
= lttv_state_find_process(
293 traceSt
, ANY_CPU
, release_pid
);
294 if (process
!= null) {
296 // Replace the C call :
297 // hashed_process_data =
298 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
299 TimeRangeEventProcess localProcess
= procContainer
300 .findProcess(process
.getPid(), process
.getCpu(), traceSt
301 .getTraceId(), process
302 .getCreation_time());
304 // This is as it was in the C ... ?
305 if (localProcess
== null) {
309 // Perform the drawing
310 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
312 localProcess
, params
);
316 .debug("Release_pid is null! (getProcessFreeHandler)");
327 * Handles: LTT_EVENT_STATEDUMP_END
329 * Replace C function named "before_statedump_end" in eventhooks.c
333 final ILttngEventProcessor
getStateDumpEndHandler() {
334 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
337 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
339 // What's below should replace the following call in C :
340 // ClosureData closure_data;
341 // closure_data.events_request = events_request;
342 // closure_data.tss = tss;
343 // closure_data.end_time = evtime;
344 // convert_time_to_pixels(time_window,evtime,width,&closure_data.x_end);
345 // g_hash_table_foreach(process_list->process_hash,
346 // draw_closure,(void*)&closure_data);
348 // And the draw is always the same then...
350 // The c-library loops through the local processes, search for
351 // the local processes in the state provider and then draws
352 // If it's present is the local processes why shuldn't they be
353 // present in the state provider?
354 // This seems more direct. and makes sure all processes are
355 // reflected in the control flow view.
356 LttngProcessState
[] processes
= traceSt
.getProcesses();
357 for (int pos
=0; pos
< processes
.length
; pos
++) {
358 LttngProcessState process
= processes
[pos
];
360 // Replace the C call :
361 // hashed_process_data =
362 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
363 TimeRangeEventProcess localProcess
= procContainer
364 .findProcess(process
.getPid(), process
.getCpu(), traceSt
365 .getTraceId(), process
366 .getCreation_time());
368 // Add process to process list if not present
369 if (localProcess
== null) {
370 TmfTimeRange timeRange
= traceSt
.getContext()
371 .getTraceTimeWindow();
372 localProcess
= addLocalProcess(process
, timeRange
373 .getStartTime().getValue(), timeRange
374 .getEndTime().getValue(), traceSt
.getTraceId());
377 // Call the function that will does the actual
379 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
380 process
, localProcess
, params
);