use time_window.end_time directly
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / eventhooks.c
CommitLineData
ce0214a6 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19
f0d936c0 20/*****************************************************************************
21 * Hooks to be called by the main window *
22 *****************************************************************************/
23
f0d936c0 24
b9a010a2 25/* Event hooks are the drawing hooks called during traceset read. They draw the
26 * icons, text, lines and background color corresponding to the events read.
27 *
e92eabaf 28 * Two hooks are used for drawing : before_schedchange and after_schedchange hooks. The
29 * before_schedchange is called before the state update that occurs with an event and
30 * the after_schedchange hook is called after this state update.
b9a010a2 31 *
e92eabaf 32 * The before_schedchange hooks fulfill the task of drawing the visible objects that
33 * corresponds to the data accumulated by the after_schedchange hook.
b9a010a2 34 *
e92eabaf 35 * The after_schedchange hook accumulates the data that need to be shown on the screen
36 * (items) into a queue. Then, the next before_schedchange hook will draw what that
b9a010a2 37 * queue contains. That's the Right Way (TM) of drawing items on the screen,
38 * because we need to draw the background first (and then add icons, text, ...
39 * over it), but we only know the length of a background region once the state
e92eabaf 40 * corresponding to it is over, which happens to be at the next before_schedchange
b9a010a2 41 * hook.
42 *
43 * We also have a hook called at the end of a chunk to draw the information left
44 * undrawn in each process queue. We use the current time as end of
45 * line/background.
46 */
47
48
cf6cb7e0 49//#define PANGO_ENABLE_BACKEND
558aa013 50#include <gtk/gtk.h>
51#include <gdk/gdk.h>
5f16133f 52#include <glib.h>
80a52ff8 53#include <assert.h>
50439712 54#include <string.h>
319e9d81 55#include <stdio.h>
5f16133f 56
cf6cb7e0 57//#include <pango/pango.h>
58
80a52ff8 59#include <ltt/event.h>
4ba42155 60#include <ltt/time.h>
50439712 61#include <ltt/type.h>
80a52ff8 62
2a2fa4f0 63#include <lttv/lttv.h>
558aa013 64#include <lttv/hook.h>
80a52ff8 65#include <lttv/state.h>
2d262115 66#include <lttvwindow/lttvwindow.h>
6395d57c 67#include <lttvwindow/lttvwindowtraces.h>
80a52ff8 68
f0d936c0 69
a117e3f7 70#include "eventhooks.h"
71#include "cfv.h"
72#include "processlist.h"
73#include "drawing.h"
74#include "cfv-private.h"
5f16133f 75
80a52ff8 76
1a31868c 77#define MAX_PATH_LEN 256
78
f0d936c0 79
b9a010a2 80#if 0
81typedef struct _ProcessAddClosure {
82 ControlFlowData *cfd;
83 guint trace_num;
84} ProcessAddClosure;
85
86static void process_add(gpointer key,
87 gpointer value,
88 gpointer user_data)
89{
90 LttvProcessState *process = (LttvProcessState*)value;
91 ProcessAddClosure *closure = (ProcessAddClosure*)user_data;
92 ControlFlowData *control_flow_data = closure->cfd;
93 guint trace_num = closure->trace_num;
94
95 /* Add process to process list (if not present) */
96 guint pid;
97 LttTime birth;
98 guint y = 0, height = 0, pl_height = 0;
99
5c230fc4 100 ProcessList *process_list = control_flow_data->process_list;
b9a010a2 101
102 pid = process->pid;
103 birth = process->creation_time;
104 const gchar *name = g_quark_to_string(process->name);
105 HashedProcessData *hashed_process_data = NULL;
106
107 if(processlist_get_process_pixels(process_list,
108 pid,
109 &birth,
110 trace_num,
111 &y,
112 &height,
113 &hashed_process_data) == 1)
114 {
115 /* Process not present */
116 processlist_add(process_list,
117 pid,
118 &birth,
119 trace_num,
120 name,
121 &pl_height,
122 &hashed_process_data);
123 processlist_get_process_pixels(process_list,
124 pid,
125 &birth,
126 trace_num,
127 &y,
128 &height,
129 &hashed_process_data);
130 drawing_insert_square( control_flow_data->drawing, y, height);
131 }
132}
133#endif //0
134
135
6395d57c 136/* Action to do when background computation completed.
137 *
e800cf84 138 * Wait for all the awaited computations to be over.
6395d57c 139 */
140
141gint background_ready(void *hook_data, void *call_data)
142{
143 ControlFlowData *control_flow_data = (ControlFlowData *)hook_data;
144 LttvTrace *trace = (LttvTrace*)call_data;
b9a010a2 145 LttvTracesetContext *tsc =
146 lttvwindow_get_traceset_context(control_flow_data->tab);
6395d57c 147
e800cf84 148 control_flow_data->background_info_waiting--;
149
150 if(control_flow_data->background_info_waiting == 0) {
151 g_debug("control flow viewer : background computation data ready.");
6395d57c 152
e800cf84 153 drawing_clear(control_flow_data->drawing);
154 processlist_clear(control_flow_data->process_list);
155 redraw_notify(control_flow_data, NULL);
b9a010a2 156 }
6395d57c 157
158 return 0;
159}
160
161
162/* Request background computation. Verify if it is in progress or ready first.
e800cf84 163 * Only for each trace in the tab's traceset.
6395d57c 164 */
165void request_background_data(ControlFlowData *control_flow_data)
166{
e800cf84 167 LttvTracesetContext * tsc =
168 lttvwindow_get_traceset_context(control_flow_data->tab);
169 gint num_traces = lttv_traceset_number(tsc->ts);
6395d57c 170 gint i;
171 LttvTrace *trace;
172
173 LttvHooks *background_ready_hook =
174 lttv_hooks_new();
175 lttv_hooks_add(background_ready_hook, background_ready, control_flow_data,
176 LTTV_PRIO_DEFAULT);
e800cf84 177 control_flow_data->background_info_waiting = 0;
6395d57c 178
179 for(i=0;i<num_traces;i++) {
e800cf84 180 trace = lttv_traceset_get(tsc->ts, i);
6395d57c 181
182 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE) {
183
184 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
185 trace) == FALSE) {
186 /* We first remove requests that could have been done for the same
187 * information. Happens when two viewers ask for it before servicing
188 * starts.
189 */
190 lttvwindowtraces_background_request_remove(trace, "state");
191 lttvwindowtraces_background_request_queue(trace,
192 "state");
193 lttvwindowtraces_background_notify_queue(control_flow_data,
194 trace,
195 ltt_time_infinite,
196 NULL,
197 background_ready_hook);
e800cf84 198 control_flow_data->background_info_waiting++;
6395d57c 199 } else { /* in progress */
200
201 lttvwindowtraces_background_notify_current(control_flow_data,
202 trace,
203 ltt_time_infinite,
204 NULL,
205 background_ready_hook);
e800cf84 206 control_flow_data->background_info_waiting++;
6395d57c 207 }
4368b993 208 } else {
209 /* Data ready. Be its nature, this viewer doesn't need to have
210 * its data ready hook called htere, because a background
211 * request is always linked with a redraw.
212 */
6395d57c 213 }
4368b993 214
6395d57c 215 }
216
217 lttv_hooks_destroy(background_ready_hook);
218}
219
220
221
222
f0d936c0 223/**
224 * Event Viewer's constructor hook
225 *
226 * This constructor is given as a parameter to the menuitem and toolbar button
227 * registration. It creates the list.
ca0f8a8e 228 * @param tab A pointer to the parent tab.
f0d936c0 229 * @return The widget created.
230 */
231GtkWidget *
d47b33d2 232h_guicontrolflow(Tab *tab)
f0d936c0 233{
d47b33d2 234 g_info("h_guicontrolflow, %p", tab);
68997a22 235 ControlFlowData *control_flow_data = guicontrolflow() ;
a56a1ba4 236
ca0f8a8e 237 control_flow_data->tab = tab;
a56a1ba4 238
2a2fa4f0 239 //g_debug("time width2 : %u",time_window->time_width);
a56a1ba4 240 // Unreg done in the GuiControlFlow_Destructor
6395d57c 241 lttvwindow_register_traceset_notify(tab,
242 traceset_notify,
243 control_flow_data);
244
ca0f8a8e 245 lttvwindow_register_time_window_notify(tab,
224446ce 246 update_time_window_hook,
247 control_flow_data);
ca0f8a8e 248 lttvwindow_register_current_time_notify(tab,
224446ce 249 update_current_time_hook,
250 control_flow_data);
ca0f8a8e 251 lttvwindow_register_redraw_notify(tab,
252 redraw_notify,
253 control_flow_data);
254 lttvwindow_register_continue_notify(tab,
255 continue_notify,
256 control_flow_data);
6395d57c 257 request_background_data(control_flow_data);
258
ca0f8a8e 259
68997a22 260 return guicontrolflow_get_widget(control_flow_data) ;
a56a1ba4 261
f0d936c0 262}
263
3cff8cc1 264int event_selected_hook(void *hook_data, void *call_data)
f0d936c0 265{
68997a22 266 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
14963be0 267 guint *event_number = (guint*) call_data;
f0d936c0 268
2a2fa4f0 269 g_debug("DEBUG : event selected by main window : %u", *event_number);
a56a1ba4 270
f0d936c0 271}
272
9a1ec01b 273/* Function that selects the color of status&exemode line */
274static __inline PropertiesLine prepare_s_e_line(LttvProcessState *process)
275{
276 PropertiesLine prop_line;
277 prop_line.line_width = 2;
278 prop_line.style = GDK_LINE_SOLID;
279 prop_line.y = MIDDLE;
280 //GdkColormap *colormap = gdk_colormap_get_system();
281
282 g_debug("prepare_status_line for state : %s",
283 g_quark_to_string(process->state->s));
c8bba5fa 284
9a1ec01b 285 if(process->state->s == LTTV_STATE_RUN) {
286 if(process->state->t == LTTV_STATE_USER_MODE)
287 prop_line.color = drawing_colors[COL_RUN_USER_MODE];
288 else if(process->state->t == LTTV_STATE_SYSCALL)
289 prop_line.color = drawing_colors[COL_RUN_SYSCALL];
290 else if(process->state->t == LTTV_STATE_TRAP)
291 prop_line.color = drawing_colors[COL_RUN_TRAP];
292 else if(process->state->t == LTTV_STATE_IRQ)
293 prop_line.color = drawing_colors[COL_RUN_IRQ];
294 else if(process->state->t == LTTV_STATE_MODE_UNKNOWN)
295 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
296 else
297 g_assert(FALSE); /* RUNNING MODE UNKNOWN */
298 } else if(process->state->s == LTTV_STATE_WAIT) {
299 /* We don't show if we wait while in user mode, trap, irq or syscall */
300 prop_line.color = drawing_colors[COL_WAIT];
301 } else if(process->state->s == LTTV_STATE_WAIT_CPU) {
302 /* We don't show if we wait for CPU while in user mode, trap, irq
303 * or syscall */
304 prop_line.color = drawing_colors[COL_WAIT_CPU];
305 } else if(process->state->s == LTTV_STATE_ZOMBIE) {
306 prop_line.color = drawing_colors[COL_ZOMBIE];
307 } else if(process->state->s == LTTV_STATE_WAIT_FORK) {
308 prop_line.color = drawing_colors[COL_WAIT_FORK];
309 } else if(process->state->s == LTTV_STATE_EXIT) {
310 prop_line.color = drawing_colors[COL_EXIT];
311 } else if(process->state->s == LTTV_STATE_UNNAMED) {
312 prop_line.color = drawing_colors[COL_UNNAMED];
313 } else
314 g_assert(FALSE); /* UNKNOWN STATE */
315
316 return prop_line;
317
318}
319
320#if 0
e92eabaf 321static __inline PropertiesLine prepare_status_line(LttvProcessState *process)
c8bba5fa 322{
323 PropertiesLine prop_line;
324 prop_line.line_width = 2;
325 prop_line.style = GDK_LINE_SOLID;
e800cf84 326 prop_line.y = MIDDLE;
327 //GdkColormap *colormap = gdk_colormap_get_system();
c8bba5fa 328
23093869 329 g_debug("prepare_status_line for state : %s",
330 g_quark_to_string(process->state->s));
c8bba5fa 331
332 /* color of line : status of the process */
333 if(process->state->s == LTTV_STATE_UNNAMED)
e800cf84 334 prop_line.color = drawing_colors[COL_WHITE];
c8bba5fa 335 else if(process->state->s == LTTV_STATE_WAIT_FORK)
e800cf84 336 prop_line.color = drawing_colors[COL_WAIT_FORK];
c8bba5fa 337 else if(process->state->s == LTTV_STATE_WAIT_CPU)
e800cf84 338 prop_line.color = drawing_colors[COL_WAIT_CPU];
dbd243b1 339 else if(process->state->s == LTTV_STATE_EXIT)
340 prop_line.color = drawing_colors[COL_EXIT];
0828099d 341 else if(process->state->s == LTTV_STATE_ZOMBIE)
342 prop_line.color = drawing_colors[COL_ZOMBIE];
c8bba5fa 343 else if(process->state->s == LTTV_STATE_WAIT)
e800cf84 344 prop_line.color = drawing_colors[COL_WAIT];
c8bba5fa 345 else if(process->state->s == LTTV_STATE_RUN)
e800cf84 346 prop_line.color = drawing_colors[COL_RUN];
c8bba5fa 347 else
23093869 348 prop_line.color = drawing_colors[COL_WHITE];
e800cf84 349
350 //gdk_colormap_alloc_color(colormap,
351 // prop_line.color,
352 // FALSE,
353 // TRUE);
c8bba5fa 354
355 return prop_line;
356
357}
9a1ec01b 358#endif //0
c8bba5fa 359
360
e92eabaf 361/* before_schedchange_hook
b9a010a2 362 *
f0d936c0 363 * This function basically draw lines and icons. Two types of lines are drawn :
364 * one small (3 pixels?) representing the state of the process and the second
365 * type is thicker (10 pixels?) representing on which CPU a process is running
366 * (and this only in running state).
367 *
368 * Extremums of the lines :
369 * x_min : time of the last event context for this process kept in memory.
370 * x_max : time of the current event.
371 * y : middle of the process in the process list. The process is found in the
372 * list, therefore is it's position in pixels.
373 *
374 * The choice of lines'color is defined by the context of the last event for this
375 * process.
376 */
b9a010a2 377
378
e92eabaf 379int before_schedchange_hook(void *hook_data, void *call_data)
f0d936c0 380{
b9a010a2 381 EventsRequest *events_request = (EventsRequest*)hook_data;
382 ControlFlowData *control_flow_data = events_request->viewer_data;
c8bba5fa 383 Drawing_t *drawing = control_flow_data->drawing;
b9a010a2 384
385 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
386
387 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
16b9cadb 388 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
b9a010a2 389
390 LttEvent *e;
391 e = tfc->e;
392
393 LttTime evtime = ltt_event_time(e);
394 TimeWindow time_window =
395 lttvwindow_get_time_window(control_flow_data->tab);
a18124ff 396#ifdef EXTRA_CHECK
b9a010a2 397 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 398 || ltt_time_compare(evtime, time_window.end_time) == 1)
b9a010a2 399 return;
a18124ff 400#endif //EXTRA_CHECK
c8bba5fa 401 guint width = drawing->width;
b9a010a2 402
10a1069a 403 /* we are in a schedchange, before the state update. We must draw the
404 * items corresponding to the state before it changes : now is the right
405 * time to do it.
406 */
b9a010a2 407
10a1069a 408 guint pid_out;
409 guint pid_in;
410 {
411 LttField *f = ltt_event_field(e);
412 LttField *element;
413 element = ltt_field_member(f,0);
414 pid_out = ltt_event_get_long_unsigned(e,element);
415 element = ltt_field_member(f,1);
416 pid_in = ltt_event_get_long_unsigned(e,element);
417 g_debug("out : %u in : %u", pid_out, pid_in);
418 }
419
420 {
421 /* For the pid_out */
422 /* First, check if the current process is in the state computation
423 * process list. If it is there, that means we must add it right now and
424 * draw items from the beginning of the read for it. If it is not
425 * present, it's a new process and it was not present : it will
426 * be added after the state update. */
427 LttvProcessState *process;
428 process = lttv_state_find_process(tfs, pid_out);
4e86ae2e 429 //process = tfs->process;
b9a010a2 430
10a1069a 431 if(process != NULL) {
432 /* Well, the process_out existed : we must get it in the process hash
433 * or add it, and draw its items.
434 */
435 /* Add process to process list (if not present) */
436 guint y = 0, height = 0, pl_height = 0;
437 HashedProcessData *hashed_process_data = NULL;
5c230fc4 438 ProcessList *process_list = control_flow_data->process_list;
10a1069a 439 LttTime birth = process->creation_time;
440 const gchar *name = g_quark_to_string(process->name);
b9a010a2 441
10a1069a 442 if(processlist_get_process_pixels(process_list,
443 pid_out,
444 process->last_cpu,
445 &birth,
446 tfc->t_context->index,
447 &y,
448 &height,
449 &hashed_process_data) == 1)
450 {
451 g_assert(pid_out == 0 || pid_out != process->ppid);
452 /* Process not present */
4e86ae2e 453 ProcessInfo *process_info;
10a1069a 454 processlist_add(process_list,
455 pid_out,
456 process->last_cpu,
457 process->ppid,
458 &birth,
459 tfc->t_context->index,
460 name,
461 &pl_height,
4e86ae2e 462 &process_info,
10a1069a 463 &hashed_process_data);
4e86ae2e 464 processlist_get_pixels_from_data(process_list,
465 process_info,
466 hashed_process_data,
e800cf84 467 &y,
4e86ae2e 468 &height);
10a1069a 469 drawing_insert_square( drawing, y, height);
470 }
471
472 /* Now, the process is in the state hash and our own process hash.
473 * We definitely can draw the items related to the ending state.
474 */
e800cf84 475
10a1069a 476 /* Check if the x position is unset. In can have been left unset by
477 * a draw closure from a after chunk hook. This should never happen,
478 * because it must be set by before chunk hook to the damage_begin
479 * value.
480 */
481 g_assert(hashed_process_data->x.middle != -1);
b2743953 482 if(ltt_time_compare(hashed_process_data->next_good_time,
483 evtime) > 0)
10a1069a 484 {
b2743953 485 if(hashed_process_data->x.middle_marked == FALSE) {
486 guint x;
487 convert_time_to_pixels(
488 time_window,
489 evtime,
490 width,
491 &x);
492
493 /* Draw collision indicator */
494 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
495 gdk_draw_point(drawing->pixmap,
496 drawing->gc,
497 x,
498 y+(height/2)-3);
499 hashed_process_data->x.middle_marked = TRUE;
500 }
501 } else {
10a1069a 502 guint x;
10a1069a 503 convert_time_to_pixels(
a18124ff 504 time_window,
4b7dc462 505 evtime,
506 width,
507 &x);
10a1069a 508
10a1069a 509
4b7dc462 510 /* Jump over draw if we are at the same x position */
e72908ed 511 if(x == hashed_process_data->x.middle &&
512 hashed_process_data->x.middle_used)
e800cf84 513 {
e72908ed 514 if(hashed_process_data->x.middle_marked == FALSE) {
515 /* Draw collision indicator */
516 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
517 gdk_draw_point(drawing->pixmap,
518 drawing->gc,
519 x,
2c6618bc 520 y+(height/2)-3);
de4ea1ad 521 hashed_process_data->x.middle_marked = TRUE;
e72908ed 522 }
4b7dc462 523 /* jump */
524 } else {
525 DrawContext draw_context;
10a1069a 526
4b7dc462 527 /* Now create the drawing context that will be used to draw
528 * items related to the last state. */
529 draw_context.drawable = drawing->pixmap;
530 draw_context.gc = drawing->gc;
531 draw_context.pango_layout = drawing->pango_layout;
532 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
533 draw_context.drawinfo.end.x = x;
534
535 draw_context.drawinfo.y.over = y+1;
536 draw_context.drawinfo.y.middle = y+(height/2);
537 draw_context.drawinfo.y.under = y+height;
538
539 draw_context.drawinfo.start.offset.over = 0;
540 draw_context.drawinfo.start.offset.middle = 0;
541 draw_context.drawinfo.start.offset.under = 0;
542 draw_context.drawinfo.end.offset.over = 0;
543 draw_context.drawinfo.end.offset.middle = 0;
544 draw_context.drawinfo.end.offset.under = 0;
545
546 {
547 /* Draw the line */
9a1ec01b 548 PropertiesLine prop_line = prepare_s_e_line(process);
4b7dc462 549 draw_line((void*)&prop_line, (void*)&draw_context);
550
551 }
552 /* become the last x position */
553 hashed_process_data->x.middle = x;
e72908ed 554 hashed_process_data->x.middle_used = TRUE;
555 hashed_process_data->x.middle_marked = FALSE;
b2743953 556
557 /* Calculate the next good time */
558 convert_pixels_to_time(width, x+1, time_window,
559 &hashed_process_data->next_good_time);
e800cf84 560 }
561 }
562 }
10a1069a 563 }
e800cf84 564
10a1069a 565 {
566 /* For the pid_in */
567 /* First, check if the current process is in the state computation
568 * process list. If it is there, that means we must add it right now and
569 * draw items from the beginning of the read for it. If it is not
570 * present, it's a new process and it was not present : it will
571 * be added after the state update. */
572 LttvProcessState *process;
573 process = lttv_state_find_process(tfs, pid_in);
574
575 if(process != NULL) {
576 /* Well, the process_out existed : we must get it in the process hash
577 * or add it, and draw its items.
578 */
579 /* Add process to process list (if not present) */
580 guint y = 0, height = 0, pl_height = 0;
581 HashedProcessData *hashed_process_data = NULL;
5c230fc4 582 ProcessList *process_list = control_flow_data->process_list;
10a1069a 583 LttTime birth = process->creation_time;
584 const gchar *name = g_quark_to_string(process->name);
e800cf84 585
10a1069a 586 if(processlist_get_process_pixels(process_list,
587 pid_in,
588 process->last_cpu,
589 &birth,
590 tfc->t_context->index,
591 &y,
592 &height,
593 &hashed_process_data) == 1)
594 {
595 g_assert(pid_in == 0 || pid_in != process->ppid);
596 /* Process not present */
4e86ae2e 597 ProcessInfo *process_info;
10a1069a 598 processlist_add(process_list,
599 pid_in,
600 process->last_cpu,
601 process->ppid,
602 &birth,
603 tfc->t_context->index,
604 name,
605 &pl_height,
4e86ae2e 606 &process_info,
10a1069a 607 &hashed_process_data);
4e86ae2e 608 processlist_get_pixels_from_data(process_list,
609 process_info,
610 hashed_process_data,
c8bba5fa 611 &y,
4e86ae2e 612 &height);
10a1069a 613 drawing_insert_square( drawing, y, height);
614 }
615
616 /* Now, the process is in the state hash and our own process hash.
617 * We definitely can draw the items related to the ending state.
618 */
b9a010a2 619
10a1069a 620 /* Check if the x position is unset. In can have been left unset by
621 * a draw closure from a after chunk hook. This should never happen,
622 * because it must be set by before chunk hook to the damage_begin
623 * value.
624 */
625 g_assert(hashed_process_data->x.middle != -1);
b2743953 626
627 if(ltt_time_compare(hashed_process_data->next_good_time,
628 evtime) > 0)
10a1069a 629 {
b2743953 630 if(hashed_process_data->x.middle_marked == FALSE) {
631 guint x;
632 convert_time_to_pixels(
633 time_window,
634 evtime,
635 width,
636 &x);
637
638 /* Draw collision indicator */
639 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
640 gdk_draw_point(drawing->pixmap,
641 drawing->gc,
642 x,
643 y+(height/2)-3);
644 hashed_process_data->x.middle_marked = TRUE;
645 }
646 } else {
10a1069a 647 guint x;
10a1069a 648
649 convert_time_to_pixels(
a18124ff 650 time_window,
4b7dc462 651 evtime,
652 width,
653 &x);
10a1069a 654
10a1069a 655
4b7dc462 656 /* Jump over draw if we are at the same x position */
e72908ed 657 if(x == hashed_process_data->x.middle &&
658 hashed_process_data->x.middle_used)
4b7dc462 659 {
e72908ed 660 if(hashed_process_data->x.middle_marked == FALSE) {
661 /* Draw collision indicator */
662 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
663 gdk_draw_point(drawing->pixmap,
664 drawing->gc,
665 x,
2c6618bc 666 y+(height/2)-3);
de4ea1ad 667 hashed_process_data->x.middle_marked = TRUE;
e72908ed 668 }
4b7dc462 669 /* jump */
670 } else {
671 DrawContext draw_context;
10a1069a 672
4b7dc462 673 /* Now create the drawing context that will be used to draw
674 * items related to the last state. */
675 draw_context.drawable = drawing->pixmap;
676 draw_context.gc = drawing->gc;
677 draw_context.pango_layout = drawing->pango_layout;
678 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
679 draw_context.drawinfo.end.x = x;
10a1069a 680
4b7dc462 681 draw_context.drawinfo.y.over = y+1;
682 draw_context.drawinfo.y.middle = y+(height/2);
683 draw_context.drawinfo.y.under = y+height;
10a1069a 684
4b7dc462 685 draw_context.drawinfo.start.offset.over = 0;
686 draw_context.drawinfo.start.offset.middle = 0;
687 draw_context.drawinfo.start.offset.under = 0;
688 draw_context.drawinfo.end.offset.over = 0;
689 draw_context.drawinfo.end.offset.middle = 0;
690 draw_context.drawinfo.end.offset.under = 0;
691
692 {
693 /* Draw the line */
9a1ec01b 694 PropertiesLine prop_line = prepare_s_e_line(process);
4b7dc462 695 draw_line((void*)&prop_line, (void*)&draw_context);
696 }
697
698
699 /* become the last x position */
700 hashed_process_data->x.middle = x;
e72908ed 701 hashed_process_data->x.middle_used = TRUE;
702 hashed_process_data->x.middle_marked = FALSE;
b2743953 703
704 /* Calculate the next good time */
705 convert_pixels_to_time(width, x+1, time_window,
706 &hashed_process_data->next_good_time);
4b7dc462 707 }
c8bba5fa 708 }
b9a010a2 709 }
710 }
b9a010a2 711 return 0;
712
713
b9a010a2 714#if 0
ca0f8a8e 715 EventsRequest *events_request = (EventsRequest*)hook_data;
716 ControlFlowData *control_flow_data =
717 (ControlFlowData*)events_request->viewer_data;
718 Tab *tab = control_flow_data->tab;
e9a9c513 719
a56a1ba4 720 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
e9a9c513 721
722 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1aff52a2 723 LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context;
a56a1ba4 724
e9a9c513 725 LttEvent *e;
e9a9c513 726 e = tfc->e;
727
9444deae 728 LttTime evtime = ltt_event_time(e);
ca0f8a8e 729 TimeWindow time_window =
730 lttvwindow_get_time_window(tab);
9444deae 731
a2aab3a3 732 LttTime time_window.end_time = time_window.time_window.end_time;
6f26fc38 733
9444deae 734 //if(time < time_beg || time > time_end) return;
ca0f8a8e 735 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 736 || ltt_time_compare(evtime, time_window.end_time) == 1)
9444deae 737 return;
738
a56a1ba4 739 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
740 {
2a2fa4f0 741 g_debug("schedchange!");
a56a1ba4 742
743 /* Add process to process list (if not present) and get drawing "y" from
744 * process position */
745 guint pid_out, pid_in;
746 LttvProcessState *process_out, *process_in;
747 LttTime birth;
748 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
749
5c230fc4 750 ProcessList *process_list = control_flow_data->process_list;
a56a1ba4 751
752
753 LttField *f = ltt_event_field(e);
754 LttField *element;
755 element = ltt_field_member(f,0);
756 pid_out = ltt_event_get_long_unsigned(e,element);
757 element = ltt_field_member(f,1);
758 pid_in = ltt_event_get_long_unsigned(e,element);
2a2fa4f0 759 g_debug("out : %u in : %u", pid_out, pid_in);
a56a1ba4 760
761
762 /* Find process pid_out in the list... */
87658614 763 process_out = lttv_state_find_process(tfs, pid_out);
1aff52a2 764 if(process_out == NULL) return 0;
2a2fa4f0 765 g_debug("out : %s",g_quark_to_string(process_out->state->s));
1aff52a2 766
a56a1ba4 767 birth = process_out->creation_time;
51705146 768 const gchar *name = g_quark_to_string(process_out->name);
14963be0 769 HashedProcessData *hashed_process_data_out = NULL;
a56a1ba4 770
771 if(processlist_get_process_pixels(process_list,
772 pid_out,
773 &birth,
d0cd7f09 774 tfc->t_context->index,
a56a1ba4 775 &y_out,
776 &height,
14963be0 777 &hashed_process_data_out) == 1)
a56a1ba4 778 {
51705146 779 /* Process not present */
780 processlist_add(process_list,
781 pid_out,
782 &birth,
783 tfc->t_context->index,
784 name,
785 &pl_height,
786 &hashed_process_data_out);
787 g_assert(processlist_get_process_pixels(process_list,
788 pid_out,
789 &birth,
790 tfc->t_context->index,
791 &y_out,
792 &height,
793 &hashed_process_data_out)==0);
794 drawing_insert_square( control_flow_data->drawing, y_out, height);
a56a1ba4 795 }
51705146 796 //g_free(name);
a56a1ba4 797
798 /* Find process pid_in in the list... */
87658614 799 process_in = lttv_state_find_process(tfs, pid_in);
1aff52a2 800 if(process_in == NULL) return 0;
2a2fa4f0 801 g_debug("in : %s",g_quark_to_string(process_in->state->s));
a56a1ba4 802
803 birth = process_in->creation_time;
51705146 804 name = g_quark_to_string(process_in->name);
14963be0 805 HashedProcessData *hashed_process_data_in = NULL;
a56a1ba4 806
807 if(processlist_get_process_pixels(process_list,
808 pid_in,
809 &birth,
d0cd7f09 810 tfc->t_context->index,
a56a1ba4 811 &y_in,
812 &height,
14963be0 813 &hashed_process_data_in) == 1)
a56a1ba4 814 {
51705146 815 /* Process not present */
a56a1ba4 816 processlist_add(process_list,
817 pid_in,
818 &birth,
d0cd7f09 819 tfc->t_context->index,
a56a1ba4 820 name,
821 &pl_height,
14963be0 822 &hashed_process_data_in);
a56a1ba4 823 processlist_get_process_pixels(process_list,
824 pid_in,
825 &birth,
d0cd7f09 826 tfc->t_context->index,
a56a1ba4 827 &y_in,
828 &height,
14963be0 829 &hashed_process_data_in);
a56a1ba4 830
ca0f8a8e 831 drawing_insert_square( control_flow_data->drawing, y_in, height);
a56a1ba4 832 }
51705146 833 //g_free(name);
a56a1ba4 834
835
836 /* Find pixels corresponding to time of the event. If the time does
837 * not fit in the window, show a warning, not supposed to happend. */
838 guint x = 0;
51705146 839 guint width = control_flow_data->drawing->width;
a56a1ba4 840
841 LttTime time = ltt_event_time(e);
842
a2aab3a3 843 LttTime window_end = time_window.time_window.end_time;
a56a1ba4 844
845 convert_time_to_pixels(
a18124ff 846 time_window,
a56a1ba4 847 time,
848 width,
849 &x);
9444deae 850 //assert(x <= width);
51705146 851 //
a56a1ba4 852 /* draw what represents the event for outgoing process. */
853
14963be0 854 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
68997a22 855 draw_context_out->current->modify_over->x = x;
319e9d81 856 draw_context_out->current->modify_under->x = x;
68997a22 857 draw_context_out->current->modify_over->y = y_out;
319e9d81 858 draw_context_out->current->modify_under->y = y_out+(height/2)+2;
501d5405 859 draw_context_out->drawable = control_flow_data->drawing->pixmap;
860 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
861 GtkWidget *widget = control_flow_data->drawing->drawing_area;
a56a1ba4 862 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
d0cd7f09 863 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
864 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
a56a1ba4 865 //draw_context_out->gc = widget->style->black_gc;
866
867 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
501d5405 868 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
a56a1ba4 869
d0cd7f09 870 /* Draw the line/background of the out process */
871 if(draw_context_out->previous->middle->x == -1)
872 {
ca0f8a8e 873 draw_context_out->previous->over->x =
874 control_flow_data->drawing->damage_begin;
875 draw_context_out->previous->middle->x =
876 control_flow_data->drawing->damage_begin;
877 draw_context_out->previous->under->x =
878 control_flow_data->drawing->damage_begin;
879
880 g_debug("out middle x_beg : %u",control_flow_data->drawing->damage_begin);
d0cd7f09 881 }
882
883 draw_context_out->current->middle->x = x;
884 draw_context_out->current->over->x = x;
885 draw_context_out->current->under->x = x;
886 draw_context_out->current->middle->y = y_out + height/2;
887 draw_context_out->current->over->y = y_out;
888 draw_context_out->current->under->y = y_out + height;
889 draw_context_out->previous->middle->y = y_out + height/2;
890 draw_context_out->previous->over->y = y_out;
891 draw_context_out->previous->under->y = y_out + height;
892
893 draw_context_out->drawable = control_flow_data->drawing->pixmap;
894 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
895
896 if(process_out->state->s == LTTV_STATE_RUN)
897 {
51705146 898 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
899 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
900 draw_context_out->gc = control_flow_data->drawing->gc;
d0cd7f09 901
902 PropertiesBG prop_bg;
903 prop_bg.color = g_new(GdkColor,1);
904
905 switch(tfc->index) {
906 case 0:
907 prop_bg.color->red = 0x1515;
908 prop_bg.color->green = 0x1515;
909 prop_bg.color->blue = 0x8c8c;
910 break;
911 case 1:
912 prop_bg.color->red = 0x4e4e;
913 prop_bg.color->green = 0xa9a9;
914 prop_bg.color->blue = 0xa4a4;
915 break;
916 case 2:
917 prop_bg.color->red = 0x7a7a;
918 prop_bg.color->green = 0x4a4a;
919 prop_bg.color->blue = 0x8b8b;
920 break;
921 case 3:
922 prop_bg.color->red = 0x8080;
923 prop_bg.color->green = 0x7777;
924 prop_bg.color->blue = 0x4747;
925 break;
926 default:
927 prop_bg.color->red = 0xe7e7;
928 prop_bg.color->green = 0xe7e7;
929 prop_bg.color->blue = 0xe7e7;
930 }
931
2a2fa4f0 932 g_debug("calling from draw_event");
d0cd7f09 933 draw_bg((void*)&prop_bg, (void*)draw_context_out);
934 g_free(prop_bg.color);
51705146 935 //gdk_gc_unref(draw_context_out->gc);
d0cd7f09 936 }
937
938 draw_context_out->gc = widget->style->black_gc;
939
a56a1ba4 940 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
2df6f2bd 941 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 942 PropertiesText prop_text_out;
943 prop_text_out.foreground = &colorfg_out;
944 prop_text_out.background = &colorbg_out;
cfe526b1 945 prop_text_out.size = 6;
a56a1ba4 946 prop_text_out.position = OVER;
947
cfe526b1 948 /* color of text : status of the process */
949 if(process_out->state->s == LTTV_STATE_UNNAMED)
950 {
951 prop_text_out.foreground->red = 0xffff;
952 prop_text_out.foreground->green = 0xffff;
953 prop_text_out.foreground->blue = 0xffff;
954 }
955 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
956 {
957 prop_text_out.foreground->red = 0x0fff;
d52cfc84 958 prop_text_out.foreground->green = 0xffff;
959 prop_text_out.foreground->blue = 0xfff0;
cfe526b1 960 }
961 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
962 {
2df6f2bd 963 prop_text_out.foreground->red = 0xffff;
964 prop_text_out.foreground->green = 0xffff;
cfe526b1 965 prop_text_out.foreground->blue = 0x0000;
966 }
0828099d 967 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
cfe526b1 968 {
969 prop_text_out.foreground->red = 0xffff;
970 prop_text_out.foreground->green = 0x0000;
971 prop_text_out.foreground->blue = 0xffff;
972 }
973 else if(process_out->state->s == LTTV_STATE_WAIT)
974 {
975 prop_text_out.foreground->red = 0xffff;
976 prop_text_out.foreground->green = 0x0000;
977 prop_text_out.foreground->blue = 0x0000;
978 }
979 else if(process_out->state->s == LTTV_STATE_RUN)
980 {
981 prop_text_out.foreground->red = 0x0000;
982 prop_text_out.foreground->green = 0xffff;
983 prop_text_out.foreground->blue = 0x0000;
984 }
985 else
986 {
987 prop_text_out.foreground->red = 0xffff;
988 prop_text_out.foreground->green = 0xffff;
989 prop_text_out.foreground->blue = 0xffff;
990 }
991
d52cfc84 992
a56a1ba4 993 /* Print status of the process : U, WF, WC, E, W, R */
994 if(process_out->state->s == LTTV_STATE_UNNAMED)
cfe526b1 995 prop_text_out.text = "U->";
a56a1ba4 996 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
cfe526b1 997 prop_text_out.text = "WF->";
a56a1ba4 998 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
cfe526b1 999 prop_text_out.text = "WC->";
0828099d 1000 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
cfe526b1 1001 prop_text_out.text = "E->";
a56a1ba4 1002 else if(process_out->state->s == LTTV_STATE_WAIT)
cfe526b1 1003 prop_text_out.text = "W->";
a56a1ba4 1004 else if(process_out->state->s == LTTV_STATE_RUN)
cfe526b1 1005 prop_text_out.text = "R->";
a56a1ba4 1006 else
68997a22 1007 prop_text_out.text = "U";
a56a1ba4 1008
1009 draw_text((void*)&prop_text_out, (void*)draw_context_out);
d0cd7f09 1010 //gdk_gc_unref(draw_context_out->gc);
a56a1ba4 1011
51705146 1012 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1013 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
1014 draw_context_out->gc = control_flow_data->drawing->gc;
a56a1ba4 1015
1016 PropertiesLine prop_line_out;
1017 prop_line_out.color = g_new(GdkColor,1);
cfe526b1 1018 prop_line_out.line_width = 2;
a56a1ba4 1019 prop_line_out.style = GDK_LINE_SOLID;
1020 prop_line_out.position = MIDDLE;
d52cfc84 1021
2a2fa4f0 1022 g_debug("out state : %s", g_quark_to_string(process_out->state->s));
a56a1ba4 1023
1024 /* color of line : status of the process */
1025 if(process_out->state->s == LTTV_STATE_UNNAMED)
1026 {
cfe526b1 1027 prop_line_out.color->red = 0xffff;
1028 prop_line_out.color->green = 0xffff;
1029 prop_line_out.color->blue = 0xffff;
a56a1ba4 1030 }
1031 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
1032 {
1033 prop_line_out.color->red = 0x0fff;
d52cfc84 1034 prop_line_out.color->green = 0xffff;
1035 prop_line_out.color->blue = 0xfff0;
a56a1ba4 1036 }
1037 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
1038 {
2df6f2bd 1039 prop_line_out.color->red = 0xffff;
1040 prop_line_out.color->green = 0xffff;
a56a1ba4 1041 prop_line_out.color->blue = 0x0000;
1042 }
0828099d 1043 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
a56a1ba4 1044 {
1045 prop_line_out.color->red = 0xffff;
1046 prop_line_out.color->green = 0x0000;
1047 prop_line_out.color->blue = 0xffff;
1048 }
1049 else if(process_out->state->s == LTTV_STATE_WAIT)
1050 {
1051 prop_line_out.color->red = 0xffff;
1052 prop_line_out.color->green = 0x0000;
1053 prop_line_out.color->blue = 0x0000;
1054 }
1055 else if(process_out->state->s == LTTV_STATE_RUN)
1056 {
1057 prop_line_out.color->red = 0x0000;
1058 prop_line_out.color->green = 0xffff;
1059 prop_line_out.color->blue = 0x0000;
1060 }
1061 else
1062 {
cfe526b1 1063 prop_line_out.color->red = 0xffff;
1064 prop_line_out.color->green = 0xffff;
1065 prop_line_out.color->blue = 0xffff;
a56a1ba4 1066 }
1067
1068 draw_line((void*)&prop_line_out, (void*)draw_context_out);
1069 g_free(prop_line_out.color);
51705146 1070 //gdk_gc_unref(draw_context_out->gc);
a56a1ba4 1071 /* Note : finishing line will have to be added when trace read over. */
1072
1073 /* Finally, update the drawing context of the pid_in. */
1074
14963be0 1075 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
68997a22 1076 draw_context_in->current->modify_over->x = x;
319e9d81 1077 draw_context_in->current->modify_under->x = x;
68997a22 1078 draw_context_in->current->modify_over->y = y_in;
319e9d81 1079 draw_context_in->current->modify_under->y = y_in+(height/2)+2;
501d5405 1080 draw_context_in->drawable = control_flow_data->drawing->pixmap;
1081 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
1082 widget = control_flow_data->drawing->drawing_area;
a56a1ba4 1083 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
1084 //draw_context_in->gc = widget->style->black_gc;
d0cd7f09 1085 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1086 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
a56a1ba4 1087
1088 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
501d5405 1089 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
d0cd7f09 1090
1091 /* Draw the line/bg of the in process */
1092 if(draw_context_in->previous->middle->x == -1)
1093 {
ca0f8a8e 1094 draw_context_in->previous->over->x =
1095 control_flow_data->drawing->damage_begin;
1096 draw_context_in->previous->middle->x =
1097 control_flow_data->drawing->damage_begin;
1098 draw_context_in->previous->under->x =
1099 control_flow_data->drawing->damage_begin;
1100
1101 g_debug("in middle x_beg : %u",control_flow_data->drawing->damage_begin);
1102
d0cd7f09 1103 }
1104
1105 draw_context_in->current->middle->x = x;
1106 draw_context_in->current->over->x = x;
1107 draw_context_in->current->under->x = x;
1108 draw_context_in->current->middle->y = y_in + height/2;
1109 draw_context_in->current->over->y = y_in;
1110 draw_context_in->current->under->y = y_in + height;
1111 draw_context_in->previous->middle->y = y_in + height/2;
1112 draw_context_in->previous->over->y = y_in;
1113 draw_context_in->previous->under->y = y_in + height;
a56a1ba4 1114
d0cd7f09 1115 draw_context_in->drawable = control_flow_data->drawing->pixmap;
1116 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
1117
1118
1119 if(process_in->state->s == LTTV_STATE_RUN)
1120 {
51705146 1121 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1122 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1123 draw_context_in->gc = control_flow_data->drawing->gc;
d0cd7f09 1124
1125 PropertiesBG prop_bg;
1126 prop_bg.color = g_new(GdkColor,1);
1127
1128 switch(tfc->index) {
1129 case 0:
1130 prop_bg.color->red = 0x1515;
1131 prop_bg.color->green = 0x1515;
1132 prop_bg.color->blue = 0x8c8c;
1133 break;
1134 case 1:
1135 prop_bg.color->red = 0x4e4e;
1136 prop_bg.color->green = 0xa9a9;
1137 prop_bg.color->blue = 0xa4a4;
1138 break;
1139 case 2:
1140 prop_bg.color->red = 0x7a7a;
1141 prop_bg.color->green = 0x4a4a;
1142 prop_bg.color->blue = 0x8b8b;
1143 break;
1144 case 3:
1145 prop_bg.color->red = 0x8080;
1146 prop_bg.color->green = 0x7777;
1147 prop_bg.color->blue = 0x4747;
1148 break;
1149 default:
1150 prop_bg.color->red = 0xe7e7;
1151 prop_bg.color->green = 0xe7e7;
1152 prop_bg.color->blue = 0xe7e7;
1153 }
1154
1155
1156 draw_bg((void*)&prop_bg, (void*)draw_context_in);
1157 g_free(prop_bg.color);
51705146 1158 //gdk_gc_unref(draw_context_in->gc);
d0cd7f09 1159 }
1160
1161 draw_context_in->gc = widget->style->black_gc;
1162
a56a1ba4 1163 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
2df6f2bd 1164 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 1165 PropertiesText prop_text_in;
1166 prop_text_in.foreground = &colorfg_in;
1167 prop_text_in.background = &colorbg_in;
cfe526b1 1168 prop_text_in.size = 6;
a56a1ba4 1169 prop_text_in.position = OVER;
1170
2a2fa4f0 1171 g_debug("in state : %s", g_quark_to_string(process_in->state->s));
cfe526b1 1172 /* foreground of text : status of the process */
1173 if(process_in->state->s == LTTV_STATE_UNNAMED)
1174 {
1175 prop_text_in.foreground->red = 0xffff;
1176 prop_text_in.foreground->green = 0xffff;
1177 prop_text_in.foreground->blue = 0xffff;
1178 }
1179 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1180 {
1181 prop_text_in.foreground->red = 0x0fff;
d52cfc84 1182 prop_text_in.foreground->green = 0xffff;
1183 prop_text_in.foreground->blue = 0xfff0;
cfe526b1 1184 }
1185 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1186 {
2df6f2bd 1187 prop_text_in.foreground->red = 0xffff;
1188 prop_text_in.foreground->green = 0xffff;
cfe526b1 1189 prop_text_in.foreground->blue = 0x0000;
1190 }
0828099d 1191 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
cfe526b1 1192 {
1193 prop_text_in.foreground->red = 0xffff;
1194 prop_text_in.foreground->green = 0x0000;
1195 prop_text_in.foreground->blue = 0xffff;
1196 }
1197 else if(process_in->state->s == LTTV_STATE_WAIT)
1198 {
1199 prop_text_in.foreground->red = 0xffff;
1200 prop_text_in.foreground->green = 0x0000;
1201 prop_text_in.foreground->blue = 0x0000;
1202 }
1203 else if(process_in->state->s == LTTV_STATE_RUN)
1204 {
1205 prop_text_in.foreground->red = 0x0000;
1206 prop_text_in.foreground->green = 0xffff;
1207 prop_text_in.foreground->blue = 0x0000;
1208 }
1209 else
1210 {
1211 prop_text_in.foreground->red = 0xffff;
1212 prop_text_in.foreground->green = 0xffff;
1213 prop_text_in.foreground->blue = 0xffff;
1214 }
1215
1216
1217
a56a1ba4 1218 /* Print status of the process : U, WF, WC, E, W, R */
1219 if(process_in->state->s == LTTV_STATE_UNNAMED)
cfe526b1 1220 prop_text_in.text = "U->";
a56a1ba4 1221 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
cfe526b1 1222 prop_text_in.text = "WF->";
a56a1ba4 1223 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
cfe526b1 1224 prop_text_in.text = "WC->";
0828099d 1225 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
cfe526b1 1226 prop_text_in.text = "E->";
a56a1ba4 1227 else if(process_in->state->s == LTTV_STATE_WAIT)
cfe526b1 1228 prop_text_in.text = "W->";
a56a1ba4 1229 else if(process_in->state->s == LTTV_STATE_RUN)
cfe526b1 1230 prop_text_in.text = "R->";
a56a1ba4 1231 else
68997a22 1232 prop_text_in.text = "U";
a56a1ba4 1233
1234 draw_text((void*)&prop_text_in, (void*)draw_context_in);
d0cd7f09 1235 //gdk_gc_unref(draw_context_in->gc);
1236
51705146 1237 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1238 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1239 draw_context_in->gc = control_flow_data->drawing->gc;
d0cd7f09 1240
a56a1ba4 1241 PropertiesLine prop_line_in;
1242 prop_line_in.color = g_new(GdkColor,1);
cfe526b1 1243 prop_line_in.line_width = 2;
a56a1ba4 1244 prop_line_in.style = GDK_LINE_SOLID;
1245 prop_line_in.position = MIDDLE;
1246
1247 /* color of line : status of the process */
1248 if(process_in->state->s == LTTV_STATE_UNNAMED)
1249 {
cfe526b1 1250 prop_line_in.color->red = 0xffff;
1251 prop_line_in.color->green = 0xffff;
1252 prop_line_in.color->blue = 0xffff;
a56a1ba4 1253 }
1254 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1255 {
1256 prop_line_in.color->red = 0x0fff;
d52cfc84 1257 prop_line_in.color->green = 0xffff;
1258 prop_line_in.color->blue = 0xfff0;
a56a1ba4 1259 }
1260 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1261 {
2df6f2bd 1262 prop_line_in.color->red = 0xffff;
1263 prop_line_in.color->green = 0xffff;
a56a1ba4 1264 prop_line_in.color->blue = 0x0000;
1265 }
0828099d 1266 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
a56a1ba4 1267 {
1268 prop_line_in.color->red = 0xffff;
1269 prop_line_in.color->green = 0x0000;
1270 prop_line_in.color->blue = 0xffff;
1271 }
1272 else if(process_in->state->s == LTTV_STATE_WAIT)
1273 {
1274 prop_line_in.color->red = 0xffff;
1275 prop_line_in.color->green = 0x0000;
1276 prop_line_in.color->blue = 0x0000;
1277 }
1278 else if(process_in->state->s == LTTV_STATE_RUN)
1279 {
1280 prop_line_in.color->red = 0x0000;
1281 prop_line_in.color->green = 0xffff;
1282 prop_line_in.color->blue = 0x0000;
1283 }
1284 else
1285 {
cfe526b1 1286 prop_line_in.color->red = 0xffff;
1287 prop_line_in.color->green = 0xffff;
1288 prop_line_in.color->blue = 0xffff;
a56a1ba4 1289 }
1290
1291 draw_line((void*)&prop_line_in, (void*)draw_context_in);
1292 g_free(prop_line_in.color);
51705146 1293 //gdk_gc_unref(draw_context_in->gc);
a56a1ba4 1294 }
1295
1296 return 0;
b9a010a2 1297#endif //0
1298
1299
a56a1ba4 1300
51705146 1301 /* Text dump */
80a52ff8 1302#ifdef DONTSHOW
a56a1ba4 1303 GString *string = g_string_new("");;
1304 gboolean field_names = TRUE, state = TRUE;
80a52ff8 1305
e9a9c513 1306 lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
1307 g_string_append_printf(string,"\n");
1308
1309 if(state) {
1310 g_string_append_printf(string, " %s",
1311 g_quark_to_string(tfs->process->state->s));
1312 }
1313
1314 g_info("%s",string->str);
1315
a56a1ba4 1316 g_string_free(string, TRUE);
1317
1318 /* End of text dump */
80a52ff8 1319#endif //DONTSHOW
50439712 1320
f0d936c0 1321}
1322
e92eabaf 1323/* after_schedchange_hook
b9a010a2 1324 *
1325 * The draw after hook is called by the reading API to have a
1326 * particular event drawn on the screen.
1327 * @param hook_data ControlFlowData structure of the viewer.
1328 * @param call_data Event context.
1329 *
1330 * This function adds items to be drawn in a queue for each process.
1331 *
1332 */
e92eabaf 1333int after_schedchange_hook(void *hook_data, void *call_data)
f0d936c0 1334{
ca0f8a8e 1335 EventsRequest *events_request = (EventsRequest*)hook_data;
1336 ControlFlowData *control_flow_data = events_request->viewer_data;
50439712 1337
a56a1ba4 1338 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
50439712 1339
1340 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
16b9cadb 1341 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
50439712 1342
b9a010a2 1343 LttEvent *e;
1344 e = tfc->e;
1345
1346 LttTime evtime = ltt_event_time(e);
1347 TimeWindow time_window =
1348 lttvwindow_get_time_window(control_flow_data->tab);
1349
a18124ff 1350#ifdef EXTRA_CHECK
b9a010a2 1351 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 1352 || ltt_time_compare(evtime, time_window.end_time) == 1)
b9a010a2 1353 return;
a18124ff 1354#endif //EXTRA_CHECK
b9a010a2 1355
1356 guint width = control_flow_data->drawing->width;
1357
10a1069a 1358 /* Add process to process list (if not present) */
1359 LttvProcessState *process_out, *process_in;
1360 LttTime birth;
1361 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
1362 HashedProcessData *hashed_process_data_in = NULL;
b9a010a2 1363
5c230fc4 1364 ProcessList *process_list = control_flow_data->process_list;
10a1069a 1365
1366 guint pid_in;
1367 {
1368 guint pid_out;
1369 LttField *f = ltt_event_field(e);
1370 LttField *element;
1371 element = ltt_field_member(f,0);
1372 pid_out = ltt_event_get_long_unsigned(e,element);
1373 element = ltt_field_member(f,1);
1374 pid_in = ltt_event_get_long_unsigned(e,element);
1375 g_debug("out : %u in : %u", pid_out, pid_in);
1376 }
b9a010a2 1377
1378
10a1069a 1379 /* Find process pid_in in the list... */
1380 process_in = lttv_state_find_process(tfs, pid_in);
1381 /* It should exist, because we are after the state update. */
1382 g_assert(process_in != NULL);
b9a010a2 1383
10a1069a 1384 birth = process_in->creation_time;
1385 const gchar *name = g_quark_to_string(process_in->name);
b9a010a2 1386
10a1069a 1387 if(processlist_get_process_pixels(process_list,
1388 pid_in,
1389 process_in->last_cpu,
1390 &birth,
1391 tfc->t_context->index,
1392 &y_in,
1393 &height,
1394 &hashed_process_data_in) == 1)
1395 {
1396 g_assert(pid_in == 0 || pid_in != process_in->ppid);
4e86ae2e 1397 ProcessInfo *process_info;
10a1069a 1398 /* Process not present */
1399 processlist_add(process_list,
1400 pid_in,
1401 process_in->last_cpu,
1402 process_in->ppid,
1403 &birth,
1404 tfc->t_context->index,
1405 name,
1406 &pl_height,
4e86ae2e 1407 &process_info,
10a1069a 1408 &hashed_process_data_in);
4e86ae2e 1409 processlist_get_pixels_from_data(process_list,
1410 process_info,
1411 hashed_process_data_in,
1412 &y_in,
1413 &height);
10a1069a 1414 drawing_insert_square( control_flow_data->drawing, y_in, height);
b9a010a2 1415 }
10a1069a 1416
b2743953 1417 if(ltt_time_compare(hashed_process_data_in->next_good_time,
1418 evtime) <= 0)
1419 {
1420 guint new_x;
1421
1422 convert_time_to_pixels(
1423 time_window,
1424 evtime,
1425 width,
1426 &new_x);
e72908ed 1427
b2743953 1428 if(hashed_process_data_in->x.middle != new_x) {
1429 hashed_process_data_in->x.middle = new_x;
1430 hashed_process_data_in->x.middle_used = FALSE;
1431 hashed_process_data_in->x.middle_marked = FALSE;
1432 }
1433 }
b9a010a2 1434 return 0;
1435
1436
1437
e72908ed 1438
1439
b9a010a2 1440#if 0
1441 EventsRequest *events_request = (EventsRequest*)hook_data;
1442 ControlFlowData *control_flow_data = events_request->viewer_data;
1443
1444 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1445
1446 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1447 LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context;
1448
a56a1ba4 1449
50439712 1450 LttEvent *e;
1451 e = tfc->e;
1452
9444deae 1453 LttTime evtime = ltt_event_time(e);
ca0f8a8e 1454 TimeWindow time_window =
1455 lttvwindow_get_time_window(control_flow_data->tab);
9444deae 1456
a2aab3a3 1457 LttTime time_window.end_time = time_window.time_window.end_time;
6f26fc38 1458
9444deae 1459 //if(time < time_beg || time > time_end) return;
ca0f8a8e 1460 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 1461 || ltt_time_compare(evtime, time_window.end_time) == 1)
9444deae 1462 return;
1463
1464
a56a1ba4 1465 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
1466 {
2a2fa4f0 1467 g_debug("schedchange!");
a56a1ba4 1468
1469 /* Add process to process list (if not present) and get drawing "y" from
1470 * process position */
1471 guint pid_out, pid_in;
1472 LttvProcessState *process_out, *process_in;
1473 LttTime birth;
1474 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
1475
5c230fc4 1476 ProcessList *process_list = control_flow_data->process_list;
a56a1ba4 1477
1478
1479 LttField *f = ltt_event_field(e);
1480 LttField *element;
1481 element = ltt_field_member(f,0);
1482 pid_out = ltt_event_get_long_unsigned(e,element);
1483 element = ltt_field_member(f,1);
1484 pid_in = ltt_event_get_long_unsigned(e,element);
2a2fa4f0 1485 //g_debug("out : %u in : %u", pid_out, pid_in);
a56a1ba4 1486
1487
1488 /* Find process pid_out in the list... */
2a2fa4f0 1489 process_out = lttv_state_find_process(tfs, pid_out);
1aff52a2 1490 if(process_out == NULL) return 0;
2a2fa4f0 1491 //g_debug("out : %s",g_quark_to_string(process_out->state->s));
a56a1ba4 1492
1493 birth = process_out->creation_time;
1494 gchar *name = strdup(g_quark_to_string(process_out->name));
14963be0 1495 HashedProcessData *hashed_process_data_out = NULL;
a56a1ba4 1496
1497 if(processlist_get_process_pixels(process_list,
1498 pid_out,
1499 &birth,
d0cd7f09 1500 tfc->t_context->index,
a56a1ba4 1501 &y_out,
1502 &height,
14963be0 1503 &hashed_process_data_out) == 1)
a56a1ba4 1504 {
51705146 1505 /* Process not present */
1506 processlist_add(process_list,
1507 pid_out,
1508 &birth,
1509 tfc->t_context->index,
1510 name,
1511 &pl_height,
1512 &hashed_process_data_out);
1513 processlist_get_process_pixels(process_list,
1514 pid_out,
1515 &birth,
1516 tfc->t_context->index,
1517 &y_out,
1518 &height,
1519 &hashed_process_data_out);
1520 drawing_insert_square( control_flow_data->drawing, y_out, height);
a56a1ba4 1521 }
1522
1523 g_free(name);
1524
1525 /* Find process pid_in in the list... */
2a2fa4f0 1526 process_in = lttv_state_find_process(tfs, pid_in);
1aff52a2 1527 if(process_in == NULL) return 0;
2a2fa4f0 1528 //g_debug("in : %s",g_quark_to_string(process_in->state->s));
a56a1ba4 1529
1530 birth = process_in->creation_time;
1531 name = strdup(g_quark_to_string(process_in->name));
14963be0 1532 HashedProcessData *hashed_process_data_in = NULL;
a56a1ba4 1533
1534 if(processlist_get_process_pixels(process_list,
1535 pid_in,
1536 &birth,
d0cd7f09 1537 tfc->t_context->index,
a56a1ba4 1538 &y_in,
1539 &height,
14963be0 1540 &hashed_process_data_in) == 1)
a56a1ba4 1541 {
1542 /* Process not present */
1543 processlist_add(process_list,
1544 pid_in,
1545 &birth,
d0cd7f09 1546 tfc->t_context->index,
a56a1ba4 1547 name,
1548 &pl_height,
14963be0 1549 &hashed_process_data_in);
a56a1ba4 1550 processlist_get_process_pixels(process_list,
1551 pid_in,
1552 &birth,
d0cd7f09 1553 tfc->t_context->index,
a56a1ba4 1554 &y_in,
1555 &height,
14963be0 1556 &hashed_process_data_in);
a56a1ba4 1557
ca0f8a8e 1558 drawing_insert_square( control_flow_data->drawing, y_in, height);
a56a1ba4 1559 }
1560 g_free(name);
1561
1562
1563 /* Find pixels corresponding to time of the event. If the time does
1564 * not fit in the window, show a warning, not supposed to happend. */
1565 //guint x = 0;
501d5405 1566 //guint width = control_flow_data->drawing->drawing_area->allocation.width;
a56a1ba4 1567
1568 //LttTime time = ltt_event_time(e);
1569
a2aab3a3 1570 //LttTime window_end = time_window->time_window.end_time;
a56a1ba4 1571
1572
1573 //convert_time_to_pixels(
a18124ff 1574 // *time_window,
a56a1ba4 1575 // time,
1576 // width,
1577 // &x);
1578
1579 //assert(x <= width);
1580
1581 /* draw what represents the event for outgoing process. */
1582
14963be0 1583 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
68997a22 1584 //draw_context_out->current->modify_over->x = x;
1585 draw_context_out->current->modify_over->y = y_out;
319e9d81 1586 draw_context_out->current->modify_under->y = y_out+(height/2)+2;
501d5405 1587 draw_context_out->drawable = control_flow_data->drawing->pixmap;
1588 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
1589 GtkWidget *widget = control_flow_data->drawing->drawing_area;
a56a1ba4 1590 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
d0cd7f09 1591
a56a1ba4 1592 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
501d5405 1593 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
d0cd7f09 1594
1595 /*if(process_out->state->s == LTTV_STATE_RUN)
1596 {
1597 draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1598 gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
1599 PropertiesBG prop_bg;
1600 prop_bg.color = g_new(GdkColor,1);
1601
1602 prop_bg.color->red = 0xffff;
1603 prop_bg.color->green = 0xffff;
1604 prop_bg.color->blue = 0xffff;
1605
1606 draw_bg((void*)&prop_bg, (void*)draw_context_out);
1607 g_free(prop_bg.color);
1608 gdk_gc_unref(draw_context_out->gc);
1609 }*/
1610
1611 draw_context_out->gc = widget->style->black_gc;
1612
a56a1ba4 1613 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
2df6f2bd 1614 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 1615 PropertiesText prop_text_out;
1616 prop_text_out.foreground = &colorfg_out;
1617 prop_text_out.background = &colorbg_out;
cfe526b1 1618 prop_text_out.size = 6;
a56a1ba4 1619 prop_text_out.position = OVER;
1620
cfe526b1 1621 /* color of text : status of the process */
1622 if(process_out->state->s == LTTV_STATE_UNNAMED)
1623 {
1624 prop_text_out.foreground->red = 0xffff;
1625 prop_text_out.foreground->green = 0xffff;
1626 prop_text_out.foreground->blue = 0xffff;
1627 }
1628 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
1629 {
1630 prop_text_out.foreground->red = 0x0fff;
d52cfc84 1631 prop_text_out.foreground->green = 0xffff;
1632 prop_text_out.foreground->blue = 0xfff0;
cfe526b1 1633 }
1634 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
1635 {
2df6f2bd 1636 prop_text_out.foreground->red = 0xffff;
1637 prop_text_out.foreground->green = 0xffff;
cfe526b1 1638 prop_text_out.foreground->blue = 0x0000;
1639 }
0828099d 1640 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
cfe526b1 1641 {
1642 prop_text_out.foreground->red = 0xffff;
1643 prop_text_out.foreground->green = 0x0000;
1644 prop_text_out.foreground->blue = 0xffff;
1645 }
1646 else if(process_out->state->s == LTTV_STATE_WAIT)
1647 {
1648 prop_text_out.foreground->red = 0xffff;
1649 prop_text_out.foreground->green = 0x0000;
1650 prop_text_out.foreground->blue = 0x0000;
1651 }
1652 else if(process_out->state->s == LTTV_STATE_RUN)
1653 {
1654 prop_text_out.foreground->red = 0x0000;
1655 prop_text_out.foreground->green = 0xffff;
1656 prop_text_out.foreground->blue = 0x0000;
1657 }
1658 else
1659 {
1660 prop_text_out.foreground->red = 0xffff;
1661 prop_text_out.foreground->green = 0xffff;
1662 prop_text_out.foreground->blue = 0xffff;
1663 }
1664
a56a1ba4 1665 /* Print status of the process : U, WF, WC, E, W, R */
1666 if(process_out->state->s == LTTV_STATE_UNNAMED)
68997a22 1667 prop_text_out.text = "U";
a56a1ba4 1668 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
68997a22 1669 prop_text_out.text = "WF";
a56a1ba4 1670 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
68997a22 1671 prop_text_out.text = "WC";
0828099d 1672 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
68997a22 1673 prop_text_out.text = "E";
a56a1ba4 1674 else if(process_out->state->s == LTTV_STATE_WAIT)
68997a22 1675 prop_text_out.text = "W";
a56a1ba4 1676 else if(process_out->state->s == LTTV_STATE_RUN)
68997a22 1677 prop_text_out.text = "R";
a56a1ba4 1678 else
68997a22 1679 prop_text_out.text = "U";
a56a1ba4 1680
1681 draw_text((void*)&prop_text_out, (void*)draw_context_out);
d0cd7f09 1682
1683 //gdk_gc_unref(draw_context_out->gc);
319e9d81 1684
68997a22 1685 draw_context_out->current->middle->y = y_out+height/2;
d0cd7f09 1686 draw_context_out->current->over->y = y_out;
1687 draw_context_out->current->under->y = y_out+height;
68997a22 1688 draw_context_out->current->status = process_out->state->s;
a56a1ba4 1689
68997a22 1690 /* for pid_out : remove previous, Prev = current, new current (default) */
1691 g_free(draw_context_out->previous->modify_under);
1692 g_free(draw_context_out->previous->modify_middle);
1693 g_free(draw_context_out->previous->modify_over);
1694 g_free(draw_context_out->previous->under);
1695 g_free(draw_context_out->previous->middle);
1696 g_free(draw_context_out->previous->over);
1697 g_free(draw_context_out->previous);
1698
1699 draw_context_out->previous = draw_context_out->current;
a56a1ba4 1700
68997a22 1701 draw_context_out->current = g_new(DrawInfo,1);
1702 draw_context_out->current->over = g_new(ItemInfo,1);
1703 draw_context_out->current->over->x = -1;
1704 draw_context_out->current->over->y = -1;
1705 draw_context_out->current->middle = g_new(ItemInfo,1);
1706 draw_context_out->current->middle->x = -1;
1707 draw_context_out->current->middle->y = -1;
1708 draw_context_out->current->under = g_new(ItemInfo,1);
1709 draw_context_out->current->under->x = -1;
1710 draw_context_out->current->under->y = -1;
1711 draw_context_out->current->modify_over = g_new(ItemInfo,1);
1712 draw_context_out->current->modify_over->x = -1;
1713 draw_context_out->current->modify_over->y = -1;
1714 draw_context_out->current->modify_middle = g_new(ItemInfo,1);
1715 draw_context_out->current->modify_middle->x = -1;
1716 draw_context_out->current->modify_middle->y = -1;
1717 draw_context_out->current->modify_under = g_new(ItemInfo,1);
1718 draw_context_out->current->modify_under->x = -1;
1719 draw_context_out->current->modify_under->y = -1;
1720 draw_context_out->current->status = LTTV_STATE_UNNAMED;
a56a1ba4 1721
1722 /* Finally, update the drawing context of the pid_in. */
1723
14963be0 1724 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
68997a22 1725 //draw_context_in->current->modify_over->x = x;
1726 draw_context_in->current->modify_over->y = y_in;
319e9d81 1727 draw_context_in->current->modify_under->y = y_in+(height/2)+2;
501d5405 1728 draw_context_in->drawable = control_flow_data->drawing->pixmap;
1729 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
1730 widget = control_flow_data->drawing->drawing_area;
a56a1ba4 1731 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
a56a1ba4 1732
1733 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
501d5405 1734 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
d0cd7f09 1735
1736 /*if(process_in->state->s == LTTV_STATE_RUN)
1737 {
1738 draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1739 gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1740 PropertiesBG prop_bg;
1741 prop_bg.color = g_new(GdkColor,1);
1742
1743 prop_bg.color->red = 0xffff;
1744 prop_bg.color->green = 0xffff;
1745 prop_bg.color->blue = 0xffff;
1746
1747 draw_bg((void*)&prop_bg, (void*)draw_context_in);
1748 g_free(prop_bg.color);
1749 gdk_gc_unref(draw_context_in->gc);
1750 }*/
1751
1752 draw_context_in->gc = widget->style->black_gc;
1753
a56a1ba4 1754 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
2df6f2bd 1755 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 1756 PropertiesText prop_text_in;
1757 prop_text_in.foreground = &colorfg_in;
1758 prop_text_in.background = &colorbg_in;
cfe526b1 1759 prop_text_in.size = 6;
a56a1ba4 1760 prop_text_in.position = OVER;
1761
cfe526b1 1762 /* foreground of text : status of the process */
1763 if(process_in->state->s == LTTV_STATE_UNNAMED)
1764 {
1765 prop_text_in.foreground->red = 0xffff;
1766 prop_text_in.foreground->green = 0xffff;
1767 prop_text_in.foreground->blue = 0xffff;
1768 }
1769 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1770 {
1771 prop_text_in.foreground->red = 0x0fff;
d52cfc84 1772 prop_text_in.foreground->green = 0xffff;
1773 prop_text_in.foreground->blue = 0xfff0;
cfe526b1 1774 }
1775 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1776 {
2df6f2bd 1777 prop_text_in.foreground->red = 0xffff;
1778 prop_text_in.foreground->green = 0xffff;
cfe526b1 1779 prop_text_in.foreground->blue = 0x0000;
1780 }
0828099d 1781 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
cfe526b1 1782 {
1783 prop_text_in.foreground->red = 0xffff;
1784 prop_text_in.foreground->green = 0x0000;
1785 prop_text_in.foreground->blue = 0xffff;
1786 }
1787 else if(process_in->state->s == LTTV_STATE_WAIT)
1788 {
1789 prop_text_in.foreground->red = 0xffff;
1790 prop_text_in.foreground->green = 0x0000;
1791 prop_text_in.foreground->blue = 0x0000;
1792 }
1793 else if(process_in->state->s == LTTV_STATE_RUN)
1794 {
1795 prop_text_in.foreground->red = 0x0000;
1796 prop_text_in.foreground->green = 0xffff;
1797 prop_text_in.foreground->blue = 0x0000;
1798 }
1799 else
1800 {
1801 prop_text_in.foreground->red = 0xffff;
1802 prop_text_in.foreground->green = 0xffff;
1803 prop_text_in.foreground->blue = 0xffff;
1804 }
1805
1806
a56a1ba4 1807 /* Print status of the process : U, WF, WC, E, W, R */
1808 if(process_in->state->s == LTTV_STATE_UNNAMED)
68997a22 1809 prop_text_in.text = "U";
a56a1ba4 1810 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
68997a22 1811 prop_text_in.text = "WF";
a56a1ba4 1812 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
68997a22 1813 prop_text_in.text = "WC";
0828099d 1814 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
68997a22 1815 prop_text_in.text = "E";
a56a1ba4 1816 else if(process_in->state->s == LTTV_STATE_WAIT)
68997a22 1817 prop_text_in.text = "W";
a56a1ba4 1818 else if(process_in->state->s == LTTV_STATE_RUN)
68997a22 1819 prop_text_in.text = "R";
a56a1ba4 1820 else
68997a22 1821 prop_text_in.text = "U";
a56a1ba4 1822
1823 draw_text((void*)&prop_text_in, (void*)draw_context_in);
1824
d0cd7f09 1825
319e9d81 1826 if(process_in->state->s == LTTV_STATE_RUN)
1827 {
1828 gchar tmp[255];
1829 prop_text_in.foreground = &colorfg_in;
1830 prop_text_in.background = &colorbg_in;
1831 prop_text_in.foreground->red = 0xffff;
1832 prop_text_in.foreground->green = 0xffff;
1833 prop_text_in.foreground->blue = 0xffff;
1834 prop_text_in.size = 6;
1835 prop_text_in.position = UNDER;
1836
1837 prop_text_in.text = g_new(gchar, 260);
1838 strcpy(prop_text_in.text, "CPU ");
1839 snprintf(tmp, 255, "%u", tfc->index);
1840 strcat(prop_text_in.text, tmp);
1841
1842 draw_text((void*)&prop_text_in, (void*)draw_context_in);
1843 g_free(prop_text_in.text);
1844 }
1845
1846
68997a22 1847 draw_context_in->current->middle->y = y_in+height/2;
d0cd7f09 1848 draw_context_in->current->over->y = y_in;
1849 draw_context_in->current->under->y = y_in+height;
68997a22 1850 draw_context_in->current->status = process_in->state->s;
1851
1852 /* for pid_in : remove previous, Prev = current, new current (default) */
1853 g_free(draw_context_in->previous->modify_under);
1854 g_free(draw_context_in->previous->modify_middle);
1855 g_free(draw_context_in->previous->modify_over);
1856 g_free(draw_context_in->previous->under);
1857 g_free(draw_context_in->previous->middle);
1858 g_free(draw_context_in->previous->over);
1859 g_free(draw_context_in->previous);
1860
1861 draw_context_in->previous = draw_context_in->current;
a56a1ba4 1862
68997a22 1863 draw_context_in->current = g_new(DrawInfo,1);
1864 draw_context_in->current->over = g_new(ItemInfo,1);
1865 draw_context_in->current->over->x = -1;
1866 draw_context_in->current->over->y = -1;
1867 draw_context_in->current->middle = g_new(ItemInfo,1);
1868 draw_context_in->current->middle->x = -1;
1869 draw_context_in->current->middle->y = -1;
1870 draw_context_in->current->under = g_new(ItemInfo,1);
1871 draw_context_in->current->under->x = -1;
1872 draw_context_in->current->under->y = -1;
1873 draw_context_in->current->modify_over = g_new(ItemInfo,1);
1874 draw_context_in->current->modify_over->x = -1;
1875 draw_context_in->current->modify_over->y = -1;
1876 draw_context_in->current->modify_middle = g_new(ItemInfo,1);
1877 draw_context_in->current->modify_middle->x = -1;
1878 draw_context_in->current->modify_middle->y = -1;
1879 draw_context_in->current->modify_under = g_new(ItemInfo,1);
1880 draw_context_in->current->modify_under->x = -1;
1881 draw_context_in->current->modify_under->y = -1;
1882 draw_context_in->current->status = LTTV_STATE_UNNAMED;
a56a1ba4 1883
1884 }
1885
1886 return 0;
b9a010a2 1887#endif //0
f0d936c0 1888}
f7afe191 1889
9a1ec01b 1890#if 0
23093869 1891static __inline PropertiesLine prepare_execmode_line(LttvProcessState *process)
1892{
1893 PropertiesLine prop_line;
1894 prop_line.line_width = 1;
1895 prop_line.style = GDK_LINE_SOLID;
1896 prop_line.y = OVER;
1897 //GdkColormap *colormap = gdk_colormap_get_system();
1898
1899 /* color of line : execution mode of the process */
1900 if(process->state->t == LTTV_STATE_USER_MODE)
1901 prop_line.color = drawing_colors[COL_USER_MODE];
1902 else if(process->state->t == LTTV_STATE_SYSCALL)
1903 prop_line.color = drawing_colors[COL_SYSCALL];
1904 else if(process->state->t == LTTV_STATE_TRAP)
1905 prop_line.color = drawing_colors[COL_TRAP];
1906 else if(process->state->t == LTTV_STATE_IRQ)
1907 prop_line.color = drawing_colors[COL_IRQ];
1908 else if(process->state->t == LTTV_STATE_MODE_UNKNOWN)
1909 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
1910 else
1911 prop_line.color = drawing_colors[COL_WHITE];
1912
1913 //gdk_colormap_alloc_color(colormap,
1914 // prop_line.color,
1915 // FALSE,
1916 // TRUE);
1917
1918 return prop_line;
1919
1920}
9a1ec01b 1921#endif //0
23093869 1922
1923
1924/* before_execmode_hook
1925 *
1926 * This function basically draw lines and icons. Two types of lines are drawn :
1927 * one small (3 pixels?) representing the state of the process and the second
1928 * type is thicker (10 pixels?) representing on which CPU a process is running
1929 * (and this only in running state).
1930 *
1931 * Extremums of the lines :
1932 * x_min : time of the last event context for this process kept in memory.
1933 * x_max : time of the current event.
1934 * y : middle of the process in the process list. The process is found in the
1935 * list, therefore is it's position in pixels.
1936 *
1937 * The choice of lines'color is defined by the context of the last event for this
1938 * process.
1939 */
1940
1941
1942int before_execmode_hook(void *hook_data, void *call_data)
1943{
1944 EventsRequest *events_request = (EventsRequest*)hook_data;
1945 ControlFlowData *control_flow_data = events_request->viewer_data;
1946 Drawing_t *drawing = control_flow_data->drawing;
1947
1948 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1949
1950 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
16b9cadb 1951 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
23093869 1952
1953 LttEvent *e;
1954 e = tfc->e;
1955
1956 LttTime evtime = ltt_event_time(e);
1957 TimeWindow time_window =
1958 lttvwindow_get_time_window(control_flow_data->tab);
1959
a18124ff 1960#ifdef EXTRA_CHECK
23093869 1961 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 1962 || ltt_time_compare(evtime, time_window.end_time) == 1)
23093869 1963 return;
a18124ff 1964#endif //EXTRA_CHECK
23093869 1965
1966 guint width = drawing->width;
1967
10a1069a 1968 /* we are in a execmode, before the state update. We must draw the
1969 * items corresponding to the state before it changes : now is the right
1970 * time to do it.
1971 */
1972 /* For the pid */
1973 LttvProcessState *process = tfs->process;
1974 g_assert(process != NULL);
23093869 1975
10a1069a 1976 guint pid = process->pid;
23093869 1977
10a1069a 1978 /* Well, the process_out existed : we must get it in the process hash
1979 * or add it, and draw its items.
1980 */
1981 /* Add process to process list (if not present) */
1982 guint y = 0, height = 0, pl_height = 0;
1983 HashedProcessData *hashed_process_data = NULL;
5c230fc4 1984 ProcessList *process_list = control_flow_data->process_list;
10a1069a 1985 LttTime birth = process->creation_time;
1986 const gchar *name = g_quark_to_string(process->name);
1987
1988 if(processlist_get_process_pixels(process_list,
1989 pid,
1990 process->last_cpu,
1991 &birth,
1992 tfc->t_context->index,
1993 &y,
1994 &height,
1995 &hashed_process_data) == 1)
1996 {
1997 g_assert(pid == 0 || pid != process->ppid);
4e86ae2e 1998 ProcessInfo *process_info;
10a1069a 1999 /* Process not present */
2000 processlist_add(process_list,
2001 pid,
2002 process->last_cpu,
2003 process->ppid,
2004 &birth,
2005 tfc->t_context->index,
2006 name,
2007 &pl_height,
4e86ae2e 2008 &process_info,
10a1069a 2009 &hashed_process_data);
4e86ae2e 2010 processlist_get_pixels_from_data(process_list,
2011 process_info,
2012 hashed_process_data,
2013 &y,
2014 &height);
10a1069a 2015 drawing_insert_square( drawing, y, height);
2016 }
23093869 2017
10a1069a 2018 /* Now, the process is in the state hash and our own process hash.
2019 * We definitely can draw the items related to the ending state.
2020 */
2021
2022 /* Check if the x position is unset. In can have been left unset by
2023 * a draw closure from a after chunk hook. This should never happen,
2024 * because it must be set by before chunk hook to the damage_begin
2025 * value.
2026 */
2027 g_assert(hashed_process_data->x.over != -1);
b2743953 2028
2029 if(ltt_time_compare(hashed_process_data->next_good_time,
2030 evtime) > 0)
10a1069a 2031 {
b2743953 2032 if(hashed_process_data->x.middle_marked == FALSE) {
2033 guint x;
2034 convert_time_to_pixels(
2035 time_window,
2036 evtime,
2037 width,
2038 &x);
2039
2040 /* Draw collision indicator */
2041 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2042 gdk_draw_point(drawing->pixmap,
2043 drawing->gc,
2044 x,
2045 y+(height/2)-3);
2046 hashed_process_data->x.middle_marked = TRUE;
2047 }
2048 } else {
10a1069a 2049 guint x;
dbd243b1 2050
10a1069a 2051 convert_time_to_pixels(
a18124ff 2052 time_window,
10a1069a 2053 evtime,
2054 width,
2055 &x);
dbd243b1 2056
23093869 2057
4b7dc462 2058 /* Jump over draw if we are at the same x position */
e72908ed 2059 if(x == hashed_process_data->x.middle &&
2060 hashed_process_data->x.middle_used)
10a1069a 2061 {
e72908ed 2062 if(hashed_process_data->x.middle_marked == FALSE) {
2063 /* Draw collision indicator */
2064 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2065 gdk_draw_point(drawing->pixmap,
2066 drawing->gc,
2067 x,
2c6618bc 2068 y+(height/2)-3);
de4ea1ad 2069 hashed_process_data->x.middle_marked = TRUE;
e72908ed 2070 }
4b7dc462 2071 /* jump */
2072 } else {
2073
2074 DrawContext draw_context;
2075 /* Now create the drawing context that will be used to draw
2076 * items related to the last state. */
2077 draw_context.drawable = drawing->pixmap;
2078 draw_context.gc = drawing->gc;
2079 draw_context.pango_layout = drawing->pango_layout;
9a1ec01b 2080 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
4b7dc462 2081 draw_context.drawinfo.end.x = x;
2082
2083 draw_context.drawinfo.y.over = y+1;
2084 draw_context.drawinfo.y.middle = y+(height/2);
2085 draw_context.drawinfo.y.under = y+height;
2086
2087 draw_context.drawinfo.start.offset.over = 0;
2088 draw_context.drawinfo.start.offset.middle = 0;
2089 draw_context.drawinfo.start.offset.under = 0;
2090 draw_context.drawinfo.end.offset.over = 0;
2091 draw_context.drawinfo.end.offset.middle = 0;
2092 draw_context.drawinfo.end.offset.under = 0;
2093
2094 {
2095 /* Draw the line */
9a1ec01b 2096 PropertiesLine prop_line = prepare_s_e_line(process);
4b7dc462 2097 draw_line((void*)&prop_line, (void*)&draw_context);
23093869 2098
4b7dc462 2099 }
2100 /* become the last x position */
9a1ec01b 2101 hashed_process_data->x.middle = x;
e72908ed 2102 hashed_process_data->x.middle_used = TRUE;
2103 hashed_process_data->x.middle_marked = FALSE;
b2743953 2104
2105 /* Calculate the next good time */
2106 convert_pixels_to_time(width, x+1, time_window,
2107 &hashed_process_data->next_good_time);
23093869 2108 }
2109 }
2110
2111 return 0;
2112}
2113
2114/* after_execmode_hook
2115 *
2116 * The draw after hook is called by the reading API to have a
2117 * particular event drawn on the screen.
2118 * @param hook_data ControlFlowData structure of the viewer.
2119 * @param call_data Event context.
2120 *
2121 * This function adds items to be drawn in a queue for each process.
2122 *
2123 */
2124int after_execmode_hook(void *hook_data, void *call_data)
2125{
2126 EventsRequest *events_request = (EventsRequest*)hook_data;
2127 ControlFlowData *control_flow_data = events_request->viewer_data;
2128
2129 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
2130
2131 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
16b9cadb 2132 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
23093869 2133
2134 LttEvent *e;
2135 e = tfc->e;
2136
2137 LttTime evtime = ltt_event_time(e);
2138 TimeWindow time_window =
2139 lttvwindow_get_time_window(control_flow_data->tab);
2140
a18124ff 2141#ifdef EXTRA_CHECK
23093869 2142 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 2143 || ltt_time_compare(evtime, time_window.end_time) == 1)
23093869 2144 return;
a18124ff 2145#endif //EXTRA_CHECK
23093869 2146
2147 guint width = control_flow_data->drawing->width;
2148
10a1069a 2149 /* Add process to process list (if not present) */
2150 LttvProcessState *process;
2151 LttTime birth;
2152 guint y = 0, height = 0, pl_height = 0;
2153 HashedProcessData *hashed_process_data = NULL;
23093869 2154
5c230fc4 2155 ProcessList *process_list = control_flow_data->process_list;
23093869 2156
10a1069a 2157 /* Find process pid_in in the list... */
2158 process = tfs->process;
2159 /* It should exist, because we are after the state update. */
2160 g_assert(process != NULL);
23093869 2161
10a1069a 2162 guint pid = process->pid;
23093869 2163
10a1069a 2164 birth = process->creation_time;
2165 const gchar *name = g_quark_to_string(process->name);
23093869 2166
10a1069a 2167 if(processlist_get_process_pixels(process_list,
2168 pid,
2169 process->last_cpu,
2170 &birth,
2171 tfc->t_context->index,
2172 &y,
2173 &height,
2174 &hashed_process_data) == 1)
2175 {
2176 g_assert(pid == 0 || pid != process->ppid);
2177 /* Process not present */
4e86ae2e 2178 ProcessInfo *process_info;
10a1069a 2179 processlist_add(process_list,
2180 pid,
2181 process->last_cpu,
2182 process->ppid,
2183 &birth,
2184 tfc->t_context->index,
2185 name,
2186 &pl_height,
4e86ae2e 2187 &process_info,
10a1069a 2188 &hashed_process_data);
4e86ae2e 2189 processlist_get_pixels_from_data(process_list,
2190 process_info,
2191 hashed_process_data,
2192 &y,
2193 &height);
10a1069a 2194 drawing_insert_square( control_flow_data->drawing, y, height);
23093869 2195 }
e72908ed 2196
b2743953 2197 if(ltt_time_compare(hashed_process_data->next_good_time,
2198 evtime) <= 0)
2199 {
2200 guint new_x;
2201
2202 convert_time_to_pixels(
2203 time_window,
2204 evtime,
2205 width,
2206 &new_x);
e72908ed 2207
b2743953 2208 if(hashed_process_data->x.middle != new_x) {
2209 hashed_process_data->x.middle = new_x;
2210 hashed_process_data->x.middle_used = FALSE;
2211 hashed_process_data->x.middle_marked = FALSE;
2212 }
2213 }
23093869 2214 return 0;
2215}
2216
2217
dbd243b1 2218
2219/* before_process_hook
2220 *
2221 * Draw lines for process event.
2222 *
2223 * @param hook_data ControlFlowData structure of the viewer.
2224 * @param call_data Event context.
2225 *
2226 * This function adds items to be drawn in a queue for each process.
2227 *
2228 */
2229int before_process_hook(void *hook_data, void *call_data)
2230{
2231 EventsRequest *events_request = (EventsRequest*)hook_data;
2232 ControlFlowData *control_flow_data = events_request->viewer_data;
2233 Drawing_t *drawing = control_flow_data->drawing;
2234
2235 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
2236
2237 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
16b9cadb 2238 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
dbd243b1 2239
2240 LttEvent *e;
2241 e = tfc->e;
2242
2243 LttTime evtime = ltt_event_time(e);
2244 TimeWindow time_window =
2245 lttvwindow_get_time_window(control_flow_data->tab);
2246
a18124ff 2247#ifdef EXTRA_CHECK
dbd243b1 2248 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 2249 || ltt_time_compare(evtime, time_window.end_time) == 1)
dbd243b1 2250 return;
a18124ff 2251#endif //EXTRA_CHECK
dbd243b1 2252
2253 guint width = control_flow_data->drawing->width;
2254
10a1069a 2255 guint sub_id;
2256 {
2257 LttField *f = ltt_event_field(e);
2258 LttField *element;
2259 element = ltt_field_member(f,0);
2260 sub_id = ltt_event_get_long_unsigned(e,element);
2261 }
dbd243b1 2262
10a1069a 2263 if(sub_id == 3) { /* exit */
dbd243b1 2264
10a1069a 2265 /* Add process to process list (if not present) */
2266 LttvProcessState *process = tfs->process;
2267 guint pid = process->pid;
2268 LttTime birth;
2269 guint y = 0, height = 0, pl_height = 0;
2270 HashedProcessData *hashed_process_data = NULL;
dbd243b1 2271
5c230fc4 2272 ProcessList *process_list = control_flow_data->process_list;
10a1069a 2273
2274 g_assert(process != NULL);
dbd243b1 2275
10a1069a 2276 birth = process->creation_time;
2277 const gchar *name = g_quark_to_string(process->name);
dbd243b1 2278
10a1069a 2279 if(processlist_get_process_pixels(process_list,
2280 pid,
2281 process->last_cpu,
2282 &birth,
2283 tfc->t_context->index,
2284 &y,
2285 &height,
2286 &hashed_process_data) == 1)
2287 {
2288 g_assert(pid == 0 || pid != process->ppid);
2289 /* Process not present */
4e86ae2e 2290 ProcessInfo *process_info;
10a1069a 2291 processlist_add(process_list,
2292 pid,
2293 process->last_cpu,
2294 process->ppid,
2295 &birth,
2296 tfc->t_context->index,
2297 name,
2298 &pl_height,
4e86ae2e 2299 &process_info,
10a1069a 2300 &hashed_process_data);
4e86ae2e 2301 processlist_get_pixels_from_data(process_list,
2302 process_info,
2303 hashed_process_data,
2304 &y,
2305 &height);
10a1069a 2306 drawing_insert_square( control_flow_data->drawing, y, height);
2307 }
dbd243b1 2308
10a1069a 2309 /* Now, the process is in the state hash and our own process hash.
2310 * We definitely can draw the items related to the ending state.
2311 */
2312
2313 /* Check if the x position is unset. In can have been left unset by
2314 * a draw closure from a after chunk hook. This should never happen,
2315 * because it must be set by before chunk hook to the damage_begin
2316 * value.
2317 */
2318 g_assert(hashed_process_data->x.over != -1);
b2743953 2319
2320 if(ltt_time_compare(hashed_process_data->next_good_time,
2321 evtime) > 0)
10a1069a 2322 {
b2743953 2323 if(hashed_process_data->x.middle_marked == FALSE) {
2324 guint x;
2325 convert_time_to_pixels(
2326 time_window,
2327 evtime,
2328 width,
2329 &x);
2330
2331 /* Draw collision indicator */
2332 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2333 gdk_draw_point(drawing->pixmap,
2334 drawing->gc,
2335 x,
2336 y+(height/2)-3);
2337 hashed_process_data->x.middle_marked = TRUE;
2338 }
2339 } else {
10a1069a 2340 guint x;
dbd243b1 2341
10a1069a 2342 convert_time_to_pixels(
a18124ff 2343 time_window,
10a1069a 2344 evtime,
2345 width,
2346 &x);
dbd243b1 2347
dbd243b1 2348
4b7dc462 2349 /* Jump over draw if we are at the same x position */
e72908ed 2350 if(x == hashed_process_data->x.middle &&
2351 hashed_process_data->x.middle_used)
2352 {
2353 if(hashed_process_data->x.middle_marked == FALSE) {
2354 /* Draw collision indicator */
2355 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2356 gdk_draw_point(drawing->pixmap,
2357 drawing->gc,
2358 x,
2c6618bc 2359 y+(height/2)-3);
de4ea1ad 2360 hashed_process_data->x.middle_marked = TRUE;
e72908ed 2361 }
4b7dc462 2362 /* jump */
2363 } else {
2364 DrawContext draw_context;
dbd243b1 2365
4b7dc462 2366 /* Now create the drawing context that will be used to draw
2367 * items related to the last state. */
2368 draw_context.drawable = drawing->pixmap;
2369 draw_context.gc = drawing->gc;
2370 draw_context.pango_layout = drawing->pango_layout;
2371 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
2372 draw_context.drawinfo.end.x = x;
dbd243b1 2373
4b7dc462 2374 draw_context.drawinfo.y.over = y+1;
2375 draw_context.drawinfo.y.middle = y+(height/2);
2376 draw_context.drawinfo.y.under = y+height;
2377
2378 draw_context.drawinfo.start.offset.over = 0;
2379 draw_context.drawinfo.start.offset.middle = 0;
2380 draw_context.drawinfo.start.offset.under = 0;
2381 draw_context.drawinfo.end.offset.over = 0;
2382 draw_context.drawinfo.end.offset.middle = 0;
2383 draw_context.drawinfo.end.offset.under = 0;
dbd243b1 2384
4b7dc462 2385 {
2386 /* Draw the line */
9a1ec01b 2387 PropertiesLine prop_line = prepare_s_e_line(process);
4b7dc462 2388 draw_line((void*)&prop_line, (void*)&draw_context);
2389
2390 }
2391 /* become the last x position */
2392 hashed_process_data->x.middle = x;
e72908ed 2393 hashed_process_data->x.middle_used = TRUE;
2394 hashed_process_data->x.middle_marked = FALSE;
b2743953 2395
2396 /* Calculate the next good time */
2397 convert_pixels_to_time(width, x+1, time_window,
2398 &hashed_process_data->next_good_time);
dbd243b1 2399 }
dbd243b1 2400 }
2401
dbd243b1 2402 }
2403 return 0;
2404
2405}
2406
2407
2408
2409
2410
2411
2412/* after_process_hook
e92eabaf 2413 *
2414 * Create the processlist entry for the child process. Put the last
2415 * position in x at the current time value.
2416 *
2417 * @param hook_data ControlFlowData structure of the viewer.
2418 * @param call_data Event context.
2419 *
2420 * This function adds items to be drawn in a queue for each process.
2421 *
2422 */
dbd243b1 2423int after_process_hook(void *hook_data, void *call_data)
e92eabaf 2424{
2425 EventsRequest *events_request = (EventsRequest*)hook_data;
2426 ControlFlowData *control_flow_data = events_request->viewer_data;
2427
2428 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
2429
2430 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
16b9cadb 2431 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
e92eabaf 2432
2433 LttEvent *e;
2434 e = tfc->e;
2435
2436 LttTime evtime = ltt_event_time(e);
2437 TimeWindow time_window =
2438 lttvwindow_get_time_window(control_flow_data->tab);
2439
a18124ff 2440#ifdef EXTRA_CHECK
e92eabaf 2441 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 2442 || ltt_time_compare(evtime, time_window.end_time) == 1)
e92eabaf 2443 return;
a18124ff 2444#endif //EXTRA_CHECK
f7afe191 2445
e92eabaf 2446 guint width = control_flow_data->drawing->width;
2447
10a1069a 2448 guint sub_id;
2449 guint param1;
2450 {
2451 LttField *f = ltt_event_field(e);
2452 LttField *element;
2453 element = ltt_field_member(f,0);
2454 sub_id = ltt_event_get_long_unsigned(e,element);
2455 element = ltt_field_member(f,1);
2456 param1 = ltt_event_get_long_unsigned(e,element);
2457 }
e92eabaf 2458
10a1069a 2459 if(sub_id == 2) { /* fork */
2460
2461 guint child_pid = param1;
2462 /* Add process to process list (if not present) */
2463 LttvProcessState *process_child;
2464 LttTime birth;
2465 guint y_child = 0, height = 0, pl_height = 0;
2466 HashedProcessData *hashed_process_data_child = NULL;
e92eabaf 2467
5c230fc4 2468 ProcessList *process_list = control_flow_data->process_list;
e92eabaf 2469
10a1069a 2470 /* Find child in the list... */
2471 process_child = lttv_state_find_process(tfs, child_pid);
2472 /* It should exist, because we are after the state update. */
2473 g_assert(process_child != NULL);
e92eabaf 2474
10a1069a 2475 birth = process_child->creation_time;
2476 const gchar *name = g_quark_to_string(process_child->name);
e92eabaf 2477
10a1069a 2478 if(processlist_get_process_pixels(process_list,
2479 child_pid,
2480 process_child->last_cpu,
2481 &birth,
2482 tfc->t_context->index,
2483 &y_child,
2484 &height,
2485 &hashed_process_data_child) == 1)
2486 {
2487 g_assert(child_pid == 0 || child_pid != process_child->ppid);
2488 /* Process not present */
4e86ae2e 2489 ProcessInfo *process_info;
10a1069a 2490 processlist_add(process_list,
2491 child_pid,
2492 process_child->last_cpu,
2493 process_child->ppid,
2494 &birth,
2495 tfc->t_context->index,
2496 name,
2497 &pl_height,
4e86ae2e 2498 &process_info,
10a1069a 2499 &hashed_process_data_child);
4e86ae2e 2500 processlist_get_pixels_from_data(process_list,
2501 process_info,
2502 hashed_process_data_child,
2503 &y_child,
2504 &height);
10a1069a 2505 drawing_insert_square( control_flow_data->drawing, y_child, height);
2506 }
e92eabaf 2507
b2743953 2508 if(ltt_time_compare(hashed_process_data_child->next_good_time,
2509 evtime) <= 0)
2510 {
2511 guint new_x;
2512 convert_time_to_pixels(
2513 time_window,
2514 evtime,
2515 width,
2516 &new_x);
e72908ed 2517
b2743953 2518 if(hashed_process_data_child->x.over != new_x) {
2519 hashed_process_data_child->x.over = new_x;
2520 hashed_process_data_child->x.over_used = FALSE;
2521 hashed_process_data_child->x.over_marked = FALSE;
2522 }
2523 if(hashed_process_data_child->x.middle != new_x) {
2524 hashed_process_data_child->x.middle = new_x;
2525 hashed_process_data_child->x.middle_used = FALSE;
2526 hashed_process_data_child->x.middle_marked = FALSE;
2527 }
2528 if(hashed_process_data_child->x.under != new_x) {
2529 hashed_process_data_child->x.under = new_x;
2530 hashed_process_data_child->x.under_used = FALSE;
2531 hashed_process_data_child->x.under_marked = FALSE;
2532 }
e72908ed 2533 }
23093869 2534
10a1069a 2535 } else if(sub_id == 3) { /* exit */
dbd243b1 2536
10a1069a 2537 /* Add process to process list (if not present) */
2538 LttvProcessState *process = tfs->process;
2539 guint pid = process->pid;
2540 LttTime birth;
2541 guint y = 0, height = 0, pl_height = 0;
2542 HashedProcessData *hashed_process_data = NULL;
dbd243b1 2543
5c230fc4 2544 ProcessList *process_list = control_flow_data->process_list;
dbd243b1 2545
10a1069a 2546 /* It should exist, because we are after the state update. */
2547 g_assert(process != NULL);
dbd243b1 2548
10a1069a 2549 birth = process->creation_time;
2550 const gchar *name = g_quark_to_string(process->name);
dbd243b1 2551
10a1069a 2552 if(processlist_get_process_pixels(process_list,
2553 pid,
2554 process->last_cpu,
2555 &birth,
2556 tfc->t_context->index,
2557 &y,
2558 &height,
2559 &hashed_process_data) == 1)
2560 {
2561 g_assert(pid == 0 || pid != process->ppid);
2562 /* Process not present */
4e86ae2e 2563 ProcessInfo *process_info;
10a1069a 2564 processlist_add(process_list,
2565 pid,
2566 process->last_cpu,
2567 process->ppid,
2568 &birth,
2569 tfc->t_context->index,
2570 name,
2571 &pl_height,
4e86ae2e 2572 &process_info,
10a1069a 2573 &hashed_process_data);
4e86ae2e 2574 processlist_get_pixels_from_data(process_list,
2575 process_info,
2576 hashed_process_data,
2577 &y,
2578 &height);
10a1069a 2579 drawing_insert_square( control_flow_data->drawing, y, height);
e92eabaf 2580 }
dbd243b1 2581
b2743953 2582 if(ltt_time_compare(hashed_process_data->next_good_time,
2583 evtime) <= 0)
2584 {
2585 guint new_x;
2586 convert_time_to_pixels(
2587 time_window,
2588 evtime,
2589 width,
2590 &new_x);
2591 if(hashed_process_data->x.middle != new_x) {
2592 hashed_process_data->x.middle = new_x;
2593 hashed_process_data->x.middle_used = FALSE;
2594 hashed_process_data->x.middle_marked = FALSE;
2595 }
e72908ed 2596 }
2597
e92eabaf 2598 }
2599 return 0;
2600
2601}
f7afe191 2602
2603
1b238973 2604gint update_time_window_hook(void *hook_data, void *call_data)
f7afe191 2605{
a56a1ba4 2606 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
a43d67ba 2607 Drawing_t *drawing = control_flow_data->drawing;
2608
224446ce 2609 const TimeWindowNotifyData *time_window_nofify_data =
2610 ((const TimeWindowNotifyData *)call_data);
2611
14963be0 2612 TimeWindow *old_time_window =
224446ce 2613 time_window_nofify_data->old_time_window;
2614 TimeWindow *new_time_window =
2615 time_window_nofify_data->new_time_window;
a56a1ba4 2616
3cb8b205 2617 /* Update the ruler */
2618 drawing_update_ruler(control_flow_data->drawing,
2619 new_time_window);
2620
2621
a56a1ba4 2622 /* Two cases : zoom in/out or scrolling */
2623
2624 /* In order to make sure we can reuse the old drawing, the scale must
2625 * be the same and the new time interval being partly located in the
2626 * currently shown time interval. (reuse is only for scrolling)
2627 */
2628
2629 g_info("Old time window HOOK : %u, %u to %u, %u",
14963be0 2630 old_time_window->start_time.tv_sec,
2631 old_time_window->start_time.tv_nsec,
2632 old_time_window->time_width.tv_sec,
2633 old_time_window->time_width.tv_nsec);
a56a1ba4 2634
2635 g_info("New time window HOOK : %u, %u to %u, %u",
14963be0 2636 new_time_window->start_time.tv_sec,
2637 new_time_window->start_time.tv_nsec,
2638 new_time_window->time_width.tv_sec,
2639 new_time_window->time_width.tv_nsec);
a56a1ba4 2640
14963be0 2641 if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec
2642 && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec)
a56a1ba4 2643 {
2644 /* Same scale (scrolling) */
2645 g_info("scrolling");
14963be0 2646 LttTime *ns = &new_time_window->start_time;
20640e70 2647 LttTime *nw = &new_time_window->time_width;
14963be0 2648 LttTime *os = &old_time_window->start_time;
20640e70 2649 LttTime *ow = &old_time_window->time_width;
6f26fc38 2650 LttTime old_end = old_time_window->end_time;
2651 LttTime new_end = new_time_window->end_time;
a56a1ba4 2652 //if(ns<os+w<ns+w)
2653 //if(ns<os+w && os+w<ns+w)
2654 //if(ns<old_end && os<ns)
2655 if(ltt_time_compare(*ns, old_end) == -1
2656 && ltt_time_compare(*os, *ns) == -1)
2657 {
2658 g_info("scrolling near right");
2659 /* Scroll right, keep right part of the screen */
2660 guint x = 0;
51705146 2661 guint width = control_flow_data->drawing->width;
a56a1ba4 2662 convert_time_to_pixels(
a18124ff 2663 *old_time_window,
a56a1ba4 2664 *ns,
2665 width,
2666 &x);
2667
2668 /* Copy old data to new location */
501d5405 2669 gdk_draw_drawable (control_flow_data->drawing->pixmap,
cfe526b1 2670 control_flow_data->drawing->drawing_area->style->black_gc,
501d5405 2671 control_flow_data->drawing->pixmap,
a56a1ba4 2672 x, 0,
2673 0, 0,
6395d57c 2674 control_flow_data->drawing->width-x+SAFETY, -1);
2675
2676 if(drawing->damage_begin == drawing->damage_end)
2677 drawing->damage_begin = control_flow_data->drawing->width-x;
2678 else
2679 drawing->damage_begin = 0;
2680
2681 drawing->damage_end = control_flow_data->drawing->width;
2682
a56a1ba4 2683 /* Clear the data request background, but not SAFETY */
501d5405 2684 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
6395d57c 2685 //control_flow_data->drawing->drawing_area->style->black_gc,
cfe526b1 2686 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 2687 TRUE,
6395d57c 2688 drawing->damage_begin+SAFETY, 0,
2689 drawing->damage_end - drawing->damage_begin, // do not overlap
51705146 2690 control_flow_data->drawing->height);
a43d67ba 2691
51705146 2692 gtk_widget_queue_draw_area (drawing->drawing_area,
a43d67ba 2693 0,0,
6395d57c 2694 control_flow_data->drawing->width,
a43d67ba 2695 control_flow_data->drawing->height);
2696
a56a1ba4 2697 /* Get new data for the rest. */
501d5405 2698 drawing_data_request(control_flow_data->drawing,
2699 &control_flow_data->drawing->pixmap,
6395d57c 2700 drawing->damage_begin, 0,
2701 drawing->damage_end - drawing->damage_begin,
501d5405 2702 control_flow_data->drawing->height);
a56a1ba4 2703 } else {
2704 //if(ns<os<ns+w)
2705 //if(ns<os && os<ns+w)
2706 //if(ns<os && os<new_end)
2707 if(ltt_time_compare(*ns,*os) == -1
2708 && ltt_time_compare(*os,new_end) == -1)
2709 {
2710 g_info("scrolling near left");
2711 /* Scroll left, keep left part of the screen */
2712 guint x = 0;
51705146 2713 guint width = control_flow_data->drawing->width;
a56a1ba4 2714 convert_time_to_pixels(
a18124ff 2715 *new_time_window,
a56a1ba4 2716 *os,
2717 width,
2718 &x);
6395d57c 2719
2720
a56a1ba4 2721 /* Copy old data to new location */
501d5405 2722 gdk_draw_drawable (control_flow_data->drawing->pixmap,
cfe526b1 2723 control_flow_data->drawing->drawing_area->style->black_gc,
501d5405 2724 control_flow_data->drawing->pixmap,
a56a1ba4 2725 0, 0,
2726 x, 0,
2727 -1, -1);
2728
6395d57c 2729 if(drawing->damage_begin == drawing->damage_end)
2730 drawing->damage_end = x;
2731 else
2732 drawing->damage_end =
51705146 2733 control_flow_data->drawing->width;
6395d57c 2734
2735 drawing->damage_begin = 0;
2736
501d5405 2737 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 2738 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 2739 TRUE,
6395d57c 2740 drawing->damage_begin, 0,
2741 drawing->damage_end - drawing->damage_begin, // do not overlap
51705146 2742 control_flow_data->drawing->height);
a43d67ba 2743
6395d57c 2744 gtk_widget_queue_draw_area (drawing->drawing_area,
2745 0,0,
2746 control_flow_data->drawing->width,
a43d67ba 2747 control_flow_data->drawing->height);
2748
6395d57c 2749
a56a1ba4 2750 /* Get new data for the rest. */
501d5405 2751 drawing_data_request(control_flow_data->drawing,
2752 &control_flow_data->drawing->pixmap,
6395d57c 2753 drawing->damage_begin, 0,
2754 drawing->damage_end - drawing->damage_begin,
501d5405 2755 control_flow_data->drawing->height);
a56a1ba4 2756
a56a1ba4 2757 } else {
a43d67ba 2758 if(ltt_time_compare(*ns,*os) == 0)
2759 {
2760 g_info("not scrolling");
2761 } else {
2762 g_info("scrolling far");
2763 /* Cannot reuse any part of the screen : far jump */
2764
2765
2766 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
2767 control_flow_data->drawing->drawing_area->style->black_gc,
2768 TRUE,
a56a1ba4 2769 0, 0,
a43d67ba 2770 control_flow_data->drawing->width+SAFETY, // do not overlap
51705146 2771 control_flow_data->drawing->height);
a43d67ba 2772
2773 gtk_widget_queue_draw_area (drawing->drawing_area,
2774 0,0,
2775 control_flow_data->drawing->width,
2776 control_flow_data->drawing->height);
2777
6395d57c 2778 drawing->damage_begin = 0;
2779 drawing->damage_end = control_flow_data->drawing->width;
2780
a43d67ba 2781 drawing_data_request(control_flow_data->drawing,
2782 &control_flow_data->drawing->pixmap,
2783 0, 0,
2784 control_flow_data->drawing->width,
2785 control_flow_data->drawing->height);
2786
2787 }
a56a1ba4 2788 }
2789 }
2790 } else {
2791 /* Different scale (zoom) */
2792 g_info("zoom");
2793
501d5405 2794 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 2795 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 2796 TRUE,
2797 0, 0,
501d5405 2798 control_flow_data->drawing->width+SAFETY, // do not overlap
51705146 2799 control_flow_data->drawing->height);
a56a1ba4 2800
a43d67ba 2801 gtk_widget_queue_draw_area (drawing->drawing_area,
2802 0,0,
2803 control_flow_data->drawing->width,
2804 control_flow_data->drawing->height);
a56a1ba4 2805
6395d57c 2806 drawing->damage_begin = 0;
2807 drawing->damage_end = control_flow_data->drawing->width;
2808
501d5405 2809 drawing_data_request(control_flow_data->drawing,
2810 &control_flow_data->drawing->pixmap,
a56a1ba4 2811 0, 0,
501d5405 2812 control_flow_data->drawing->width,
2813 control_flow_data->drawing->height);
a56a1ba4 2814 }
2815
3cb8b205 2816
2817
a56a1ba4 2818 return 0;
f7afe191 2819}
2820
6395d57c 2821gint traceset_notify(void *hook_data, void *call_data)
2822{
2823 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2824 Drawing_t *drawing = control_flow_data->drawing;
2825 GtkWidget *widget = drawing->drawing_area;
2826
6395d57c 2827
b9a010a2 2828 drawing_clear(control_flow_data->drawing);
2829 processlist_clear(control_flow_data->process_list);
d9267eec 2830 redraw_notify(control_flow_data, NULL);
6395d57c 2831
d9267eec 2832 request_background_data(control_flow_data);
2833#if 0
2834 drawing->damage_begin = 0;
2835 drawing->damage_end = drawing->width;
6395d57c 2836 if(drawing->damage_begin < drawing->damage_end)
2837 {
2838 drawing_data_request(drawing,
2839 &drawing->pixmap,
2840 drawing->damage_begin,
2841 0,
2842 drawing->damage_end-drawing->damage_begin,
51705146 2843 drawing->height);
6395d57c 2844 }
2845
2846 gtk_widget_queue_draw_area(drawing->drawing_area,
2847 0,0,
2848 drawing->width,
2849 drawing->height);
d9267eec 2850#endif //0
6395d57c 2851
2852 return FALSE;
2853}
2854
ca0f8a8e 2855gint redraw_notify(void *hook_data, void *call_data)
2856{
2857 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2858 Drawing_t *drawing = control_flow_data->drawing;
2859 GtkWidget *widget = drawing->drawing_area;
2860
2861 drawing->damage_begin = 0;
51705146 2862 drawing->damage_end = drawing->width;
ca0f8a8e 2863
49217bd4 2864 /* fun feature, to be separated someday... */
2865 drawing_clear(control_flow_data->drawing);
2866 processlist_clear(control_flow_data->process_list);
ca0f8a8e 2867
2868 // Clear the image
2869 gdk_draw_rectangle (drawing->pixmap,
2870 widget->style->black_gc,
2871 TRUE,
2872 0, 0,
51705146 2873 drawing->width+SAFETY,
2874 drawing->height);
ca0f8a8e 2875
2876
2877 if(drawing->damage_begin < drawing->damage_end)
2878 {
2879 drawing_data_request(drawing,
2880 &drawing->pixmap,
2881 drawing->damage_begin,
2882 0,
2883 drawing->damage_end-drawing->damage_begin,
51705146 2884 drawing->height);
ca0f8a8e 2885 }
2886
2887 gtk_widget_queue_draw_area(drawing->drawing_area,
2888 0,0,
2889 drawing->width,
2890 drawing->height);
ca0f8a8e 2891 return FALSE;
2892
2893}
2894
2895
2896gint continue_notify(void *hook_data, void *call_data)
a43d67ba 2897{
2898 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
ca0f8a8e 2899 Drawing_t *drawing = control_flow_data->drawing;
2900 GtkWidget *widget = drawing->drawing_area;
a43d67ba 2901
6395d57c 2902 //g_assert(widget->allocation.width == drawing->damage_end);
ca0f8a8e 2903
2904 if(drawing->damage_begin < drawing->damage_end)
2905 {
2906 drawing_data_request(drawing,
2907 &drawing->pixmap,
2908 drawing->damage_begin,
2909 0,
2910 drawing->damage_end-drawing->damage_begin,
51705146 2911 drawing->height);
ca0f8a8e 2912 }
2913
2914 return FALSE;
2915}
2916
2917
1b238973 2918gint update_current_time_hook(void *hook_data, void *call_data)
f7afe191 2919{
14963be0 2920 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
a43d67ba 2921 Drawing_t *drawing = control_flow_data->drawing;
a56a1ba4 2922
224446ce 2923 LttTime current_time = *((LttTime*)call_data);
a56a1ba4 2924
ca0f8a8e 2925 TimeWindow time_window =
2926 lttvwindow_get_time_window(control_flow_data->tab);
a56a1ba4 2927
ca0f8a8e 2928 LttTime time_begin = time_window.start_time;
2929 LttTime width = time_window.time_width;
90ef7e4a 2930 LttTime half_width;
2931 {
2932 guint64 time_ll = ltt_time_to_uint64(width);
2933 time_ll = time_ll >> 1; /* divide by two */
2934 half_width = ltt_time_from_uint64(time_ll);
2935 }
a56a1ba4 2936 LttTime time_end = ltt_time_add(time_begin, width);
2937
2938 LttvTracesetContext * tsc =
ca0f8a8e 2939 lttvwindow_get_traceset_context(control_flow_data->tab);
a56a1ba4 2940
ca0f8a8e 2941 LttTime trace_start = tsc->time_span.start_time;
2942 LttTime trace_end = tsc->time_span.end_time;
a56a1ba4 2943
224446ce 2944 g_info("New current time HOOK : %u, %u", current_time.tv_sec,
2945 current_time.tv_nsec);
a56a1ba4 2946
2947
2948
2949 /* If current time is inside time interval, just move the highlight
2950 * bar */
2951
2952 /* Else, we have to change the time interval. We have to tell it
2953 * to the main window. */
2954 /* The time interval change will take care of placing the current
2955 * time at the center of the visible area, or nearest possible if we are
2956 * at one end of the trace. */
2957
2958
224446ce 2959 if(ltt_time_compare(current_time, time_begin) == -1)
a56a1ba4 2960 {
224446ce 2961 TimeWindow new_time_window;
2962
2963 if(ltt_time_compare(current_time,
a56a1ba4 2964 ltt_time_add(trace_start,half_width)) == -1)
2965 time_begin = trace_start;
2966 else
224446ce 2967 time_begin = ltt_time_sub(current_time,half_width);
a56a1ba4 2968
224446ce 2969 new_time_window.start_time = time_begin;
2970 new_time_window.time_width = width;
a18124ff 2971 new_time_window.time_width_double = ltt_time_to_double(width);
6f26fc38 2972 new_time_window.end_time = ltt_time_add(time_begin, width);
a56a1ba4 2973
e800cf84 2974 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
a56a1ba4 2975 }
224446ce 2976 else if(ltt_time_compare(current_time, time_end) == 1)
a56a1ba4 2977 {
224446ce 2978 TimeWindow new_time_window;
2979
2980 if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) == 1)
a56a1ba4 2981 time_begin = ltt_time_sub(trace_end,width);
2982 else
224446ce 2983 time_begin = ltt_time_sub(current_time,half_width);
a56a1ba4 2984
224446ce 2985 new_time_window.start_time = time_begin;
2986 new_time_window.time_width = width;
a18124ff 2987 new_time_window.time_width_double = ltt_time_to_double(width);
6f26fc38 2988 new_time_window.end_time = ltt_time_add(time_begin, width);
a56a1ba4 2989
e800cf84 2990 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
a56a1ba4 2991
2992 }
a43d67ba 2993 //gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
2994 gtk_widget_queue_draw_area(drawing->drawing_area,
2995 0,0,
2996 drawing->width,
2997 drawing->height);
a56a1ba4 2998
2999 return 0;
f7afe191 3000}
3001
8b90e648 3002typedef struct _ClosureData {
ca0f8a8e 3003 EventsRequest *events_request;
d0cd7f09 3004 LttvTracesetState *tss;
b9a010a2 3005 LttTime end_time;
8b90e648 3006} ClosureData;
a56a1ba4 3007
8b90e648 3008
e800cf84 3009void draw_closure(gpointer key, gpointer value, gpointer user_data)
3010{
a56a1ba4 3011 ProcessInfo *process_info = (ProcessInfo*)key;
3012 HashedProcessData *hashed_process_data = (HashedProcessData*)value;
3013 ClosureData *closure_data = (ClosureData*)user_data;
3014
e800cf84 3015 EventsRequest *events_request = closure_data->events_request;
3016 ControlFlowData *control_flow_data = events_request->viewer_data;
3017 Drawing_t *drawing = control_flow_data->drawing;
a56a1ba4 3018
e800cf84 3019 LttvTracesetState *tss = closure_data->tss;
3020 LttvTracesetContext *tsc = (LttvTracesetContext*)closure_data->tss;
a56a1ba4 3021
e800cf84 3022 LttTime evtime = closure_data->end_time;
3023 TimeWindow time_window =
3024 lttvwindow_get_time_window(control_flow_data->tab);
ca0f8a8e 3025
a18124ff 3026#ifdef EXTRA_CHECK
e800cf84 3027 if(ltt_time_compare(evtime, time_window.start_time) == -1
a2aab3a3 3028 || ltt_time_compare(evtime, time_window.end_time) == 1)
e800cf84 3029 return;
a18124ff 3030#endif //EXTRA_CHECK
ca0f8a8e 3031
e800cf84 3032 guint width = drawing->width;
d0cd7f09 3033
e800cf84 3034 {
3035 /* For the process */
3036 /* First, check if the current process is in the state computation
3037 * process list. If it is there, that means we must add it right now and
3038 * draw items from the beginning of the read for it. If it is not
3039 * present, it's a new process and it was not present : it will
3040 * be added after the state update. */
3041 g_assert(lttv_traceset_number(tsc->ts) > 0);
d0cd7f09 3042
e025a729 3043 /* tracefiles[0] is ok here, because we draw for every PID, and
3044 * assume CPU 0 for PID 0 //FIXME */
3045 LttvTracefileState *tfs =
3046 (LttvTracefileState*)tsc->traces[process_info->trace_num]->tracefiles[0];
a56a1ba4 3047
e800cf84 3048 LttvProcessState *process;
e025a729 3049 process = lttv_state_find_process(tfs,
3050 process_info->pid);
a56a1ba4 3051
e800cf84 3052 if(process != NULL) {
3053
3054 /* Only draw for processes that are currently in the trace states */
ad2e83ba 3055
e800cf84 3056 guint y = 0, height = 0, pl_height = 0;
5c230fc4 3057 ProcessList *process_list = control_flow_data->process_list;
e800cf84 3058 LttTime birth = process_info->birth;
3059
3060 /* Should be alike when background info is ready */
3061 if(control_flow_data->background_info_waiting==0)
3062 g_assert(ltt_time_compare(process->creation_time,
3063 process_info->birth) == 0);
3064 const gchar *name = g_quark_to_string(process->name);
3065
3066 /* process HAS to be present */
fae7b8ee 3067 processlist_get_pixels_from_data(process_list,
3068 process_info,
3069 hashed_process_data,
e800cf84 3070 &y,
fae7b8ee 3071 &height);
e800cf84 3072
3073 /* Now, the process is in the state hash and our own process hash.
3074 * We definitely can draw the items related to the ending state.
3075 */
3076
3077 /* Check if the x position is unset. In can have been left unset by
3078 * a draw closure from a after chunk hook. This should never happen,
3079 * because it must be set by before chunk hook to the damage_begin
3080 * value.
3081 */
23093869 3082 g_assert(hashed_process_data->x.over != -1);
b2743953 3083
3084 if(ltt_time_compare(hashed_process_data->next_good_time,
3085 evtime) <= 0)
e800cf84 3086 {
3087 guint x;
a56a1ba4 3088
e800cf84 3089 convert_time_to_pixels(
a18124ff 3090 time_window,
e800cf84 3091 evtime,
3092 width,
3093 &x);
8b90e648 3094
4b7dc462 3095 DrawContext draw_context;
3096
e800cf84 3097 /* Now create the drawing context that will be used to draw
3098 * items related to the last state. */
3099 draw_context.drawable = drawing->pixmap;
3100 draw_context.gc = drawing->gc;
3101 draw_context.pango_layout = drawing->pango_layout;
e800cf84 3102 draw_context.drawinfo.end.x = x;
3103
23093869 3104 draw_context.drawinfo.y.over = y+1;
3105 draw_context.drawinfo.y.middle = y+(height/2);
3106 draw_context.drawinfo.y.under = y+height;
e800cf84 3107
3108 draw_context.drawinfo.start.offset.over = 0;
3109 draw_context.drawinfo.start.offset.middle = 0;
3110 draw_context.drawinfo.start.offset.under = 0;
3111 draw_context.drawinfo.end.offset.over = 0;
3112 draw_context.drawinfo.end.offset.middle = 0;
3113 draw_context.drawinfo.end.offset.under = 0;
9a1ec01b 3114#if 0
4b7dc462 3115 /* Jump over draw if we are at the same x position */
3116 if(x == hashed_process_data->x.over)
e800cf84 3117 {
4b7dc462 3118 /* jump */
3119 } else {
23093869 3120 draw_context.drawinfo.start.x = hashed_process_data->x.over;
3121 /* Draw the line */
3122 PropertiesLine prop_line = prepare_execmode_line(process);
3123 draw_line((void*)&prop_line, (void*)&draw_context);
3124
4b7dc462 3125 hashed_process_data->x.over = x;
23093869 3126 }
9a1ec01b 3127#endif //0
4b7dc462 3128
e72908ed 3129 if(x == hashed_process_data->x.middle &&
3130 hashed_process_data->x.middle_used) {
b2743953 3131#if 0 /* do not mark closure : not missing information */
e72908ed 3132 if(hashed_process_data->x.middle_marked == FALSE) {
3133 /* Draw collision indicator */
3134 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
3135 gdk_draw_point(drawing->pixmap,
3136 drawing->gc,
3137 x,
2c6618bc 3138 y+(height/2)-3);
de4ea1ad 3139 hashed_process_data->x.middle_marked = TRUE;
e72908ed 3140 }
b2743953 3141#endif //0
4b7dc462 3142 /* Jump */
3143 } else {
23093869 3144 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
e800cf84 3145 /* Draw the line */
9a1ec01b 3146 PropertiesLine prop_line = prepare_s_e_line(process);
e800cf84 3147 draw_line((void*)&prop_line, (void*)&draw_context);
3148
4b7dc462 3149 /* become the last x position */
e72908ed 3150 if(x != hashed_process_data->x.middle) {
3151 hashed_process_data->x.middle = x;
3152 /* but don't use the pixel */
3153 hashed_process_data->x.middle_used = FALSE;
b2743953 3154
3155 /* Calculate the next good time */
3156 convert_pixels_to_time(width, x+1, time_window,
3157 &hashed_process_data->next_good_time);
e72908ed 3158 }
e800cf84 3159 }
e800cf84 3160 }
3161 }
3162 }
3163 return;
8b90e648 3164}
3165
b9a010a2 3166int before_chunk(void *hook_data, void *call_data)
3167{
3168 EventsRequest *events_request = (EventsRequest*)hook_data;
16b9cadb 3169 LttvTracesetState *tss = (LttvTracesetState*)call_data;
b9a010a2 3170
3171 drawing_chunk_begin(events_request, tss);
3172
3173 return 0;
3174}
3175
3176int before_request(void *hook_data, void *call_data)
ca0f8a8e 3177{
3178 EventsRequest *events_request = (EventsRequest*)hook_data;
16b9cadb 3179 LttvTracesetState *tss = (LttvTracesetState*)call_data;
ca0f8a8e 3180
3181 drawing_data_request_begin(events_request, tss);
3182
3183 return 0;
3184}
3185
3186
8b90e648 3187/*
b9a010a2 3188 * after request is necessary in addition of after chunk in order to draw
3189 * lines until the end of the screen. after chunk just draws lines until
3190 * the last event.
3191 *
8b90e648 3192 * for each process
a56a1ba4 3193 * draw closing line
b9a010a2 3194 * expose
8b90e648 3195 */
b9a010a2 3196int after_request(void *hook_data, void *call_data)
8b90e648 3197{
ca0f8a8e 3198 EventsRequest *events_request = (EventsRequest*)hook_data;
3199 ControlFlowData *control_flow_data = events_request->viewer_data;
16b9cadb 3200 LttvTracesetState *tss = (LttvTracesetState*)call_data;
3201 LttvTracesetContext *tsc = (LttvTracesetContext*)call_data;
a56a1ba4 3202
5c230fc4 3203 ProcessList *process_list = control_flow_data->process_list;
b9a010a2 3204 LttTime end_time = events_request->end_time;
3205
3206 ClosureData closure_data;
3207 closure_data.events_request = (EventsRequest*)hook_data;
3208 closure_data.tss = tss;
3209 closure_data.end_time = end_time;
3210
3211 /* Draw last items */
3212 g_hash_table_foreach(process_list->process_hash, draw_closure,
3213 (void*)&closure_data);
3214
3215 /* Request expose */
3216 drawing_request_expose(events_request, tss, end_time);
3217 return 0;
3218}
3219
3220/*
3221 * for each process
3222 * draw closing line
e800cf84 3223 * expose
b9a010a2 3224 */
3225int after_chunk(void *hook_data, void *call_data)
3226{
3227 EventsRequest *events_request = (EventsRequest*)hook_data;
3228 ControlFlowData *control_flow_data = events_request->viewer_data;
16b9cadb 3229 LttvTracesetState *tss = (LttvTracesetState*)call_data;
3230 LttvTracesetContext *tsc = (LttvTracesetContext*)call_data;
b9a010a2 3231 LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc);
3232 LttTime end_time;
3233
5c230fc4 3234 ProcessList *process_list = control_flow_data->process_list;
b9a010a2 3235
e800cf84 3236 if(tfc != NULL)
3237 end_time = LTT_TIME_MIN(tfc->timestamp, events_request->end_time);
0c5dbe3b 3238 else /* end of traceset, or position now out of request : end */
3239 end_time = events_request->end_time;
3240
a56a1ba4 3241 ClosureData closure_data;
ca0f8a8e 3242 closure_data.events_request = (EventsRequest*)hook_data;
3243 closure_data.tss = tss;
b9a010a2 3244 closure_data.end_time = end_time;
a56a1ba4 3245
b9a010a2 3246 /* Draw last items */
14963be0 3247 g_hash_table_foreach(process_list->process_hash, draw_closure,
a56a1ba4 3248 (void*)&closure_data);
a43d67ba 3249
ca0f8a8e 3250 /* Request expose */
b9a010a2 3251 drawing_request_expose(events_request, tss, end_time);
ca0f8a8e 3252
3253 return 0;
8b90e648 3254}
3255
This page took 0.204695 seconds and 4 git commands to generate.