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