line current : dash style
[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
189a5d08 25#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
26#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
27
cf6cb7e0 28//#define PANGO_ENABLE_BACKEND
558aa013 29#include <gtk/gtk.h>
30#include <gdk/gdk.h>
5f16133f 31#include <glib.h>
80a52ff8 32#include <assert.h>
50439712 33#include <string.h>
5f16133f 34
cf6cb7e0 35//#include <pango/pango.h>
36
80a52ff8 37#include <ltt/event.h>
4ba42155 38#include <ltt/time.h>
50439712 39#include <ltt/type.h>
80a52ff8 40
558aa013 41#include <lttv/hook.h>
42#include <lttv/common.h>
80a52ff8 43#include <lttv/state.h>
1b238973 44#include <lttv/gtkTraceSet.h>
80a52ff8 45
f0d936c0 46
a117e3f7 47#include "eventhooks.h"
48#include "cfv.h"
49#include "processlist.h"
50#include "drawing.h"
51#include "cfv-private.h"
5f16133f 52
80a52ff8 53
1a31868c 54#define MAX_PATH_LEN 256
55
f0d936c0 56
57/**
58 * Event Viewer's constructor hook
59 *
60 * This constructor is given as a parameter to the menuitem and toolbar button
61 * registration. It creates the list.
14963be0 62 * @param mw A pointer to the parent window.
f0d936c0 63 * @return The widget created.
64 */
65GtkWidget *
14963be0 66h_guicontrolflow(MainWindow *mw, LttvTracesetSelector * s, char * key)
f0d936c0 67{
14963be0 68 g_info("h_guicontrolflow, %p, %p, %s", mw, s, key);
68997a22 69 ControlFlowData *control_flow_data = guicontrolflow() ;
a56a1ba4 70
14963be0 71 control_flow_data->mw = mw;
68997a22 72 TimeWindow *time_window = guicontrolflow_get_time_window(control_flow_data);
a56a1ba4 73 time_window->start_time.tv_sec = 0;
74 time_window->start_time.tv_nsec = 0;
75 time_window->time_width.tv_sec = 0;
76 time_window->time_width.tv_nsec = 0;
77
68997a22 78 LttTime *current_time = guicontrolflow_get_current_time(control_flow_data);
a56a1ba4 79 current_time->tv_sec = 0;
80 current_time->tv_nsec = 0;
81
82 //g_critical("time width1 : %u",time_window->time_width);
83
14963be0 84 get_time_window(mw,
a56a1ba4 85 time_window);
14963be0 86 get_current_time(mw,
a56a1ba4 87 current_time);
88
89 //g_critical("time width2 : %u",time_window->time_width);
90 // Unreg done in the GuiControlFlow_Destructor
68997a22 91 reg_update_time_window(update_time_window_hook, control_flow_data,
14963be0 92 mw);
68997a22 93 reg_update_current_time(update_current_time_hook, control_flow_data,
14963be0 94 mw);
68997a22 95 return guicontrolflow_get_widget(control_flow_data) ;
a56a1ba4 96
f0d936c0 97}
98
3cff8cc1 99int event_selected_hook(void *hook_data, void *call_data)
f0d936c0 100{
68997a22 101 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
14963be0 102 guint *event_number = (guint*) call_data;
f0d936c0 103
14963be0 104 g_critical("DEBUG : event selected by main window : %u", *event_number);
a56a1ba4 105
14963be0 106// control_flow_data->currently_Selected_Event = *event_number;
68997a22 107// control_flow_data->Selected_Event = TRUE ;
a56a1ba4 108
68997a22 109// tree_v_set_cursor(control_flow_data);
f0d936c0 110
111}
112
f0d936c0 113/* Hook called before drawing. Gets the initial context at the beginning of the
14963be0 114 * drawing interval and copy it to the context in event_request.
f0d936c0 115 */
4c69e0cc 116int draw_before_hook(void *hook_data, void *call_data)
f0d936c0 117{
14963be0 118 EventRequest *event_request = (EventRequest*)hook_data;
a56a1ba4 119 //EventsContext Events_Context = (EventsContext*)call_data;
120
14963be0 121 //event_request->Events_Context = Events_Context;
f0d936c0 122
a56a1ba4 123 return 0;
f0d936c0 124}
125
126/*
127 * The draw event hook is called by the reading API to have a
128 * particular event drawn on the screen.
129 * @param hook_data ControlFlowData structure of the viewer.
130 * @param call_data Event context.
131 *
132 * This function basically draw lines and icons. Two types of lines are drawn :
133 * one small (3 pixels?) representing the state of the process and the second
134 * type is thicker (10 pixels?) representing on which CPU a process is running
135 * (and this only in running state).
136 *
137 * Extremums of the lines :
138 * x_min : time of the last event context for this process kept in memory.
139 * x_max : time of the current event.
140 * y : middle of the process in the process list. The process is found in the
141 * list, therefore is it's position in pixels.
142 *
143 * The choice of lines'color is defined by the context of the last event for this
144 * process.
145 */
4c69e0cc 146int draw_event_hook(void *hook_data, void *call_data)
f0d936c0 147{
14963be0 148 EventRequest *event_request = (EventRequest*)hook_data;
149 ControlFlowData *control_flow_data = event_request->control_flow_data;
e9a9c513 150
a56a1ba4 151 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
e9a9c513 152
153 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
154
a56a1ba4 155
e9a9c513 156 LttEvent *e;
e9a9c513 157 e = tfc->e;
158
a56a1ba4 159 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
160 {
161 g_critical("schedchange!");
162
163 /* Add process to process list (if not present) and get drawing "y" from
164 * process position */
165 guint pid_out, pid_in;
166 LttvProcessState *process_out, *process_in;
167 LttTime birth;
168 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
169
170 ProcessList *process_list =
14963be0 171 guicontrolflow_get_process_list(event_request->control_flow_data);
a56a1ba4 172
173
174 LttField *f = ltt_event_field(e);
175 LttField *element;
176 element = ltt_field_member(f,0);
177 pid_out = ltt_event_get_long_unsigned(e,element);
178 element = ltt_field_member(f,1);
179 pid_in = ltt_event_get_long_unsigned(e,element);
180 g_critical("out : %u in : %u", pid_out, pid_in);
181
182
183 /* Find process pid_out in the list... */
184 process_out = lttv_state_find_process(tfs, pid_out);
185 g_critical("out : %s",g_quark_to_string(process_out->state->s));
186
187 birth = process_out->creation_time;
188 gchar *name = strdup(g_quark_to_string(process_out->name));
14963be0 189 HashedProcessData *hashed_process_data_out = NULL;
a56a1ba4 190
191 if(processlist_get_process_pixels(process_list,
192 pid_out,
193 &birth,
194 &y_out,
195 &height,
14963be0 196 &hashed_process_data_out) == 1)
a56a1ba4 197 {
198 /* Process not present */
199 processlist_add(process_list,
200 pid_out,
201 &birth,
202 name,
203 &pl_height,
14963be0 204 &hashed_process_data_out);
a56a1ba4 205 processlist_get_process_pixels(process_list,
206 pid_out,
207 &birth,
208 &y_out,
209 &height,
14963be0 210 &hashed_process_data_out);
501d5405 211 drawing_insert_square( event_request->control_flow_data->drawing, y_out, height);
a56a1ba4 212 }
213
214 g_free(name);
215
216 /* Find process pid_in in the list... */
217 process_in = lttv_state_find_process(tfs, pid_in);
218 g_critical("in : %s",g_quark_to_string(process_in->state->s));
219
220 birth = process_in->creation_time;
221 name = strdup(g_quark_to_string(process_in->name));
14963be0 222 HashedProcessData *hashed_process_data_in = NULL;
a56a1ba4 223
224 if(processlist_get_process_pixels(process_list,
225 pid_in,
226 &birth,
227 &y_in,
228 &height,
14963be0 229 &hashed_process_data_in) == 1)
a56a1ba4 230 {
231 /* Process not present */
232 processlist_add(process_list,
233 pid_in,
234 &birth,
235 name,
236 &pl_height,
14963be0 237 &hashed_process_data_in);
a56a1ba4 238 processlist_get_process_pixels(process_list,
239 pid_in,
240 &birth,
241 &y_in,
242 &height,
14963be0 243 &hashed_process_data_in);
a56a1ba4 244
501d5405 245 drawing_insert_square( event_request->control_flow_data->drawing, y_in, height);
a56a1ba4 246 }
247 g_free(name);
248
249
250 /* Find pixels corresponding to time of the event. If the time does
251 * not fit in the window, show a warning, not supposed to happend. */
252 guint x = 0;
501d5405 253 guint width = control_flow_data->drawing->drawing_area->allocation.width;
a56a1ba4 254
255 LttTime time = ltt_event_time(e);
256
ba90bc77 257 LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width,
258 control_flow_data->time_window.start_time);
a56a1ba4 259
260
261 convert_time_to_pixels(
ba90bc77 262 control_flow_data->time_window.start_time,
a56a1ba4 263 window_end,
264 time,
265 width,
266 &x);
267
268 assert(x <= width);
269
270 /* draw what represents the event for outgoing process. */
271
14963be0 272 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
68997a22 273 draw_context_out->current->modify_over->x = x;
274 draw_context_out->current->modify_over->y = y_out;
501d5405 275 draw_context_out->drawable = control_flow_data->drawing->pixmap;
276 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
277 GtkWidget *widget = control_flow_data->drawing->drawing_area;
a56a1ba4 278 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
501d5405 279 draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 280 gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
281 //draw_context_out->gc = widget->style->black_gc;
282
283 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
501d5405 284 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
a56a1ba4 285
286 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
2df6f2bd 287 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 288 PropertiesText prop_text_out;
289 prop_text_out.foreground = &colorfg_out;
290 prop_text_out.background = &colorbg_out;
cfe526b1 291 prop_text_out.size = 6;
a56a1ba4 292 prop_text_out.position = OVER;
293
cfe526b1 294 /* color of text : status of the process */
295 if(process_out->state->s == LTTV_STATE_UNNAMED)
296 {
297 prop_text_out.foreground->red = 0xffff;
298 prop_text_out.foreground->green = 0xffff;
299 prop_text_out.foreground->blue = 0xffff;
300 }
301 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
302 {
303 prop_text_out.foreground->red = 0x0fff;
304 prop_text_out.foreground->green = 0x0000;
305 prop_text_out.foreground->blue = 0x0fff;
306 }
307 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
308 {
2df6f2bd 309 prop_text_out.foreground->red = 0xffff;
310 prop_text_out.foreground->green = 0xffff;
cfe526b1 311 prop_text_out.foreground->blue = 0x0000;
312 }
313 else if(process_out->state->s == LTTV_STATE_EXIT)
314 {
315 prop_text_out.foreground->red = 0xffff;
316 prop_text_out.foreground->green = 0x0000;
317 prop_text_out.foreground->blue = 0xffff;
318 }
319 else if(process_out->state->s == LTTV_STATE_WAIT)
320 {
321 prop_text_out.foreground->red = 0xffff;
322 prop_text_out.foreground->green = 0x0000;
323 prop_text_out.foreground->blue = 0x0000;
324 }
325 else if(process_out->state->s == LTTV_STATE_RUN)
326 {
327 prop_text_out.foreground->red = 0x0000;
328 prop_text_out.foreground->green = 0xffff;
329 prop_text_out.foreground->blue = 0x0000;
330 }
331 else
332 {
333 prop_text_out.foreground->red = 0xffff;
334 prop_text_out.foreground->green = 0xffff;
335 prop_text_out.foreground->blue = 0xffff;
336 }
337
a56a1ba4 338 /* Print status of the process : U, WF, WC, E, W, R */
339 if(process_out->state->s == LTTV_STATE_UNNAMED)
cfe526b1 340 prop_text_out.text = "U->";
a56a1ba4 341 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
cfe526b1 342 prop_text_out.text = "WF->";
a56a1ba4 343 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
cfe526b1 344 prop_text_out.text = "WC->";
a56a1ba4 345 else if(process_out->state->s == LTTV_STATE_EXIT)
cfe526b1 346 prop_text_out.text = "E->";
a56a1ba4 347 else if(process_out->state->s == LTTV_STATE_WAIT)
cfe526b1 348 prop_text_out.text = "W->";
a56a1ba4 349 else if(process_out->state->s == LTTV_STATE_RUN)
cfe526b1 350 prop_text_out.text = "R->";
a56a1ba4 351 else
68997a22 352 prop_text_out.text = "U";
a56a1ba4 353
354 draw_text((void*)&prop_text_out, (void*)draw_context_out);
355 gdk_gc_unref(draw_context_out->gc);
356
357 /* Draw the line of the out process */
68997a22 358 if(draw_context_out->previous->middle->x == -1)
a56a1ba4 359 {
14963be0 360 draw_context_out->previous->middle->x = event_request->x_begin;
361 g_critical("out middle x_beg : %u",event_request->x_begin);
a56a1ba4 362 }
363
68997a22 364 draw_context_out->current->middle->x = x;
365 draw_context_out->current->middle->y = y_out + height/2;
366 draw_context_out->previous->middle->y = y_out + height/2;
501d5405 367 draw_context_out->drawable = control_flow_data->drawing->pixmap;
368 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
a56a1ba4 369 //draw_context_out->gc = widget->style->black_gc;
501d5405 370 draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 371 gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
372
373 PropertiesLine prop_line_out;
374 prop_line_out.color = g_new(GdkColor,1);
cfe526b1 375 prop_line_out.line_width = 2;
a56a1ba4 376 prop_line_out.style = GDK_LINE_SOLID;
377 prop_line_out.position = MIDDLE;
378
379 /* color of line : status of the process */
380 if(process_out->state->s == LTTV_STATE_UNNAMED)
381 {
cfe526b1 382 prop_line_out.color->red = 0xffff;
383 prop_line_out.color->green = 0xffff;
384 prop_line_out.color->blue = 0xffff;
a56a1ba4 385 }
386 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
387 {
388 prop_line_out.color->red = 0x0fff;
389 prop_line_out.color->green = 0x0000;
390 prop_line_out.color->blue = 0x0fff;
391 }
392 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
393 {
2df6f2bd 394 prop_line_out.color->red = 0xffff;
395 prop_line_out.color->green = 0xffff;
a56a1ba4 396 prop_line_out.color->blue = 0x0000;
397 }
398 else if(process_out->state->s == LTTV_STATE_EXIT)
399 {
400 prop_line_out.color->red = 0xffff;
401 prop_line_out.color->green = 0x0000;
402 prop_line_out.color->blue = 0xffff;
403 }
404 else if(process_out->state->s == LTTV_STATE_WAIT)
405 {
406 prop_line_out.color->red = 0xffff;
407 prop_line_out.color->green = 0x0000;
408 prop_line_out.color->blue = 0x0000;
409 }
410 else if(process_out->state->s == LTTV_STATE_RUN)
411 {
412 prop_line_out.color->red = 0x0000;
413 prop_line_out.color->green = 0xffff;
414 prop_line_out.color->blue = 0x0000;
415 }
416 else
417 {
cfe526b1 418 prop_line_out.color->red = 0xffff;
419 prop_line_out.color->green = 0xffff;
420 prop_line_out.color->blue = 0xffff;
a56a1ba4 421 }
422
423 draw_line((void*)&prop_line_out, (void*)draw_context_out);
424 g_free(prop_line_out.color);
425 gdk_gc_unref(draw_context_out->gc);
426 /* Note : finishing line will have to be added when trace read over. */
427
428 /* Finally, update the drawing context of the pid_in. */
429
14963be0 430 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
68997a22 431 draw_context_in->current->modify_over->x = x;
432 draw_context_in->current->modify_over->y = y_in;
501d5405 433 draw_context_in->drawable = control_flow_data->drawing->pixmap;
434 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
435 widget = control_flow_data->drawing->drawing_area;
a56a1ba4 436 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
437 //draw_context_in->gc = widget->style->black_gc;
501d5405 438 draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 439 gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
440
441 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
501d5405 442 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
a56a1ba4 443
444 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
2df6f2bd 445 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 446 PropertiesText prop_text_in;
447 prop_text_in.foreground = &colorfg_in;
448 prop_text_in.background = &colorbg_in;
cfe526b1 449 prop_text_in.size = 6;
a56a1ba4 450 prop_text_in.position = OVER;
451
cfe526b1 452 /* foreground of text : status of the process */
453 if(process_in->state->s == LTTV_STATE_UNNAMED)
454 {
455 prop_text_in.foreground->red = 0xffff;
456 prop_text_in.foreground->green = 0xffff;
457 prop_text_in.foreground->blue = 0xffff;
458 }
459 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
460 {
461 prop_text_in.foreground->red = 0x0fff;
462 prop_text_in.foreground->green = 0x0000;
463 prop_text_in.foreground->blue = 0x0fff;
464 }
465 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
466 {
2df6f2bd 467 prop_text_in.foreground->red = 0xffff;
468 prop_text_in.foreground->green = 0xffff;
cfe526b1 469 prop_text_in.foreground->blue = 0x0000;
470 }
471 else if(process_in->state->s == LTTV_STATE_EXIT)
472 {
473 prop_text_in.foreground->red = 0xffff;
474 prop_text_in.foreground->green = 0x0000;
475 prop_text_in.foreground->blue = 0xffff;
476 }
477 else if(process_in->state->s == LTTV_STATE_WAIT)
478 {
479 prop_text_in.foreground->red = 0xffff;
480 prop_text_in.foreground->green = 0x0000;
481 prop_text_in.foreground->blue = 0x0000;
482 }
483 else if(process_in->state->s == LTTV_STATE_RUN)
484 {
485 prop_text_in.foreground->red = 0x0000;
486 prop_text_in.foreground->green = 0xffff;
487 prop_text_in.foreground->blue = 0x0000;
488 }
489 else
490 {
491 prop_text_in.foreground->red = 0xffff;
492 prop_text_in.foreground->green = 0xffff;
493 prop_text_in.foreground->blue = 0xffff;
494 }
495
496
497
a56a1ba4 498 /* Print status of the process : U, WF, WC, E, W, R */
499 if(process_in->state->s == LTTV_STATE_UNNAMED)
cfe526b1 500 prop_text_in.text = "U->";
a56a1ba4 501 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
cfe526b1 502 prop_text_in.text = "WF->";
a56a1ba4 503 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
cfe526b1 504 prop_text_in.text = "WC->";
a56a1ba4 505 else if(process_in->state->s == LTTV_STATE_EXIT)
cfe526b1 506 prop_text_in.text = "E->";
a56a1ba4 507 else if(process_in->state->s == LTTV_STATE_WAIT)
cfe526b1 508 prop_text_in.text = "W->";
a56a1ba4 509 else if(process_in->state->s == LTTV_STATE_RUN)
cfe526b1 510 prop_text_in.text = "R->";
a56a1ba4 511 else
68997a22 512 prop_text_in.text = "U";
a56a1ba4 513
514 draw_text((void*)&prop_text_in, (void*)draw_context_in);
515 gdk_gc_unref(draw_context_in->gc);
516
517 /* Draw the line of the in process */
68997a22 518 if(draw_context_in->previous->middle->x == -1)
a56a1ba4 519 {
14963be0 520 draw_context_in->previous->middle->x = event_request->x_begin;
521 g_critical("in middle x_beg : %u",event_request->x_begin);
a56a1ba4 522 }
523
68997a22 524 draw_context_in->current->middle->x = x;
525 draw_context_in->previous->middle->y = y_in + height/2;
526 draw_context_in->current->middle->y = y_in + height/2;
501d5405 527 draw_context_in->drawable = control_flow_data->drawing->pixmap;
528 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
a56a1ba4 529 //draw_context_in->gc = widget->style->black_gc;
501d5405 530 draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 531 gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
532
533 PropertiesLine prop_line_in;
534 prop_line_in.color = g_new(GdkColor,1);
cfe526b1 535 prop_line_in.line_width = 2;
a56a1ba4 536 prop_line_in.style = GDK_LINE_SOLID;
537 prop_line_in.position = MIDDLE;
538
539 /* color of line : status of the process */
540 if(process_in->state->s == LTTV_STATE_UNNAMED)
541 {
cfe526b1 542 prop_line_in.color->red = 0xffff;
543 prop_line_in.color->green = 0xffff;
544 prop_line_in.color->blue = 0xffff;
a56a1ba4 545 }
546 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
547 {
548 prop_line_in.color->red = 0x0fff;
549 prop_line_in.color->green = 0x0000;
550 prop_line_in.color->blue = 0x0fff;
551 }
552 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
553 {
2df6f2bd 554 prop_line_in.color->red = 0xffff;
555 prop_line_in.color->green = 0xffff;
a56a1ba4 556 prop_line_in.color->blue = 0x0000;
557 }
558 else if(process_in->state->s == LTTV_STATE_EXIT)
559 {
560 prop_line_in.color->red = 0xffff;
561 prop_line_in.color->green = 0x0000;
562 prop_line_in.color->blue = 0xffff;
563 }
564 else if(process_in->state->s == LTTV_STATE_WAIT)
565 {
566 prop_line_in.color->red = 0xffff;
567 prop_line_in.color->green = 0x0000;
568 prop_line_in.color->blue = 0x0000;
569 }
570 else if(process_in->state->s == LTTV_STATE_RUN)
571 {
572 prop_line_in.color->red = 0x0000;
573 prop_line_in.color->green = 0xffff;
574 prop_line_in.color->blue = 0x0000;
575 }
576 else
577 {
cfe526b1 578 prop_line_in.color->red = 0xffff;
579 prop_line_in.color->green = 0xffff;
580 prop_line_in.color->blue = 0xffff;
a56a1ba4 581 }
582
583 draw_line((void*)&prop_line_in, (void*)draw_context_in);
584 g_free(prop_line_in.color);
585 gdk_gc_unref(draw_context_in->gc);
586 }
587
588 return 0;
589
590 /* Temp dump */
80a52ff8 591#ifdef DONTSHOW
a56a1ba4 592 GString *string = g_string_new("");;
593 gboolean field_names = TRUE, state = TRUE;
80a52ff8 594
e9a9c513 595 lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
596 g_string_append_printf(string,"\n");
597
598 if(state) {
599 g_string_append_printf(string, " %s",
600 g_quark_to_string(tfs->process->state->s));
601 }
602
603 g_info("%s",string->str);
604
a56a1ba4 605 g_string_free(string, TRUE);
606
607 /* End of text dump */
80a52ff8 608#endif //DONTSHOW
50439712 609
f0d936c0 610}
611
612
4c69e0cc 613int draw_after_hook(void *hook_data, void *call_data)
f0d936c0 614{
14963be0 615 EventRequest *event_request = (EventRequest*)hook_data;
616 ControlFlowData *control_flow_data = event_request->control_flow_data;
50439712 617
a56a1ba4 618 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
50439712 619
620 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
621
a56a1ba4 622
50439712 623 LttEvent *e;
624 e = tfc->e;
625
a56a1ba4 626 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
627 {
628 g_critical("schedchange!");
629
630 /* Add process to process list (if not present) and get drawing "y" from
631 * process position */
632 guint pid_out, pid_in;
633 LttvProcessState *process_out, *process_in;
634 LttTime birth;
635 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
636
637 ProcessList *process_list =
14963be0 638 guicontrolflow_get_process_list(event_request->control_flow_data);
a56a1ba4 639
640
641 LttField *f = ltt_event_field(e);
642 LttField *element;
643 element = ltt_field_member(f,0);
644 pid_out = ltt_event_get_long_unsigned(e,element);
645 element = ltt_field_member(f,1);
646 pid_in = ltt_event_get_long_unsigned(e,element);
cfe526b1 647 //g_critical("out : %u in : %u", pid_out, pid_in);
a56a1ba4 648
649
650 /* Find process pid_out in the list... */
651 process_out = lttv_state_find_process(tfs, pid_out);
cfe526b1 652 //g_critical("out : %s",g_quark_to_string(process_out->state->s));
a56a1ba4 653
654 birth = process_out->creation_time;
655 gchar *name = strdup(g_quark_to_string(process_out->name));
14963be0 656 HashedProcessData *hashed_process_data_out = NULL;
a56a1ba4 657
658 if(processlist_get_process_pixels(process_list,
659 pid_out,
660 &birth,
661 &y_out,
662 &height,
14963be0 663 &hashed_process_data_out) == 1)
a56a1ba4 664 {
665 /* Process not present */
666 processlist_add(process_list,
667 pid_out,
668 &birth,
669 name,
670 &pl_height,
14963be0 671 &hashed_process_data_out);
a56a1ba4 672 processlist_get_process_pixels(process_list,
673 pid_out,
674 &birth,
675 &y_out,
676 &height,
14963be0 677 &hashed_process_data_out);
501d5405 678 drawing_insert_square( event_request->control_flow_data->drawing, y_out, height);
a56a1ba4 679 }
680
681 g_free(name);
682
683 /* Find process pid_in in the list... */
684 process_in = lttv_state_find_process(tfs, pid_in);
cfe526b1 685 //g_critical("in : %s",g_quark_to_string(process_in->state->s));
a56a1ba4 686
687 birth = process_in->creation_time;
688 name = strdup(g_quark_to_string(process_in->name));
14963be0 689 HashedProcessData *hashed_process_data_in = NULL;
a56a1ba4 690
691 if(processlist_get_process_pixels(process_list,
692 pid_in,
693 &birth,
694 &y_in,
695 &height,
14963be0 696 &hashed_process_data_in) == 1)
a56a1ba4 697 {
698 /* Process not present */
699 processlist_add(process_list,
700 pid_in,
701 &birth,
702 name,
703 &pl_height,
14963be0 704 &hashed_process_data_in);
a56a1ba4 705 processlist_get_process_pixels(process_list,
706 pid_in,
707 &birth,
708 &y_in,
709 &height,
14963be0 710 &hashed_process_data_in);
a56a1ba4 711
501d5405 712 drawing_insert_square( event_request->control_flow_data->drawing, y_in, height);
a56a1ba4 713 }
714 g_free(name);
715
716
717 /* Find pixels corresponding to time of the event. If the time does
718 * not fit in the window, show a warning, not supposed to happend. */
719 //guint x = 0;
501d5405 720 //guint width = control_flow_data->drawing->drawing_area->allocation.width;
a56a1ba4 721
722 //LttTime time = ltt_event_time(e);
723
ba90bc77 724 //LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width,
725 // control_flow_data->time_window.start_time);
a56a1ba4 726
727
728 //convert_time_to_pixels(
ba90bc77 729 // control_flow_data->time_window.start_time,
a56a1ba4 730 // window_end,
731 // time,
732 // width,
733 // &x);
734
735 //assert(x <= width);
736
737 /* draw what represents the event for outgoing process. */
738
14963be0 739 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
68997a22 740 //draw_context_out->current->modify_over->x = x;
741 draw_context_out->current->modify_over->y = y_out;
501d5405 742 draw_context_out->drawable = control_flow_data->drawing->pixmap;
743 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
744 GtkWidget *widget = control_flow_data->drawing->drawing_area;
a56a1ba4 745 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
746 draw_context_out->gc = widget->style->black_gc;
747
748 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
501d5405 749 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
a56a1ba4 750
751 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
2df6f2bd 752 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 753 PropertiesText prop_text_out;
754 prop_text_out.foreground = &colorfg_out;
755 prop_text_out.background = &colorbg_out;
cfe526b1 756 prop_text_out.size = 6;
a56a1ba4 757 prop_text_out.position = OVER;
758
cfe526b1 759 /* color of text : status of the process */
760 if(process_out->state->s == LTTV_STATE_UNNAMED)
761 {
762 prop_text_out.foreground->red = 0xffff;
763 prop_text_out.foreground->green = 0xffff;
764 prop_text_out.foreground->blue = 0xffff;
765 }
766 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
767 {
768 prop_text_out.foreground->red = 0x0fff;
769 prop_text_out.foreground->green = 0x0000;
770 prop_text_out.foreground->blue = 0x0fff;
771 }
772 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
773 {
2df6f2bd 774 prop_text_out.foreground->red = 0xffff;
775 prop_text_out.foreground->green = 0xffff;
cfe526b1 776 prop_text_out.foreground->blue = 0x0000;
777 }
778 else if(process_out->state->s == LTTV_STATE_EXIT)
779 {
780 prop_text_out.foreground->red = 0xffff;
781 prop_text_out.foreground->green = 0x0000;
782 prop_text_out.foreground->blue = 0xffff;
783 }
784 else if(process_out->state->s == LTTV_STATE_WAIT)
785 {
786 prop_text_out.foreground->red = 0xffff;
787 prop_text_out.foreground->green = 0x0000;
788 prop_text_out.foreground->blue = 0x0000;
789 }
790 else if(process_out->state->s == LTTV_STATE_RUN)
791 {
792 prop_text_out.foreground->red = 0x0000;
793 prop_text_out.foreground->green = 0xffff;
794 prop_text_out.foreground->blue = 0x0000;
795 }
796 else
797 {
798 prop_text_out.foreground->red = 0xffff;
799 prop_text_out.foreground->green = 0xffff;
800 prop_text_out.foreground->blue = 0xffff;
801 }
802
a56a1ba4 803 /* Print status of the process : U, WF, WC, E, W, R */
804 if(process_out->state->s == LTTV_STATE_UNNAMED)
68997a22 805 prop_text_out.text = "U";
a56a1ba4 806 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
68997a22 807 prop_text_out.text = "WF";
a56a1ba4 808 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
68997a22 809 prop_text_out.text = "WC";
a56a1ba4 810 else if(process_out->state->s == LTTV_STATE_EXIT)
68997a22 811 prop_text_out.text = "E";
a56a1ba4 812 else if(process_out->state->s == LTTV_STATE_WAIT)
68997a22 813 prop_text_out.text = "W";
a56a1ba4 814 else if(process_out->state->s == LTTV_STATE_RUN)
68997a22 815 prop_text_out.text = "R";
a56a1ba4 816 else
68997a22 817 prop_text_out.text = "U";
a56a1ba4 818
819 draw_text((void*)&prop_text_out, (void*)draw_context_out);
820
68997a22 821 draw_context_out->current->middle->y = y_out+height/2;
822 draw_context_out->current->status = process_out->state->s;
a56a1ba4 823
68997a22 824 /* for pid_out : remove previous, Prev = current, new current (default) */
825 g_free(draw_context_out->previous->modify_under);
826 g_free(draw_context_out->previous->modify_middle);
827 g_free(draw_context_out->previous->modify_over);
828 g_free(draw_context_out->previous->under);
829 g_free(draw_context_out->previous->middle);
830 g_free(draw_context_out->previous->over);
831 g_free(draw_context_out->previous);
832
833 draw_context_out->previous = draw_context_out->current;
a56a1ba4 834
68997a22 835 draw_context_out->current = g_new(DrawInfo,1);
836 draw_context_out->current->over = g_new(ItemInfo,1);
837 draw_context_out->current->over->x = -1;
838 draw_context_out->current->over->y = -1;
839 draw_context_out->current->middle = g_new(ItemInfo,1);
840 draw_context_out->current->middle->x = -1;
841 draw_context_out->current->middle->y = -1;
842 draw_context_out->current->under = g_new(ItemInfo,1);
843 draw_context_out->current->under->x = -1;
844 draw_context_out->current->under->y = -1;
845 draw_context_out->current->modify_over = g_new(ItemInfo,1);
846 draw_context_out->current->modify_over->x = -1;
847 draw_context_out->current->modify_over->y = -1;
848 draw_context_out->current->modify_middle = g_new(ItemInfo,1);
849 draw_context_out->current->modify_middle->x = -1;
850 draw_context_out->current->modify_middle->y = -1;
851 draw_context_out->current->modify_under = g_new(ItemInfo,1);
852 draw_context_out->current->modify_under->x = -1;
853 draw_context_out->current->modify_under->y = -1;
854 draw_context_out->current->status = LTTV_STATE_UNNAMED;
a56a1ba4 855
856 /* Finally, update the drawing context of the pid_in. */
857
14963be0 858 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
68997a22 859 //draw_context_in->current->modify_over->x = x;
860 draw_context_in->current->modify_over->y = y_in;
501d5405 861 draw_context_in->drawable = control_flow_data->drawing->pixmap;
862 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
863 widget = control_flow_data->drawing->drawing_area;
a56a1ba4 864 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
865 draw_context_in->gc = widget->style->black_gc;
866
867 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
501d5405 868 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
a56a1ba4 869
870 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
2df6f2bd 871 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 872 PropertiesText prop_text_in;
873 prop_text_in.foreground = &colorfg_in;
874 prop_text_in.background = &colorbg_in;
cfe526b1 875 prop_text_in.size = 6;
a56a1ba4 876 prop_text_in.position = OVER;
877
cfe526b1 878 /* foreground of text : status of the process */
879 if(process_in->state->s == LTTV_STATE_UNNAMED)
880 {
881 prop_text_in.foreground->red = 0xffff;
882 prop_text_in.foreground->green = 0xffff;
883 prop_text_in.foreground->blue = 0xffff;
884 }
885 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
886 {
887 prop_text_in.foreground->red = 0x0fff;
888 prop_text_in.foreground->green = 0x0000;
889 prop_text_in.foreground->blue = 0x0fff;
890 }
891 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
892 {
2df6f2bd 893 prop_text_in.foreground->red = 0xffff;
894 prop_text_in.foreground->green = 0xffff;
cfe526b1 895 prop_text_in.foreground->blue = 0x0000;
896 }
897 else if(process_in->state->s == LTTV_STATE_EXIT)
898 {
899 prop_text_in.foreground->red = 0xffff;
900 prop_text_in.foreground->green = 0x0000;
901 prop_text_in.foreground->blue = 0xffff;
902 }
903 else if(process_in->state->s == LTTV_STATE_WAIT)
904 {
905 prop_text_in.foreground->red = 0xffff;
906 prop_text_in.foreground->green = 0x0000;
907 prop_text_in.foreground->blue = 0x0000;
908 }
909 else if(process_in->state->s == LTTV_STATE_RUN)
910 {
911 prop_text_in.foreground->red = 0x0000;
912 prop_text_in.foreground->green = 0xffff;
913 prop_text_in.foreground->blue = 0x0000;
914 }
915 else
916 {
917 prop_text_in.foreground->red = 0xffff;
918 prop_text_in.foreground->green = 0xffff;
919 prop_text_in.foreground->blue = 0xffff;
920 }
921
922
a56a1ba4 923 /* Print status of the process : U, WF, WC, E, W, R */
924 if(process_in->state->s == LTTV_STATE_UNNAMED)
68997a22 925 prop_text_in.text = "U";
a56a1ba4 926 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
68997a22 927 prop_text_in.text = "WF";
a56a1ba4 928 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
68997a22 929 prop_text_in.text = "WC";
a56a1ba4 930 else if(process_in->state->s == LTTV_STATE_EXIT)
68997a22 931 prop_text_in.text = "E";
a56a1ba4 932 else if(process_in->state->s == LTTV_STATE_WAIT)
68997a22 933 prop_text_in.text = "W";
a56a1ba4 934 else if(process_in->state->s == LTTV_STATE_RUN)
68997a22 935 prop_text_in.text = "R";
a56a1ba4 936 else
68997a22 937 prop_text_in.text = "U";
a56a1ba4 938
939 draw_text((void*)&prop_text_in, (void*)draw_context_in);
940
68997a22 941 draw_context_in->current->middle->y = y_in+height/2;
942 draw_context_in->current->status = process_in->state->s;
943
944 /* for pid_in : remove previous, Prev = current, new current (default) */
945 g_free(draw_context_in->previous->modify_under);
946 g_free(draw_context_in->previous->modify_middle);
947 g_free(draw_context_in->previous->modify_over);
948 g_free(draw_context_in->previous->under);
949 g_free(draw_context_in->previous->middle);
950 g_free(draw_context_in->previous->over);
951 g_free(draw_context_in->previous);
952
953 draw_context_in->previous = draw_context_in->current;
a56a1ba4 954
68997a22 955 draw_context_in->current = g_new(DrawInfo,1);
956 draw_context_in->current->over = g_new(ItemInfo,1);
957 draw_context_in->current->over->x = -1;
958 draw_context_in->current->over->y = -1;
959 draw_context_in->current->middle = g_new(ItemInfo,1);
960 draw_context_in->current->middle->x = -1;
961 draw_context_in->current->middle->y = -1;
962 draw_context_in->current->under = g_new(ItemInfo,1);
963 draw_context_in->current->under->x = -1;
964 draw_context_in->current->under->y = -1;
965 draw_context_in->current->modify_over = g_new(ItemInfo,1);
966 draw_context_in->current->modify_over->x = -1;
967 draw_context_in->current->modify_over->y = -1;
968 draw_context_in->current->modify_middle = g_new(ItemInfo,1);
969 draw_context_in->current->modify_middle->x = -1;
970 draw_context_in->current->modify_middle->y = -1;
971 draw_context_in->current->modify_under = g_new(ItemInfo,1);
972 draw_context_in->current->modify_under->x = -1;
973 draw_context_in->current->modify_under->y = -1;
974 draw_context_in->current->status = LTTV_STATE_UNNAMED;
a56a1ba4 975
976 }
977
978 return 0;
f0d936c0 979}
f7afe191 980
981
982
983
1b238973 984gint update_time_window_hook(void *hook_data, void *call_data)
f7afe191 985{
a56a1ba4 986 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
14963be0 987 TimeWindow *old_time_window =
a56a1ba4 988 guicontrolflow_get_time_window(control_flow_data);
14963be0 989 TimeWindow *new_time_window = ((TimeWindow*)call_data);
a56a1ba4 990
991 /* Two cases : zoom in/out or scrolling */
992
993 /* In order to make sure we can reuse the old drawing, the scale must
994 * be the same and the new time interval being partly located in the
995 * currently shown time interval. (reuse is only for scrolling)
996 */
997
998 g_info("Old time window HOOK : %u, %u to %u, %u",
14963be0 999 old_time_window->start_time.tv_sec,
1000 old_time_window->start_time.tv_nsec,
1001 old_time_window->time_width.tv_sec,
1002 old_time_window->time_width.tv_nsec);
a56a1ba4 1003
1004 g_info("New time window HOOK : %u, %u to %u, %u",
14963be0 1005 new_time_window->start_time.tv_sec,
1006 new_time_window->start_time.tv_nsec,
1007 new_time_window->time_width.tv_sec,
1008 new_time_window->time_width.tv_nsec);
a56a1ba4 1009
14963be0 1010 if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec
1011 && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec)
a56a1ba4 1012 {
1013 /* Same scale (scrolling) */
1014 g_info("scrolling");
14963be0 1015 LttTime *ns = &new_time_window->start_time;
1016 LttTime *os = &old_time_window->start_time;
1017 LttTime old_end = ltt_time_add(old_time_window->start_time,
1018 old_time_window->time_width);
1019 LttTime new_end = ltt_time_add(new_time_window->start_time,
1020 new_time_window->time_width);
a56a1ba4 1021 //if(ns<os+w<ns+w)
1022 //if(ns<os+w && os+w<ns+w)
1023 //if(ns<old_end && os<ns)
1024 if(ltt_time_compare(*ns, old_end) == -1
1025 && ltt_time_compare(*os, *ns) == -1)
1026 {
1027 g_info("scrolling near right");
1028 /* Scroll right, keep right part of the screen */
1029 guint x = 0;
501d5405 1030 guint width = control_flow_data->drawing->drawing_area->allocation.width;
a56a1ba4 1031 convert_time_to_pixels(
1032 *os,
1033 old_end,
1034 *ns,
1035 width,
1036 &x);
1037
1038 /* Copy old data to new location */
501d5405 1039 gdk_draw_drawable (control_flow_data->drawing->pixmap,
cfe526b1 1040 control_flow_data->drawing->drawing_area->style->black_gc,
501d5405 1041 control_flow_data->drawing->pixmap,
a56a1ba4 1042 x, 0,
1043 0, 0,
1044 -1, -1);
1045
1046 convert_time_to_pixels(
1047 *ns,
1048 new_end,
1049 old_end,
1050 width,
1051 &x);
1052
14963be0 1053 *old_time_window = *new_time_window;
a56a1ba4 1054 /* Clear the data request background, but not SAFETY */
501d5405 1055 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 1056 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 1057 TRUE,
1058 x+SAFETY, 0,
501d5405 1059 control_flow_data->drawing->width - x, // do not overlap
1060 control_flow_data->drawing->height+SAFETY);
a56a1ba4 1061 /* Get new data for the rest. */
501d5405 1062 drawing_data_request(control_flow_data->drawing,
1063 &control_flow_data->drawing->pixmap,
a56a1ba4 1064 x, 0,
501d5405 1065 control_flow_data->drawing->width - x,
1066 control_flow_data->drawing->height);
a56a1ba4 1067
501d5405 1068 drawing_refresh(control_flow_data->drawing,
a56a1ba4 1069 0, 0,
501d5405 1070 control_flow_data->drawing->width,
1071 control_flow_data->drawing->height);
a56a1ba4 1072
1073
1074 } else {
1075 //if(ns<os<ns+w)
1076 //if(ns<os && os<ns+w)
1077 //if(ns<os && os<new_end)
1078 if(ltt_time_compare(*ns,*os) == -1
1079 && ltt_time_compare(*os,new_end) == -1)
1080 {
1081 g_info("scrolling near left");
1082 /* Scroll left, keep left part of the screen */
1083 guint x = 0;
501d5405 1084 guint width = control_flow_data->drawing->drawing_area->allocation.width;
a56a1ba4 1085 convert_time_to_pixels(
1086 *ns,
1087 new_end,
1088 *os,
1089 width,
1090 &x);
1091
1092 /* Copy old data to new location */
501d5405 1093 gdk_draw_drawable (control_flow_data->drawing->pixmap,
cfe526b1 1094 control_flow_data->drawing->drawing_area->style->black_gc,
501d5405 1095 control_flow_data->drawing->pixmap,
a56a1ba4 1096 0, 0,
1097 x, 0,
1098 -1, -1);
1099
14963be0 1100 *old_time_window = *new_time_window;
a56a1ba4 1101
1102 /* Clean the data request background */
501d5405 1103 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 1104 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 1105 TRUE,
1106 0, 0,
1107 x, // do not overlap
501d5405 1108 control_flow_data->drawing->height+SAFETY);
a56a1ba4 1109 /* Get new data for the rest. */
501d5405 1110 drawing_data_request(control_flow_data->drawing,
1111 &control_flow_data->drawing->pixmap,
a56a1ba4 1112 0, 0,
1113 x,
501d5405 1114 control_flow_data->drawing->height);
a56a1ba4 1115
501d5405 1116 drawing_refresh(control_flow_data->drawing,
a56a1ba4 1117 0, 0,
501d5405 1118 control_flow_data->drawing->width,
1119 control_flow_data->drawing->height);
a56a1ba4 1120
1121 } else {
1122 g_info("scrolling far");
1123 /* Cannot reuse any part of the screen : far jump */
14963be0 1124 *old_time_window = *new_time_window;
a56a1ba4 1125
1126
501d5405 1127 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 1128 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 1129 TRUE,
1130 0, 0,
501d5405 1131 control_flow_data->drawing->width+SAFETY, // do not overlap
1132 control_flow_data->drawing->height+SAFETY);
a56a1ba4 1133
501d5405 1134 drawing_data_request(control_flow_data->drawing,
1135 &control_flow_data->drawing->pixmap,
a56a1ba4 1136 0, 0,
501d5405 1137 control_flow_data->drawing->width,
1138 control_flow_data->drawing->height);
a56a1ba4 1139
501d5405 1140 drawing_refresh(control_flow_data->drawing,
a56a1ba4 1141 0, 0,
501d5405 1142 control_flow_data->drawing->width,
1143 control_flow_data->drawing->height);
a56a1ba4 1144 }
1145 }
1146 } else {
1147 /* Different scale (zoom) */
1148 g_info("zoom");
1149
14963be0 1150 *old_time_window = *new_time_window;
a56a1ba4 1151
501d5405 1152 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 1153 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 1154 TRUE,
1155 0, 0,
501d5405 1156 control_flow_data->drawing->width+SAFETY, // do not overlap
1157 control_flow_data->drawing->height+SAFETY);
a56a1ba4 1158
1159
501d5405 1160 drawing_data_request(control_flow_data->drawing,
1161 &control_flow_data->drawing->pixmap,
a56a1ba4 1162 0, 0,
501d5405 1163 control_flow_data->drawing->width,
1164 control_flow_data->drawing->height);
a56a1ba4 1165
501d5405 1166 drawing_refresh(control_flow_data->drawing,
a56a1ba4 1167 0, 0,
501d5405 1168 control_flow_data->drawing->width,
1169 control_flow_data->drawing->height);
a56a1ba4 1170 }
1171
1172 return 0;
f7afe191 1173}
1174
1b238973 1175gint update_current_time_hook(void *hook_data, void *call_data)
f7afe191 1176{
14963be0 1177 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
a56a1ba4 1178
1179 LttTime* current_time =
1180 guicontrolflow_get_current_time(control_flow_data);
1181 *current_time = *((LttTime*)call_data);
1182
1183 TimeWindow time_window;
1184
ba90bc77 1185 LttTime time_begin = control_flow_data->time_window.start_time;
1186 LttTime width = control_flow_data->time_window.time_width;
a56a1ba4 1187 LttTime half_width = ltt_time_div(width,2.0);
1188 LttTime time_end = ltt_time_add(time_begin, width);
1189
1190 LttvTracesetContext * tsc =
ba90bc77 1191 get_traceset_context(control_flow_data->mw);
a56a1ba4 1192
1193 LttTime trace_start = tsc->Time_Span->startTime;
1194 LttTime trace_end = tsc->Time_Span->endTime;
1195
68997a22 1196 g_info("New current time HOOK : %u, %u", current_time->tv_sec,
a56a1ba4 1197 current_time->tv_nsec);
1198
1199
1200
1201 /* If current time is inside time interval, just move the highlight
1202 * bar */
1203
1204 /* Else, we have to change the time interval. We have to tell it
1205 * to the main window. */
1206 /* The time interval change will take care of placing the current
1207 * time at the center of the visible area, or nearest possible if we are
1208 * at one end of the trace. */
1209
1210
1211 if(ltt_time_compare(*current_time, time_begin) == -1)
1212 {
1213 if(ltt_time_compare(*current_time,
1214 ltt_time_add(trace_start,half_width)) == -1)
1215 time_begin = trace_start;
1216 else
1217 time_begin = ltt_time_sub(*current_time,half_width);
1218
1219 time_window.start_time = time_begin;
1220 time_window.time_width = width;
1221
ba90bc77 1222 set_time_window(control_flow_data->mw, &time_window);
a56a1ba4 1223 }
1224 else if(ltt_time_compare(*current_time, time_end) == 1)
1225 {
1226 if(ltt_time_compare(*current_time, ltt_time_sub(trace_end, half_width)) == 1)
1227 time_begin = ltt_time_sub(trace_end,width);
1228 else
1229 time_begin = ltt_time_sub(*current_time,half_width);
1230
1231 time_window.start_time = time_begin;
1232 time_window.time_width = width;
1233
ba90bc77 1234 set_time_window(control_flow_data->mw, &time_window);
a56a1ba4 1235
1236 }
501d5405 1237 gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
a56a1ba4 1238
1239 return 0;
f7afe191 1240}
1241
8b90e648 1242typedef struct _ClosureData {
a56a1ba4 1243 EventRequest *event_request;
1244 LttvTraceState *ts;
8b90e648 1245} ClosureData;
a56a1ba4 1246
8b90e648 1247
1248void draw_closure(gpointer key, gpointer value, gpointer user_data)
1249{
a56a1ba4 1250 ProcessInfo *process_info = (ProcessInfo*)key;
1251 HashedProcessData *hashed_process_data = (HashedProcessData*)value;
1252 ClosureData *closure_data = (ClosureData*)user_data;
1253
1254 ControlFlowData *control_flow_data =
68997a22 1255 closure_data->event_request->control_flow_data;
a56a1ba4 1256
501d5405 1257 GtkWidget *widget = control_flow_data->drawing->drawing_area;
a56a1ba4 1258
1259 /* Get y position of process */
1260 gint y=0, height=0;
1261
ba90bc77 1262 processlist_get_pixels_from_data( control_flow_data->process_list,
a56a1ba4 1263 process_info,
1264 hashed_process_data,
1265 &y,
1266 &height);
1267 /* Get last state of process */
1268 LttvTraceContext *tc =
1269 (LttvTraceContext *)closure_data->ts;
8b90e648 1270
1271 LttvTraceState *ts = closure_data->ts;
a56a1ba4 1272 LttvProcessState *process;
1273
1274 process = lttv_state_find_process((LttvTracefileState*)ts, process_info->pid);
1275
1276 /* Draw the closing line */
1277 DrawContext *draw_context = hashed_process_data->draw_context;
68997a22 1278 if(draw_context->previous->middle->x == -1)
a56a1ba4 1279 {
68997a22 1280 draw_context->previous->middle->x = closure_data->event_request->x_begin;
a56a1ba4 1281 g_critical("out middle x_beg : %u",closure_data->event_request->x_begin);
1282 }
1283
68997a22 1284 draw_context->current->middle->x = closure_data->event_request->x_end;
1285 draw_context->current->middle->y = y + height/2;
1286 draw_context->previous->middle->y = y + height/2;
501d5405 1287 draw_context->drawable = control_flow_data->drawing->pixmap;
1288 draw_context->pango_layout = control_flow_data->drawing->pango_layout;
a56a1ba4 1289 //draw_context->gc = widget->style->black_gc;
501d5405 1290 draw_context->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 1291 gdk_gc_copy(draw_context->gc, widget->style->black_gc);
1292
1293 PropertiesLine prop_line;
1294 prop_line.color = g_new(GdkColor,1);
cfe526b1 1295 prop_line.line_width = 2;
a56a1ba4 1296 prop_line.style = GDK_LINE_SOLID;
1297 prop_line.position = MIDDLE;
1298
1299 /* color of line : status of the process */
1300 if(process->state->s == LTTV_STATE_UNNAMED)
1301 {
cfe526b1 1302 prop_line.color->red = 0xffff;
1303 prop_line.color->green = 0xffff;
1304 prop_line.color->blue = 0xffff;
a56a1ba4 1305 }
1306 else if(process->state->s == LTTV_STATE_WAIT_FORK)
1307 {
1308 prop_line.color->red = 0x0fff;
1309 prop_line.color->green = 0x0000;
1310 prop_line.color->blue = 0x0fff;
1311 }
1312 else if(process->state->s == LTTV_STATE_WAIT_CPU)
1313 {
2df6f2bd 1314 prop_line.color->red = 0xffff;
1315 prop_line.color->green = 0xffff;
a56a1ba4 1316 prop_line.color->blue = 0x0000;
1317 }
1318 else if(process->state->s == LTTV_STATE_EXIT)
1319 {
1320 prop_line.color->red = 0xffff;
1321 prop_line.color->green = 0x0000;
1322 prop_line.color->blue = 0xffff;
1323 }
1324 else if(process->state->s == LTTV_STATE_WAIT)
1325 {
1326 prop_line.color->red = 0xffff;
1327 prop_line.color->green = 0x0000;
1328 prop_line.color->blue = 0x0000;
1329 }
1330 else if(process->state->s == LTTV_STATE_RUN)
1331 {
1332 prop_line.color->red = 0x0000;
1333 prop_line.color->green = 0xffff;
1334 prop_line.color->blue = 0x0000;
1335 }
1336 else
1337 {
cfe526b1 1338 prop_line.color->red = 0xffff;
1339 prop_line.color->green = 0xffff;
1340 prop_line.color->blue = 0xffff;
a56a1ba4 1341 }
1342
1343 draw_line((void*)&prop_line, (void*)draw_context);
1344 g_free(prop_line.color);
1345 gdk_gc_unref(draw_context->gc);
1346
1347 /* Reset draw_context of the process for next request */
1348
1349 hashed_process_data->draw_context->drawable = NULL;
1350 hashed_process_data->draw_context->gc = NULL;
1351 hashed_process_data->draw_context->pango_layout = NULL;
68997a22 1352 hashed_process_data->draw_context->current->over->x = -1;
1353 hashed_process_data->draw_context->current->over->y = -1;
1354 hashed_process_data->draw_context->current->middle->x = -1;
1355 hashed_process_data->draw_context->current->middle->y = -1;
1356 hashed_process_data->draw_context->current->under->x = -1;
1357 hashed_process_data->draw_context->current->under->y = -1;
1358 hashed_process_data->draw_context->current->modify_over->x = -1;
1359 hashed_process_data->draw_context->current->modify_over->y = -1;
1360 hashed_process_data->draw_context->current->modify_middle->x = -1;
1361 hashed_process_data->draw_context->current->modify_middle->y = -1;
1362 hashed_process_data->draw_context->current->modify_under->x = -1;
1363 hashed_process_data->draw_context->current->modify_under->y = -1;
1364 hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED;
1365 hashed_process_data->draw_context->previous->over->x = -1;
1366 hashed_process_data->draw_context->previous->over->y = -1;
1367 hashed_process_data->draw_context->previous->middle->x = -1;
1368 hashed_process_data->draw_context->previous->middle->y = -1;
1369 hashed_process_data->draw_context->previous->under->x = -1;
1370 hashed_process_data->draw_context->previous->under->y = -1;
1371 hashed_process_data->draw_context->previous->modify_over->x = -1;
1372 hashed_process_data->draw_context->previous->modify_over->y = -1;
1373 hashed_process_data->draw_context->previous->modify_middle->x = -1;
1374 hashed_process_data->draw_context->previous->modify_middle->y = -1;
1375 hashed_process_data->draw_context->previous->modify_under->x = -1;
1376 hashed_process_data->draw_context->previous->modify_under->y = -1;
1377 hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED;
a56a1ba4 1378
8b90e648 1379
1380}
1381
1382/*
1383 * for each process
a56a1ba4 1384 * draw closing line
1385 * new default prev and current
8b90e648 1386 */
1387int after_data_request(void *hook_data, void *call_data)
1388{
14963be0 1389 EventRequest *event_request = (EventRequest*)hook_data;
1390 ControlFlowData *control_flow_data = event_request->control_flow_data;
a56a1ba4 1391
1392 ProcessList *process_list =
14963be0 1393 guicontrolflow_get_process_list(event_request->control_flow_data);
a56a1ba4 1394
1395 ClosureData closure_data;
1396 closure_data.event_request = (EventRequest*)hook_data;
1397 closure_data.ts = (LttvTraceState*)call_data;
1398
14963be0 1399 g_hash_table_foreach(process_list->process_hash, draw_closure,
a56a1ba4 1400 (void*)&closure_data);
1401
8b90e648 1402}
1403
This page took 0.127183 seconds and 4 git commands to generate.