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