whole new time bar, plus some additions to control flow viewer.. this is work in...
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / eventhooks.c
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
20 /*****************************************************************************
21 * Hooks to be called by the main window *
22 *****************************************************************************/
23
24
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 *
28 * Two hooks are used for drawing : draw_before and draw_after hooks. The
29 * draw_before is called before the state update that occurs with an event and
30 * the draw_after hook is called after this state update.
31 *
32 * The draw_before hooks fulfill the task of drawing the visible objects that
33 * corresponds to the data accumulated by the draw_after hook.
34 *
35 * The draw_after hook accumulates the data that need to be shown on the screen
36 * (items) into a queue. Then, the next draw_before hook will draw what that
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
40 * corresponding to it is over, which happens to be at the next draw_before
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
49 //#define PANGO_ENABLE_BACKEND
50 #include <gtk/gtk.h>
51 #include <gdk/gdk.h>
52 #include <glib.h>
53 #include <assert.h>
54 #include <string.h>
55 #include <stdio.h>
56
57 //#include <pango/pango.h>
58
59 #include <ltt/event.h>
60 #include <ltt/time.h>
61 #include <ltt/type.h>
62
63 #include <lttv/lttv.h>
64 #include <lttv/hook.h>
65 #include <lttv/state.h>
66 #include <lttvwindow/lttvwindow.h>
67 #include <lttvwindow/lttvwindowtraces.h>
68
69
70 #include "eventhooks.h"
71 #include "cfv.h"
72 #include "processlist.h"
73 #include "drawing.h"
74 #include "cfv-private.h"
75
76
77 #define MAX_PATH_LEN 256
78
79
80 #if 0
81 typedef struct _ProcessAddClosure {
82 ControlFlowData *cfd;
83 guint trace_num;
84 } ProcessAddClosure;
85
86 static 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
100 ProcessList *process_list =
101 guicontrolflow_get_process_list(control_flow_data);
102
103 pid = process->pid;
104 birth = process->creation_time;
105 const gchar *name = g_quark_to_string(process->name);
106 HashedProcessData *hashed_process_data = NULL;
107
108 if(processlist_get_process_pixels(process_list,
109 pid,
110 &birth,
111 trace_num,
112 &y,
113 &height,
114 &hashed_process_data) == 1)
115 {
116 /* Process not present */
117 processlist_add(process_list,
118 pid,
119 &birth,
120 trace_num,
121 name,
122 &pl_height,
123 &hashed_process_data);
124 processlist_get_process_pixels(process_list,
125 pid,
126 &birth,
127 trace_num,
128 &y,
129 &height,
130 &hashed_process_data);
131 drawing_insert_square( control_flow_data->drawing, y, height);
132 }
133 }
134 #endif //0
135
136
137 /* Action to do when background computation completed.
138 *
139 * Wait for all the awaited computations to be over.
140 */
141
142 gint background_ready(void *hook_data, void *call_data)
143 {
144 ControlFlowData *control_flow_data = (ControlFlowData *)hook_data;
145 LttvTrace *trace = (LttvTrace*)call_data;
146 LttvTracesetContext *tsc =
147 lttvwindow_get_traceset_context(control_flow_data->tab);
148
149 control_flow_data->background_info_waiting--;
150
151 if(control_flow_data->background_info_waiting == 0) {
152 g_debug("control flow viewer : background computation data ready.");
153
154 drawing_clear(control_flow_data->drawing);
155 processlist_clear(control_flow_data->process_list);
156 redraw_notify(control_flow_data, NULL);
157 }
158
159 return 0;
160 }
161
162
163 /* Request background computation. Verify if it is in progress or ready first.
164 * Only for each trace in the tab's traceset.
165 */
166 void request_background_data(ControlFlowData *control_flow_data)
167 {
168 LttvTracesetContext * tsc =
169 lttvwindow_get_traceset_context(control_flow_data->tab);
170 gint num_traces = lttv_traceset_number(tsc->ts);
171 gint i;
172 LttvTrace *trace;
173
174 LttvHooks *background_ready_hook =
175 lttv_hooks_new();
176 lttv_hooks_add(background_ready_hook, background_ready, control_flow_data,
177 LTTV_PRIO_DEFAULT);
178 control_flow_data->background_info_waiting = 0;
179
180 for(i=0;i<num_traces;i++) {
181 trace = lttv_traceset_get(tsc->ts, i);
182
183 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE) {
184
185 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
186 trace) == FALSE) {
187 /* We first remove requests that could have been done for the same
188 * information. Happens when two viewers ask for it before servicing
189 * starts.
190 */
191 lttvwindowtraces_background_request_remove(trace, "state");
192 lttvwindowtraces_background_request_queue(trace,
193 "state");
194 lttvwindowtraces_background_notify_queue(control_flow_data,
195 trace,
196 ltt_time_infinite,
197 NULL,
198 background_ready_hook);
199 control_flow_data->background_info_waiting++;
200 } else { /* in progress */
201
202 lttvwindowtraces_background_notify_current(control_flow_data,
203 trace,
204 ltt_time_infinite,
205 NULL,
206 background_ready_hook);
207 control_flow_data->background_info_waiting++;
208 }
209 }
210 }
211
212 lttv_hooks_destroy(background_ready_hook);
213 }
214
215
216
217
218 /**
219 * Event Viewer's constructor hook
220 *
221 * This constructor is given as a parameter to the menuitem and toolbar button
222 * registration. It creates the list.
223 * @param tab A pointer to the parent tab.
224 * @return The widget created.
225 */
226 GtkWidget *
227 h_guicontrolflow(Tab *tab, LttvTracesetSelector * s, char * key)
228 {
229 g_info("h_guicontrolflow, %p, %p, %s", tab, s, key);
230 ControlFlowData *control_flow_data = guicontrolflow() ;
231
232 control_flow_data->tab = tab;
233
234 //g_debug("time width2 : %u",time_window->time_width);
235 // Unreg done in the GuiControlFlow_Destructor
236 lttvwindow_register_traceset_notify(tab,
237 traceset_notify,
238 control_flow_data);
239
240 lttvwindow_register_time_window_notify(tab,
241 update_time_window_hook,
242 control_flow_data);
243 lttvwindow_register_current_time_notify(tab,
244 update_current_time_hook,
245 control_flow_data);
246 lttvwindow_register_redraw_notify(tab,
247 redraw_notify,
248 control_flow_data);
249 lttvwindow_register_continue_notify(tab,
250 continue_notify,
251 control_flow_data);
252 request_background_data(control_flow_data);
253
254
255 return guicontrolflow_get_widget(control_flow_data) ;
256
257 }
258
259 int event_selected_hook(void *hook_data, void *call_data)
260 {
261 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
262 guint *event_number = (guint*) call_data;
263
264 g_debug("DEBUG : event selected by main window : %u", *event_number);
265
266 }
267
268
269 static __inline PropertiesLine prepare_line(LttvProcessState *process)
270 {
271 PropertiesLine prop_line;
272 prop_line.line_width = 2;
273 prop_line.style = GDK_LINE_SOLID;
274 prop_line.y = MIDDLE;
275 //GdkColormap *colormap = gdk_colormap_get_system();
276
277 g_debug("prepare_line for state : %s", g_quark_to_string(process->state->s));
278
279 /* color of line : status of the process */
280 if(process->state->s == LTTV_STATE_UNNAMED)
281 prop_line.color = drawing_colors[COL_WHITE];
282 else if(process->state->s == LTTV_STATE_WAIT_FORK)
283 prop_line.color = drawing_colors[COL_WAIT_FORK];
284 else if(process->state->s == LTTV_STATE_WAIT_CPU)
285 prop_line.color = drawing_colors[COL_WAIT_CPU];
286 else if(process->state->s == LTTV_STATE_EXIT)
287 prop_line.color = drawing_colors[COL_EXIT];
288 else if(process->state->s == LTTV_STATE_WAIT)
289 prop_line.color = drawing_colors[COL_WAIT];
290 else if(process->state->s == LTTV_STATE_RUN)
291 prop_line.color = drawing_colors[COL_RUN];
292 else
293 prop_line.color = drawing_colors[COL_WHITE];
294
295 //gdk_colormap_alloc_color(colormap,
296 // prop_line.color,
297 // FALSE,
298 // TRUE);
299
300 return prop_line;
301
302 }
303
304
305
306 /* draw_before_hook
307 *
308 * This function basically draw lines and icons. Two types of lines are drawn :
309 * one small (3 pixels?) representing the state of the process and the second
310 * type is thicker (10 pixels?) representing on which CPU a process is running
311 * (and this only in running state).
312 *
313 * Extremums of the lines :
314 * x_min : time of the last event context for this process kept in memory.
315 * x_max : time of the current event.
316 * y : middle of the process in the process list. The process is found in the
317 * list, therefore is it's position in pixels.
318 *
319 * The choice of lines'color is defined by the context of the last event for this
320 * process.
321 */
322
323
324 int draw_before_hook(void *hook_data, void *call_data)
325 {
326 EventsRequest *events_request = (EventsRequest*)hook_data;
327 ControlFlowData *control_flow_data = events_request->viewer_data;
328 Drawing_t *drawing = control_flow_data->drawing;
329
330 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
331
332 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
333 LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context;
334
335 LttEvent *e;
336 e = tfc->e;
337
338 LttTime evtime = ltt_event_time(e);
339 TimeWindow time_window =
340 lttvwindow_get_time_window(control_flow_data->tab);
341
342 LttTime end_time = ltt_time_add(time_window.start_time,
343 time_window.time_width);
344
345 if(ltt_time_compare(evtime, time_window.start_time) == -1
346 || ltt_time_compare(evtime, end_time) == 1)
347 return;
348
349 guint width = drawing->width;
350
351 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) {
352
353 /* we are in a schedchange, before the state update. We must draw the
354 * items corresponding to the state before it changes : now is the right
355 * time to do it.
356 */
357
358 guint pid_out;
359 guint pid_in;
360 {
361 LttField *f = ltt_event_field(e);
362 LttField *element;
363 element = ltt_field_member(f,0);
364 pid_out = ltt_event_get_long_unsigned(e,element);
365 element = ltt_field_member(f,1);
366 pid_in = ltt_event_get_long_unsigned(e,element);
367 g_debug("out : %u in : %u", pid_out, pid_in);
368 }
369
370 {
371 /* For the pid_out */
372 /* First, check if the current process is in the state computation
373 * process list. If it is there, that means we must add it right now and
374 * draw items from the beginning of the read for it. If it is not
375 * present, it's a new process and it was not present : it will
376 * be added after the state update. */
377 LttvProcessState *process;
378 process = lttv_state_find_process(tfs, pid_out);
379
380 if(process != NULL) {
381 /* Well, the process_out existed : we must get it in the process hash
382 * or add it, and draw its items.
383 */
384 /* Add process to process list (if not present) */
385 guint y = 0, height = 0, pl_height = 0;
386 HashedProcessData *hashed_process_data = NULL;
387 ProcessList *process_list =
388 guicontrolflow_get_process_list(control_flow_data);
389 LttTime birth = process->creation_time;
390 const gchar *name = g_quark_to_string(process->name);
391
392 if(processlist_get_process_pixels(process_list,
393 pid_out,
394 &birth,
395 tfc->t_context->index,
396 &y,
397 &height,
398 &hashed_process_data) == 1)
399 {
400 /* Process not present */
401 processlist_add(process_list,
402 pid_out,
403 &birth,
404 tfc->t_context->index,
405 name,
406 &pl_height,
407 &hashed_process_data);
408 processlist_get_process_pixels(process_list,
409 pid_out,
410 &birth,
411 tfc->t_context->index,
412 &y,
413 &height,
414 &hashed_process_data);
415 drawing_insert_square( drawing, y, height);
416 }
417
418 /* Now, the process is in the state hash and our own process hash.
419 * We definitely can draw the items related to the ending state.
420 */
421
422 /* Check if the x position is unset. In can have been left unset by
423 * a draw closure from a after chunk hook. This should never happen,
424 * because it must be set by before chunk hook to the damage_begin
425 * value.
426 */
427 g_assert(hashed_process_data->x != -1);
428 {
429 guint x;
430 DrawContext draw_context;
431
432 convert_time_to_pixels(
433 time_window.start_time,
434 end_time,
435 evtime,
436 width,
437 &x);
438
439 /* Now create the drawing context that will be used to draw
440 * items related to the last state. */
441 draw_context.drawable = drawing->pixmap;
442 draw_context.gc = drawing->gc;
443 draw_context.pango_layout = drawing->pango_layout;
444 draw_context.drawinfo.start.x = hashed_process_data->x;
445 draw_context.drawinfo.end.x = x;
446
447 draw_context.drawinfo.y.over = y;
448 draw_context.drawinfo.y.middle = y+(height/4);
449 draw_context.drawinfo.y.under = y+(height/2)+2;
450
451 draw_context.drawinfo.start.offset.over = 0;
452 draw_context.drawinfo.start.offset.middle = 0;
453 draw_context.drawinfo.start.offset.under = 0;
454 draw_context.drawinfo.end.offset.over = 0;
455 draw_context.drawinfo.end.offset.middle = 0;
456 draw_context.drawinfo.end.offset.under = 0;
457
458 {
459 /* Draw the line */
460 PropertiesLine prop_line = prepare_line(process);
461 draw_line((void*)&prop_line, (void*)&draw_context);
462
463 }
464 /* become the last x position */
465 hashed_process_data->x = x;
466 }
467 }
468 }
469
470 {
471 /* For the pid_in */
472 /* First, check if the current process is in the state computation
473 * process list. If it is there, that means we must add it right now and
474 * draw items from the beginning of the read for it. If it is not
475 * present, it's a new process and it was not present : it will
476 * be added after the state update. */
477 LttvProcessState *process;
478 process = lttv_state_find_process(tfs, pid_in);
479
480 if(process != NULL) {
481 /* Well, the process_out existed : we must get it in the process hash
482 * or add it, and draw its items.
483 */
484 /* Add process to process list (if not present) */
485 guint y = 0, height = 0, pl_height = 0;
486 HashedProcessData *hashed_process_data = NULL;
487 ProcessList *process_list =
488 guicontrolflow_get_process_list(control_flow_data);
489 LttTime birth = process->creation_time;
490 const gchar *name = g_quark_to_string(process->name);
491
492 if(processlist_get_process_pixels(process_list,
493 pid_in,
494 &birth,
495 tfc->t_context->index,
496 &y,
497 &height,
498 &hashed_process_data) == 1)
499 {
500 /* Process not present */
501 processlist_add(process_list,
502 pid_in,
503 &birth,
504 tfc->t_context->index,
505 name,
506 &pl_height,
507 &hashed_process_data);
508 processlist_get_process_pixels(process_list,
509 pid_in,
510 &birth,
511 tfc->t_context->index,
512 &y,
513 &height,
514 &hashed_process_data);
515 drawing_insert_square( drawing, y, height);
516 }
517
518 /* Now, the process is in the state hash and our own process hash.
519 * We definitely can draw the items related to the ending state.
520 */
521
522 /* Check if the x position is unset. In can have been left unset by
523 * a draw closure from a after chunk hook. This should never happen,
524 * because it must be set by before chunk hook to the damage_begin
525 * value.
526 */
527 g_assert(hashed_process_data->x != -1);
528 {
529 guint x;
530 DrawContext draw_context;
531
532 convert_time_to_pixels(
533 time_window.start_time,
534 end_time,
535 evtime,
536 width,
537 &x);
538
539 /* Now create the drawing context that will be used to draw
540 * items related to the last state. */
541 draw_context.drawable = drawing->pixmap;
542 draw_context.gc = drawing->gc;
543 draw_context.pango_layout = drawing->pango_layout;
544 draw_context.drawinfo.start.x = hashed_process_data->x;
545 draw_context.drawinfo.end.x = x;
546
547 draw_context.drawinfo.y.over = y;
548 draw_context.drawinfo.y.middle = y+(height/4);
549 draw_context.drawinfo.y.under = y+(height/2)+2;
550
551 draw_context.drawinfo.start.offset.over = 0;
552 draw_context.drawinfo.start.offset.middle = 0;
553 draw_context.drawinfo.start.offset.under = 0;
554 draw_context.drawinfo.end.offset.over = 0;
555 draw_context.drawinfo.end.offset.middle = 0;
556 draw_context.drawinfo.end.offset.under = 0;
557
558 {
559 /* Draw the line */
560 PropertiesLine prop_line = prepare_line(process);
561 draw_line((void*)&prop_line, (void*)&draw_context);
562 }
563
564
565 /* become the last x position */
566 hashed_process_data->x = x;
567 }
568 }
569 }
570 }
571
572
573 return 0;
574
575
576 #if 0
577 EventsRequest *events_request = (EventsRequest*)hook_data;
578 ControlFlowData *control_flow_data =
579 (ControlFlowData*)events_request->viewer_data;
580 Tab *tab = control_flow_data->tab;
581
582 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
583
584 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
585 LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context;
586
587 LttEvent *e;
588 e = tfc->e;
589
590 LttTime evtime = ltt_event_time(e);
591 TimeWindow time_window =
592 lttvwindow_get_time_window(tab);
593
594 LttTime end_time = ltt_time_add(time_window.start_time,
595 time_window.time_width);
596 //if(time < time_beg || time > time_end) return;
597 if(ltt_time_compare(evtime, time_window.start_time) == -1
598 || ltt_time_compare(evtime, end_time) == 1)
599 return;
600
601 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
602 {
603 g_debug("schedchange!");
604
605 /* Add process to process list (if not present) and get drawing "y" from
606 * process position */
607 guint pid_out, pid_in;
608 LttvProcessState *process_out, *process_in;
609 LttTime birth;
610 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
611
612 ProcessList *process_list =
613 guicontrolflow_get_process_list(control_flow_data);
614
615
616 LttField *f = ltt_event_field(e);
617 LttField *element;
618 element = ltt_field_member(f,0);
619 pid_out = ltt_event_get_long_unsigned(e,element);
620 element = ltt_field_member(f,1);
621 pid_in = ltt_event_get_long_unsigned(e,element);
622 g_debug("out : %u in : %u", pid_out, pid_in);
623
624
625 /* Find process pid_out in the list... */
626 process_out = lttv_state_find_process(tfs, pid_out);
627 if(process_out == NULL) return 0;
628 g_debug("out : %s",g_quark_to_string(process_out->state->s));
629
630 birth = process_out->creation_time;
631 const gchar *name = g_quark_to_string(process_out->name);
632 HashedProcessData *hashed_process_data_out = NULL;
633
634 if(processlist_get_process_pixels(process_list,
635 pid_out,
636 &birth,
637 tfc->t_context->index,
638 &y_out,
639 &height,
640 &hashed_process_data_out) == 1)
641 {
642 /* Process not present */
643 processlist_add(process_list,
644 pid_out,
645 &birth,
646 tfc->t_context->index,
647 name,
648 &pl_height,
649 &hashed_process_data_out);
650 g_assert(processlist_get_process_pixels(process_list,
651 pid_out,
652 &birth,
653 tfc->t_context->index,
654 &y_out,
655 &height,
656 &hashed_process_data_out)==0);
657 drawing_insert_square( control_flow_data->drawing, y_out, height);
658 }
659 //g_free(name);
660
661 /* Find process pid_in in the list... */
662 process_in = lttv_state_find_process(tfs, pid_in);
663 if(process_in == NULL) return 0;
664 g_debug("in : %s",g_quark_to_string(process_in->state->s));
665
666 birth = process_in->creation_time;
667 name = g_quark_to_string(process_in->name);
668 HashedProcessData *hashed_process_data_in = NULL;
669
670 if(processlist_get_process_pixels(process_list,
671 pid_in,
672 &birth,
673 tfc->t_context->index,
674 &y_in,
675 &height,
676 &hashed_process_data_in) == 1)
677 {
678 /* Process not present */
679 processlist_add(process_list,
680 pid_in,
681 &birth,
682 tfc->t_context->index,
683 name,
684 &pl_height,
685 &hashed_process_data_in);
686 processlist_get_process_pixels(process_list,
687 pid_in,
688 &birth,
689 tfc->t_context->index,
690 &y_in,
691 &height,
692 &hashed_process_data_in);
693
694 drawing_insert_square( control_flow_data->drawing, y_in, height);
695 }
696 //g_free(name);
697
698
699 /* Find pixels corresponding to time of the event. If the time does
700 * not fit in the window, show a warning, not supposed to happend. */
701 guint x = 0;
702 guint width = control_flow_data->drawing->width;
703
704 LttTime time = ltt_event_time(e);
705
706 LttTime window_end = ltt_time_add(time_window.time_width,
707 time_window.start_time);
708
709
710 convert_time_to_pixels(
711 time_window.start_time,
712 window_end,
713 time,
714 width,
715 &x);
716 //assert(x <= width);
717 //
718 /* draw what represents the event for outgoing process. */
719
720 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
721 draw_context_out->current->modify_over->x = x;
722 draw_context_out->current->modify_under->x = x;
723 draw_context_out->current->modify_over->y = y_out;
724 draw_context_out->current->modify_under->y = y_out+(height/2)+2;
725 draw_context_out->drawable = control_flow_data->drawing->pixmap;
726 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
727 GtkWidget *widget = control_flow_data->drawing->drawing_area;
728 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
729 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
730 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
731 //draw_context_out->gc = widget->style->black_gc;
732
733 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
734 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
735
736 /* Draw the line/background of the out process */
737 if(draw_context_out->previous->middle->x == -1)
738 {
739 draw_context_out->previous->over->x =
740 control_flow_data->drawing->damage_begin;
741 draw_context_out->previous->middle->x =
742 control_flow_data->drawing->damage_begin;
743 draw_context_out->previous->under->x =
744 control_flow_data->drawing->damage_begin;
745
746 g_debug("out middle x_beg : %u",control_flow_data->drawing->damage_begin);
747 }
748
749 draw_context_out->current->middle->x = x;
750 draw_context_out->current->over->x = x;
751 draw_context_out->current->under->x = x;
752 draw_context_out->current->middle->y = y_out + height/2;
753 draw_context_out->current->over->y = y_out;
754 draw_context_out->current->under->y = y_out + height;
755 draw_context_out->previous->middle->y = y_out + height/2;
756 draw_context_out->previous->over->y = y_out;
757 draw_context_out->previous->under->y = y_out + height;
758
759 draw_context_out->drawable = control_flow_data->drawing->pixmap;
760 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
761
762 if(process_out->state->s == LTTV_STATE_RUN)
763 {
764 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
765 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
766 draw_context_out->gc = control_flow_data->drawing->gc;
767
768 PropertiesBG prop_bg;
769 prop_bg.color = g_new(GdkColor,1);
770
771 switch(tfc->index) {
772 case 0:
773 prop_bg.color->red = 0x1515;
774 prop_bg.color->green = 0x1515;
775 prop_bg.color->blue = 0x8c8c;
776 break;
777 case 1:
778 prop_bg.color->red = 0x4e4e;
779 prop_bg.color->green = 0xa9a9;
780 prop_bg.color->blue = 0xa4a4;
781 break;
782 case 2:
783 prop_bg.color->red = 0x7a7a;
784 prop_bg.color->green = 0x4a4a;
785 prop_bg.color->blue = 0x8b8b;
786 break;
787 case 3:
788 prop_bg.color->red = 0x8080;
789 prop_bg.color->green = 0x7777;
790 prop_bg.color->blue = 0x4747;
791 break;
792 default:
793 prop_bg.color->red = 0xe7e7;
794 prop_bg.color->green = 0xe7e7;
795 prop_bg.color->blue = 0xe7e7;
796 }
797
798 g_debug("calling from draw_event");
799 draw_bg((void*)&prop_bg, (void*)draw_context_out);
800 g_free(prop_bg.color);
801 //gdk_gc_unref(draw_context_out->gc);
802 }
803
804 draw_context_out->gc = widget->style->black_gc;
805
806 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
807 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
808 PropertiesText prop_text_out;
809 prop_text_out.foreground = &colorfg_out;
810 prop_text_out.background = &colorbg_out;
811 prop_text_out.size = 6;
812 prop_text_out.position = OVER;
813
814 /* color of text : status of the process */
815 if(process_out->state->s == LTTV_STATE_UNNAMED)
816 {
817 prop_text_out.foreground->red = 0xffff;
818 prop_text_out.foreground->green = 0xffff;
819 prop_text_out.foreground->blue = 0xffff;
820 }
821 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
822 {
823 prop_text_out.foreground->red = 0x0fff;
824 prop_text_out.foreground->green = 0xffff;
825 prop_text_out.foreground->blue = 0xfff0;
826 }
827 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
828 {
829 prop_text_out.foreground->red = 0xffff;
830 prop_text_out.foreground->green = 0xffff;
831 prop_text_out.foreground->blue = 0x0000;
832 }
833 else if(process_out->state->s == LTTV_STATE_EXIT)
834 {
835 prop_text_out.foreground->red = 0xffff;
836 prop_text_out.foreground->green = 0x0000;
837 prop_text_out.foreground->blue = 0xffff;
838 }
839 else if(process_out->state->s == LTTV_STATE_WAIT)
840 {
841 prop_text_out.foreground->red = 0xffff;
842 prop_text_out.foreground->green = 0x0000;
843 prop_text_out.foreground->blue = 0x0000;
844 }
845 else if(process_out->state->s == LTTV_STATE_RUN)
846 {
847 prop_text_out.foreground->red = 0x0000;
848 prop_text_out.foreground->green = 0xffff;
849 prop_text_out.foreground->blue = 0x0000;
850 }
851 else
852 {
853 prop_text_out.foreground->red = 0xffff;
854 prop_text_out.foreground->green = 0xffff;
855 prop_text_out.foreground->blue = 0xffff;
856 }
857
858
859 /* Print status of the process : U, WF, WC, E, W, R */
860 if(process_out->state->s == LTTV_STATE_UNNAMED)
861 prop_text_out.text = "U->";
862 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
863 prop_text_out.text = "WF->";
864 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
865 prop_text_out.text = "WC->";
866 else if(process_out->state->s == LTTV_STATE_EXIT)
867 prop_text_out.text = "E->";
868 else if(process_out->state->s == LTTV_STATE_WAIT)
869 prop_text_out.text = "W->";
870 else if(process_out->state->s == LTTV_STATE_RUN)
871 prop_text_out.text = "R->";
872 else
873 prop_text_out.text = "U";
874
875 draw_text((void*)&prop_text_out, (void*)draw_context_out);
876 //gdk_gc_unref(draw_context_out->gc);
877
878 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
879 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
880 draw_context_out->gc = control_flow_data->drawing->gc;
881
882 PropertiesLine prop_line_out;
883 prop_line_out.color = g_new(GdkColor,1);
884 prop_line_out.line_width = 2;
885 prop_line_out.style = GDK_LINE_SOLID;
886 prop_line_out.position = MIDDLE;
887
888 g_debug("out state : %s", g_quark_to_string(process_out->state->s));
889
890 /* color of line : status of the process */
891 if(process_out->state->s == LTTV_STATE_UNNAMED)
892 {
893 prop_line_out.color->red = 0xffff;
894 prop_line_out.color->green = 0xffff;
895 prop_line_out.color->blue = 0xffff;
896 }
897 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
898 {
899 prop_line_out.color->red = 0x0fff;
900 prop_line_out.color->green = 0xffff;
901 prop_line_out.color->blue = 0xfff0;
902 }
903 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
904 {
905 prop_line_out.color->red = 0xffff;
906 prop_line_out.color->green = 0xffff;
907 prop_line_out.color->blue = 0x0000;
908 }
909 else if(process_out->state->s == LTTV_STATE_EXIT)
910 {
911 prop_line_out.color->red = 0xffff;
912 prop_line_out.color->green = 0x0000;
913 prop_line_out.color->blue = 0xffff;
914 }
915 else if(process_out->state->s == LTTV_STATE_WAIT)
916 {
917 prop_line_out.color->red = 0xffff;
918 prop_line_out.color->green = 0x0000;
919 prop_line_out.color->blue = 0x0000;
920 }
921 else if(process_out->state->s == LTTV_STATE_RUN)
922 {
923 prop_line_out.color->red = 0x0000;
924 prop_line_out.color->green = 0xffff;
925 prop_line_out.color->blue = 0x0000;
926 }
927 else
928 {
929 prop_line_out.color->red = 0xffff;
930 prop_line_out.color->green = 0xffff;
931 prop_line_out.color->blue = 0xffff;
932 }
933
934 draw_line((void*)&prop_line_out, (void*)draw_context_out);
935 g_free(prop_line_out.color);
936 //gdk_gc_unref(draw_context_out->gc);
937 /* Note : finishing line will have to be added when trace read over. */
938
939 /* Finally, update the drawing context of the pid_in. */
940
941 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
942 draw_context_in->current->modify_over->x = x;
943 draw_context_in->current->modify_under->x = x;
944 draw_context_in->current->modify_over->y = y_in;
945 draw_context_in->current->modify_under->y = y_in+(height/2)+2;
946 draw_context_in->drawable = control_flow_data->drawing->pixmap;
947 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
948 widget = control_flow_data->drawing->drawing_area;
949 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
950 //draw_context_in->gc = widget->style->black_gc;
951 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
952 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
953
954 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
955 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
956
957 /* Draw the line/bg of the in process */
958 if(draw_context_in->previous->middle->x == -1)
959 {
960 draw_context_in->previous->over->x =
961 control_flow_data->drawing->damage_begin;
962 draw_context_in->previous->middle->x =
963 control_flow_data->drawing->damage_begin;
964 draw_context_in->previous->under->x =
965 control_flow_data->drawing->damage_begin;
966
967 g_debug("in middle x_beg : %u",control_flow_data->drawing->damage_begin);
968
969 }
970
971 draw_context_in->current->middle->x = x;
972 draw_context_in->current->over->x = x;
973 draw_context_in->current->under->x = x;
974 draw_context_in->current->middle->y = y_in + height/2;
975 draw_context_in->current->over->y = y_in;
976 draw_context_in->current->under->y = y_in + height;
977 draw_context_in->previous->middle->y = y_in + height/2;
978 draw_context_in->previous->over->y = y_in;
979 draw_context_in->previous->under->y = y_in + height;
980
981 draw_context_in->drawable = control_flow_data->drawing->pixmap;
982 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
983
984
985 if(process_in->state->s == LTTV_STATE_RUN)
986 {
987 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
988 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
989 draw_context_in->gc = control_flow_data->drawing->gc;
990
991 PropertiesBG prop_bg;
992 prop_bg.color = g_new(GdkColor,1);
993
994 switch(tfc->index) {
995 case 0:
996 prop_bg.color->red = 0x1515;
997 prop_bg.color->green = 0x1515;
998 prop_bg.color->blue = 0x8c8c;
999 break;
1000 case 1:
1001 prop_bg.color->red = 0x4e4e;
1002 prop_bg.color->green = 0xa9a9;
1003 prop_bg.color->blue = 0xa4a4;
1004 break;
1005 case 2:
1006 prop_bg.color->red = 0x7a7a;
1007 prop_bg.color->green = 0x4a4a;
1008 prop_bg.color->blue = 0x8b8b;
1009 break;
1010 case 3:
1011 prop_bg.color->red = 0x8080;
1012 prop_bg.color->green = 0x7777;
1013 prop_bg.color->blue = 0x4747;
1014 break;
1015 default:
1016 prop_bg.color->red = 0xe7e7;
1017 prop_bg.color->green = 0xe7e7;
1018 prop_bg.color->blue = 0xe7e7;
1019 }
1020
1021
1022 draw_bg((void*)&prop_bg, (void*)draw_context_in);
1023 g_free(prop_bg.color);
1024 //gdk_gc_unref(draw_context_in->gc);
1025 }
1026
1027 draw_context_in->gc = widget->style->black_gc;
1028
1029 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
1030 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
1031 PropertiesText prop_text_in;
1032 prop_text_in.foreground = &colorfg_in;
1033 prop_text_in.background = &colorbg_in;
1034 prop_text_in.size = 6;
1035 prop_text_in.position = OVER;
1036
1037 g_debug("in state : %s", g_quark_to_string(process_in->state->s));
1038 /* foreground of text : status of the process */
1039 if(process_in->state->s == LTTV_STATE_UNNAMED)
1040 {
1041 prop_text_in.foreground->red = 0xffff;
1042 prop_text_in.foreground->green = 0xffff;
1043 prop_text_in.foreground->blue = 0xffff;
1044 }
1045 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1046 {
1047 prop_text_in.foreground->red = 0x0fff;
1048 prop_text_in.foreground->green = 0xffff;
1049 prop_text_in.foreground->blue = 0xfff0;
1050 }
1051 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1052 {
1053 prop_text_in.foreground->red = 0xffff;
1054 prop_text_in.foreground->green = 0xffff;
1055 prop_text_in.foreground->blue = 0x0000;
1056 }
1057 else if(process_in->state->s == LTTV_STATE_EXIT)
1058 {
1059 prop_text_in.foreground->red = 0xffff;
1060 prop_text_in.foreground->green = 0x0000;
1061 prop_text_in.foreground->blue = 0xffff;
1062 }
1063 else if(process_in->state->s == LTTV_STATE_WAIT)
1064 {
1065 prop_text_in.foreground->red = 0xffff;
1066 prop_text_in.foreground->green = 0x0000;
1067 prop_text_in.foreground->blue = 0x0000;
1068 }
1069 else if(process_in->state->s == LTTV_STATE_RUN)
1070 {
1071 prop_text_in.foreground->red = 0x0000;
1072 prop_text_in.foreground->green = 0xffff;
1073 prop_text_in.foreground->blue = 0x0000;
1074 }
1075 else
1076 {
1077 prop_text_in.foreground->red = 0xffff;
1078 prop_text_in.foreground->green = 0xffff;
1079 prop_text_in.foreground->blue = 0xffff;
1080 }
1081
1082
1083
1084 /* Print status of the process : U, WF, WC, E, W, R */
1085 if(process_in->state->s == LTTV_STATE_UNNAMED)
1086 prop_text_in.text = "U->";
1087 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1088 prop_text_in.text = "WF->";
1089 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1090 prop_text_in.text = "WC->";
1091 else if(process_in->state->s == LTTV_STATE_EXIT)
1092 prop_text_in.text = "E->";
1093 else if(process_in->state->s == LTTV_STATE_WAIT)
1094 prop_text_in.text = "W->";
1095 else if(process_in->state->s == LTTV_STATE_RUN)
1096 prop_text_in.text = "R->";
1097 else
1098 prop_text_in.text = "U";
1099
1100 draw_text((void*)&prop_text_in, (void*)draw_context_in);
1101 //gdk_gc_unref(draw_context_in->gc);
1102
1103 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1104 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1105 draw_context_in->gc = control_flow_data->drawing->gc;
1106
1107 PropertiesLine prop_line_in;
1108 prop_line_in.color = g_new(GdkColor,1);
1109 prop_line_in.line_width = 2;
1110 prop_line_in.style = GDK_LINE_SOLID;
1111 prop_line_in.position = MIDDLE;
1112
1113 /* color of line : status of the process */
1114 if(process_in->state->s == LTTV_STATE_UNNAMED)
1115 {
1116 prop_line_in.color->red = 0xffff;
1117 prop_line_in.color->green = 0xffff;
1118 prop_line_in.color->blue = 0xffff;
1119 }
1120 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1121 {
1122 prop_line_in.color->red = 0x0fff;
1123 prop_line_in.color->green = 0xffff;
1124 prop_line_in.color->blue = 0xfff0;
1125 }
1126 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1127 {
1128 prop_line_in.color->red = 0xffff;
1129 prop_line_in.color->green = 0xffff;
1130 prop_line_in.color->blue = 0x0000;
1131 }
1132 else if(process_in->state->s == LTTV_STATE_EXIT)
1133 {
1134 prop_line_in.color->red = 0xffff;
1135 prop_line_in.color->green = 0x0000;
1136 prop_line_in.color->blue = 0xffff;
1137 }
1138 else if(process_in->state->s == LTTV_STATE_WAIT)
1139 {
1140 prop_line_in.color->red = 0xffff;
1141 prop_line_in.color->green = 0x0000;
1142 prop_line_in.color->blue = 0x0000;
1143 }
1144 else if(process_in->state->s == LTTV_STATE_RUN)
1145 {
1146 prop_line_in.color->red = 0x0000;
1147 prop_line_in.color->green = 0xffff;
1148 prop_line_in.color->blue = 0x0000;
1149 }
1150 else
1151 {
1152 prop_line_in.color->red = 0xffff;
1153 prop_line_in.color->green = 0xffff;
1154 prop_line_in.color->blue = 0xffff;
1155 }
1156
1157 draw_line((void*)&prop_line_in, (void*)draw_context_in);
1158 g_free(prop_line_in.color);
1159 //gdk_gc_unref(draw_context_in->gc);
1160 }
1161
1162 return 0;
1163 #endif //0
1164
1165
1166
1167 /* Text dump */
1168 #ifdef DONTSHOW
1169 GString *string = g_string_new("");;
1170 gboolean field_names = TRUE, state = TRUE;
1171
1172 lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
1173 g_string_append_printf(string,"\n");
1174
1175 if(state) {
1176 g_string_append_printf(string, " %s",
1177 g_quark_to_string(tfs->process->state->s));
1178 }
1179
1180 g_info("%s",string->str);
1181
1182 g_string_free(string, TRUE);
1183
1184 /* End of text dump */
1185 #endif //DONTSHOW
1186
1187 }
1188
1189 /* draw_after_hook
1190 *
1191 * The draw after hook is called by the reading API to have a
1192 * particular event drawn on the screen.
1193 * @param hook_data ControlFlowData structure of the viewer.
1194 * @param call_data Event context.
1195 *
1196 * This function adds items to be drawn in a queue for each process.
1197 *
1198 */
1199 int draw_after_hook(void *hook_data, void *call_data)
1200 {
1201 EventsRequest *events_request = (EventsRequest*)hook_data;
1202 ControlFlowData *control_flow_data = events_request->viewer_data;
1203
1204 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1205
1206 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1207 LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context;
1208
1209 LttEvent *e;
1210 e = tfc->e;
1211
1212 LttTime evtime = ltt_event_time(e);
1213 TimeWindow time_window =
1214 lttvwindow_get_time_window(control_flow_data->tab);
1215
1216 LttTime end_time = ltt_time_add(time_window.start_time,
1217 time_window.time_width);
1218
1219 if(ltt_time_compare(evtime, time_window.start_time) == -1
1220 || ltt_time_compare(evtime, end_time) == 1)
1221 return;
1222
1223 guint width = control_flow_data->drawing->width;
1224
1225 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) {
1226
1227 g_debug("schedchange!");
1228
1229 {
1230 /* Add process to process list (if not present) */
1231 LttvProcessState *process_out, *process_in;
1232 LttTime birth;
1233 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
1234 HashedProcessData *hashed_process_data_in = NULL;
1235
1236 ProcessList *process_list =
1237 guicontrolflow_get_process_list(control_flow_data);
1238
1239 guint pid_in;
1240 {
1241 guint pid_out;
1242 LttField *f = ltt_event_field(e);
1243 LttField *element;
1244 element = ltt_field_member(f,0);
1245 pid_out = ltt_event_get_long_unsigned(e,element);
1246 element = ltt_field_member(f,1);
1247 pid_in = ltt_event_get_long_unsigned(e,element);
1248 g_debug("out : %u in : %u", pid_out, pid_in);
1249 }
1250
1251
1252 /* Find process pid_in in the list... */
1253 process_in = lttv_state_find_process(tfs, pid_in);
1254 /* It should exist, because we are after the state update. */
1255 g_assert(process_in != NULL);
1256
1257 birth = process_in->creation_time;
1258 const gchar *name = g_quark_to_string(process_in->name);
1259
1260 if(processlist_get_process_pixels(process_list,
1261 pid_in,
1262 &birth,
1263 tfc->t_context->index,
1264 &y_in,
1265 &height,
1266 &hashed_process_data_in) == 1)
1267 {
1268 /* Process not present */
1269 processlist_add(process_list,
1270 pid_in,
1271 &birth,
1272 tfc->t_context->index,
1273 name,
1274 &pl_height,
1275 &hashed_process_data_in);
1276 processlist_get_process_pixels(process_list,
1277 pid_in,
1278 &birth,
1279 tfc->t_context->index,
1280 &y_in,
1281 &height,
1282 &hashed_process_data_in);
1283 drawing_insert_square( control_flow_data->drawing, y_in, height);
1284 }
1285
1286 convert_time_to_pixels(
1287 time_window.start_time,
1288 end_time,
1289 evtime,
1290 width,
1291 &hashed_process_data_in->x);
1292 }
1293 }
1294 return 0;
1295
1296
1297
1298 #if 0
1299 EventsRequest *events_request = (EventsRequest*)hook_data;
1300 ControlFlowData *control_flow_data = events_request->viewer_data;
1301
1302 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1303
1304 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1305 LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context;
1306
1307
1308 LttEvent *e;
1309 e = tfc->e;
1310
1311 LttTime evtime = ltt_event_time(e);
1312 TimeWindow time_window =
1313 lttvwindow_get_time_window(control_flow_data->tab);
1314
1315 LttTime end_time = ltt_time_add(time_window.start_time,
1316 time_window.time_width);
1317 //if(time < time_beg || time > time_end) return;
1318 if(ltt_time_compare(evtime, time_window.start_time) == -1
1319 || ltt_time_compare(evtime, end_time) == 1)
1320 return;
1321
1322
1323 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
1324 {
1325 g_debug("schedchange!");
1326
1327 /* Add process to process list (if not present) and get drawing "y" from
1328 * process position */
1329 guint pid_out, pid_in;
1330 LttvProcessState *process_out, *process_in;
1331 LttTime birth;
1332 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
1333
1334 ProcessList *process_list =
1335 guicontrolflow_get_process_list(control_flow_data);
1336
1337
1338 LttField *f = ltt_event_field(e);
1339 LttField *element;
1340 element = ltt_field_member(f,0);
1341 pid_out = ltt_event_get_long_unsigned(e,element);
1342 element = ltt_field_member(f,1);
1343 pid_in = ltt_event_get_long_unsigned(e,element);
1344 //g_debug("out : %u in : %u", pid_out, pid_in);
1345
1346
1347 /* Find process pid_out in the list... */
1348 process_out = lttv_state_find_process(tfs, pid_out);
1349 if(process_out == NULL) return 0;
1350 //g_debug("out : %s",g_quark_to_string(process_out->state->s));
1351
1352 birth = process_out->creation_time;
1353 gchar *name = strdup(g_quark_to_string(process_out->name));
1354 HashedProcessData *hashed_process_data_out = NULL;
1355
1356 if(processlist_get_process_pixels(process_list,
1357 pid_out,
1358 &birth,
1359 tfc->t_context->index,
1360 &y_out,
1361 &height,
1362 &hashed_process_data_out) == 1)
1363 {
1364 /* Process not present */
1365 processlist_add(process_list,
1366 pid_out,
1367 &birth,
1368 tfc->t_context->index,
1369 name,
1370 &pl_height,
1371 &hashed_process_data_out);
1372 processlist_get_process_pixels(process_list,
1373 pid_out,
1374 &birth,
1375 tfc->t_context->index,
1376 &y_out,
1377 &height,
1378 &hashed_process_data_out);
1379 drawing_insert_square( control_flow_data->drawing, y_out, height);
1380 }
1381
1382 g_free(name);
1383
1384 /* Find process pid_in in the list... */
1385 process_in = lttv_state_find_process(tfs, pid_in);
1386 if(process_in == NULL) return 0;
1387 //g_debug("in : %s",g_quark_to_string(process_in->state->s));
1388
1389 birth = process_in->creation_time;
1390 name = strdup(g_quark_to_string(process_in->name));
1391 HashedProcessData *hashed_process_data_in = NULL;
1392
1393 if(processlist_get_process_pixels(process_list,
1394 pid_in,
1395 &birth,
1396 tfc->t_context->index,
1397 &y_in,
1398 &height,
1399 &hashed_process_data_in) == 1)
1400 {
1401 /* Process not present */
1402 processlist_add(process_list,
1403 pid_in,
1404 &birth,
1405 tfc->t_context->index,
1406 name,
1407 &pl_height,
1408 &hashed_process_data_in);
1409 processlist_get_process_pixels(process_list,
1410 pid_in,
1411 &birth,
1412 tfc->t_context->index,
1413 &y_in,
1414 &height,
1415 &hashed_process_data_in);
1416
1417 drawing_insert_square( control_flow_data->drawing, y_in, height);
1418 }
1419 g_free(name);
1420
1421
1422 /* Find pixels corresponding to time of the event. If the time does
1423 * not fit in the window, show a warning, not supposed to happend. */
1424 //guint x = 0;
1425 //guint width = control_flow_data->drawing->drawing_area->allocation.width;
1426
1427 //LttTime time = ltt_event_time(e);
1428
1429 //LttTime window_end = ltt_time_add(time_window->time_width,
1430 // time_window->start_time);
1431
1432
1433 //convert_time_to_pixels(
1434 // time_window->start_time,
1435 // window_end,
1436 // time,
1437 // width,
1438 // &x);
1439
1440 //assert(x <= width);
1441
1442 /* draw what represents the event for outgoing process. */
1443
1444 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
1445 //draw_context_out->current->modify_over->x = x;
1446 draw_context_out->current->modify_over->y = y_out;
1447 draw_context_out->current->modify_under->y = y_out+(height/2)+2;
1448 draw_context_out->drawable = control_flow_data->drawing->pixmap;
1449 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
1450 GtkWidget *widget = control_flow_data->drawing->drawing_area;
1451 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
1452
1453 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
1454 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
1455
1456 /*if(process_out->state->s == LTTV_STATE_RUN)
1457 {
1458 draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1459 gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
1460 PropertiesBG prop_bg;
1461 prop_bg.color = g_new(GdkColor,1);
1462
1463 prop_bg.color->red = 0xffff;
1464 prop_bg.color->green = 0xffff;
1465 prop_bg.color->blue = 0xffff;
1466
1467 draw_bg((void*)&prop_bg, (void*)draw_context_out);
1468 g_free(prop_bg.color);
1469 gdk_gc_unref(draw_context_out->gc);
1470 }*/
1471
1472 draw_context_out->gc = widget->style->black_gc;
1473
1474 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
1475 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
1476 PropertiesText prop_text_out;
1477 prop_text_out.foreground = &colorfg_out;
1478 prop_text_out.background = &colorbg_out;
1479 prop_text_out.size = 6;
1480 prop_text_out.position = OVER;
1481
1482 /* color of text : status of the process */
1483 if(process_out->state->s == LTTV_STATE_UNNAMED)
1484 {
1485 prop_text_out.foreground->red = 0xffff;
1486 prop_text_out.foreground->green = 0xffff;
1487 prop_text_out.foreground->blue = 0xffff;
1488 }
1489 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
1490 {
1491 prop_text_out.foreground->red = 0x0fff;
1492 prop_text_out.foreground->green = 0xffff;
1493 prop_text_out.foreground->blue = 0xfff0;
1494 }
1495 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
1496 {
1497 prop_text_out.foreground->red = 0xffff;
1498 prop_text_out.foreground->green = 0xffff;
1499 prop_text_out.foreground->blue = 0x0000;
1500 }
1501 else if(process_out->state->s == LTTV_STATE_EXIT)
1502 {
1503 prop_text_out.foreground->red = 0xffff;
1504 prop_text_out.foreground->green = 0x0000;
1505 prop_text_out.foreground->blue = 0xffff;
1506 }
1507 else if(process_out->state->s == LTTV_STATE_WAIT)
1508 {
1509 prop_text_out.foreground->red = 0xffff;
1510 prop_text_out.foreground->green = 0x0000;
1511 prop_text_out.foreground->blue = 0x0000;
1512 }
1513 else if(process_out->state->s == LTTV_STATE_RUN)
1514 {
1515 prop_text_out.foreground->red = 0x0000;
1516 prop_text_out.foreground->green = 0xffff;
1517 prop_text_out.foreground->blue = 0x0000;
1518 }
1519 else
1520 {
1521 prop_text_out.foreground->red = 0xffff;
1522 prop_text_out.foreground->green = 0xffff;
1523 prop_text_out.foreground->blue = 0xffff;
1524 }
1525
1526 /* Print status of the process : U, WF, WC, E, W, R */
1527 if(process_out->state->s == LTTV_STATE_UNNAMED)
1528 prop_text_out.text = "U";
1529 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
1530 prop_text_out.text = "WF";
1531 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
1532 prop_text_out.text = "WC";
1533 else if(process_out->state->s == LTTV_STATE_EXIT)
1534 prop_text_out.text = "E";
1535 else if(process_out->state->s == LTTV_STATE_WAIT)
1536 prop_text_out.text = "W";
1537 else if(process_out->state->s == LTTV_STATE_RUN)
1538 prop_text_out.text = "R";
1539 else
1540 prop_text_out.text = "U";
1541
1542 draw_text((void*)&prop_text_out, (void*)draw_context_out);
1543
1544 //gdk_gc_unref(draw_context_out->gc);
1545
1546 draw_context_out->current->middle->y = y_out+height/2;
1547 draw_context_out->current->over->y = y_out;
1548 draw_context_out->current->under->y = y_out+height;
1549 draw_context_out->current->status = process_out->state->s;
1550
1551 /* for pid_out : remove previous, Prev = current, new current (default) */
1552 g_free(draw_context_out->previous->modify_under);
1553 g_free(draw_context_out->previous->modify_middle);
1554 g_free(draw_context_out->previous->modify_over);
1555 g_free(draw_context_out->previous->under);
1556 g_free(draw_context_out->previous->middle);
1557 g_free(draw_context_out->previous->over);
1558 g_free(draw_context_out->previous);
1559
1560 draw_context_out->previous = draw_context_out->current;
1561
1562 draw_context_out->current = g_new(DrawInfo,1);
1563 draw_context_out->current->over = g_new(ItemInfo,1);
1564 draw_context_out->current->over->x = -1;
1565 draw_context_out->current->over->y = -1;
1566 draw_context_out->current->middle = g_new(ItemInfo,1);
1567 draw_context_out->current->middle->x = -1;
1568 draw_context_out->current->middle->y = -1;
1569 draw_context_out->current->under = g_new(ItemInfo,1);
1570 draw_context_out->current->under->x = -1;
1571 draw_context_out->current->under->y = -1;
1572 draw_context_out->current->modify_over = g_new(ItemInfo,1);
1573 draw_context_out->current->modify_over->x = -1;
1574 draw_context_out->current->modify_over->y = -1;
1575 draw_context_out->current->modify_middle = g_new(ItemInfo,1);
1576 draw_context_out->current->modify_middle->x = -1;
1577 draw_context_out->current->modify_middle->y = -1;
1578 draw_context_out->current->modify_under = g_new(ItemInfo,1);
1579 draw_context_out->current->modify_under->x = -1;
1580 draw_context_out->current->modify_under->y = -1;
1581 draw_context_out->current->status = LTTV_STATE_UNNAMED;
1582
1583 /* Finally, update the drawing context of the pid_in. */
1584
1585 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
1586 //draw_context_in->current->modify_over->x = x;
1587 draw_context_in->current->modify_over->y = y_in;
1588 draw_context_in->current->modify_under->y = y_in+(height/2)+2;
1589 draw_context_in->drawable = control_flow_data->drawing->pixmap;
1590 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
1591 widget = control_flow_data->drawing->drawing_area;
1592 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
1593
1594 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
1595 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
1596
1597 /*if(process_in->state->s == LTTV_STATE_RUN)
1598 {
1599 draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1600 gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1601 PropertiesBG prop_bg;
1602 prop_bg.color = g_new(GdkColor,1);
1603
1604 prop_bg.color->red = 0xffff;
1605 prop_bg.color->green = 0xffff;
1606 prop_bg.color->blue = 0xffff;
1607
1608 draw_bg((void*)&prop_bg, (void*)draw_context_in);
1609 g_free(prop_bg.color);
1610 gdk_gc_unref(draw_context_in->gc);
1611 }*/
1612
1613 draw_context_in->gc = widget->style->black_gc;
1614
1615 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
1616 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
1617 PropertiesText prop_text_in;
1618 prop_text_in.foreground = &colorfg_in;
1619 prop_text_in.background = &colorbg_in;
1620 prop_text_in.size = 6;
1621 prop_text_in.position = OVER;
1622
1623 /* foreground of text : status of the process */
1624 if(process_in->state->s == LTTV_STATE_UNNAMED)
1625 {
1626 prop_text_in.foreground->red = 0xffff;
1627 prop_text_in.foreground->green = 0xffff;
1628 prop_text_in.foreground->blue = 0xffff;
1629 }
1630 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1631 {
1632 prop_text_in.foreground->red = 0x0fff;
1633 prop_text_in.foreground->green = 0xffff;
1634 prop_text_in.foreground->blue = 0xfff0;
1635 }
1636 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1637 {
1638 prop_text_in.foreground->red = 0xffff;
1639 prop_text_in.foreground->green = 0xffff;
1640 prop_text_in.foreground->blue = 0x0000;
1641 }
1642 else if(process_in->state->s == LTTV_STATE_EXIT)
1643 {
1644 prop_text_in.foreground->red = 0xffff;
1645 prop_text_in.foreground->green = 0x0000;
1646 prop_text_in.foreground->blue = 0xffff;
1647 }
1648 else if(process_in->state->s == LTTV_STATE_WAIT)
1649 {
1650 prop_text_in.foreground->red = 0xffff;
1651 prop_text_in.foreground->green = 0x0000;
1652 prop_text_in.foreground->blue = 0x0000;
1653 }
1654 else if(process_in->state->s == LTTV_STATE_RUN)
1655 {
1656 prop_text_in.foreground->red = 0x0000;
1657 prop_text_in.foreground->green = 0xffff;
1658 prop_text_in.foreground->blue = 0x0000;
1659 }
1660 else
1661 {
1662 prop_text_in.foreground->red = 0xffff;
1663 prop_text_in.foreground->green = 0xffff;
1664 prop_text_in.foreground->blue = 0xffff;
1665 }
1666
1667
1668 /* Print status of the process : U, WF, WC, E, W, R */
1669 if(process_in->state->s == LTTV_STATE_UNNAMED)
1670 prop_text_in.text = "U";
1671 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1672 prop_text_in.text = "WF";
1673 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1674 prop_text_in.text = "WC";
1675 else if(process_in->state->s == LTTV_STATE_EXIT)
1676 prop_text_in.text = "E";
1677 else if(process_in->state->s == LTTV_STATE_WAIT)
1678 prop_text_in.text = "W";
1679 else if(process_in->state->s == LTTV_STATE_RUN)
1680 prop_text_in.text = "R";
1681 else
1682 prop_text_in.text = "U";
1683
1684 draw_text((void*)&prop_text_in, (void*)draw_context_in);
1685
1686
1687 if(process_in->state->s == LTTV_STATE_RUN)
1688 {
1689 gchar tmp[255];
1690 prop_text_in.foreground = &colorfg_in;
1691 prop_text_in.background = &colorbg_in;
1692 prop_text_in.foreground->red = 0xffff;
1693 prop_text_in.foreground->green = 0xffff;
1694 prop_text_in.foreground->blue = 0xffff;
1695 prop_text_in.size = 6;
1696 prop_text_in.position = UNDER;
1697
1698 prop_text_in.text = g_new(gchar, 260);
1699 strcpy(prop_text_in.text, "CPU ");
1700 snprintf(tmp, 255, "%u", tfc->index);
1701 strcat(prop_text_in.text, tmp);
1702
1703 draw_text((void*)&prop_text_in, (void*)draw_context_in);
1704 g_free(prop_text_in.text);
1705 }
1706
1707
1708 draw_context_in->current->middle->y = y_in+height/2;
1709 draw_context_in->current->over->y = y_in;
1710 draw_context_in->current->under->y = y_in+height;
1711 draw_context_in->current->status = process_in->state->s;
1712
1713 /* for pid_in : remove previous, Prev = current, new current (default) */
1714 g_free(draw_context_in->previous->modify_under);
1715 g_free(draw_context_in->previous->modify_middle);
1716 g_free(draw_context_in->previous->modify_over);
1717 g_free(draw_context_in->previous->under);
1718 g_free(draw_context_in->previous->middle);
1719 g_free(draw_context_in->previous->over);
1720 g_free(draw_context_in->previous);
1721
1722 draw_context_in->previous = draw_context_in->current;
1723
1724 draw_context_in->current = g_new(DrawInfo,1);
1725 draw_context_in->current->over = g_new(ItemInfo,1);
1726 draw_context_in->current->over->x = -1;
1727 draw_context_in->current->over->y = -1;
1728 draw_context_in->current->middle = g_new(ItemInfo,1);
1729 draw_context_in->current->middle->x = -1;
1730 draw_context_in->current->middle->y = -1;
1731 draw_context_in->current->under = g_new(ItemInfo,1);
1732 draw_context_in->current->under->x = -1;
1733 draw_context_in->current->under->y = -1;
1734 draw_context_in->current->modify_over = g_new(ItemInfo,1);
1735 draw_context_in->current->modify_over->x = -1;
1736 draw_context_in->current->modify_over->y = -1;
1737 draw_context_in->current->modify_middle = g_new(ItemInfo,1);
1738 draw_context_in->current->modify_middle->x = -1;
1739 draw_context_in->current->modify_middle->y = -1;
1740 draw_context_in->current->modify_under = g_new(ItemInfo,1);
1741 draw_context_in->current->modify_under->x = -1;
1742 draw_context_in->current->modify_under->y = -1;
1743 draw_context_in->current->status = LTTV_STATE_UNNAMED;
1744
1745 }
1746
1747 return 0;
1748 #endif //0
1749 }
1750
1751
1752
1753
1754 gint update_time_window_hook(void *hook_data, void *call_data)
1755 {
1756 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1757 Drawing_t *drawing = control_flow_data->drawing;
1758
1759 const TimeWindowNotifyData *time_window_nofify_data =
1760 ((const TimeWindowNotifyData *)call_data);
1761
1762 TimeWindow *old_time_window =
1763 time_window_nofify_data->old_time_window;
1764 TimeWindow *new_time_window =
1765 time_window_nofify_data->new_time_window;
1766
1767 /* Update the ruler */
1768 drawing_update_ruler(control_flow_data->drawing,
1769 new_time_window);
1770
1771
1772 /* Two cases : zoom in/out or scrolling */
1773
1774 /* In order to make sure we can reuse the old drawing, the scale must
1775 * be the same and the new time interval being partly located in the
1776 * currently shown time interval. (reuse is only for scrolling)
1777 */
1778
1779 g_info("Old time window HOOK : %u, %u to %u, %u",
1780 old_time_window->start_time.tv_sec,
1781 old_time_window->start_time.tv_nsec,
1782 old_time_window->time_width.tv_sec,
1783 old_time_window->time_width.tv_nsec);
1784
1785 g_info("New time window HOOK : %u, %u to %u, %u",
1786 new_time_window->start_time.tv_sec,
1787 new_time_window->start_time.tv_nsec,
1788 new_time_window->time_width.tv_sec,
1789 new_time_window->time_width.tv_nsec);
1790
1791 if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec
1792 && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec)
1793 {
1794 /* Same scale (scrolling) */
1795 g_info("scrolling");
1796 LttTime *ns = &new_time_window->start_time;
1797 LttTime *os = &old_time_window->start_time;
1798 LttTime old_end = ltt_time_add(old_time_window->start_time,
1799 old_time_window->time_width);
1800 LttTime new_end = ltt_time_add(new_time_window->start_time,
1801 new_time_window->time_width);
1802 //if(ns<os+w<ns+w)
1803 //if(ns<os+w && os+w<ns+w)
1804 //if(ns<old_end && os<ns)
1805 if(ltt_time_compare(*ns, old_end) == -1
1806 && ltt_time_compare(*os, *ns) == -1)
1807 {
1808 g_info("scrolling near right");
1809 /* Scroll right, keep right part of the screen */
1810 guint x = 0;
1811 guint width = control_flow_data->drawing->width;
1812 convert_time_to_pixels(
1813 *os,
1814 old_end,
1815 *ns,
1816 width,
1817 &x);
1818
1819 /* Copy old data to new location */
1820 gdk_draw_drawable (control_flow_data->drawing->pixmap,
1821 control_flow_data->drawing->drawing_area->style->black_gc,
1822 control_flow_data->drawing->pixmap,
1823 x, 0,
1824 0, 0,
1825 control_flow_data->drawing->width-x+SAFETY, -1);
1826
1827 if(drawing->damage_begin == drawing->damage_end)
1828 drawing->damage_begin = control_flow_data->drawing->width-x;
1829 else
1830 drawing->damage_begin = 0;
1831
1832 drawing->damage_end = control_flow_data->drawing->width;
1833
1834 /* Clear the data request background, but not SAFETY */
1835 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
1836 //control_flow_data->drawing->drawing_area->style->black_gc,
1837 control_flow_data->drawing->drawing_area->style->black_gc,
1838 TRUE,
1839 drawing->damage_begin+SAFETY, 0,
1840 drawing->damage_end - drawing->damage_begin, // do not overlap
1841 control_flow_data->drawing->height);
1842
1843 gtk_widget_queue_draw_area (drawing->drawing_area,
1844 0,0,
1845 control_flow_data->drawing->width,
1846 control_flow_data->drawing->height);
1847
1848 /* Get new data for the rest. */
1849 drawing_data_request(control_flow_data->drawing,
1850 &control_flow_data->drawing->pixmap,
1851 drawing->damage_begin, 0,
1852 drawing->damage_end - drawing->damage_begin,
1853 control_flow_data->drawing->height);
1854 } else {
1855 //if(ns<os<ns+w)
1856 //if(ns<os && os<ns+w)
1857 //if(ns<os && os<new_end)
1858 if(ltt_time_compare(*ns,*os) == -1
1859 && ltt_time_compare(*os,new_end) == -1)
1860 {
1861 g_info("scrolling near left");
1862 /* Scroll left, keep left part of the screen */
1863 guint x = 0;
1864 guint width = control_flow_data->drawing->width;
1865 convert_time_to_pixels(
1866 *ns,
1867 new_end,
1868 *os,
1869 width,
1870 &x);
1871
1872
1873 /* Copy old data to new location */
1874 gdk_draw_drawable (control_flow_data->drawing->pixmap,
1875 control_flow_data->drawing->drawing_area->style->black_gc,
1876 control_flow_data->drawing->pixmap,
1877 0, 0,
1878 x, 0,
1879 -1, -1);
1880
1881 if(drawing->damage_begin == drawing->damage_end)
1882 drawing->damage_end = x;
1883 else
1884 drawing->damage_end =
1885 control_flow_data->drawing->width;
1886
1887 drawing->damage_begin = 0;
1888
1889 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
1890 control_flow_data->drawing->drawing_area->style->black_gc,
1891 TRUE,
1892 drawing->damage_begin, 0,
1893 drawing->damage_end - drawing->damage_begin, // do not overlap
1894 control_flow_data->drawing->height);
1895
1896 gtk_widget_queue_draw_area (drawing->drawing_area,
1897 0,0,
1898 control_flow_data->drawing->width,
1899 control_flow_data->drawing->height);
1900
1901
1902 /* Get new data for the rest. */
1903 drawing_data_request(control_flow_data->drawing,
1904 &control_flow_data->drawing->pixmap,
1905 drawing->damage_begin, 0,
1906 drawing->damage_end - drawing->damage_begin,
1907 control_flow_data->drawing->height);
1908
1909 } else {
1910 if(ltt_time_compare(*ns,*os) == 0)
1911 {
1912 g_info("not scrolling");
1913 } else {
1914 g_info("scrolling far");
1915 /* Cannot reuse any part of the screen : far jump */
1916
1917
1918 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
1919 control_flow_data->drawing->drawing_area->style->black_gc,
1920 TRUE,
1921 0, 0,
1922 control_flow_data->drawing->width+SAFETY, // do not overlap
1923 control_flow_data->drawing->height);
1924
1925 gtk_widget_queue_draw_area (drawing->drawing_area,
1926 0,0,
1927 control_flow_data->drawing->width,
1928 control_flow_data->drawing->height);
1929
1930 drawing->damage_begin = 0;
1931 drawing->damage_end = control_flow_data->drawing->width;
1932
1933 drawing_data_request(control_flow_data->drawing,
1934 &control_flow_data->drawing->pixmap,
1935 0, 0,
1936 control_flow_data->drawing->width,
1937 control_flow_data->drawing->height);
1938
1939 }
1940 }
1941 }
1942 } else {
1943 /* Different scale (zoom) */
1944 g_info("zoom");
1945
1946 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
1947 control_flow_data->drawing->drawing_area->style->black_gc,
1948 TRUE,
1949 0, 0,
1950 control_flow_data->drawing->width+SAFETY, // do not overlap
1951 control_flow_data->drawing->height);
1952
1953 gtk_widget_queue_draw_area (drawing->drawing_area,
1954 0,0,
1955 control_flow_data->drawing->width,
1956 control_flow_data->drawing->height);
1957
1958 drawing->damage_begin = 0;
1959 drawing->damage_end = control_flow_data->drawing->width;
1960
1961 drawing_data_request(control_flow_data->drawing,
1962 &control_flow_data->drawing->pixmap,
1963 0, 0,
1964 control_flow_data->drawing->width,
1965 control_flow_data->drawing->height);
1966 }
1967
1968
1969
1970 return 0;
1971 }
1972
1973 gint traceset_notify(void *hook_data, void *call_data)
1974 {
1975 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1976 Drawing_t *drawing = control_flow_data->drawing;
1977 GtkWidget *widget = drawing->drawing_area;
1978
1979 drawing->damage_begin = 0;
1980 drawing->damage_end = drawing->width;
1981
1982 drawing_clear(control_flow_data->drawing);
1983 processlist_clear(control_flow_data->process_list);
1984
1985 if(drawing->damage_begin < drawing->damage_end)
1986 {
1987 drawing_data_request(drawing,
1988 &drawing->pixmap,
1989 drawing->damage_begin,
1990 0,
1991 drawing->damage_end-drawing->damage_begin,
1992 drawing->height);
1993 }
1994
1995 gtk_widget_queue_draw_area(drawing->drawing_area,
1996 0,0,
1997 drawing->width,
1998 drawing->height);
1999
2000 request_background_data(control_flow_data);
2001
2002 return FALSE;
2003 }
2004
2005 gint redraw_notify(void *hook_data, void *call_data)
2006 {
2007 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2008 Drawing_t *drawing = control_flow_data->drawing;
2009 GtkWidget *widget = drawing->drawing_area;
2010
2011 drawing->damage_begin = 0;
2012 drawing->damage_end = drawing->width;
2013
2014
2015 // Clear the image
2016 gdk_draw_rectangle (drawing->pixmap,
2017 widget->style->black_gc,
2018 TRUE,
2019 0, 0,
2020 drawing->width+SAFETY,
2021 drawing->height);
2022
2023
2024 if(drawing->damage_begin < drawing->damage_end)
2025 {
2026 drawing_data_request(drawing,
2027 &drawing->pixmap,
2028 drawing->damage_begin,
2029 0,
2030 drawing->damage_end-drawing->damage_begin,
2031 drawing->height);
2032 }
2033
2034 gtk_widget_queue_draw_area(drawing->drawing_area,
2035 0,0,
2036 drawing->width,
2037 drawing->height);
2038
2039 return FALSE;
2040
2041 }
2042
2043
2044 gint continue_notify(void *hook_data, void *call_data)
2045 {
2046 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2047 Drawing_t *drawing = control_flow_data->drawing;
2048 GtkWidget *widget = drawing->drawing_area;
2049
2050 //g_assert(widget->allocation.width == drawing->damage_end);
2051
2052 if(drawing->damage_begin < drawing->damage_end)
2053 {
2054 drawing_data_request(drawing,
2055 &drawing->pixmap,
2056 drawing->damage_begin,
2057 0,
2058 drawing->damage_end-drawing->damage_begin,
2059 drawing->height);
2060 }
2061
2062 return FALSE;
2063 }
2064
2065
2066 gint update_current_time_hook(void *hook_data, void *call_data)
2067 {
2068 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
2069 Drawing_t *drawing = control_flow_data->drawing;
2070
2071 LttTime current_time = *((LttTime*)call_data);
2072
2073 TimeWindow time_window =
2074 lttvwindow_get_time_window(control_flow_data->tab);
2075
2076 LttTime time_begin = time_window.start_time;
2077 LttTime width = time_window.time_width;
2078 LttTime half_width = ltt_time_div(width,2.0);
2079 LttTime time_end = ltt_time_add(time_begin, width);
2080
2081 LttvTracesetContext * tsc =
2082 lttvwindow_get_traceset_context(control_flow_data->tab);
2083
2084 LttTime trace_start = tsc->time_span.start_time;
2085 LttTime trace_end = tsc->time_span.end_time;
2086
2087 g_info("New current time HOOK : %u, %u", current_time.tv_sec,
2088 current_time.tv_nsec);
2089
2090
2091
2092 /* If current time is inside time interval, just move the highlight
2093 * bar */
2094
2095 /* Else, we have to change the time interval. We have to tell it
2096 * to the main window. */
2097 /* The time interval change will take care of placing the current
2098 * time at the center of the visible area, or nearest possible if we are
2099 * at one end of the trace. */
2100
2101
2102 if(ltt_time_compare(current_time, time_begin) == -1)
2103 {
2104 TimeWindow new_time_window;
2105
2106 if(ltt_time_compare(current_time,
2107 ltt_time_add(trace_start,half_width)) == -1)
2108 time_begin = trace_start;
2109 else
2110 time_begin = ltt_time_sub(current_time,half_width);
2111
2112 new_time_window.start_time = time_begin;
2113 new_time_window.time_width = width;
2114
2115 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
2116 }
2117 else if(ltt_time_compare(current_time, time_end) == 1)
2118 {
2119 TimeWindow new_time_window;
2120
2121 if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) == 1)
2122 time_begin = ltt_time_sub(trace_end,width);
2123 else
2124 time_begin = ltt_time_sub(current_time,half_width);
2125
2126 new_time_window.start_time = time_begin;
2127 new_time_window.time_width = width;
2128
2129 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
2130
2131 }
2132 //gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
2133 gtk_widget_queue_draw_area(drawing->drawing_area,
2134 0,0,
2135 drawing->width,
2136 drawing->height);
2137
2138 return 0;
2139 }
2140
2141 typedef struct _ClosureData {
2142 EventsRequest *events_request;
2143 LttvTracesetState *tss;
2144 LttTime end_time;
2145 } ClosureData;
2146
2147
2148 /* find_process
2149 * Input : A trace and a PID.
2150 *
2151 * - For each CPU of the trace
2152 * - Search in trace states by PID and CPU key
2153 * - For each ProcessState found
2154 * - If state is not LTTV_STATE_WAIT
2155 * - Then this process state is the current one for this PID.
2156 * - Stop search.
2157 * - If no ProcessState found, return NULL.
2158 * - If all ProcessState were in LTTV_STATE_WAIT state, return one of
2159 * them arbitrarily.
2160 * Than means state is LTTV_STATE_WAIT, CPU unknown.
2161 */
2162 static LttvProcessState *find_process(LttvTraceState *tstate, guint pid)
2163 {
2164 guint cpu_num = ltt_trace_per_cpu_tracefile_number(tstate->parent.t);
2165 GQuark cpu_name;
2166 guint i;
2167
2168 LttvProcessState *real_state = NULL;
2169
2170 for(i=0;i<cpu_num;i++) {
2171 cpu_name = ((LttvTracefileState*)tstate->parent.tracefiles[i])->cpu_name;
2172 LttvProcessState *state = lttv_state_find_process_from_trace(tstate,
2173 cpu_name,
2174 pid);
2175
2176 if(state != NULL) {
2177 real_state = state;
2178 if(state->state->s != LTTV_STATE_WAIT)
2179 break;
2180 }
2181 }
2182 return real_state;
2183 }
2184
2185
2186 void draw_closure(gpointer key, gpointer value, gpointer user_data)
2187 {
2188 ProcessInfo *process_info = (ProcessInfo*)key;
2189 HashedProcessData *hashed_process_data = (HashedProcessData*)value;
2190 ClosureData *closure_data = (ClosureData*)user_data;
2191
2192 EventsRequest *events_request = closure_data->events_request;
2193 ControlFlowData *control_flow_data = events_request->viewer_data;
2194 Drawing_t *drawing = control_flow_data->drawing;
2195
2196 LttvTracesetState *tss = closure_data->tss;
2197 LttvTracesetContext *tsc = (LttvTracesetContext*)closure_data->tss;
2198
2199 LttTime evtime = closure_data->end_time;
2200 TimeWindow time_window =
2201 lttvwindow_get_time_window(control_flow_data->tab);
2202
2203 LttTime end_time = ltt_time_add(time_window.start_time,
2204 time_window.time_width);
2205
2206 if(ltt_time_compare(evtime, time_window.start_time) == -1
2207 || ltt_time_compare(evtime, end_time) == 1)
2208 return;
2209
2210 guint width = drawing->width;
2211
2212 {
2213 /* For the process */
2214 /* First, check if the current process is in the state computation
2215 * process list. If it is there, that means we must add it right now and
2216 * draw items from the beginning of the read for it. If it is not
2217 * present, it's a new process and it was not present : it will
2218 * be added after the state update. */
2219 g_assert(lttv_traceset_number(tsc->ts) > 0);
2220
2221 LttvTraceState *trace_state =
2222 (LttvTraceState*)tsc->traces[process_info->trace_num];
2223
2224 LttvProcessState *process;
2225 process = find_process(trace_state, process_info->pid);
2226
2227 if(process != NULL) {
2228
2229 /* Only draw for processes that are currently in the trace states */
2230
2231 guint y = 0, height = 0, pl_height = 0;
2232 ProcessList *process_list =
2233 guicontrolflow_get_process_list(control_flow_data);
2234 LttTime birth = process_info->birth;
2235
2236 /* Should be alike when background info is ready */
2237 if(control_flow_data->background_info_waiting==0)
2238 g_assert(ltt_time_compare(process->creation_time,
2239 process_info->birth) == 0);
2240 const gchar *name = g_quark_to_string(process->name);
2241
2242 /* process HAS to be present */
2243 g_assert(processlist_get_process_pixels(process_list,
2244 process_info->pid,
2245 &birth,
2246 process_info->trace_num,
2247 &y,
2248 &height,
2249 &hashed_process_data) != 1);
2250
2251 /* Now, the process is in the state hash and our own process hash.
2252 * We definitely can draw the items related to the ending state.
2253 */
2254
2255 /* Check if the x position is unset. In can have been left unset by
2256 * a draw closure from a after chunk hook. This should never happen,
2257 * because it must be set by before chunk hook to the damage_begin
2258 * value.
2259 */
2260 g_assert(hashed_process_data->x != -1);
2261 {
2262 guint x;
2263 DrawContext draw_context;
2264
2265 convert_time_to_pixels(
2266 time_window.start_time,
2267 end_time,
2268 evtime,
2269 width,
2270 &x);
2271
2272 /* Now create the drawing context that will be used to draw
2273 * items related to the last state. */
2274 draw_context.drawable = drawing->pixmap;
2275 draw_context.gc = drawing->gc;
2276 draw_context.pango_layout = drawing->pango_layout;
2277 draw_context.drawinfo.start.x = hashed_process_data->x;
2278 draw_context.drawinfo.end.x = x;
2279
2280 draw_context.drawinfo.y.over = y;
2281 draw_context.drawinfo.y.middle = y+(height/4);
2282 draw_context.drawinfo.y.under = y+(height/2)+2;
2283
2284 draw_context.drawinfo.start.offset.over = 0;
2285 draw_context.drawinfo.start.offset.middle = 0;
2286 draw_context.drawinfo.start.offset.under = 0;
2287 draw_context.drawinfo.end.offset.over = 0;
2288 draw_context.drawinfo.end.offset.middle = 0;
2289 draw_context.drawinfo.end.offset.under = 0;
2290
2291 {
2292 /* Draw the line */
2293 PropertiesLine prop_line = prepare_line(process);
2294 draw_line((void*)&prop_line, (void*)&draw_context);
2295
2296 }
2297
2298 /* special case LTTV_STATE_WAIT : CPU is unknown. */
2299
2300 /* become the last x position */
2301 hashed_process_data->x = x;
2302 }
2303 }
2304 }
2305 return;
2306 }
2307
2308 int before_chunk(void *hook_data, void *call_data)
2309 {
2310 EventsRequest *events_request = (EventsRequest*)hook_data;
2311 LttvTracesetState *tss = LTTV_TRACESET_STATE(call_data);
2312
2313 drawing_chunk_begin(events_request, tss);
2314
2315 return 0;
2316 }
2317
2318 int before_request(void *hook_data, void *call_data)
2319 {
2320 EventsRequest *events_request = (EventsRequest*)hook_data;
2321 LttvTracesetState *tss = LTTV_TRACESET_STATE(call_data);
2322
2323 drawing_data_request_begin(events_request, tss);
2324
2325 return 0;
2326 }
2327
2328
2329 /*
2330 * after request is necessary in addition of after chunk in order to draw
2331 * lines until the end of the screen. after chunk just draws lines until
2332 * the last event.
2333 *
2334 * for each process
2335 * draw closing line
2336 * expose
2337 */
2338 int after_request(void *hook_data, void *call_data)
2339 {
2340 EventsRequest *events_request = (EventsRequest*)hook_data;
2341 ControlFlowData *control_flow_data = events_request->viewer_data;
2342 LttvTracesetState *tss = LTTV_TRACESET_STATE(call_data);
2343 LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(call_data);
2344
2345 ProcessList *process_list =
2346 guicontrolflow_get_process_list(control_flow_data);
2347 LttTime end_time = events_request->end_time;
2348
2349 ClosureData closure_data;
2350 closure_data.events_request = (EventsRequest*)hook_data;
2351 closure_data.tss = tss;
2352 closure_data.end_time = end_time;
2353
2354 /* Draw last items */
2355 g_hash_table_foreach(process_list->process_hash, draw_closure,
2356 (void*)&closure_data);
2357
2358 /* Request expose */
2359 drawing_request_expose(events_request, tss, end_time);
2360 return 0;
2361 }
2362
2363 /*
2364 * for each process
2365 * draw closing line
2366 * expose
2367 */
2368 int after_chunk(void *hook_data, void *call_data)
2369 {
2370 EventsRequest *events_request = (EventsRequest*)hook_data;
2371 ControlFlowData *control_flow_data = events_request->viewer_data;
2372 LttvTracesetState *tss = LTTV_TRACESET_STATE(call_data);
2373 LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(call_data);
2374 LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc);
2375 LttTime end_time;
2376
2377 ProcessList *process_list =
2378 guicontrolflow_get_process_list(control_flow_data);
2379
2380 if(tfc != NULL)
2381 end_time = LTT_TIME_MIN(tfc->timestamp, events_request->end_time);
2382 else /* end of traceset, or position now out of request : end */
2383 end_time = events_request->end_time;
2384
2385 ClosureData closure_data;
2386 closure_data.events_request = (EventsRequest*)hook_data;
2387 closure_data.tss = tss;
2388 closure_data.end_time = end_time;
2389
2390 /* Draw last items */
2391 g_hash_table_foreach(process_list->process_hash, draw_closure,
2392 (void*)&closure_data);
2393
2394 /* Request expose */
2395 drawing_request_expose(events_request, tss, end_time);
2396
2397 return 0;
2398 }
2399
This page took 0.165379 seconds and 4 git commands to generate.