use state seek closest, incomplete data ok
[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;
d52cfc84 307 prop_text_out.foreground->green = 0xffff;
308 prop_text_out.foreground->blue = 0xfff0;
cfe526b1 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
d52cfc84 341
a56a1ba4 342 /* Print status of the process : U, WF, WC, E, W, R */
343 if(process_out->state->s == LTTV_STATE_UNNAMED)
cfe526b1 344 prop_text_out.text = "U->";
a56a1ba4 345 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
cfe526b1 346 prop_text_out.text = "WF->";
a56a1ba4 347 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
cfe526b1 348 prop_text_out.text = "WC->";
a56a1ba4 349 else if(process_out->state->s == LTTV_STATE_EXIT)
cfe526b1 350 prop_text_out.text = "E->";
a56a1ba4 351 else if(process_out->state->s == LTTV_STATE_WAIT)
cfe526b1 352 prop_text_out.text = "W->";
a56a1ba4 353 else if(process_out->state->s == LTTV_STATE_RUN)
cfe526b1 354 prop_text_out.text = "R->";
a56a1ba4 355 else
68997a22 356 prop_text_out.text = "U";
a56a1ba4 357
358 draw_text((void*)&prop_text_out, (void*)draw_context_out);
359 gdk_gc_unref(draw_context_out->gc);
360
361 /* Draw the line of the out process */
68997a22 362 if(draw_context_out->previous->middle->x == -1)
a56a1ba4 363 {
14963be0 364 draw_context_out->previous->middle->x = event_request->x_begin;
365 g_critical("out middle x_beg : %u",event_request->x_begin);
a56a1ba4 366 }
367
68997a22 368 draw_context_out->current->middle->x = x;
369 draw_context_out->current->middle->y = y_out + height/2;
370 draw_context_out->previous->middle->y = y_out + height/2;
501d5405 371 draw_context_out->drawable = control_flow_data->drawing->pixmap;
372 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
a56a1ba4 373 //draw_context_out->gc = widget->style->black_gc;
501d5405 374 draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 375 gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
376
377 PropertiesLine prop_line_out;
378 prop_line_out.color = g_new(GdkColor,1);
cfe526b1 379 prop_line_out.line_width = 2;
a56a1ba4 380 prop_line_out.style = GDK_LINE_SOLID;
381 prop_line_out.position = MIDDLE;
d52cfc84 382
383 g_critical("out state : %s", g_quark_to_string(process_out->state->s));
a56a1ba4 384
385 /* color of line : status of the process */
386 if(process_out->state->s == LTTV_STATE_UNNAMED)
387 {
cfe526b1 388 prop_line_out.color->red = 0xffff;
389 prop_line_out.color->green = 0xffff;
390 prop_line_out.color->blue = 0xffff;
a56a1ba4 391 }
392 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
393 {
394 prop_line_out.color->red = 0x0fff;
d52cfc84 395 prop_line_out.color->green = 0xffff;
396 prop_line_out.color->blue = 0xfff0;
a56a1ba4 397 }
398 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
399 {
2df6f2bd 400 prop_line_out.color->red = 0xffff;
401 prop_line_out.color->green = 0xffff;
a56a1ba4 402 prop_line_out.color->blue = 0x0000;
403 }
404 else if(process_out->state->s == LTTV_STATE_EXIT)
405 {
406 prop_line_out.color->red = 0xffff;
407 prop_line_out.color->green = 0x0000;
408 prop_line_out.color->blue = 0xffff;
409 }
410 else if(process_out->state->s == LTTV_STATE_WAIT)
411 {
412 prop_line_out.color->red = 0xffff;
413 prop_line_out.color->green = 0x0000;
414 prop_line_out.color->blue = 0x0000;
415 }
416 else if(process_out->state->s == LTTV_STATE_RUN)
417 {
418 prop_line_out.color->red = 0x0000;
419 prop_line_out.color->green = 0xffff;
420 prop_line_out.color->blue = 0x0000;
421 }
422 else
423 {
cfe526b1 424 prop_line_out.color->red = 0xffff;
425 prop_line_out.color->green = 0xffff;
426 prop_line_out.color->blue = 0xffff;
a56a1ba4 427 }
428
429 draw_line((void*)&prop_line_out, (void*)draw_context_out);
430 g_free(prop_line_out.color);
431 gdk_gc_unref(draw_context_out->gc);
432 /* Note : finishing line will have to be added when trace read over. */
433
434 /* Finally, update the drawing context of the pid_in. */
435
14963be0 436 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
68997a22 437 draw_context_in->current->modify_over->x = x;
319e9d81 438 draw_context_in->current->modify_under->x = x;
68997a22 439 draw_context_in->current->modify_over->y = y_in;
319e9d81 440 draw_context_in->current->modify_under->y = y_in+(height/2)+2;
501d5405 441 draw_context_in->drawable = control_flow_data->drawing->pixmap;
442 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
443 widget = control_flow_data->drawing->drawing_area;
a56a1ba4 444 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
445 //draw_context_in->gc = widget->style->black_gc;
501d5405 446 draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 447 gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
448
449 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
501d5405 450 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
a56a1ba4 451
452 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
2df6f2bd 453 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 454 PropertiesText prop_text_in;
455 prop_text_in.foreground = &colorfg_in;
456 prop_text_in.background = &colorbg_in;
cfe526b1 457 prop_text_in.size = 6;
a56a1ba4 458 prop_text_in.position = OVER;
459
d52cfc84 460 g_critical("in state : %s", g_quark_to_string(process_in->state->s));
cfe526b1 461 /* foreground of text : status of the process */
462 if(process_in->state->s == LTTV_STATE_UNNAMED)
463 {
464 prop_text_in.foreground->red = 0xffff;
465 prop_text_in.foreground->green = 0xffff;
466 prop_text_in.foreground->blue = 0xffff;
467 }
468 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
469 {
470 prop_text_in.foreground->red = 0x0fff;
d52cfc84 471 prop_text_in.foreground->green = 0xffff;
472 prop_text_in.foreground->blue = 0xfff0;
cfe526b1 473 }
474 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
475 {
2df6f2bd 476 prop_text_in.foreground->red = 0xffff;
477 prop_text_in.foreground->green = 0xffff;
cfe526b1 478 prop_text_in.foreground->blue = 0x0000;
479 }
480 else if(process_in->state->s == LTTV_STATE_EXIT)
481 {
482 prop_text_in.foreground->red = 0xffff;
483 prop_text_in.foreground->green = 0x0000;
484 prop_text_in.foreground->blue = 0xffff;
485 }
486 else if(process_in->state->s == LTTV_STATE_WAIT)
487 {
488 prop_text_in.foreground->red = 0xffff;
489 prop_text_in.foreground->green = 0x0000;
490 prop_text_in.foreground->blue = 0x0000;
491 }
492 else if(process_in->state->s == LTTV_STATE_RUN)
493 {
494 prop_text_in.foreground->red = 0x0000;
495 prop_text_in.foreground->green = 0xffff;
496 prop_text_in.foreground->blue = 0x0000;
497 }
498 else
499 {
500 prop_text_in.foreground->red = 0xffff;
501 prop_text_in.foreground->green = 0xffff;
502 prop_text_in.foreground->blue = 0xffff;
503 }
504
505
506
a56a1ba4 507 /* Print status of the process : U, WF, WC, E, W, R */
508 if(process_in->state->s == LTTV_STATE_UNNAMED)
cfe526b1 509 prop_text_in.text = "U->";
a56a1ba4 510 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
cfe526b1 511 prop_text_in.text = "WF->";
a56a1ba4 512 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
cfe526b1 513 prop_text_in.text = "WC->";
a56a1ba4 514 else if(process_in->state->s == LTTV_STATE_EXIT)
cfe526b1 515 prop_text_in.text = "E->";
a56a1ba4 516 else if(process_in->state->s == LTTV_STATE_WAIT)
cfe526b1 517 prop_text_in.text = "W->";
a56a1ba4 518 else if(process_in->state->s == LTTV_STATE_RUN)
cfe526b1 519 prop_text_in.text = "R->";
a56a1ba4 520 else
68997a22 521 prop_text_in.text = "U";
a56a1ba4 522
523 draw_text((void*)&prop_text_in, (void*)draw_context_in);
524 gdk_gc_unref(draw_context_in->gc);
525
526 /* Draw the line of the in process */
68997a22 527 if(draw_context_in->previous->middle->x == -1)
a56a1ba4 528 {
14963be0 529 draw_context_in->previous->middle->x = event_request->x_begin;
530 g_critical("in middle x_beg : %u",event_request->x_begin);
a56a1ba4 531 }
532
68997a22 533 draw_context_in->current->middle->x = x;
534 draw_context_in->previous->middle->y = y_in + height/2;
535 draw_context_in->current->middle->y = y_in + height/2;
501d5405 536 draw_context_in->drawable = control_flow_data->drawing->pixmap;
537 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
a56a1ba4 538 //draw_context_in->gc = widget->style->black_gc;
501d5405 539 draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 540 gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
541
542 PropertiesLine prop_line_in;
543 prop_line_in.color = g_new(GdkColor,1);
cfe526b1 544 prop_line_in.line_width = 2;
a56a1ba4 545 prop_line_in.style = GDK_LINE_SOLID;
546 prop_line_in.position = MIDDLE;
547
548 /* color of line : status of the process */
549 if(process_in->state->s == LTTV_STATE_UNNAMED)
550 {
cfe526b1 551 prop_line_in.color->red = 0xffff;
552 prop_line_in.color->green = 0xffff;
553 prop_line_in.color->blue = 0xffff;
a56a1ba4 554 }
555 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
556 {
557 prop_line_in.color->red = 0x0fff;
d52cfc84 558 prop_line_in.color->green = 0xffff;
559 prop_line_in.color->blue = 0xfff0;
a56a1ba4 560 }
561 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
562 {
2df6f2bd 563 prop_line_in.color->red = 0xffff;
564 prop_line_in.color->green = 0xffff;
a56a1ba4 565 prop_line_in.color->blue = 0x0000;
566 }
567 else if(process_in->state->s == LTTV_STATE_EXIT)
568 {
569 prop_line_in.color->red = 0xffff;
570 prop_line_in.color->green = 0x0000;
571 prop_line_in.color->blue = 0xffff;
572 }
573 else if(process_in->state->s == LTTV_STATE_WAIT)
574 {
575 prop_line_in.color->red = 0xffff;
576 prop_line_in.color->green = 0x0000;
577 prop_line_in.color->blue = 0x0000;
578 }
579 else if(process_in->state->s == LTTV_STATE_RUN)
580 {
581 prop_line_in.color->red = 0x0000;
582 prop_line_in.color->green = 0xffff;
583 prop_line_in.color->blue = 0x0000;
584 }
585 else
586 {
cfe526b1 587 prop_line_in.color->red = 0xffff;
588 prop_line_in.color->green = 0xffff;
589 prop_line_in.color->blue = 0xffff;
a56a1ba4 590 }
591
592 draw_line((void*)&prop_line_in, (void*)draw_context_in);
593 g_free(prop_line_in.color);
594 gdk_gc_unref(draw_context_in->gc);
595 }
596
597 return 0;
598
599 /* Temp dump */
80a52ff8 600#ifdef DONTSHOW
a56a1ba4 601 GString *string = g_string_new("");;
602 gboolean field_names = TRUE, state = TRUE;
80a52ff8 603
e9a9c513 604 lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
605 g_string_append_printf(string,"\n");
606
607 if(state) {
608 g_string_append_printf(string, " %s",
609 g_quark_to_string(tfs->process->state->s));
610 }
611
612 g_info("%s",string->str);
613
a56a1ba4 614 g_string_free(string, TRUE);
615
616 /* End of text dump */
80a52ff8 617#endif //DONTSHOW
50439712 618
f0d936c0 619}
620
621
4c69e0cc 622int draw_after_hook(void *hook_data, void *call_data)
f0d936c0 623{
14963be0 624 EventRequest *event_request = (EventRequest*)hook_data;
625 ControlFlowData *control_flow_data = event_request->control_flow_data;
50439712 626
a56a1ba4 627 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
50439712 628
629 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
630
a56a1ba4 631
50439712 632 LttEvent *e;
633 e = tfc->e;
634
a56a1ba4 635 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
636 {
637 g_critical("schedchange!");
638
639 /* Add process to process list (if not present) and get drawing "y" from
640 * process position */
641 guint pid_out, pid_in;
642 LttvProcessState *process_out, *process_in;
643 LttTime birth;
644 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
645
646 ProcessList *process_list =
14963be0 647 guicontrolflow_get_process_list(event_request->control_flow_data);
a56a1ba4 648
649
650 LttField *f = ltt_event_field(e);
651 LttField *element;
652 element = ltt_field_member(f,0);
653 pid_out = ltt_event_get_long_unsigned(e,element);
654 element = ltt_field_member(f,1);
655 pid_in = ltt_event_get_long_unsigned(e,element);
cfe526b1 656 //g_critical("out : %u in : %u", pid_out, pid_in);
a56a1ba4 657
658
659 /* Find process pid_out in the list... */
660 process_out = lttv_state_find_process(tfs, pid_out);
cfe526b1 661 //g_critical("out : %s",g_quark_to_string(process_out->state->s));
a56a1ba4 662
663 birth = process_out->creation_time;
664 gchar *name = strdup(g_quark_to_string(process_out->name));
14963be0 665 HashedProcessData *hashed_process_data_out = NULL;
a56a1ba4 666
667 if(processlist_get_process_pixels(process_list,
668 pid_out,
669 &birth,
670 &y_out,
671 &height,
14963be0 672 &hashed_process_data_out) == 1)
a56a1ba4 673 {
674 /* Process not present */
675 processlist_add(process_list,
676 pid_out,
677 &birth,
678 name,
679 &pl_height,
14963be0 680 &hashed_process_data_out);
a56a1ba4 681 processlist_get_process_pixels(process_list,
682 pid_out,
683 &birth,
684 &y_out,
685 &height,
14963be0 686 &hashed_process_data_out);
501d5405 687 drawing_insert_square( event_request->control_flow_data->drawing, y_out, height);
a56a1ba4 688 }
689
690 g_free(name);
691
692 /* Find process pid_in in the list... */
693 process_in = lttv_state_find_process(tfs, pid_in);
cfe526b1 694 //g_critical("in : %s",g_quark_to_string(process_in->state->s));
a56a1ba4 695
696 birth = process_in->creation_time;
697 name = strdup(g_quark_to_string(process_in->name));
14963be0 698 HashedProcessData *hashed_process_data_in = NULL;
a56a1ba4 699
700 if(processlist_get_process_pixels(process_list,
701 pid_in,
702 &birth,
703 &y_in,
704 &height,
14963be0 705 &hashed_process_data_in) == 1)
a56a1ba4 706 {
707 /* Process not present */
708 processlist_add(process_list,
709 pid_in,
710 &birth,
711 name,
712 &pl_height,
14963be0 713 &hashed_process_data_in);
a56a1ba4 714 processlist_get_process_pixels(process_list,
715 pid_in,
716 &birth,
717 &y_in,
718 &height,
14963be0 719 &hashed_process_data_in);
a56a1ba4 720
501d5405 721 drawing_insert_square( event_request->control_flow_data->drawing, y_in, height);
a56a1ba4 722 }
723 g_free(name);
724
725
726 /* Find pixels corresponding to time of the event. If the time does
727 * not fit in the window, show a warning, not supposed to happend. */
728 //guint x = 0;
501d5405 729 //guint width = control_flow_data->drawing->drawing_area->allocation.width;
a56a1ba4 730
731 //LttTime time = ltt_event_time(e);
732
ba90bc77 733 //LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width,
734 // control_flow_data->time_window.start_time);
a56a1ba4 735
736
737 //convert_time_to_pixels(
ba90bc77 738 // control_flow_data->time_window.start_time,
a56a1ba4 739 // window_end,
740 // time,
741 // width,
742 // &x);
743
744 //assert(x <= width);
745
746 /* draw what represents the event for outgoing process. */
747
14963be0 748 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
68997a22 749 //draw_context_out->current->modify_over->x = x;
750 draw_context_out->current->modify_over->y = y_out;
319e9d81 751 draw_context_out->current->modify_under->y = y_out+(height/2)+2;
501d5405 752 draw_context_out->drawable = control_flow_data->drawing->pixmap;
753 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
754 GtkWidget *widget = control_flow_data->drawing->drawing_area;
a56a1ba4 755 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
756 draw_context_out->gc = widget->style->black_gc;
757
758 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
501d5405 759 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
a56a1ba4 760
761 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
2df6f2bd 762 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 763 PropertiesText prop_text_out;
764 prop_text_out.foreground = &colorfg_out;
765 prop_text_out.background = &colorbg_out;
cfe526b1 766 prop_text_out.size = 6;
a56a1ba4 767 prop_text_out.position = OVER;
768
cfe526b1 769 /* color of text : status of the process */
770 if(process_out->state->s == LTTV_STATE_UNNAMED)
771 {
772 prop_text_out.foreground->red = 0xffff;
773 prop_text_out.foreground->green = 0xffff;
774 prop_text_out.foreground->blue = 0xffff;
775 }
776 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
777 {
778 prop_text_out.foreground->red = 0x0fff;
d52cfc84 779 prop_text_out.foreground->green = 0xffff;
780 prop_text_out.foreground->blue = 0xfff0;
cfe526b1 781 }
782 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
783 {
2df6f2bd 784 prop_text_out.foreground->red = 0xffff;
785 prop_text_out.foreground->green = 0xffff;
cfe526b1 786 prop_text_out.foreground->blue = 0x0000;
787 }
788 else if(process_out->state->s == LTTV_STATE_EXIT)
789 {
790 prop_text_out.foreground->red = 0xffff;
791 prop_text_out.foreground->green = 0x0000;
792 prop_text_out.foreground->blue = 0xffff;
793 }
794 else if(process_out->state->s == LTTV_STATE_WAIT)
795 {
796 prop_text_out.foreground->red = 0xffff;
797 prop_text_out.foreground->green = 0x0000;
798 prop_text_out.foreground->blue = 0x0000;
799 }
800 else if(process_out->state->s == LTTV_STATE_RUN)
801 {
802 prop_text_out.foreground->red = 0x0000;
803 prop_text_out.foreground->green = 0xffff;
804 prop_text_out.foreground->blue = 0x0000;
805 }
806 else
807 {
808 prop_text_out.foreground->red = 0xffff;
809 prop_text_out.foreground->green = 0xffff;
810 prop_text_out.foreground->blue = 0xffff;
811 }
812
a56a1ba4 813 /* Print status of the process : U, WF, WC, E, W, R */
814 if(process_out->state->s == LTTV_STATE_UNNAMED)
68997a22 815 prop_text_out.text = "U";
a56a1ba4 816 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
68997a22 817 prop_text_out.text = "WF";
a56a1ba4 818 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
68997a22 819 prop_text_out.text = "WC";
a56a1ba4 820 else if(process_out->state->s == LTTV_STATE_EXIT)
68997a22 821 prop_text_out.text = "E";
a56a1ba4 822 else if(process_out->state->s == LTTV_STATE_WAIT)
68997a22 823 prop_text_out.text = "W";
a56a1ba4 824 else if(process_out->state->s == LTTV_STATE_RUN)
68997a22 825 prop_text_out.text = "R";
a56a1ba4 826 else
68997a22 827 prop_text_out.text = "U";
a56a1ba4 828
829 draw_text((void*)&prop_text_out, (void*)draw_context_out);
319e9d81 830
68997a22 831 draw_context_out->current->middle->y = y_out+height/2;
832 draw_context_out->current->status = process_out->state->s;
a56a1ba4 833
68997a22 834 /* for pid_out : remove previous, Prev = current, new current (default) */
835 g_free(draw_context_out->previous->modify_under);
836 g_free(draw_context_out->previous->modify_middle);
837 g_free(draw_context_out->previous->modify_over);
838 g_free(draw_context_out->previous->under);
839 g_free(draw_context_out->previous->middle);
840 g_free(draw_context_out->previous->over);
841 g_free(draw_context_out->previous);
842
843 draw_context_out->previous = draw_context_out->current;
a56a1ba4 844
68997a22 845 draw_context_out->current = g_new(DrawInfo,1);
846 draw_context_out->current->over = g_new(ItemInfo,1);
847 draw_context_out->current->over->x = -1;
848 draw_context_out->current->over->y = -1;
849 draw_context_out->current->middle = g_new(ItemInfo,1);
850 draw_context_out->current->middle->x = -1;
851 draw_context_out->current->middle->y = -1;
852 draw_context_out->current->under = g_new(ItemInfo,1);
853 draw_context_out->current->under->x = -1;
854 draw_context_out->current->under->y = -1;
855 draw_context_out->current->modify_over = g_new(ItemInfo,1);
856 draw_context_out->current->modify_over->x = -1;
857 draw_context_out->current->modify_over->y = -1;
858 draw_context_out->current->modify_middle = g_new(ItemInfo,1);
859 draw_context_out->current->modify_middle->x = -1;
860 draw_context_out->current->modify_middle->y = -1;
861 draw_context_out->current->modify_under = g_new(ItemInfo,1);
862 draw_context_out->current->modify_under->x = -1;
863 draw_context_out->current->modify_under->y = -1;
864 draw_context_out->current->status = LTTV_STATE_UNNAMED;
a56a1ba4 865
866 /* Finally, update the drawing context of the pid_in. */
867
14963be0 868 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
68997a22 869 //draw_context_in->current->modify_over->x = x;
870 draw_context_in->current->modify_over->y = y_in;
319e9d81 871 draw_context_in->current->modify_under->y = y_in+(height/2)+2;
501d5405 872 draw_context_in->drawable = control_flow_data->drawing->pixmap;
873 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
874 widget = control_flow_data->drawing->drawing_area;
a56a1ba4 875 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
876 draw_context_in->gc = widget->style->black_gc;
877
878 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
501d5405 879 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
a56a1ba4 880
881 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
2df6f2bd 882 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
a56a1ba4 883 PropertiesText prop_text_in;
884 prop_text_in.foreground = &colorfg_in;
885 prop_text_in.background = &colorbg_in;
cfe526b1 886 prop_text_in.size = 6;
a56a1ba4 887 prop_text_in.position = OVER;
888
cfe526b1 889 /* foreground of text : status of the process */
890 if(process_in->state->s == LTTV_STATE_UNNAMED)
891 {
892 prop_text_in.foreground->red = 0xffff;
893 prop_text_in.foreground->green = 0xffff;
894 prop_text_in.foreground->blue = 0xffff;
895 }
896 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
897 {
898 prop_text_in.foreground->red = 0x0fff;
d52cfc84 899 prop_text_in.foreground->green = 0xffff;
900 prop_text_in.foreground->blue = 0xfff0;
cfe526b1 901 }
902 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
903 {
2df6f2bd 904 prop_text_in.foreground->red = 0xffff;
905 prop_text_in.foreground->green = 0xffff;
cfe526b1 906 prop_text_in.foreground->blue = 0x0000;
907 }
908 else if(process_in->state->s == LTTV_STATE_EXIT)
909 {
910 prop_text_in.foreground->red = 0xffff;
911 prop_text_in.foreground->green = 0x0000;
912 prop_text_in.foreground->blue = 0xffff;
913 }
914 else if(process_in->state->s == LTTV_STATE_WAIT)
915 {
916 prop_text_in.foreground->red = 0xffff;
917 prop_text_in.foreground->green = 0x0000;
918 prop_text_in.foreground->blue = 0x0000;
919 }
920 else if(process_in->state->s == LTTV_STATE_RUN)
921 {
922 prop_text_in.foreground->red = 0x0000;
923 prop_text_in.foreground->green = 0xffff;
924 prop_text_in.foreground->blue = 0x0000;
925 }
926 else
927 {
928 prop_text_in.foreground->red = 0xffff;
929 prop_text_in.foreground->green = 0xffff;
930 prop_text_in.foreground->blue = 0xffff;
931 }
932
933
a56a1ba4 934 /* Print status of the process : U, WF, WC, E, W, R */
935 if(process_in->state->s == LTTV_STATE_UNNAMED)
68997a22 936 prop_text_in.text = "U";
a56a1ba4 937 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
68997a22 938 prop_text_in.text = "WF";
a56a1ba4 939 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
68997a22 940 prop_text_in.text = "WC";
a56a1ba4 941 else if(process_in->state->s == LTTV_STATE_EXIT)
68997a22 942 prop_text_in.text = "E";
a56a1ba4 943 else if(process_in->state->s == LTTV_STATE_WAIT)
68997a22 944 prop_text_in.text = "W";
a56a1ba4 945 else if(process_in->state->s == LTTV_STATE_RUN)
68997a22 946 prop_text_in.text = "R";
a56a1ba4 947 else
68997a22 948 prop_text_in.text = "U";
a56a1ba4 949
950 draw_text((void*)&prop_text_in, (void*)draw_context_in);
951
319e9d81 952 if(process_in->state->s == LTTV_STATE_RUN)
953 {
954 gchar tmp[255];
955 prop_text_in.foreground = &colorfg_in;
956 prop_text_in.background = &colorbg_in;
957 prop_text_in.foreground->red = 0xffff;
958 prop_text_in.foreground->green = 0xffff;
959 prop_text_in.foreground->blue = 0xffff;
960 prop_text_in.size = 6;
961 prop_text_in.position = UNDER;
962
963 prop_text_in.text = g_new(gchar, 260);
964 strcpy(prop_text_in.text, "CPU ");
965 snprintf(tmp, 255, "%u", tfc->index);
966 strcat(prop_text_in.text, tmp);
967
968 draw_text((void*)&prop_text_in, (void*)draw_context_in);
969 g_free(prop_text_in.text);
970 }
971
972
68997a22 973 draw_context_in->current->middle->y = y_in+height/2;
974 draw_context_in->current->status = process_in->state->s;
975
976 /* for pid_in : remove previous, Prev = current, new current (default) */
977 g_free(draw_context_in->previous->modify_under);
978 g_free(draw_context_in->previous->modify_middle);
979 g_free(draw_context_in->previous->modify_over);
980 g_free(draw_context_in->previous->under);
981 g_free(draw_context_in->previous->middle);
982 g_free(draw_context_in->previous->over);
983 g_free(draw_context_in->previous);
984
985 draw_context_in->previous = draw_context_in->current;
a56a1ba4 986
68997a22 987 draw_context_in->current = g_new(DrawInfo,1);
988 draw_context_in->current->over = g_new(ItemInfo,1);
989 draw_context_in->current->over->x = -1;
990 draw_context_in->current->over->y = -1;
991 draw_context_in->current->middle = g_new(ItemInfo,1);
992 draw_context_in->current->middle->x = -1;
993 draw_context_in->current->middle->y = -1;
994 draw_context_in->current->under = g_new(ItemInfo,1);
995 draw_context_in->current->under->x = -1;
996 draw_context_in->current->under->y = -1;
997 draw_context_in->current->modify_over = g_new(ItemInfo,1);
998 draw_context_in->current->modify_over->x = -1;
999 draw_context_in->current->modify_over->y = -1;
1000 draw_context_in->current->modify_middle = g_new(ItemInfo,1);
1001 draw_context_in->current->modify_middle->x = -1;
1002 draw_context_in->current->modify_middle->y = -1;
1003 draw_context_in->current->modify_under = g_new(ItemInfo,1);
1004 draw_context_in->current->modify_under->x = -1;
1005 draw_context_in->current->modify_under->y = -1;
1006 draw_context_in->current->status = LTTV_STATE_UNNAMED;
a56a1ba4 1007
1008 }
1009
1010 return 0;
f0d936c0 1011}
f7afe191 1012
1013
1014
1015
1b238973 1016gint update_time_window_hook(void *hook_data, void *call_data)
f7afe191 1017{
a56a1ba4 1018 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
14963be0 1019 TimeWindow *old_time_window =
a56a1ba4 1020 guicontrolflow_get_time_window(control_flow_data);
14963be0 1021 TimeWindow *new_time_window = ((TimeWindow*)call_data);
a56a1ba4 1022
3cb8b205 1023 /* Update the ruler */
1024 drawing_update_ruler(control_flow_data->drawing,
1025 new_time_window);
1026
1027
a56a1ba4 1028 /* Two cases : zoom in/out or scrolling */
1029
1030 /* In order to make sure we can reuse the old drawing, the scale must
1031 * be the same and the new time interval being partly located in the
1032 * currently shown time interval. (reuse is only for scrolling)
1033 */
1034
1035 g_info("Old time window HOOK : %u, %u to %u, %u",
14963be0 1036 old_time_window->start_time.tv_sec,
1037 old_time_window->start_time.tv_nsec,
1038 old_time_window->time_width.tv_sec,
1039 old_time_window->time_width.tv_nsec);
a56a1ba4 1040
1041 g_info("New time window HOOK : %u, %u to %u, %u",
14963be0 1042 new_time_window->start_time.tv_sec,
1043 new_time_window->start_time.tv_nsec,
1044 new_time_window->time_width.tv_sec,
1045 new_time_window->time_width.tv_nsec);
a56a1ba4 1046
14963be0 1047 if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec
1048 && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec)
a56a1ba4 1049 {
1050 /* Same scale (scrolling) */
1051 g_info("scrolling");
14963be0 1052 LttTime *ns = &new_time_window->start_time;
1053 LttTime *os = &old_time_window->start_time;
1054 LttTime old_end = ltt_time_add(old_time_window->start_time,
1055 old_time_window->time_width);
1056 LttTime new_end = ltt_time_add(new_time_window->start_time,
1057 new_time_window->time_width);
a56a1ba4 1058 //if(ns<os+w<ns+w)
1059 //if(ns<os+w && os+w<ns+w)
1060 //if(ns<old_end && os<ns)
1061 if(ltt_time_compare(*ns, old_end) == -1
1062 && ltt_time_compare(*os, *ns) == -1)
1063 {
1064 g_info("scrolling near right");
1065 /* Scroll right, keep right part of the screen */
1066 guint x = 0;
501d5405 1067 guint width = control_flow_data->drawing->drawing_area->allocation.width;
a56a1ba4 1068 convert_time_to_pixels(
1069 *os,
1070 old_end,
1071 *ns,
1072 width,
1073 &x);
1074
1075 /* Copy old data to new location */
501d5405 1076 gdk_draw_drawable (control_flow_data->drawing->pixmap,
cfe526b1 1077 control_flow_data->drawing->drawing_area->style->black_gc,
501d5405 1078 control_flow_data->drawing->pixmap,
a56a1ba4 1079 x, 0,
1080 0, 0,
1081 -1, -1);
1082
1083 convert_time_to_pixels(
1084 *ns,
1085 new_end,
1086 old_end,
1087 width,
1088 &x);
1089
14963be0 1090 *old_time_window = *new_time_window;
a56a1ba4 1091 /* Clear the data request background, but not SAFETY */
501d5405 1092 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 1093 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 1094 TRUE,
1095 x+SAFETY, 0,
501d5405 1096 control_flow_data->drawing->width - x, // do not overlap
1097 control_flow_data->drawing->height+SAFETY);
a56a1ba4 1098 /* Get new data for the rest. */
501d5405 1099 drawing_data_request(control_flow_data->drawing,
1100 &control_flow_data->drawing->pixmap,
a56a1ba4 1101 x, 0,
501d5405 1102 control_flow_data->drawing->width - x,
1103 control_flow_data->drawing->height);
a56a1ba4 1104
501d5405 1105 drawing_refresh(control_flow_data->drawing,
a56a1ba4 1106 0, 0,
501d5405 1107 control_flow_data->drawing->width,
1108 control_flow_data->drawing->height);
a56a1ba4 1109
1110
1111 } else {
1112 //if(ns<os<ns+w)
1113 //if(ns<os && os<ns+w)
1114 //if(ns<os && os<new_end)
1115 if(ltt_time_compare(*ns,*os) == -1
1116 && ltt_time_compare(*os,new_end) == -1)
1117 {
1118 g_info("scrolling near left");
1119 /* Scroll left, keep left part of the screen */
1120 guint x = 0;
501d5405 1121 guint width = control_flow_data->drawing->drawing_area->allocation.width;
a56a1ba4 1122 convert_time_to_pixels(
1123 *ns,
1124 new_end,
1125 *os,
1126 width,
1127 &x);
1128
1129 /* Copy old data to new location */
501d5405 1130 gdk_draw_drawable (control_flow_data->drawing->pixmap,
cfe526b1 1131 control_flow_data->drawing->drawing_area->style->black_gc,
501d5405 1132 control_flow_data->drawing->pixmap,
a56a1ba4 1133 0, 0,
1134 x, 0,
1135 -1, -1);
1136
14963be0 1137 *old_time_window = *new_time_window;
a56a1ba4 1138
1139 /* Clean the data request background */
501d5405 1140 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 1141 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 1142 TRUE,
1143 0, 0,
1144 x, // do not overlap
501d5405 1145 control_flow_data->drawing->height+SAFETY);
a56a1ba4 1146 /* Get new data for the rest. */
501d5405 1147 drawing_data_request(control_flow_data->drawing,
1148 &control_flow_data->drawing->pixmap,
a56a1ba4 1149 0, 0,
1150 x,
501d5405 1151 control_flow_data->drawing->height);
a56a1ba4 1152
501d5405 1153 drawing_refresh(control_flow_data->drawing,
a56a1ba4 1154 0, 0,
501d5405 1155 control_flow_data->drawing->width,
1156 control_flow_data->drawing->height);
a56a1ba4 1157
1158 } else {
1159 g_info("scrolling far");
1160 /* Cannot reuse any part of the screen : far jump */
14963be0 1161 *old_time_window = *new_time_window;
a56a1ba4 1162
1163
501d5405 1164 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 1165 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 1166 TRUE,
1167 0, 0,
501d5405 1168 control_flow_data->drawing->width+SAFETY, // do not overlap
1169 control_flow_data->drawing->height+SAFETY);
a56a1ba4 1170
501d5405 1171 drawing_data_request(control_flow_data->drawing,
1172 &control_flow_data->drawing->pixmap,
a56a1ba4 1173 0, 0,
501d5405 1174 control_flow_data->drawing->width,
1175 control_flow_data->drawing->height);
a56a1ba4 1176
501d5405 1177 drawing_refresh(control_flow_data->drawing,
a56a1ba4 1178 0, 0,
501d5405 1179 control_flow_data->drawing->width,
1180 control_flow_data->drawing->height);
a56a1ba4 1181 }
1182 }
1183 } else {
1184 /* Different scale (zoom) */
1185 g_info("zoom");
1186
14963be0 1187 *old_time_window = *new_time_window;
a56a1ba4 1188
501d5405 1189 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
cfe526b1 1190 control_flow_data->drawing->drawing_area->style->black_gc,
a56a1ba4 1191 TRUE,
1192 0, 0,
501d5405 1193 control_flow_data->drawing->width+SAFETY, // do not overlap
1194 control_flow_data->drawing->height+SAFETY);
a56a1ba4 1195
1196
501d5405 1197 drawing_data_request(control_flow_data->drawing,
1198 &control_flow_data->drawing->pixmap,
a56a1ba4 1199 0, 0,
501d5405 1200 control_flow_data->drawing->width,
1201 control_flow_data->drawing->height);
a56a1ba4 1202
501d5405 1203 drawing_refresh(control_flow_data->drawing,
a56a1ba4 1204 0, 0,
501d5405 1205 control_flow_data->drawing->width,
1206 control_flow_data->drawing->height);
a56a1ba4 1207 }
1208
3cb8b205 1209
1210
a56a1ba4 1211 return 0;
f7afe191 1212}
1213
1b238973 1214gint update_current_time_hook(void *hook_data, void *call_data)
f7afe191 1215{
14963be0 1216 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
a56a1ba4 1217
1218 LttTime* current_time =
1219 guicontrolflow_get_current_time(control_flow_data);
1220 *current_time = *((LttTime*)call_data);
1221
1222 TimeWindow time_window;
1223
ba90bc77 1224 LttTime time_begin = control_flow_data->time_window.start_time;
1225 LttTime width = control_flow_data->time_window.time_width;
a56a1ba4 1226 LttTime half_width = ltt_time_div(width,2.0);
1227 LttTime time_end = ltt_time_add(time_begin, width);
1228
1229 LttvTracesetContext * tsc =
ba90bc77 1230 get_traceset_context(control_flow_data->mw);
a56a1ba4 1231
1232 LttTime trace_start = tsc->Time_Span->startTime;
1233 LttTime trace_end = tsc->Time_Span->endTime;
1234
68997a22 1235 g_info("New current time HOOK : %u, %u", current_time->tv_sec,
a56a1ba4 1236 current_time->tv_nsec);
1237
1238
1239
1240 /* If current time is inside time interval, just move the highlight
1241 * bar */
1242
1243 /* Else, we have to change the time interval. We have to tell it
1244 * to the main window. */
1245 /* The time interval change will take care of placing the current
1246 * time at the center of the visible area, or nearest possible if we are
1247 * at one end of the trace. */
1248
1249
1250 if(ltt_time_compare(*current_time, time_begin) == -1)
1251 {
1252 if(ltt_time_compare(*current_time,
1253 ltt_time_add(trace_start,half_width)) == -1)
1254 time_begin = trace_start;
1255 else
1256 time_begin = ltt_time_sub(*current_time,half_width);
1257
1258 time_window.start_time = time_begin;
1259 time_window.time_width = width;
1260
ba90bc77 1261 set_time_window(control_flow_data->mw, &time_window);
a56a1ba4 1262 }
1263 else if(ltt_time_compare(*current_time, time_end) == 1)
1264 {
1265 if(ltt_time_compare(*current_time, ltt_time_sub(trace_end, half_width)) == 1)
1266 time_begin = ltt_time_sub(trace_end,width);
1267 else
1268 time_begin = ltt_time_sub(*current_time,half_width);
1269
1270 time_window.start_time = time_begin;
1271 time_window.time_width = width;
1272
ba90bc77 1273 set_time_window(control_flow_data->mw, &time_window);
a56a1ba4 1274
1275 }
501d5405 1276 gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
a56a1ba4 1277
1278 return 0;
f7afe191 1279}
1280
8b90e648 1281typedef struct _ClosureData {
a56a1ba4 1282 EventRequest *event_request;
1283 LttvTraceState *ts;
8b90e648 1284} ClosureData;
a56a1ba4 1285
8b90e648 1286
1287void draw_closure(gpointer key, gpointer value, gpointer user_data)
1288{
a56a1ba4 1289 ProcessInfo *process_info = (ProcessInfo*)key;
1290 HashedProcessData *hashed_process_data = (HashedProcessData*)value;
1291 ClosureData *closure_data = (ClosureData*)user_data;
1292
1293 ControlFlowData *control_flow_data =
68997a22 1294 closure_data->event_request->control_flow_data;
a56a1ba4 1295
501d5405 1296 GtkWidget *widget = control_flow_data->drawing->drawing_area;
a56a1ba4 1297
1298 /* Get y position of process */
1299 gint y=0, height=0;
1300
ba90bc77 1301 processlist_get_pixels_from_data( control_flow_data->process_list,
a56a1ba4 1302 process_info,
1303 hashed_process_data,
1304 &y,
1305 &height);
1306 /* Get last state of process */
1307 LttvTraceContext *tc =
1308 (LttvTraceContext *)closure_data->ts;
8b90e648 1309
1310 LttvTraceState *ts = closure_data->ts;
a56a1ba4 1311 LttvProcessState *process;
1312
1313 process = lttv_state_find_process((LttvTracefileState*)ts, process_info->pid);
1314
1315 /* Draw the closing line */
1316 DrawContext *draw_context = hashed_process_data->draw_context;
68997a22 1317 if(draw_context->previous->middle->x == -1)
a56a1ba4 1318 {
68997a22 1319 draw_context->previous->middle->x = closure_data->event_request->x_begin;
a56a1ba4 1320 g_critical("out middle x_beg : %u",closure_data->event_request->x_begin);
1321 }
1322
68997a22 1323 draw_context->current->middle->x = closure_data->event_request->x_end;
1324 draw_context->current->middle->y = y + height/2;
1325 draw_context->previous->middle->y = y + height/2;
501d5405 1326 draw_context->drawable = control_flow_data->drawing->pixmap;
1327 draw_context->pango_layout = control_flow_data->drawing->pango_layout;
a56a1ba4 1328 //draw_context->gc = widget->style->black_gc;
501d5405 1329 draw_context->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
a56a1ba4 1330 gdk_gc_copy(draw_context->gc, widget->style->black_gc);
1331
1332 PropertiesLine prop_line;
1333 prop_line.color = g_new(GdkColor,1);
cfe526b1 1334 prop_line.line_width = 2;
a56a1ba4 1335 prop_line.style = GDK_LINE_SOLID;
1336 prop_line.position = MIDDLE;
1337
1338 /* color of line : status of the process */
1339 if(process->state->s == LTTV_STATE_UNNAMED)
1340 {
cfe526b1 1341 prop_line.color->red = 0xffff;
1342 prop_line.color->green = 0xffff;
1343 prop_line.color->blue = 0xffff;
a56a1ba4 1344 }
1345 else if(process->state->s == LTTV_STATE_WAIT_FORK)
1346 {
1347 prop_line.color->red = 0x0fff;
d52cfc84 1348 prop_line.color->green = 0xffff;
1349 prop_line.color->blue = 0xfff0;
a56a1ba4 1350 }
1351 else if(process->state->s == LTTV_STATE_WAIT_CPU)
1352 {
2df6f2bd 1353 prop_line.color->red = 0xffff;
1354 prop_line.color->green = 0xffff;
a56a1ba4 1355 prop_line.color->blue = 0x0000;
1356 }
1357 else if(process->state->s == LTTV_STATE_EXIT)
1358 {
1359 prop_line.color->red = 0xffff;
1360 prop_line.color->green = 0x0000;
1361 prop_line.color->blue = 0xffff;
1362 }
1363 else if(process->state->s == LTTV_STATE_WAIT)
1364 {
1365 prop_line.color->red = 0xffff;
1366 prop_line.color->green = 0x0000;
1367 prop_line.color->blue = 0x0000;
1368 }
1369 else if(process->state->s == LTTV_STATE_RUN)
1370 {
1371 prop_line.color->red = 0x0000;
1372 prop_line.color->green = 0xffff;
1373 prop_line.color->blue = 0x0000;
1374 }
1375 else
1376 {
cfe526b1 1377 prop_line.color->red = 0xffff;
1378 prop_line.color->green = 0xffff;
1379 prop_line.color->blue = 0xffff;
a56a1ba4 1380 }
1381
1382 draw_line((void*)&prop_line, (void*)draw_context);
1383 g_free(prop_line.color);
1384 gdk_gc_unref(draw_context->gc);
1385
1386 /* Reset draw_context of the process for next request */
1387
1388 hashed_process_data->draw_context->drawable = NULL;
1389 hashed_process_data->draw_context->gc = NULL;
1390 hashed_process_data->draw_context->pango_layout = NULL;
68997a22 1391 hashed_process_data->draw_context->current->over->x = -1;
1392 hashed_process_data->draw_context->current->over->y = -1;
1393 hashed_process_data->draw_context->current->middle->x = -1;
1394 hashed_process_data->draw_context->current->middle->y = -1;
1395 hashed_process_data->draw_context->current->under->x = -1;
1396 hashed_process_data->draw_context->current->under->y = -1;
1397 hashed_process_data->draw_context->current->modify_over->x = -1;
1398 hashed_process_data->draw_context->current->modify_over->y = -1;
1399 hashed_process_data->draw_context->current->modify_middle->x = -1;
1400 hashed_process_data->draw_context->current->modify_middle->y = -1;
1401 hashed_process_data->draw_context->current->modify_under->x = -1;
1402 hashed_process_data->draw_context->current->modify_under->y = -1;
1403 hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED;
1404 hashed_process_data->draw_context->previous->over->x = -1;
1405 hashed_process_data->draw_context->previous->over->y = -1;
1406 hashed_process_data->draw_context->previous->middle->x = -1;
1407 hashed_process_data->draw_context->previous->middle->y = -1;
1408 hashed_process_data->draw_context->previous->under->x = -1;
1409 hashed_process_data->draw_context->previous->under->y = -1;
1410 hashed_process_data->draw_context->previous->modify_over->x = -1;
1411 hashed_process_data->draw_context->previous->modify_over->y = -1;
1412 hashed_process_data->draw_context->previous->modify_middle->x = -1;
1413 hashed_process_data->draw_context->previous->modify_middle->y = -1;
1414 hashed_process_data->draw_context->previous->modify_under->x = -1;
1415 hashed_process_data->draw_context->previous->modify_under->y = -1;
1416 hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED;
a56a1ba4 1417
8b90e648 1418
1419}
1420
1421/*
1422 * for each process
a56a1ba4 1423 * draw closing line
1424 * new default prev and current
8b90e648 1425 */
1426int after_data_request(void *hook_data, void *call_data)
1427{
14963be0 1428 EventRequest *event_request = (EventRequest*)hook_data;
1429 ControlFlowData *control_flow_data = event_request->control_flow_data;
a56a1ba4 1430
1431 ProcessList *process_list =
14963be0 1432 guicontrolflow_get_process_list(event_request->control_flow_data);
a56a1ba4 1433
1434 ClosureData closure_data;
1435 closure_data.event_request = (EventRequest*)hook_data;
1436 closure_data.ts = (LttvTraceState*)call_data;
1437
14963be0 1438 g_hash_table_foreach(process_list->process_hash, draw_closure,
a56a1ba4 1439 (void*)&closure_data);
1440
8b90e648 1441}
1442
This page took 0.118984 seconds and 4 git commands to generate.