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