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