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 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.controlflow
.evProcessor
;
15 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngEvent
;
16 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.StateStrings
.Fields
;
17 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.evProcessor
.ILttngEventProcessor
;
18 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.model
.LttngProcessState
;
19 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.model
.LttngTraceState
;
20 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.TraceDebug
;
21 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.model
.trange
.TimeRangeEventProcess
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
25 * Creates instances of specific before state update handlers, per corresponding
31 class FlowBeforeUpdateHandlers
{
34 * Handles: LTT_EVENT_SYSCALL_ENTRY
36 * Replace C function named "before_execmode_hook" in eventhooks.c
40 final ILttngEventProcessor
getStateModesHandler() {
41 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
45 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
47 Long cpu
= trcEvent
.getCpuId();
48 LttngProcessState stateProcess
= traceSt
.getRunning_process()
50 // TraceDebug.debug("Before handler called");
51 String traceId
= traceSt
.getTraceId();
53 if (stateProcess
!= null) {
54 // Find process within the list of registered time-range
58 // key process attributes to look for it or store it
59 // are: pid, birth, trace_num, note: cpu not relevant since
62 TimeRangeEventProcess localProcess
= procContainer
63 .findProcess(stateProcess
.getPid(), stateProcess
.getCpu(), traceId
, stateProcess
66 // Add process to process list if not present
67 if (localProcess
== null) {
68 TmfTimeRange timeRange
= traceSt
.getContext()
69 .getTraceTimeWindow();
70 localProcess
= addLocalProcess(stateProcess
, timeRange
71 .getStartTime().getValue(), timeRange
72 .getEndTime().getValue(), traceId
);
75 // Do the actual drawing
76 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
77 stateProcess
, localProcess
, params
);
80 .debug("Running state process is null! (getStateModesHandler)"); //$NON-NLS-1$
91 * Handles: LTT_EVENT_SCHED_SCHEDULE
93 * Replace C function named "before_schedchange_hook" in eventhooks.c
95 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE (?)
100 final ILttngEventProcessor
getBeforeSchedChangeHandler() {
101 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
105 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
107 Long pid_out
= getAFieldLong(trcEvent
, traceSt
,
108 Fields
.LTT_FIELD_PREV_PID
);
109 Long pid_in
= getAFieldLong(trcEvent
, traceSt
,
110 Fields
.LTT_FIELD_NEXT_PID
);
112 // This is useless even in Lttv !!
113 // Long state_out = getAFieldLong(trcEvent, traceSt,
114 // Fields.LTT_FIELD_PREV_STATE);
116 // We need to process information.
117 LttngProcessState process
= traceSt
.getRunning_process().get(
118 trcEvent
.getCpuId());
120 if (process
!= null) {
121 if (process
.getPid().equals(pid_out
) == false) {
123 // process = lttv_state_find_process(ts,tfs->cpu,
125 process
= lttv_state_find_process(traceSt
, trcEvent
126 .getCpuId(), pid_out
);
128 // guint trace_num = ts->parent.index;
131 if (process
!= null) {
132 // TODO: Implement something similar to current hash in
133 // order to keep track of the current process and speed
134 // up finding the local resource.
136 // HashedProcessData *hashed_process_data = NULL;
137 // hashed_process_data =
138 // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
139 TimeRangeEventProcess localProcess
= procContainer
140 .findProcess(process
.getPid(), process
.getCpu(), traceSt
141 .getTraceId(), process
.getCreation_time());
143 // Add process to process list if not present
145 // 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);
146 if (localProcess
== null) {
147 TmfTimeRange timeRange
= traceSt
.getContext()
148 .getTraceTimeWindow();
149 localProcess
= addLocalProcess(process
, timeRange
150 .getStartTime().getValue(), timeRange
151 .getEndTime().getValue(), traceSt
155 // Do the actual drawing
156 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
158 localProcess
, params
);
160 // Process may be null if the process started BEFORE the
162 // TraceDebug.debug("Process is null for pid_out! (getBeforeSchedChangeHandler)");
166 process
= lttv_state_find_process(traceSt
, trcEvent
167 .getCpuId(), pid_in
);
169 if (process
!= null) {
170 // HashedProcessData *hashed_process_data = NULL;
171 // hashed_process_data =
172 // processlist_get_process_data(process_list, pid_in,
173 // tfs->cpu, &birth, trace_num);
174 TimeRangeEventProcess localProcess
= procContainer
175 .findProcess(process
.getPid(), process
.getCpu(), traceSt
176 .getTraceId(), process
.getCreation_time());
178 // Add process to process list if not present
180 // processlist_add(process_list, drawing, pid_in,
181 // process->tgid, tfs->cpu, process->ppid, &birth,
182 // trace_num, process->name, process->brand, &pl_height,
183 // &process_info, &hashed_process_data);
184 if (localProcess
== null) {
185 TmfTimeRange timeRange
= traceSt
.getContext()
186 .getTraceTimeWindow();
187 localProcess
= addLocalProcess(process
, timeRange
188 .getStartTime().getValue(), timeRange
189 .getEndTime().getValue(), traceSt
193 // Do the actual drawing
194 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
196 localProcess
, params
);
199 // Process can be null if it started AFTER the trace
200 // end. Do nothing...
201 // TraceDebug.debug("No process found for pid_in! Something is wrong? (getBeforeSchedChangeHandler)");
205 .debug("Running process is null! (getBeforeSchedChangeHandler)"); //$NON-NLS-1$
217 * Handles: LTT_EVENT_PROCESS_EXIT
219 * Replace C function named "before_process_exit_hook" in eventhooks.c
223 final ILttngEventProcessor
getProcessExitHandler() {
224 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
228 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
230 // We need to process information.
231 LttngProcessState process
= traceSt
.getRunning_process().get(
232 trcEvent
.getCpuId());
234 if (process
!= null) {
235 // TODO: Implement a similar method to track the current
236 // local process in order to speed up finding the local
239 // hashed_process_data =
240 // processlist_get_process_data(process_list, pid,
241 // process->cpu, &birth,trace_num);
242 TimeRangeEventProcess localProcess
= procContainer
243 .findProcess(process
.getPid(), process
.getCpu(), traceSt
244 .getTraceId(), process
.getCreation_time());
246 // Add process to process list if not present
248 // processlist_add(process_list, drawing, pid,
249 // process->tgid, process->cpu, process->ppid, &birth,
250 // trace_num, process->name, process->brand,&pl_height,
251 // &process_info, &hashed_process_data);
252 if (localProcess
== null) {
253 TmfTimeRange timeRange
= traceSt
.getContext()
254 .getTraceTimeWindow();
255 localProcess
= addLocalProcess(process
, timeRange
256 .getStartTime().getValue(), timeRange
257 .getEndTime().getValue(), traceSt
.getTraceId());
260 // Call the function that does the actual drawing
261 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
262 process
, localProcess
, params
);
266 .debug("Running process is null! (getProcessExitHandler)"); //$NON-NLS-1$
277 * Handles: LTT_EVENT_PROCESS_FREE
279 * Replace C function named "before_process_release_hook" in eventhooks.c
281 * Fields: LTT_FIELD_PID
286 final ILttngEventProcessor
getProcessFreeHandler() {
287 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
291 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
292 // PID of the process to release
293 Long release_pid
= getAFieldLong(trcEvent
, traceSt
,
294 Fields
.LTT_FIELD_PID
);
296 if ((release_pid
!= null)) {
297 LttngProcessState process
= lttv_state_find_process(
298 traceSt
, ANY_CPU
, release_pid
);
299 if (process
!= null) {
301 // Replace the C call :
302 // hashed_process_data =
303 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
304 TimeRangeEventProcess localProcess
= procContainer
305 .findProcess(process
.getPid(), process
.getCpu(), traceSt
306 .getTraceId(), process
307 .getCreation_time());
309 // This is as it was in the C ... ?
310 if (localProcess
== null) {
314 // Perform the drawing
315 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
317 localProcess
, params
);
321 .debug("Release_pid is null! (getProcessFreeHandler)"); //$NON-NLS-1$
332 * Handles: LTT_EVENT_STATEDUMP_END
334 * Replace C function named "before_statedump_end" in eventhooks.c
338 final ILttngEventProcessor
getStateDumpEndHandler() {
339 AbsFlowTRangeUpdate handler
= new AbsFlowTRangeUpdate() {
343 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
345 // What's below should replace the following call in C :
346 // ClosureData closure_data;
347 // closure_data.events_request = events_request;
348 // closure_data.tss = tss;
349 // closure_data.end_time = evtime;
350 // convert_time_to_pixels(time_window,evtime,width,&closure_data.x_end);
351 // g_hash_table_foreach(process_list->process_hash,
352 // draw_closure,(void*)&closure_data);
354 // And the draw is always the same then...
356 // The c-library loops through the local processes, search for
357 // the local processes in the state provider and then draws
358 // If it's present is the local processes why shuldn't they be
359 // present in the state provider?
360 // This seems more direct. and makes sure all processes are
361 // reflected in the control flow view.
362 LttngProcessState
[] processes
= traceSt
.getProcesses();
363 for (int pos
=0; pos
< processes
.length
; pos
++) {
364 LttngProcessState process
= processes
[pos
];
366 // Replace the C call :
367 // hashed_process_data =
368 // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
369 TimeRangeEventProcess localProcess
= procContainer
370 .findProcess(process
.getPid(), process
.getCpu(), traceSt
371 .getTraceId(), process
372 .getCreation_time());
374 // Add process to process list if not present
375 if (localProcess
== null) {
376 TmfTimeRange timeRange
= traceSt
.getContext()
377 .getTraceTimeWindow();
378 localProcess
= addLocalProcess(process
, timeRange
379 .getStartTime().getValue(), timeRange
380 .getEndTime().getValue(), traceSt
.getTraceId());
383 // Call the function that will does the actual
385 makeDraw(traceSt
, trcEvent
.getTimestamp().getValue(),
386 process
, localProcess
, params
);