From: compudj Date: Thu, 29 Jan 2004 01:31:11 +0000 (+0000) Subject: file names mod part 2 X-Git-Tag: v0.12.20~3056 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d66666fecab8c35e69a2ee4eca1fb240057f1346;p=lttv.git file names mod part 2 git-svn-id: http://ltt.polymtl.ca/svn@433 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/Makefile.am b/ltt/branches/poly/lttv/modules/gui/ControlFlow/Makefile.am index 7ce36161..8e62355c 100644 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/Makefile.am +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/Makefile.am @@ -13,8 +13,8 @@ libdir = ${lttvplugindir} lib_LTLIBRARIES = libguiControlFlow.la libguiControlFlow_la_LDFLAGS = -module -libguiControlFlow_la_SOURCES = module.c Event_Hooks.c CFV.c Process_List.c\ - Drawing.c Draw_Item.c +libguiControlFlow_la_SOURCES = module.c eventhooks.c cfv.c processlist.c\ + drawing.c drawitem.c -noinst_HEADERS = Event_Hooks.h CFV.h Process_List.h\ - Drawing.h Draw_Item.h +noinst_HEADERS = eventhooks.h cfv.h cfv-private.h processlist.h\ + drawing.h drawitem.h diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/cfv.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/cfv.c index 18636ba0..94a4c08b 100644 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/cfv.c +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/cfv.c @@ -5,8 +5,8 @@ #include "cfv.h" #include "drawing.h" -#include "process-list.h" -#include "event-hooks.h" +#include "processlist.h" +#include "eventhooks.h" #include "cfv-private.h" diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/cfv.h b/ltt/branches/poly/lttv/modules/gui/ControlFlow/cfv.h index add1331a..6113453e 100644 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/cfv.h +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/cfv.h @@ -4,7 +4,7 @@ #include #include #include -#include "process-list.h" +#include "processlist.h" typedef struct _ControlFlowData ControlFlowData; diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/draw_item.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/draw_item.c deleted file mode 100644 index 7c929c82..00000000 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/draw_item.c +++ /dev/null @@ -1,345 +0,0 @@ -/****************************************************************************** - * Draw_Item.c - * - * This file contains methods responsible for drawing a generic type of data - * in a drawable. Doing this generically will permit user defined drawing - * behavior in a later time. - * - * This file provides an API which is meant to be reusable for all viewers that - * need to show information in line, icon, text, background or point form in - * a drawable area having time for x axis. The y axis, in the control flow - * viewer case, is corresponding to the different processes, but it can be - * reused integrally for cpu, and eventually locks, buffers, network - * interfaces... What will differ between the viewers is the precise - * information which interests us. We may think that the most useful - * information for control flow are some specific events, like schedule - * change, and processes'states. It may differ for a cpu viewer : the - * interesting information could be more the execution mode of each cpu. - * This API in meant to make viewer's writers life easier : it will become - * a simple choice of icons and line types for the precise information - * the viewer has to provide (agremented with keeping supplementary records - * and modifying slightly the DrawContext to suit the needs.) - * - * We keep each data type in attributes, keys to specific information - * being formed from the GQuark corresponding to the information received. - * (facilities / facility_name / events / eventname.) - * (cpus/cpu_name, process_states/ps_name, - * execution_modes/em_name, execution_submodes/es_name). - * The goal is then to provide a generic way to print information on the - * screen for all this different information. - * - * Information can be printed as - * - * - text (text + color + size + position (over or under line) - * - icon (icon filename, corresponding to a loaded icon, accessible through - * a GQuark. Icons are loaded statically at the guiControlFlow level during - * module initialization and can be added on the fly if not present in the - * GQuark.) The habitual place for xpm icons is in - * ${prefix}/share/LinuxTraceToolkit.) + position (over or under line) - * - line (color, width, style) - * - Arc (big points) (color, size) - * - background color (color) - * - * An item is a leaf of the attributes tree. It is, in that case, including - * all kind of events categories we can have. It then associates each category - * with one or more actions (drawing something) or nothing. - * - * Each item has an array of hooks (hook list). Each hook represents an - * operation to perform. We seek the array each time we want to - * draw an item. We execute each operation in order. An operation type - * is associated with each hook to permit user listing and modification - * of these operations. The operation type is also used to find the - * corresponding priority for the sorting. Operation type and priorities - * are enum and a static int table. - * - * The array has to be sorted by priority each time we add a task in it. - * A priority is associated with each operation type. It permits - * to perform background color selection before line or text drawing. We also - * draw lines before text, so the text appears over the lines. - * - * Executing all the arrays of operations for a specific event (which - * implies information for state, event, cpu, execution mode and submode) - * has to be done in a same DrawContext. The goal there is to keep the offset - * of the text and icons over and under the middle line, so a specific - * event could be printed as ( R Si 0 for running, scheduled in, cpu 0 ), - * text being easy to replace with icons. The DrawContext is passed as - * call_data for the operation hooks. - * - * We use the lttv global attributes to keep track of the loaded icons. - * If we need an icon, we look for it in the icons / icon name pathname. - * If found, we use the pointer to it. If not, we load the pixmap in - * memory and set the pointer to the GdkPixmap in the attributes. The - * structure pointed to contains the pixmap and the mask bitmap. - * - * Author : Mathieu Desnoyers, October 2003 - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "Draw_Item.h" - - -#define MAX_PATH_LEN 256 - -/* drawing hook functions */ -gboolean draw_text( void *hook_data, void *call_data) -{ - PropertiesText *Properties = (PropertiesText*)hook_data; - DrawContext *Draw_Context = (DrawContext*)call_data; - - PangoContext *context; - PangoLayout *layout; - PangoAttribute *attribute; - PangoFontDescription *FontDesc;// = pango_font_description_new(); - gint Font_Size; - PangoRectangle ink_rect; - - layout = Draw_Context->pango_layout; - - context = pango_layout_get_context(layout); - FontDesc = pango_context_get_font_description(context); - - pango_font_description_set_size(FontDesc, Properties->size*PANGO_SCALE); - pango_layout_context_changed(layout); - - pango_layout_set_text(layout, Properties->text, -1); - pango_layout_get_pixel_extents(layout, &ink_rect, NULL); - switch(Properties->position) { - case OVER: - gdk_draw_layout_with_colors(Draw_Context->drawable, - Draw_Context->gc, - Draw_Context->current->modify_over->x, - Draw_Context->current->modify_over->y, - layout, Properties->foreground, Properties->background); - Draw_Context->current->modify_over->x += ink_rect.width; - - break; - case MIDDLE: - gdk_draw_layout_with_colors(Draw_Context->drawable, - Draw_Context->gc, - Draw_Context->current->modify_middle->x, - Draw_Context->current->modify_middle->y, - layout, Properties->foreground, Properties->background); - Draw_Context->current->modify_middle->x += ink_rect.width; - break; - case UNDER: - gdk_draw_layout_with_colors(Draw_Context->drawable, - Draw_Context->gc, - Draw_Context->current->modify_under->x, - Draw_Context->current->modify_under->y, - layout, Properties->foreground, Properties->background); - Draw_Context->current->modify_under->x += ink_rect.width; - break; - } - - return 0; -} - - -/* To speed up the process, search in already loaded icons list first. Only - * load it if not present. - */ -gboolean draw_icon( void *hook_data, void *call_data) -{ - PropertiesIcon *Properties = (PropertiesIcon*)hook_data; - DrawContext *Draw_Context = (DrawContext*)call_data; - - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - LttvAttributeValue value; - gchar icon_name[MAX_PATH_LEN] = "icons/"; - IconStruct *icon_info; - - strcat(icon_name, Properties->icon_name); - - g_assert(lttv_iattribute_find_by_path(attributes, icon_name, - LTTV_POINTER, &value)); - if(*(value.v_pointer) == NULL) - { - *(value.v_pointer) = icon_info = g_new(IconStruct,1); - - icon_info->pixmap = gdk_pixmap_create_from_xpm(Draw_Context->drawable, - &icon_info->mask, NULL, Properties->icon_name); - } - else - { - icon_info = *(value.v_pointer); - } - - gdk_gc_set_clip_mask(Draw_Context->gc, icon_info->mask); - - switch(Properties->position) { - case OVER: - gdk_gc_set_clip_origin( - Draw_Context->gc, - Draw_Context->current->modify_over->x, - Draw_Context->current->modify_over->y); - gdk_draw_drawable(Draw_Context->drawable, - Draw_Context->gc, - icon_info->pixmap, - 0, 0, - Draw_Context->current->modify_over->x, - Draw_Context->current->modify_over->y, - Properties->width, Properties->height); - - Draw_Context->current->modify_over->x += Properties->width; - - break; - case MIDDLE: - gdk_gc_set_clip_origin( - Draw_Context->gc, - Draw_Context->current->modify_middle->x, - Draw_Context->current->modify_middle->y); - gdk_draw_drawable(Draw_Context->drawable, - Draw_Context->gc, - icon_info->pixmap, - 0, 0, - Draw_Context->current->modify_middle->x, - Draw_Context->current->modify_middle->y, - Properties->width, Properties->height); - - Draw_Context->current->modify_middle->x += Properties->width; - break; - case UNDER: - gdk_gc_set_clip_origin( - Draw_Context->gc, - Draw_Context->current->modify_under->x, - Draw_Context->current->modify_under->y); - gdk_draw_drawable(Draw_Context->drawable, - Draw_Context->gc, - icon_info->pixmap, - 0, 0, - Draw_Context->current->modify_under->x, - Draw_Context->current->modify_under->y, - Properties->width, Properties->height); - - Draw_Context->current->modify_under->x += Properties->width; - break; - } - - gdk_gc_set_clip_origin(Draw_Context->gc, 0, 0); - gdk_gc_set_clip_mask(Draw_Context->gc, NULL); - - return 0; -} - -gboolean draw_line( void *hook_data, void *call_data) -{ - PropertiesLine *Properties = (PropertiesLine*)hook_data; - DrawContext *Draw_Context = (DrawContext*)call_data; - //GdkGC *gc = gdk_gc_new(Draw_Context->drawable); - - //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); - gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); - //gdk_gc_set_foreground(gc, Properties->color); - gdk_gc_set_line_attributes( Draw_Context->gc, - Properties->line_width, - Properties->style, - GDK_CAP_BUTT, - GDK_JOIN_MITER); - - switch(Properties->position) { - case OVER: - drawing_draw_line( - NULL, Draw_Context->drawable, - Draw_Context->previous->over->x, - Draw_Context->previous->over->y, - Draw_Context->current->over->x, - Draw_Context->current->over->y, - Draw_Context->gc); - break; - case MIDDLE: - drawing_draw_line( - NULL, Draw_Context->drawable, - Draw_Context->previous->middle->x, - Draw_Context->previous->middle->y, - Draw_Context->current->middle->x, - Draw_Context->current->middle->y, - Draw_Context->gc); - break; - case UNDER: - drawing_draw_line( - NULL, Draw_Context->drawable, - Draw_Context->previous->under->x, - Draw_Context->previous->under->y, - Draw_Context->current->under->x, - Draw_Context->current->under->y, - Draw_Context->gc); - - break; - } - - //gdk_gc_unref(gc); - - return 0; -} - -gboolean draw_arc( void *hook_data, void *call_data) -{ - PropertiesArc *Properties = (PropertiesArc*)hook_data; - DrawContext *Draw_Context = (DrawContext*)call_data; - - //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); - gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); - - switch(Properties->position) { - case OVER: - gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, - Properties->filled, - Draw_Context->current->modify_over->x, - Draw_Context->current->modify_over->y, - Properties->size, Properties->size, 0, 360*64); - Draw_Context->current->modify_over->x += Properties->size; - break; - case MIDDLE: - gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, - Properties->filled, - Draw_Context->current->modify_middle->x, - Draw_Context->current->modify_middle->y, - Properties->size, Properties->size, 0, 360*64); - Draw_Context->current->modify_middle->x += Properties->size; - - break; - case UNDER: - gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, - Properties->filled, - Draw_Context->current->modify_under->x, - Draw_Context->current->modify_under->y, - Properties->size, Properties->size, 0, 360*64); - Draw_Context->current->modify_under->x += Properties->size; - - break; - } - - - return 0; -} - -gboolean draw_bg( void *hook_data, void *call_data) -{ - PropertiesBG *Properties = (PropertiesBG*)hook_data; - DrawContext *Draw_Context = (DrawContext*)call_data; - - //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); - gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); - - - gdk_draw_rectangle(Draw_Context->drawable, Draw_Context->gc, - TRUE, - Draw_Context->previous->over->x, - Draw_Context->previous->over->y, - Draw_Context->current->over->x - Draw_Context->previous->over->x, - Draw_Context->previous->under->y); - - return 0; -} - - diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/draw_item.h b/ltt/branches/poly/lttv/modules/gui/ControlFlow/draw_item.h deleted file mode 100644 index 9f342052..00000000 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/draw_item.h +++ /dev/null @@ -1,283 +0,0 @@ -#ifndef _DRAW_ITEM_H -#define _DRAW_ITEM_H - -#include - -typedef struct _DrawContext DrawContext; -typedef struct _DrawInfo DrawInfo; -typedef struct _ItemInfo ItemInfo; - -typedef struct _IconStruct IconStruct; - -typedef struct _DrawOperation DrawOperation; - - -typedef struct _PropertiesText PropertiesText; -typedef struct _PropertiesIcon PropertiesIcon; -typedef struct _PropertiesLine PropertiesLine; -typedef struct _PropertiesArc PropertiesArc; -typedef struct _PropertiesBG PropertiesBG; - -typedef enum _DrawableItems DrawableItems; -enum _DrawableItems { - ITEM_TEXT, ITEM_ICON, ITEM_LINE, ITEM_POINT, ITEM_BACKGROUND -}; - - -typedef enum _RelPos { - OVER, MIDDLE, UNDER -} RelPos; - - -/* The DrawContext keeps information about the current drawing position and - * the previous one, so we can use both to draw lines. - * - * over : position for drawing over the middle line. - * middle : middle line position. - * under : position for drawing under the middle line. - * - * the modify_* are used to take into account that we should go forward - * when we draw a text, an arc or an icon, while it's unneeded when we - * draw a line or background. - * - */ - - -struct _DrawContext { - GdkDrawable *drawable; - GdkGC *gc; - PangoLayout *pango_layout; - - DrawInfo *current; - DrawInfo *previous; -}; - -/* LttvExecutionState is accessible through the LttvTracefileState. Is has - * a pointer to the LttvProcessState which points to the top of stack - * execution state : LttvExecutionState *state. - * - * LttvExecutionState contains (useful here): - * LttvExecutionMode t, - * LttvExecutionSubmode n, - * LttvProcessStatus s - * - * - * LttvTraceState will be used in the case we need the string of the - * different processes, eventtype_names, syscall_names, trap_names, irq_names. - * - * LttvTracefileState also gives the cpu_name and, as it herits from - * LttvTracefileContext, it gives the LttEvent structure, which is needed - * to get facility name and event name. - */ -struct _DrawInfo { - ItemInfo *over; - ItemInfo *middle; - ItemInfo *under; - - ItemInfo *modify_over; - ItemInfo *modify_middle; - ItemInfo *modify_under; - LttvProcessStatus status; -}; - -struct _ItemInfo { - gint x, y; -}; - -/* - * Structure used to keep information about icons. - */ -struct _IconStruct { - GdkPixmap *pixmap; - GdkBitmap *mask; -}; - - -/* - * The Item element is only used so the DrawOperation is modifiable by users. - * During drawing, only the Hook is needed. - */ -struct _DrawOperation { - DrawableItems item; - LttvHooks *hook; -}; - -/* - * We define here each items that can be drawn, together with their - * associated priority. Many item types can have the same priority, - * it's only used for quicksorting the operations when we add a new one - * to the array of operations to perform. Lower priorities are executed - * first. So, for example, we may want to give background color a value - * of 10 while a line would have 20, so the background color, which - * is in fact a rectangle, does not hide the line. - */ - -static int Items_Priorities[] = { - 50, /* ITEM_TEXT */ - 40, /* ITEM_ICON */ - 20, /* ITEM_LINE */ - 30, /* ITEM_POINT */ - 10 /* ITEM_BACKGROUND */ -}; - -/* - * Here are the different structures describing each item type that can be - * drawn. They contain the information necessary to draw the item : not the - * position (this is provided by the DrawContext), but the text, icon name, - * line width, color; all the properties of the specific items. - */ - -struct _PropertiesText { - GdkColor *foreground; - GdkColor *background; - gint size; - gchar *text; - RelPos position; -}; - - -struct _PropertiesIcon { - gchar *icon_name; - gint width; - gint height; - RelPos position; -}; - -struct _PropertiesLine { - GdkColor *color; - gint line_width; - GdkLineStyle style; - RelPos position; -}; - -struct _PropertiesArc { - GdkColor *color; - gint size; /* We force circle by width = height */ - gboolean filled; - RelPos position; -}; - -struct _PropertiesBG { - GdkColor *color; -}; - - - -void draw_item( GdkDrawable *drawable, - gint x, - gint y, - LttvTraceState *ts, - LttvTracefileState *tfs, - LttvIAttribute *attributes); - -/* - * The tree of attributes used to store drawing operations goes like this : - * - * event_types/ - * "facility-event_type" - * cpus/ - * "cpu name" - * mode_types/ - * "execution mode"/ - * submodes/ - * "submode" - * process_states/ - * "state name" - * - * So if, for example, we want to add a hook to get called each time we - * receive an event that is in state LTTV_STATE_SYSCALL, we put the - * pointer to the GArray of DrawOperation in - * process_states/ "name associated with LTTV_STATE_SYSCALL" - */ - -/* - * The add_operation has to do a quick sort by priority to keep the operations - * in the right order. - */ -void add_operation( LttvIAttribute *attributes, - gchar *pathname, - DrawOperation *operation); - -/* - * The del_operation seeks the array present at pathname (if any) and - * removes the DrawOperation if present. It returns 0 on success, -1 - * if it fails. - */ -gint del_operation( LttvIAttribute *attributes, - gchar *pathname, - DrawOperation *operation); - -/* - * The clean_operations removes all operations present at a pathname. - * returns 0 on success, -1 if it fails. - */ -gint clean_operations( LttvIAttribute *attributes, - gchar *pathname ); - - -/* - * The list_operations gives a pointer to the operation array associated - * with the pathname. It will be NULL if no operation is present. - */ -void list_operations( LttvIAttribute *attributes, - gchar *pathname, - GArray **operation); - - - -/* - * exec_operation executes the operations if present in the attributes, or - * do nothing if not present. - */ -void exec_operations( LttvIAttribute *attributes, - gchar *pathname); - - -/* - * Functions to create Properties structures. - */ - -PropertiesText *properties_text_create( - GdkColor *foreground, - GdkColor *background, - gint size, - gchar *text, - RelPos position); - -PropertiesIcon *properties_icon_create( - gchar *icon_name, - gint width, - gint height, - RelPos position); - -PropertiesLine *properties_line_create( - GdkColor *color, - gint line_width, - GdkLineStyle style, - RelPos position); - -PropertiesArc *properties_arc_create( - GdkColor *color, - gint size, - gboolean filled, - RelPos position); - -PropertiesBG *properties_bg_create( - GdkColor *color); - - - - -/* - * Here follow the prototypes of the hook functions used to draw the - * different items. - */ - -gboolean draw_text( void *hook_data, void *call_data); -gboolean draw_icon( void *hook_data, void *call_data); -gboolean draw_line( void *hook_data, void *call_data); -gboolean draw_arc( void *hook_data, void *call_data); -gboolean draw_bg( void *hook_data, void *call_data); - - -#endif // _DRAW_ITEM_H diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawing.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawing.c index 85d2efcb..8ed214a3 100644 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawing.c +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawing.c @@ -6,10 +6,10 @@ #include #include -#include "Drawing.h" -#include "CFV.h" -#include "CFV-private.h" -#include "Event_Hooks.h" +#include "drawing.h" +#include "cfv.h" +#include "cfv-private.h" +#include "eventhooks.h" #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawing.h b/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawing.h index d4b6afd6..6ffc61a5 100644 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawing.h +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawing.h @@ -5,8 +5,8 @@ #include #include #include -#include "CFV.h" -#include "Draw_Item.h" +#include "cfv.h" +#include "drawitem.h" #define SAFETY 50 // safety pixels at right and bottom of pixmap buffer diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawitem.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawitem.c new file mode 100644 index 00000000..ef840f5a --- /dev/null +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawitem.c @@ -0,0 +1,345 @@ +/****************************************************************************** + * drawitem.c + * + * This file contains methods responsible for drawing a generic type of data + * in a drawable. Doing this generically will permit user defined drawing + * behavior in a later time. + * + * This file provides an API which is meant to be reusable for all viewers that + * need to show information in line, icon, text, background or point form in + * a drawable area having time for x axis. The y axis, in the control flow + * viewer case, is corresponding to the different processes, but it can be + * reused integrally for cpu, and eventually locks, buffers, network + * interfaces... What will differ between the viewers is the precise + * information which interests us. We may think that the most useful + * information for control flow are some specific events, like schedule + * change, and processes'states. It may differ for a cpu viewer : the + * interesting information could be more the execution mode of each cpu. + * This API in meant to make viewer's writers life easier : it will become + * a simple choice of icons and line types for the precise information + * the viewer has to provide (agremented with keeping supplementary records + * and modifying slightly the DrawContext to suit the needs.) + * + * We keep each data type in attributes, keys to specific information + * being formed from the GQuark corresponding to the information received. + * (facilities / facility_name / events / eventname.) + * (cpus/cpu_name, process_states/ps_name, + * execution_modes/em_name, execution_submodes/es_name). + * The goal is then to provide a generic way to print information on the + * screen for all this different information. + * + * Information can be printed as + * + * - text (text + color + size + position (over or under line) + * - icon (icon filename, corresponding to a loaded icon, accessible through + * a GQuark. Icons are loaded statically at the guiControlFlow level during + * module initialization and can be added on the fly if not present in the + * GQuark.) The habitual place for xpm icons is in + * ${prefix}/share/LinuxTraceToolkit.) + position (over or under line) + * - line (color, width, style) + * - Arc (big points) (color, size) + * - background color (color) + * + * An item is a leaf of the attributes tree. It is, in that case, including + * all kind of events categories we can have. It then associates each category + * with one or more actions (drawing something) or nothing. + * + * Each item has an array of hooks (hook list). Each hook represents an + * operation to perform. We seek the array each time we want to + * draw an item. We execute each operation in order. An operation type + * is associated with each hook to permit user listing and modification + * of these operations. The operation type is also used to find the + * corresponding priority for the sorting. Operation type and priorities + * are enum and a static int table. + * + * The array has to be sorted by priority each time we add a task in it. + * A priority is associated with each operation type. It permits + * to perform background color selection before line or text drawing. We also + * draw lines before text, so the text appears over the lines. + * + * Executing all the arrays of operations for a specific event (which + * implies information for state, event, cpu, execution mode and submode) + * has to be done in a same DrawContext. The goal there is to keep the offset + * of the text and icons over and under the middle line, so a specific + * event could be printed as ( R Si 0 for running, scheduled in, cpu 0 ), + * text being easy to replace with icons. The DrawContext is passed as + * call_data for the operation hooks. + * + * We use the lttv global attributes to keep track of the loaded icons. + * If we need an icon, we look for it in the icons / icon name pathname. + * If found, we use the pointer to it. If not, we load the pixmap in + * memory and set the pointer to the GdkPixmap in the attributes. The + * structure pointed to contains the pixmap and the mask bitmap. + * + * Author : Mathieu Desnoyers, October 2003 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "drawitem.h" + + +#define MAX_PATH_LEN 256 + +/* drawing hook functions */ +gboolean draw_text( void *hook_data, void *call_data) +{ + PropertiesText *Properties = (PropertiesText*)hook_data; + DrawContext *Draw_Context = (DrawContext*)call_data; + + PangoContext *context; + PangoLayout *layout; + PangoAttribute *attribute; + PangoFontDescription *FontDesc;// = pango_font_description_new(); + gint Font_Size; + PangoRectangle ink_rect; + + layout = Draw_Context->pango_layout; + + context = pango_layout_get_context(layout); + FontDesc = pango_context_get_font_description(context); + + pango_font_description_set_size(FontDesc, Properties->size*PANGO_SCALE); + pango_layout_context_changed(layout); + + pango_layout_set_text(layout, Properties->text, -1); + pango_layout_get_pixel_extents(layout, &ink_rect, NULL); + switch(Properties->position) { + case OVER: + gdk_draw_layout_with_colors(Draw_Context->drawable, + Draw_Context->gc, + Draw_Context->current->modify_over->x, + Draw_Context->current->modify_over->y, + layout, Properties->foreground, Properties->background); + Draw_Context->current->modify_over->x += ink_rect.width; + + break; + case MIDDLE: + gdk_draw_layout_with_colors(Draw_Context->drawable, + Draw_Context->gc, + Draw_Context->current->modify_middle->x, + Draw_Context->current->modify_middle->y, + layout, Properties->foreground, Properties->background); + Draw_Context->current->modify_middle->x += ink_rect.width; + break; + case UNDER: + gdk_draw_layout_with_colors(Draw_Context->drawable, + Draw_Context->gc, + Draw_Context->current->modify_under->x, + Draw_Context->current->modify_under->y, + layout, Properties->foreground, Properties->background); + Draw_Context->current->modify_under->x += ink_rect.width; + break; + } + + return 0; +} + + +/* To speed up the process, search in already loaded icons list first. Only + * load it if not present. + */ +gboolean draw_icon( void *hook_data, void *call_data) +{ + PropertiesIcon *Properties = (PropertiesIcon*)hook_data; + DrawContext *Draw_Context = (DrawContext*)call_data; + + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + LttvAttributeValue value; + gchar icon_name[MAX_PATH_LEN] = "icons/"; + IconStruct *icon_info; + + strcat(icon_name, Properties->icon_name); + + g_assert(lttv_iattribute_find_by_path(attributes, icon_name, + LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + { + *(value.v_pointer) = icon_info = g_new(IconStruct,1); + + icon_info->pixmap = gdk_pixmap_create_from_xpm(Draw_Context->drawable, + &icon_info->mask, NULL, Properties->icon_name); + } + else + { + icon_info = *(value.v_pointer); + } + + gdk_gc_set_clip_mask(Draw_Context->gc, icon_info->mask); + + switch(Properties->position) { + case OVER: + gdk_gc_set_clip_origin( + Draw_Context->gc, + Draw_Context->current->modify_over->x, + Draw_Context->current->modify_over->y); + gdk_draw_drawable(Draw_Context->drawable, + Draw_Context->gc, + icon_info->pixmap, + 0, 0, + Draw_Context->current->modify_over->x, + Draw_Context->current->modify_over->y, + Properties->width, Properties->height); + + Draw_Context->current->modify_over->x += Properties->width; + + break; + case MIDDLE: + gdk_gc_set_clip_origin( + Draw_Context->gc, + Draw_Context->current->modify_middle->x, + Draw_Context->current->modify_middle->y); + gdk_draw_drawable(Draw_Context->drawable, + Draw_Context->gc, + icon_info->pixmap, + 0, 0, + Draw_Context->current->modify_middle->x, + Draw_Context->current->modify_middle->y, + Properties->width, Properties->height); + + Draw_Context->current->modify_middle->x += Properties->width; + break; + case UNDER: + gdk_gc_set_clip_origin( + Draw_Context->gc, + Draw_Context->current->modify_under->x, + Draw_Context->current->modify_under->y); + gdk_draw_drawable(Draw_Context->drawable, + Draw_Context->gc, + icon_info->pixmap, + 0, 0, + Draw_Context->current->modify_under->x, + Draw_Context->current->modify_under->y, + Properties->width, Properties->height); + + Draw_Context->current->modify_under->x += Properties->width; + break; + } + + gdk_gc_set_clip_origin(Draw_Context->gc, 0, 0); + gdk_gc_set_clip_mask(Draw_Context->gc, NULL); + + return 0; +} + +gboolean draw_line( void *hook_data, void *call_data) +{ + PropertiesLine *Properties = (PropertiesLine*)hook_data; + DrawContext *Draw_Context = (DrawContext*)call_data; + //GdkGC *gc = gdk_gc_new(Draw_Context->drawable); + + //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); + gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); + //gdk_gc_set_foreground(gc, Properties->color); + gdk_gc_set_line_attributes( Draw_Context->gc, + Properties->line_width, + Properties->style, + GDK_CAP_BUTT, + GDK_JOIN_MITER); + + switch(Properties->position) { + case OVER: + drawing_draw_line( + NULL, Draw_Context->drawable, + Draw_Context->previous->over->x, + Draw_Context->previous->over->y, + Draw_Context->current->over->x, + Draw_Context->current->over->y, + Draw_Context->gc); + break; + case MIDDLE: + drawing_draw_line( + NULL, Draw_Context->drawable, + Draw_Context->previous->middle->x, + Draw_Context->previous->middle->y, + Draw_Context->current->middle->x, + Draw_Context->current->middle->y, + Draw_Context->gc); + break; + case UNDER: + drawing_draw_line( + NULL, Draw_Context->drawable, + Draw_Context->previous->under->x, + Draw_Context->previous->under->y, + Draw_Context->current->under->x, + Draw_Context->current->under->y, + Draw_Context->gc); + + break; + } + + //gdk_gc_unref(gc); + + return 0; +} + +gboolean draw_arc( void *hook_data, void *call_data) +{ + PropertiesArc *Properties = (PropertiesArc*)hook_data; + DrawContext *Draw_Context = (DrawContext*)call_data; + + //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); + gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); + + switch(Properties->position) { + case OVER: + gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, + Properties->filled, + Draw_Context->current->modify_over->x, + Draw_Context->current->modify_over->y, + Properties->size, Properties->size, 0, 360*64); + Draw_Context->current->modify_over->x += Properties->size; + break; + case MIDDLE: + gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, + Properties->filled, + Draw_Context->current->modify_middle->x, + Draw_Context->current->modify_middle->y, + Properties->size, Properties->size, 0, 360*64); + Draw_Context->current->modify_middle->x += Properties->size; + + break; + case UNDER: + gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, + Properties->filled, + Draw_Context->current->modify_under->x, + Draw_Context->current->modify_under->y, + Properties->size, Properties->size, 0, 360*64); + Draw_Context->current->modify_under->x += Properties->size; + + break; + } + + + return 0; +} + +gboolean draw_bg( void *hook_data, void *call_data) +{ + PropertiesBG *Properties = (PropertiesBG*)hook_data; + DrawContext *Draw_Context = (DrawContext*)call_data; + + //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); + gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); + + + gdk_draw_rectangle(Draw_Context->drawable, Draw_Context->gc, + TRUE, + Draw_Context->previous->over->x, + Draw_Context->previous->over->y, + Draw_Context->current->over->x - Draw_Context->previous->over->x, + Draw_Context->previous->under->y); + + return 0; +} + + diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawitem.h b/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawitem.h new file mode 100644 index 00000000..9f342052 --- /dev/null +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/drawitem.h @@ -0,0 +1,283 @@ +#ifndef _DRAW_ITEM_H +#define _DRAW_ITEM_H + +#include + +typedef struct _DrawContext DrawContext; +typedef struct _DrawInfo DrawInfo; +typedef struct _ItemInfo ItemInfo; + +typedef struct _IconStruct IconStruct; + +typedef struct _DrawOperation DrawOperation; + + +typedef struct _PropertiesText PropertiesText; +typedef struct _PropertiesIcon PropertiesIcon; +typedef struct _PropertiesLine PropertiesLine; +typedef struct _PropertiesArc PropertiesArc; +typedef struct _PropertiesBG PropertiesBG; + +typedef enum _DrawableItems DrawableItems; +enum _DrawableItems { + ITEM_TEXT, ITEM_ICON, ITEM_LINE, ITEM_POINT, ITEM_BACKGROUND +}; + + +typedef enum _RelPos { + OVER, MIDDLE, UNDER +} RelPos; + + +/* The DrawContext keeps information about the current drawing position and + * the previous one, so we can use both to draw lines. + * + * over : position for drawing over the middle line. + * middle : middle line position. + * under : position for drawing under the middle line. + * + * the modify_* are used to take into account that we should go forward + * when we draw a text, an arc or an icon, while it's unneeded when we + * draw a line or background. + * + */ + + +struct _DrawContext { + GdkDrawable *drawable; + GdkGC *gc; + PangoLayout *pango_layout; + + DrawInfo *current; + DrawInfo *previous; +}; + +/* LttvExecutionState is accessible through the LttvTracefileState. Is has + * a pointer to the LttvProcessState which points to the top of stack + * execution state : LttvExecutionState *state. + * + * LttvExecutionState contains (useful here): + * LttvExecutionMode t, + * LttvExecutionSubmode n, + * LttvProcessStatus s + * + * + * LttvTraceState will be used in the case we need the string of the + * different processes, eventtype_names, syscall_names, trap_names, irq_names. + * + * LttvTracefileState also gives the cpu_name and, as it herits from + * LttvTracefileContext, it gives the LttEvent structure, which is needed + * to get facility name and event name. + */ +struct _DrawInfo { + ItemInfo *over; + ItemInfo *middle; + ItemInfo *under; + + ItemInfo *modify_over; + ItemInfo *modify_middle; + ItemInfo *modify_under; + LttvProcessStatus status; +}; + +struct _ItemInfo { + gint x, y; +}; + +/* + * Structure used to keep information about icons. + */ +struct _IconStruct { + GdkPixmap *pixmap; + GdkBitmap *mask; +}; + + +/* + * The Item element is only used so the DrawOperation is modifiable by users. + * During drawing, only the Hook is needed. + */ +struct _DrawOperation { + DrawableItems item; + LttvHooks *hook; +}; + +/* + * We define here each items that can be drawn, together with their + * associated priority. Many item types can have the same priority, + * it's only used for quicksorting the operations when we add a new one + * to the array of operations to perform. Lower priorities are executed + * first. So, for example, we may want to give background color a value + * of 10 while a line would have 20, so the background color, which + * is in fact a rectangle, does not hide the line. + */ + +static int Items_Priorities[] = { + 50, /* ITEM_TEXT */ + 40, /* ITEM_ICON */ + 20, /* ITEM_LINE */ + 30, /* ITEM_POINT */ + 10 /* ITEM_BACKGROUND */ +}; + +/* + * Here are the different structures describing each item type that can be + * drawn. They contain the information necessary to draw the item : not the + * position (this is provided by the DrawContext), but the text, icon name, + * line width, color; all the properties of the specific items. + */ + +struct _PropertiesText { + GdkColor *foreground; + GdkColor *background; + gint size; + gchar *text; + RelPos position; +}; + + +struct _PropertiesIcon { + gchar *icon_name; + gint width; + gint height; + RelPos position; +}; + +struct _PropertiesLine { + GdkColor *color; + gint line_width; + GdkLineStyle style; + RelPos position; +}; + +struct _PropertiesArc { + GdkColor *color; + gint size; /* We force circle by width = height */ + gboolean filled; + RelPos position; +}; + +struct _PropertiesBG { + GdkColor *color; +}; + + + +void draw_item( GdkDrawable *drawable, + gint x, + gint y, + LttvTraceState *ts, + LttvTracefileState *tfs, + LttvIAttribute *attributes); + +/* + * The tree of attributes used to store drawing operations goes like this : + * + * event_types/ + * "facility-event_type" + * cpus/ + * "cpu name" + * mode_types/ + * "execution mode"/ + * submodes/ + * "submode" + * process_states/ + * "state name" + * + * So if, for example, we want to add a hook to get called each time we + * receive an event that is in state LTTV_STATE_SYSCALL, we put the + * pointer to the GArray of DrawOperation in + * process_states/ "name associated with LTTV_STATE_SYSCALL" + */ + +/* + * The add_operation has to do a quick sort by priority to keep the operations + * in the right order. + */ +void add_operation( LttvIAttribute *attributes, + gchar *pathname, + DrawOperation *operation); + +/* + * The del_operation seeks the array present at pathname (if any) and + * removes the DrawOperation if present. It returns 0 on success, -1 + * if it fails. + */ +gint del_operation( LttvIAttribute *attributes, + gchar *pathname, + DrawOperation *operation); + +/* + * The clean_operations removes all operations present at a pathname. + * returns 0 on success, -1 if it fails. + */ +gint clean_operations( LttvIAttribute *attributes, + gchar *pathname ); + + +/* + * The list_operations gives a pointer to the operation array associated + * with the pathname. It will be NULL if no operation is present. + */ +void list_operations( LttvIAttribute *attributes, + gchar *pathname, + GArray **operation); + + + +/* + * exec_operation executes the operations if present in the attributes, or + * do nothing if not present. + */ +void exec_operations( LttvIAttribute *attributes, + gchar *pathname); + + +/* + * Functions to create Properties structures. + */ + +PropertiesText *properties_text_create( + GdkColor *foreground, + GdkColor *background, + gint size, + gchar *text, + RelPos position); + +PropertiesIcon *properties_icon_create( + gchar *icon_name, + gint width, + gint height, + RelPos position); + +PropertiesLine *properties_line_create( + GdkColor *color, + gint line_width, + GdkLineStyle style, + RelPos position); + +PropertiesArc *properties_arc_create( + GdkColor *color, + gint size, + gboolean filled, + RelPos position); + +PropertiesBG *properties_bg_create( + GdkColor *color); + + + + +/* + * Here follow the prototypes of the hook functions used to draw the + * different items. + */ + +gboolean draw_text( void *hook_data, void *call_data); +gboolean draw_icon( void *hook_data, void *call_data); +gboolean draw_line( void *hook_data, void *call_data); +gboolean draw_arc( void *hook_data, void *call_data); +gboolean draw_bg( void *hook_data, void *call_data); + + +#endif // _DRAW_ITEM_H diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/event_hooks.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/event_hooks.c deleted file mode 100644 index 2905f6bd..00000000 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/event_hooks.c +++ /dev/null @@ -1,1205 +0,0 @@ -/***************************************************************************** - * Hooks to be called by the main window * - *****************************************************************************/ - - -#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) -#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) - -//#define PANGO_ENABLE_BACKEND -#include -#include -#include -#include -#include - -//#include - -#include -#include -#include - -#include -#include -#include -#include - - -#include "Event_Hooks.h" -#include "CFV.h" -#include "Process_List.h" -#include "Drawing.h" -#include "CFV-private.h" - - -#define MAX_PATH_LEN 256 - - -/** - * Event Viewer's constructor hook - * - * This constructor is given as a parameter to the menuitem and toolbar button - * registration. It creates the list. - * @param mw A pointer to the parent window. - * @return The widget created. - */ -GtkWidget * -h_guicontrolflow(MainWindow *mw, LttvTracesetSelector * s, char * key) -{ - g_info("h_guicontrolflow, %p, %p, %s", mw, s, key); - ControlFlowData *control_flow_data = guicontrolflow() ; - - control_flow_data->mw = mw; - TimeWindow *time_window = guicontrolflow_get_time_window(control_flow_data); - time_window->start_time.tv_sec = 0; - time_window->start_time.tv_nsec = 0; - time_window->time_width.tv_sec = 0; - time_window->time_width.tv_nsec = 0; - - LttTime *current_time = guicontrolflow_get_current_time(control_flow_data); - current_time->tv_sec = 0; - current_time->tv_nsec = 0; - - //g_critical("time width1 : %u",time_window->time_width); - - get_time_window(mw, - time_window); - get_current_time(mw, - current_time); - - //g_critical("time width2 : %u",time_window->time_width); - // Unreg done in the GuiControlFlow_Destructor - reg_update_time_window(update_time_window_hook, control_flow_data, - mw); - reg_update_current_time(update_current_time_hook, control_flow_data, - mw); - return guicontrolflow_get_widget(control_flow_data) ; - -} - -int event_selected_hook(void *hook_data, void *call_data) -{ - ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; - guint *event_number = (guint*) call_data; - - g_critical("DEBUG : event selected by main window : %u", *event_number); - -// control_flow_data->currently_Selected_Event = *event_number; -// control_flow_data->Selected_Event = TRUE ; - -// tree_v_set_cursor(control_flow_data); - -} - -/* Hook called before drawing. Gets the initial context at the beginning of the - * drawing interval and copy it to the context in event_request. - */ -int draw_before_hook(void *hook_data, void *call_data) -{ - EventRequest *event_request = (EventRequest*)hook_data; - //EventsContext Events_Context = (EventsContext*)call_data; - - //event_request->Events_Context = Events_Context; - - return 0; -} - -/* - * The draw event hook is called by the reading API to have a - * particular event drawn on the screen. - * @param hook_data ControlFlowData structure of the viewer. - * @param call_data Event context. - * - * This function basically draw lines and icons. Two types of lines are drawn : - * one small (3 pixels?) representing the state of the process and the second - * type is thicker (10 pixels?) representing on which CPU a process is running - * (and this only in running state). - * - * Extremums of the lines : - * x_min : time of the last event context for this process kept in memory. - * x_max : time of the current event. - * y : middle of the process in the process list. The process is found in the - * list, therefore is it's position in pixels. - * - * The choice of lines'color is defined by the context of the last event for this - * process. - */ -int draw_event_hook(void *hook_data, void *call_data) -{ - EventRequest *event_request = (EventRequest*)hook_data; - ControlFlowData *control_flow_data = event_request->control_flow_data; - - LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; - - LttvTracefileState *tfs = (LttvTracefileState *)call_data; - - - LttEvent *e; - e = tfc->e; - - if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) - { - g_critical("schedchange!"); - - /* Add process to process list (if not present) and get drawing "y" from - * process position */ - guint pid_out, pid_in; - LttvProcessState *process_out, *process_in; - LttTime birth; - guint y_in = 0, y_out = 0, height = 0, pl_height = 0; - - ProcessList *process_list = - guicontrolflow_get_process_list(event_request->control_flow_data); - - - LttField *f = ltt_event_field(e); - LttField *element; - element = ltt_field_member(f,0); - pid_out = ltt_event_get_long_unsigned(e,element); - element = ltt_field_member(f,1); - pid_in = ltt_event_get_long_unsigned(e,element); - g_critical("out : %u in : %u", pid_out, pid_in); - - - /* Find process pid_out in the list... */ - process_out = lttv_state_find_process(tfs, pid_out); - g_critical("out : %s",g_quark_to_string(process_out->state->s)); - - birth = process_out->creation_time; - gchar *name = strdup(g_quark_to_string(process_out->name)); - HashedProcessData *hashed_process_data_out = NULL; - - if(processlist_get_process_pixels(process_list, - pid_out, - &birth, - &y_out, - &height, - &hashed_process_data_out) == 1) - { - /* Process not present */ - processlist_add(process_list, - pid_out, - &birth, - name, - &pl_height, - &hashed_process_data_out); - processlist_get_process_pixels(process_list, - pid_out, - &birth, - &y_out, - &height, - &hashed_process_data_out); - drawing_insert_square( event_request->control_flow_data->drawing, y_out, height); - } - - g_free(name); - - /* Find process pid_in in the list... */ - process_in = lttv_state_find_process(tfs, pid_in); - g_critical("in : %s",g_quark_to_string(process_in->state->s)); - - birth = process_in->creation_time; - name = strdup(g_quark_to_string(process_in->name)); - HashedProcessData *hashed_process_data_in = NULL; - - if(processlist_get_process_pixels(process_list, - pid_in, - &birth, - &y_in, - &height, - &hashed_process_data_in) == 1) - { - /* Process not present */ - processlist_add(process_list, - pid_in, - &birth, - name, - &pl_height, - &hashed_process_data_in); - processlist_get_process_pixels(process_list, - pid_in, - &birth, - &y_in, - &height, - &hashed_process_data_in); - - drawing_insert_square( event_request->control_flow_data->drawing, y_in, height); - } - g_free(name); - - - /* Find pixels corresponding to time of the event. If the time does - * not fit in the window, show a warning, not supposed to happend. */ - guint x = 0; - guint width = control_flow_data->drawing->drawing_area->allocation.width; - - LttTime time = ltt_event_time(e); - - LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, - control_flow_data->time_window.start_time); - - - convert_time_to_pixels( - control_flow_data->time_window.start_time, - window_end, - time, - width, - &x); - - assert(x <= width); - - /* draw what represents the event for outgoing process. */ - - DrawContext *draw_context_out = hashed_process_data_out->draw_context; - draw_context_out->current->modify_over->x = x; - draw_context_out->current->modify_over->y = y_out; - draw_context_out->drawable = control_flow_data->drawing->pixmap; - draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; - GtkWidget *widget = control_flow_data->drawing->drawing_area; - //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; - draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); - gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); - //draw_context_out->gc = widget->style->black_gc; - - //draw_arc((void*)&prop_arc, (void*)draw_context_out); - //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); - - GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 }; - GdkColor colorbg_out = { 0, 0xffff, 0xffff, 0xffff }; - PropertiesText prop_text_out; - prop_text_out.foreground = &colorfg_out; - prop_text_out.background = &colorbg_out; - prop_text_out.size = 10; - prop_text_out.position = OVER; - - /* Print status of the process : U, WF, WC, E, W, R */ - if(process_out->state->s == LTTV_STATE_UNNAMED) - prop_text_out.text = "U"; - else if(process_out->state->s == LTTV_STATE_WAIT_FORK) - prop_text_out.text = "WF"; - else if(process_out->state->s == LTTV_STATE_WAIT_CPU) - prop_text_out.text = "WC"; - else if(process_out->state->s == LTTV_STATE_EXIT) - prop_text_out.text = "E"; - else if(process_out->state->s == LTTV_STATE_WAIT) - prop_text_out.text = "W"; - else if(process_out->state->s == LTTV_STATE_RUN) - prop_text_out.text = "R"; - else - prop_text_out.text = "U"; - - draw_text((void*)&prop_text_out, (void*)draw_context_out); - gdk_gc_unref(draw_context_out->gc); - - /* Draw the line of the out process */ - if(draw_context_out->previous->middle->x == -1) - { - draw_context_out->previous->middle->x = event_request->x_begin; - g_critical("out middle x_beg : %u",event_request->x_begin); - } - - draw_context_out->current->middle->x = x; - draw_context_out->current->middle->y = y_out + height/2; - draw_context_out->previous->middle->y = y_out + height/2; - draw_context_out->drawable = control_flow_data->drawing->pixmap; - draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; - //draw_context_out->gc = widget->style->black_gc; - draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); - gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); - - PropertiesLine prop_line_out; - prop_line_out.color = g_new(GdkColor,1); - prop_line_out.line_width = 4; - prop_line_out.style = GDK_LINE_SOLID; - prop_line_out.position = MIDDLE; - - /* color of line : status of the process */ - if(process_out->state->s == LTTV_STATE_UNNAMED) - { - prop_line_out.color->red = 0x0000; - prop_line_out.color->green = 0x0000; - prop_line_out.color->blue = 0x0000; - } - else if(process_out->state->s == LTTV_STATE_WAIT_FORK) - { - prop_line_out.color->red = 0x0fff; - prop_line_out.color->green = 0x0000; - prop_line_out.color->blue = 0x0fff; - } - else if(process_out->state->s == LTTV_STATE_WAIT_CPU) - { - prop_line_out.color->red = 0x0fff; - prop_line_out.color->green = 0x0fff; - prop_line_out.color->blue = 0x0000; - } - else if(process_out->state->s == LTTV_STATE_EXIT) - { - prop_line_out.color->red = 0xffff; - prop_line_out.color->green = 0x0000; - prop_line_out.color->blue = 0xffff; - } - else if(process_out->state->s == LTTV_STATE_WAIT) - { - prop_line_out.color->red = 0xffff; - prop_line_out.color->green = 0x0000; - prop_line_out.color->blue = 0x0000; - } - else if(process_out->state->s == LTTV_STATE_RUN) - { - prop_line_out.color->red = 0x0000; - prop_line_out.color->green = 0xffff; - prop_line_out.color->blue = 0x0000; - } - else - { - prop_line_out.color->red = 0x0000; - prop_line_out.color->green = 0x0000; - prop_line_out.color->blue = 0x0000; - } - - draw_line((void*)&prop_line_out, (void*)draw_context_out); - g_free(prop_line_out.color); - gdk_gc_unref(draw_context_out->gc); - /* Note : finishing line will have to be added when trace read over. */ - - /* Finally, update the drawing context of the pid_in. */ - - DrawContext *draw_context_in = hashed_process_data_in->draw_context; - draw_context_in->current->modify_over->x = x; - draw_context_in->current->modify_over->y = y_in; - draw_context_in->drawable = control_flow_data->drawing->pixmap; - draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; - widget = control_flow_data->drawing->drawing_area; - //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; - //draw_context_in->gc = widget->style->black_gc; - draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); - gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); - - //draw_arc((void*)&prop_arc, (void*)draw_context_in); - //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); - - GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 }; - GdkColor colorbg_in = { 0, 0xffff, 0xffff, 0xffff }; - PropertiesText prop_text_in; - prop_text_in.foreground = &colorfg_in; - prop_text_in.background = &colorbg_in; - prop_text_in.size = 10; - prop_text_in.position = OVER; - - /* Print status of the process : U, WF, WC, E, W, R */ - if(process_in->state->s == LTTV_STATE_UNNAMED) - prop_text_in.text = "U"; - else if(process_in->state->s == LTTV_STATE_WAIT_FORK) - prop_text_in.text = "WF"; - else if(process_in->state->s == LTTV_STATE_WAIT_CPU) - prop_text_in.text = "WC"; - else if(process_in->state->s == LTTV_STATE_EXIT) - prop_text_in.text = "E"; - else if(process_in->state->s == LTTV_STATE_WAIT) - prop_text_in.text = "W"; - else if(process_in->state->s == LTTV_STATE_RUN) - prop_text_in.text = "R"; - else - prop_text_in.text = "U"; - - draw_text((void*)&prop_text_in, (void*)draw_context_in); - gdk_gc_unref(draw_context_in->gc); - - /* Draw the line of the in process */ - if(draw_context_in->previous->middle->x == -1) - { - draw_context_in->previous->middle->x = event_request->x_begin; - g_critical("in middle x_beg : %u",event_request->x_begin); - } - - draw_context_in->current->middle->x = x; - draw_context_in->previous->middle->y = y_in + height/2; - draw_context_in->current->middle->y = y_in + height/2; - draw_context_in->drawable = control_flow_data->drawing->pixmap; - draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; - //draw_context_in->gc = widget->style->black_gc; - draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); - gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); - - PropertiesLine prop_line_in; - prop_line_in.color = g_new(GdkColor,1); - prop_line_in.line_width = 4; - prop_line_in.style = GDK_LINE_SOLID; - prop_line_in.position = MIDDLE; - - /* color of line : status of the process */ - if(process_in->state->s == LTTV_STATE_UNNAMED) - { - prop_line_in.color->red = 0x0000; - prop_line_in.color->green = 0x0000; - prop_line_in.color->blue = 0x0000; - } - else if(process_in->state->s == LTTV_STATE_WAIT_FORK) - { - prop_line_in.color->red = 0x0fff; - prop_line_in.color->green = 0x0000; - prop_line_in.color->blue = 0x0fff; - } - else if(process_in->state->s == LTTV_STATE_WAIT_CPU) - { - prop_line_in.color->red = 0x0fff; - prop_line_in.color->green = 0x0fff; - prop_line_in.color->blue = 0x0000; - } - else if(process_in->state->s == LTTV_STATE_EXIT) - { - prop_line_in.color->red = 0xffff; - prop_line_in.color->green = 0x0000; - prop_line_in.color->blue = 0xffff; - } - else if(process_in->state->s == LTTV_STATE_WAIT) - { - prop_line_in.color->red = 0xffff; - prop_line_in.color->green = 0x0000; - prop_line_in.color->blue = 0x0000; - } - else if(process_in->state->s == LTTV_STATE_RUN) - { - prop_line_in.color->red = 0x0000; - prop_line_in.color->green = 0xffff; - prop_line_in.color->blue = 0x0000; - } - else - { - prop_line_in.color->red = 0x0000; - prop_line_in.color->green = 0x0000; - prop_line_in.color->blue = 0x0000; - } - - draw_line((void*)&prop_line_in, (void*)draw_context_in); - g_free(prop_line_in.color); - gdk_gc_unref(draw_context_in->gc); - } - - return 0; - - /* Temp dump */ -#ifdef DONTSHOW - GString *string = g_string_new("");; - gboolean field_names = TRUE, state = TRUE; - - lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs); - g_string_append_printf(string,"\n"); - - if(state) { - g_string_append_printf(string, " %s", - g_quark_to_string(tfs->process->state->s)); - } - - g_info("%s",string->str); - - g_string_free(string, TRUE); - - /* End of text dump */ -#endif //DONTSHOW - -} - - -int draw_after_hook(void *hook_data, void *call_data) -{ - EventRequest *event_request = (EventRequest*)hook_data; - ControlFlowData *control_flow_data = event_request->control_flow_data; - - LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; - - LttvTracefileState *tfs = (LttvTracefileState *)call_data; - - - LttEvent *e; - e = tfc->e; - - if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) - { - g_critical("schedchange!"); - - /* Add process to process list (if not present) and get drawing "y" from - * process position */ - guint pid_out, pid_in; - LttvProcessState *process_out, *process_in; - LttTime birth; - guint y_in = 0, y_out = 0, height = 0, pl_height = 0; - - ProcessList *process_list = - guicontrolflow_get_process_list(event_request->control_flow_data); - - - LttField *f = ltt_event_field(e); - LttField *element; - element = ltt_field_member(f,0); - pid_out = ltt_event_get_long_unsigned(e,element); - element = ltt_field_member(f,1); - pid_in = ltt_event_get_long_unsigned(e,element); - g_critical("out : %u in : %u", pid_out, pid_in); - - - /* Find process pid_out in the list... */ - process_out = lttv_state_find_process(tfs, pid_out); - g_critical("out : %s",g_quark_to_string(process_out->state->s)); - - birth = process_out->creation_time; - gchar *name = strdup(g_quark_to_string(process_out->name)); - HashedProcessData *hashed_process_data_out = NULL; - - if(processlist_get_process_pixels(process_list, - pid_out, - &birth, - &y_out, - &height, - &hashed_process_data_out) == 1) - { - /* Process not present */ - processlist_add(process_list, - pid_out, - &birth, - name, - &pl_height, - &hashed_process_data_out); - processlist_get_process_pixels(process_list, - pid_out, - &birth, - &y_out, - &height, - &hashed_process_data_out); - drawing_insert_square( event_request->control_flow_data->drawing, y_out, height); - } - - g_free(name); - - /* Find process pid_in in the list... */ - process_in = lttv_state_find_process(tfs, pid_in); - g_critical("in : %s",g_quark_to_string(process_in->state->s)); - - birth = process_in->creation_time; - name = strdup(g_quark_to_string(process_in->name)); - HashedProcessData *hashed_process_data_in = NULL; - - if(processlist_get_process_pixels(process_list, - pid_in, - &birth, - &y_in, - &height, - &hashed_process_data_in) == 1) - { - /* Process not present */ - processlist_add(process_list, - pid_in, - &birth, - name, - &pl_height, - &hashed_process_data_in); - processlist_get_process_pixels(process_list, - pid_in, - &birth, - &y_in, - &height, - &hashed_process_data_in); - - drawing_insert_square( event_request->control_flow_data->drawing, y_in, height); - } - g_free(name); - - - /* Find pixels corresponding to time of the event. If the time does - * not fit in the window, show a warning, not supposed to happend. */ - //guint x = 0; - //guint width = control_flow_data->drawing->drawing_area->allocation.width; - - //LttTime time = ltt_event_time(e); - - //LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, - // control_flow_data->time_window.start_time); - - - //convert_time_to_pixels( - // control_flow_data->time_window.start_time, - // window_end, - // time, - // width, - // &x); - - //assert(x <= width); - - /* draw what represents the event for outgoing process. */ - - DrawContext *draw_context_out = hashed_process_data_out->draw_context; - //draw_context_out->current->modify_over->x = x; - draw_context_out->current->modify_over->y = y_out; - draw_context_out->drawable = control_flow_data->drawing->pixmap; - draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; - GtkWidget *widget = control_flow_data->drawing->drawing_area; - //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; - draw_context_out->gc = widget->style->black_gc; - - //draw_arc((void*)&prop_arc, (void*)draw_context_out); - //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); - - GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 }; - GdkColor colorbg_out = { 0, 0xffff, 0xffff, 0xffff }; - PropertiesText prop_text_out; - prop_text_out.foreground = &colorfg_out; - prop_text_out.background = &colorbg_out; - prop_text_out.size = 10; - prop_text_out.position = OVER; - - /* Print status of the process : U, WF, WC, E, W, R */ - if(process_out->state->s == LTTV_STATE_UNNAMED) - prop_text_out.text = "U"; - else if(process_out->state->s == LTTV_STATE_WAIT_FORK) - prop_text_out.text = "WF"; - else if(process_out->state->s == LTTV_STATE_WAIT_CPU) - prop_text_out.text = "WC"; - else if(process_out->state->s == LTTV_STATE_EXIT) - prop_text_out.text = "E"; - else if(process_out->state->s == LTTV_STATE_WAIT) - prop_text_out.text = "W"; - else if(process_out->state->s == LTTV_STATE_RUN) - prop_text_out.text = "R"; - else - prop_text_out.text = "U"; - - draw_text((void*)&prop_text_out, (void*)draw_context_out); - - draw_context_out->current->middle->y = y_out+height/2; - draw_context_out->current->status = process_out->state->s; - - /* for pid_out : remove previous, Prev = current, new current (default) */ - g_free(draw_context_out->previous->modify_under); - g_free(draw_context_out->previous->modify_middle); - g_free(draw_context_out->previous->modify_over); - g_free(draw_context_out->previous->under); - g_free(draw_context_out->previous->middle); - g_free(draw_context_out->previous->over); - g_free(draw_context_out->previous); - - draw_context_out->previous = draw_context_out->current; - - draw_context_out->current = g_new(DrawInfo,1); - draw_context_out->current->over = g_new(ItemInfo,1); - draw_context_out->current->over->x = -1; - draw_context_out->current->over->y = -1; - draw_context_out->current->middle = g_new(ItemInfo,1); - draw_context_out->current->middle->x = -1; - draw_context_out->current->middle->y = -1; - draw_context_out->current->under = g_new(ItemInfo,1); - draw_context_out->current->under->x = -1; - draw_context_out->current->under->y = -1; - draw_context_out->current->modify_over = g_new(ItemInfo,1); - draw_context_out->current->modify_over->x = -1; - draw_context_out->current->modify_over->y = -1; - draw_context_out->current->modify_middle = g_new(ItemInfo,1); - draw_context_out->current->modify_middle->x = -1; - draw_context_out->current->modify_middle->y = -1; - draw_context_out->current->modify_under = g_new(ItemInfo,1); - draw_context_out->current->modify_under->x = -1; - draw_context_out->current->modify_under->y = -1; - draw_context_out->current->status = LTTV_STATE_UNNAMED; - - /* Finally, update the drawing context of the pid_in. */ - - DrawContext *draw_context_in = hashed_process_data_in->draw_context; - //draw_context_in->current->modify_over->x = x; - draw_context_in->current->modify_over->y = y_in; - draw_context_in->drawable = control_flow_data->drawing->pixmap; - draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; - widget = control_flow_data->drawing->drawing_area; - //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; - draw_context_in->gc = widget->style->black_gc; - - //draw_arc((void*)&prop_arc, (void*)draw_context_in); - //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); - - GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 }; - GdkColor colorbg_in = { 0, 0xffff, 0xffff, 0xffff }; - PropertiesText prop_text_in; - prop_text_in.foreground = &colorfg_in; - prop_text_in.background = &colorbg_in; - prop_text_in.size = 10; - prop_text_in.position = OVER; - - /* Print status of the process : U, WF, WC, E, W, R */ - if(process_in->state->s == LTTV_STATE_UNNAMED) - prop_text_in.text = "U"; - else if(process_in->state->s == LTTV_STATE_WAIT_FORK) - prop_text_in.text = "WF"; - else if(process_in->state->s == LTTV_STATE_WAIT_CPU) - prop_text_in.text = "WC"; - else if(process_in->state->s == LTTV_STATE_EXIT) - prop_text_in.text = "E"; - else if(process_in->state->s == LTTV_STATE_WAIT) - prop_text_in.text = "W"; - else if(process_in->state->s == LTTV_STATE_RUN) - prop_text_in.text = "R"; - else - prop_text_in.text = "U"; - - draw_text((void*)&prop_text_in, (void*)draw_context_in); - - draw_context_in->current->middle->y = y_in+height/2; - draw_context_in->current->status = process_in->state->s; - - /* for pid_in : remove previous, Prev = current, new current (default) */ - g_free(draw_context_in->previous->modify_under); - g_free(draw_context_in->previous->modify_middle); - g_free(draw_context_in->previous->modify_over); - g_free(draw_context_in->previous->under); - g_free(draw_context_in->previous->middle); - g_free(draw_context_in->previous->over); - g_free(draw_context_in->previous); - - draw_context_in->previous = draw_context_in->current; - - draw_context_in->current = g_new(DrawInfo,1); - draw_context_in->current->over = g_new(ItemInfo,1); - draw_context_in->current->over->x = -1; - draw_context_in->current->over->y = -1; - draw_context_in->current->middle = g_new(ItemInfo,1); - draw_context_in->current->middle->x = -1; - draw_context_in->current->middle->y = -1; - draw_context_in->current->under = g_new(ItemInfo,1); - draw_context_in->current->under->x = -1; - draw_context_in->current->under->y = -1; - draw_context_in->current->modify_over = g_new(ItemInfo,1); - draw_context_in->current->modify_over->x = -1; - draw_context_in->current->modify_over->y = -1; - draw_context_in->current->modify_middle = g_new(ItemInfo,1); - draw_context_in->current->modify_middle->x = -1; - draw_context_in->current->modify_middle->y = -1; - draw_context_in->current->modify_under = g_new(ItemInfo,1); - draw_context_in->current->modify_under->x = -1; - draw_context_in->current->modify_under->y = -1; - draw_context_in->current->status = LTTV_STATE_UNNAMED; - - } - - return 0; -} - - - - -gint update_time_window_hook(void *hook_data, void *call_data) -{ - ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; - TimeWindow *old_time_window = - guicontrolflow_get_time_window(control_flow_data); - TimeWindow *new_time_window = ((TimeWindow*)call_data); - - /* Two cases : zoom in/out or scrolling */ - - /* In order to make sure we can reuse the old drawing, the scale must - * be the same and the new time interval being partly located in the - * currently shown time interval. (reuse is only for scrolling) - */ - - g_info("Old time window HOOK : %u, %u to %u, %u", - old_time_window->start_time.tv_sec, - old_time_window->start_time.tv_nsec, - old_time_window->time_width.tv_sec, - old_time_window->time_width.tv_nsec); - - g_info("New time window HOOK : %u, %u to %u, %u", - new_time_window->start_time.tv_sec, - new_time_window->start_time.tv_nsec, - new_time_window->time_width.tv_sec, - new_time_window->time_width.tv_nsec); - - if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec - && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec) - { - /* Same scale (scrolling) */ - g_info("scrolling"); - LttTime *ns = &new_time_window->start_time; - LttTime *os = &old_time_window->start_time; - LttTime old_end = ltt_time_add(old_time_window->start_time, - old_time_window->time_width); - LttTime new_end = ltt_time_add(new_time_window->start_time, - new_time_window->time_width); - //if(nsdrawing->drawing_area->allocation.width; - convert_time_to_pixels( - *os, - old_end, - *ns, - width, - &x); - - /* Copy old data to new location */ - gdk_draw_drawable (control_flow_data->drawing->pixmap, - control_flow_data->drawing->drawing_area->style->white_gc, - control_flow_data->drawing->pixmap, - x, 0, - 0, 0, - -1, -1); - - convert_time_to_pixels( - *ns, - new_end, - old_end, - width, - &x); - - *old_time_window = *new_time_window; - /* Clear the data request background, but not SAFETY */ - gdk_draw_rectangle (control_flow_data->drawing->pixmap, - control_flow_data->drawing->drawing_area->style->white_gc, - TRUE, - x+SAFETY, 0, - control_flow_data->drawing->width - x, // do not overlap - control_flow_data->drawing->height+SAFETY); - /* Get new data for the rest. */ - drawing_data_request(control_flow_data->drawing, - &control_flow_data->drawing->pixmap, - x, 0, - control_flow_data->drawing->width - x, - control_flow_data->drawing->height); - - drawing_refresh(control_flow_data->drawing, - 0, 0, - control_flow_data->drawing->width, - control_flow_data->drawing->height); - - - } else { - //if(nsdrawing->drawing_area->allocation.width; - convert_time_to_pixels( - *ns, - new_end, - *os, - width, - &x); - - /* Copy old data to new location */ - gdk_draw_drawable (control_flow_data->drawing->pixmap, - control_flow_data->drawing->drawing_area->style->white_gc, - control_flow_data->drawing->pixmap, - 0, 0, - x, 0, - -1, -1); - - *old_time_window = *new_time_window; - - /* Clean the data request background */ - gdk_draw_rectangle (control_flow_data->drawing->pixmap, - control_flow_data->drawing->drawing_area->style->white_gc, - TRUE, - 0, 0, - x, // do not overlap - control_flow_data->drawing->height+SAFETY); - /* Get new data for the rest. */ - drawing_data_request(control_flow_data->drawing, - &control_flow_data->drawing->pixmap, - 0, 0, - x, - control_flow_data->drawing->height); - - drawing_refresh(control_flow_data->drawing, - 0, 0, - control_flow_data->drawing->width, - control_flow_data->drawing->height); - - } else { - g_info("scrolling far"); - /* Cannot reuse any part of the screen : far jump */ - *old_time_window = *new_time_window; - - - gdk_draw_rectangle (control_flow_data->drawing->pixmap, - control_flow_data->drawing->drawing_area->style->white_gc, - TRUE, - 0, 0, - control_flow_data->drawing->width+SAFETY, // do not overlap - control_flow_data->drawing->height+SAFETY); - - drawing_data_request(control_flow_data->drawing, - &control_flow_data->drawing->pixmap, - 0, 0, - control_flow_data->drawing->width, - control_flow_data->drawing->height); - - drawing_refresh(control_flow_data->drawing, - 0, 0, - control_flow_data->drawing->width, - control_flow_data->drawing->height); - } - } - } else { - /* Different scale (zoom) */ - g_info("zoom"); - - *old_time_window = *new_time_window; - - gdk_draw_rectangle (control_flow_data->drawing->pixmap, - control_flow_data->drawing->drawing_area->style->white_gc, - TRUE, - 0, 0, - control_flow_data->drawing->width+SAFETY, // do not overlap - control_flow_data->drawing->height+SAFETY); - - - drawing_data_request(control_flow_data->drawing, - &control_flow_data->drawing->pixmap, - 0, 0, - control_flow_data->drawing->width, - control_flow_data->drawing->height); - - drawing_refresh(control_flow_data->drawing, - 0, 0, - control_flow_data->drawing->width, - control_flow_data->drawing->height); - } - - return 0; -} - -gint update_current_time_hook(void *hook_data, void *call_data) -{ - ControlFlowData *control_flow_data = (ControlFlowData*)hook_data; - - LttTime* current_time = - guicontrolflow_get_current_time(control_flow_data); - *current_time = *((LttTime*)call_data); - - TimeWindow time_window; - - LttTime time_begin = control_flow_data->time_window.start_time; - LttTime width = control_flow_data->time_window.time_width; - LttTime half_width = ltt_time_div(width,2.0); - LttTime time_end = ltt_time_add(time_begin, width); - - LttvTracesetContext * tsc = - get_traceset_context(control_flow_data->mw); - - LttTime trace_start = tsc->Time_Span->startTime; - LttTime trace_end = tsc->Time_Span->endTime; - - g_info("New current time HOOK : %u, %u", current_time->tv_sec, - current_time->tv_nsec); - - - - /* If current time is inside time interval, just move the highlight - * bar */ - - /* Else, we have to change the time interval. We have to tell it - * to the main window. */ - /* The time interval change will take care of placing the current - * time at the center of the visible area, or nearest possible if we are - * at one end of the trace. */ - - - if(ltt_time_compare(*current_time, time_begin) == -1) - { - if(ltt_time_compare(*current_time, - ltt_time_add(trace_start,half_width)) == -1) - time_begin = trace_start; - else - time_begin = ltt_time_sub(*current_time,half_width); - - time_window.start_time = time_begin; - time_window.time_width = width; - - set_time_window(control_flow_data->mw, &time_window); - } - else if(ltt_time_compare(*current_time, time_end) == 1) - { - if(ltt_time_compare(*current_time, ltt_time_sub(trace_end, half_width)) == 1) - time_begin = ltt_time_sub(trace_end,width); - else - time_begin = ltt_time_sub(*current_time,half_width); - - time_window.start_time = time_begin; - time_window.time_width = width; - - set_time_window(control_flow_data->mw, &time_window); - - } - gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); - - return 0; -} - -typedef struct _ClosureData { - EventRequest *event_request; - LttvTraceState *ts; -} ClosureData; - - -void draw_closure(gpointer key, gpointer value, gpointer user_data) -{ - ProcessInfo *process_info = (ProcessInfo*)key; - HashedProcessData *hashed_process_data = (HashedProcessData*)value; - ClosureData *closure_data = (ClosureData*)user_data; - - ControlFlowData *control_flow_data = - closure_data->event_request->control_flow_data; - - GtkWidget *widget = control_flow_data->drawing->drawing_area; - - /* Get y position of process */ - gint y=0, height=0; - - processlist_get_pixels_from_data( control_flow_data->process_list, - process_info, - hashed_process_data, - &y, - &height); - /* Get last state of process */ - LttvTraceContext *tc = - (LttvTraceContext *)closure_data->ts; - - LttvTraceState *ts = closure_data->ts; - LttvProcessState *process; - - process = lttv_state_find_process((LttvTracefileState*)ts, process_info->pid); - - /* Draw the closing line */ - DrawContext *draw_context = hashed_process_data->draw_context; - if(draw_context->previous->middle->x == -1) - { - draw_context->previous->middle->x = closure_data->event_request->x_begin; - g_critical("out middle x_beg : %u",closure_data->event_request->x_begin); - } - - draw_context->current->middle->x = closure_data->event_request->x_end; - draw_context->current->middle->y = y + height/2; - draw_context->previous->middle->y = y + height/2; - draw_context->drawable = control_flow_data->drawing->pixmap; - draw_context->pango_layout = control_flow_data->drawing->pango_layout; - //draw_context->gc = widget->style->black_gc; - draw_context->gc = gdk_gc_new(control_flow_data->drawing->pixmap); - gdk_gc_copy(draw_context->gc, widget->style->black_gc); - - PropertiesLine prop_line; - prop_line.color = g_new(GdkColor,1); - prop_line.line_width = 6; - prop_line.style = GDK_LINE_SOLID; - prop_line.position = MIDDLE; - - /* color of line : status of the process */ - if(process->state->s == LTTV_STATE_UNNAMED) - { - prop_line.color->red = 0x0000; - prop_line.color->green = 0x0000; - prop_line.color->blue = 0x0000; - } - else if(process->state->s == LTTV_STATE_WAIT_FORK) - { - prop_line.color->red = 0x0fff; - prop_line.color->green = 0x0000; - prop_line.color->blue = 0x0fff; - } - else if(process->state->s == LTTV_STATE_WAIT_CPU) - { - prop_line.color->red = 0x0fff; - prop_line.color->green = 0x0fff; - prop_line.color->blue = 0x0000; - } - else if(process->state->s == LTTV_STATE_EXIT) - { - prop_line.color->red = 0xffff; - prop_line.color->green = 0x0000; - prop_line.color->blue = 0xffff; - } - else if(process->state->s == LTTV_STATE_WAIT) - { - prop_line.color->red = 0xffff; - prop_line.color->green = 0x0000; - prop_line.color->blue = 0x0000; - } - else if(process->state->s == LTTV_STATE_RUN) - { - prop_line.color->red = 0x0000; - prop_line.color->green = 0xffff; - prop_line.color->blue = 0x0000; - } - else - { - prop_line.color->red = 0x0000; - prop_line.color->green = 0x0000; - prop_line.color->blue = 0x0000; - } - - draw_line((void*)&prop_line, (void*)draw_context); - g_free(prop_line.color); - gdk_gc_unref(draw_context->gc); - - /* Reset draw_context of the process for next request */ - - hashed_process_data->draw_context->drawable = NULL; - hashed_process_data->draw_context->gc = NULL; - hashed_process_data->draw_context->pango_layout = NULL; - hashed_process_data->draw_context->current->over->x = -1; - hashed_process_data->draw_context->current->over->y = -1; - hashed_process_data->draw_context->current->middle->x = -1; - hashed_process_data->draw_context->current->middle->y = -1; - hashed_process_data->draw_context->current->under->x = -1; - hashed_process_data->draw_context->current->under->y = -1; - hashed_process_data->draw_context->current->modify_over->x = -1; - hashed_process_data->draw_context->current->modify_over->y = -1; - hashed_process_data->draw_context->current->modify_middle->x = -1; - hashed_process_data->draw_context->current->modify_middle->y = -1; - hashed_process_data->draw_context->current->modify_under->x = -1; - hashed_process_data->draw_context->current->modify_under->y = -1; - hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED; - hashed_process_data->draw_context->previous->over->x = -1; - hashed_process_data->draw_context->previous->over->y = -1; - hashed_process_data->draw_context->previous->middle->x = -1; - hashed_process_data->draw_context->previous->middle->y = -1; - hashed_process_data->draw_context->previous->under->x = -1; - hashed_process_data->draw_context->previous->under->y = -1; - hashed_process_data->draw_context->previous->modify_over->x = -1; - hashed_process_data->draw_context->previous->modify_over->y = -1; - hashed_process_data->draw_context->previous->modify_middle->x = -1; - hashed_process_data->draw_context->previous->modify_middle->y = -1; - hashed_process_data->draw_context->previous->modify_under->x = -1; - hashed_process_data->draw_context->previous->modify_under->y = -1; - hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED; - - -} - -/* - * for each process - * draw closing line - * new default prev and current - */ -int after_data_request(void *hook_data, void *call_data) -{ - EventRequest *event_request = (EventRequest*)hook_data; - ControlFlowData *control_flow_data = event_request->control_flow_data; - - ProcessList *process_list = - guicontrolflow_get_process_list(event_request->control_flow_data); - - ClosureData closure_data; - closure_data.event_request = (EventRequest*)hook_data; - closure_data.ts = (LttvTraceState*)call_data; - - g_hash_table_foreach(process_list->process_hash, draw_closure, - (void*)&closure_data); - -} - diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/event_hooks.h b/ltt/branches/poly/lttv/modules/gui/ControlFlow/event_hooks.h deleted file mode 100644 index 66170d3c..00000000 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/event_hooks.h +++ /dev/null @@ -1,84 +0,0 @@ -/* Event_hooks.c defines the hooks that are given to processTrace as parameter. - * These hooks call the drawing API to draw the information on the screen, - * using information from Context, but mostly state (running, waiting...). - */ - - -#ifndef _EVENT_HOOKS_H -#define _EVENT_HOOKS_H - -#include -#include -#include -#include "Process_List.h" -#include "Drawing.h" -#include "CFV.h" - - -/* Structure used to store and use information relative to one events refresh - * request. Typically filled in by the expose event callback, then passed to the - * library call, then used by the drawing hooks. Then, once all the events are - * sent, it is freed by the hook called after the reading. - */ -typedef struct _EventRequest -{ - ControlFlowData *control_flow_data; - LttTime time_begin, time_end; - gint x_begin, x_end; - /* Fill the Events_Context during the initial expose, before calling for - * events. - */ - //GArray Events_Context; //FIXME -} EventRequest ; - - - - - -void send_test_data(ProcessList *process_list, Drawing_t *drawing); - -GtkWidget *h_guicontrolflow(MainWindow *mw, LttvTracesetSelector * s, char * key); - -int event_selected_hook(void *hook_data, void *call_data); - -/* Hook called before drawing. Gets the initial context at the beginning of the - * drawing interval and copy it to the context in event_request. - */ -int draw_before_hook(void *hook_data, void *call_data); - -/* - * The draw event hook is called by the reading API to have a - * particular event drawn on the screen. - * @param hook_data ControlFlowData structure of the viewer. - * @param call_data Event context. - * - * This function basically draw lines and icons. Two types of lines are drawn : - * one small (3 pixels?) representing the state of the process and the second - * type is thicker (10 pixels?) representing on which CPU a process is running - * (and this only in running state). - * - * Extremums of the lines : - * x_min : time of the last event context for this process kept in memory. - * x_max : time of the current event. - * y : middle of the process in the process list. The process is found in the - * list, therefore is it's position in pixels. - * - * The choice of lines'color is defined by the context of the last event for this - * process. - */ -int draw_event_hook(void *hook_data, void *call_data); - -int draw_after_hook(void *hook_data, void *call_data); - -void draw_closure(gpointer key, gpointer value, gpointer user_data); - -int after_data_request(void *hook_data, void *call_data); - - -gint update_time_window_hook(void *hook_data, void *call_data); -gint update_current_time_hook(void *hook_data, void *call_data); - - - - -#endif // _EVENT_HOOKS_H diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/eventhooks.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/eventhooks.c new file mode 100644 index 00000000..2905f6bd --- /dev/null +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/eventhooks.c @@ -0,0 +1,1205 @@ +/***************************************************************************** + * Hooks to be called by the main window * + *****************************************************************************/ + + +#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) +#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) + +//#define PANGO_ENABLE_BACKEND +#include +#include +#include +#include +#include + +//#include + +#include +#include +#include + +#include +#include +#include +#include + + +#include "Event_Hooks.h" +#include "CFV.h" +#include "Process_List.h" +#include "Drawing.h" +#include "CFV-private.h" + + +#define MAX_PATH_LEN 256 + + +/** + * Event Viewer's constructor hook + * + * This constructor is given as a parameter to the menuitem and toolbar button + * registration. It creates the list. + * @param mw A pointer to the parent window. + * @return The widget created. + */ +GtkWidget * +h_guicontrolflow(MainWindow *mw, LttvTracesetSelector * s, char * key) +{ + g_info("h_guicontrolflow, %p, %p, %s", mw, s, key); + ControlFlowData *control_flow_data = guicontrolflow() ; + + control_flow_data->mw = mw; + TimeWindow *time_window = guicontrolflow_get_time_window(control_flow_data); + time_window->start_time.tv_sec = 0; + time_window->start_time.tv_nsec = 0; + time_window->time_width.tv_sec = 0; + time_window->time_width.tv_nsec = 0; + + LttTime *current_time = guicontrolflow_get_current_time(control_flow_data); + current_time->tv_sec = 0; + current_time->tv_nsec = 0; + + //g_critical("time width1 : %u",time_window->time_width); + + get_time_window(mw, + time_window); + get_current_time(mw, + current_time); + + //g_critical("time width2 : %u",time_window->time_width); + // Unreg done in the GuiControlFlow_Destructor + reg_update_time_window(update_time_window_hook, control_flow_data, + mw); + reg_update_current_time(update_current_time_hook, control_flow_data, + mw); + return guicontrolflow_get_widget(control_flow_data) ; + +} + +int event_selected_hook(void *hook_data, void *call_data) +{ + ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; + guint *event_number = (guint*) call_data; + + g_critical("DEBUG : event selected by main window : %u", *event_number); + +// control_flow_data->currently_Selected_Event = *event_number; +// control_flow_data->Selected_Event = TRUE ; + +// tree_v_set_cursor(control_flow_data); + +} + +/* Hook called before drawing. Gets the initial context at the beginning of the + * drawing interval and copy it to the context in event_request. + */ +int draw_before_hook(void *hook_data, void *call_data) +{ + EventRequest *event_request = (EventRequest*)hook_data; + //EventsContext Events_Context = (EventsContext*)call_data; + + //event_request->Events_Context = Events_Context; + + return 0; +} + +/* + * The draw event hook is called by the reading API to have a + * particular event drawn on the screen. + * @param hook_data ControlFlowData structure of the viewer. + * @param call_data Event context. + * + * This function basically draw lines and icons. Two types of lines are drawn : + * one small (3 pixels?) representing the state of the process and the second + * type is thicker (10 pixels?) representing on which CPU a process is running + * (and this only in running state). + * + * Extremums of the lines : + * x_min : time of the last event context for this process kept in memory. + * x_max : time of the current event. + * y : middle of the process in the process list. The process is found in the + * list, therefore is it's position in pixels. + * + * The choice of lines'color is defined by the context of the last event for this + * process. + */ +int draw_event_hook(void *hook_data, void *call_data) +{ + EventRequest *event_request = (EventRequest*)hook_data; + ControlFlowData *control_flow_data = event_request->control_flow_data; + + LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; + + LttvTracefileState *tfs = (LttvTracefileState *)call_data; + + + LttEvent *e; + e = tfc->e; + + if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) + { + g_critical("schedchange!"); + + /* Add process to process list (if not present) and get drawing "y" from + * process position */ + guint pid_out, pid_in; + LttvProcessState *process_out, *process_in; + LttTime birth; + guint y_in = 0, y_out = 0, height = 0, pl_height = 0; + + ProcessList *process_list = + guicontrolflow_get_process_list(event_request->control_flow_data); + + + LttField *f = ltt_event_field(e); + LttField *element; + element = ltt_field_member(f,0); + pid_out = ltt_event_get_long_unsigned(e,element); + element = ltt_field_member(f,1); + pid_in = ltt_event_get_long_unsigned(e,element); + g_critical("out : %u in : %u", pid_out, pid_in); + + + /* Find process pid_out in the list... */ + process_out = lttv_state_find_process(tfs, pid_out); + g_critical("out : %s",g_quark_to_string(process_out->state->s)); + + birth = process_out->creation_time; + gchar *name = strdup(g_quark_to_string(process_out->name)); + HashedProcessData *hashed_process_data_out = NULL; + + if(processlist_get_process_pixels(process_list, + pid_out, + &birth, + &y_out, + &height, + &hashed_process_data_out) == 1) + { + /* Process not present */ + processlist_add(process_list, + pid_out, + &birth, + name, + &pl_height, + &hashed_process_data_out); + processlist_get_process_pixels(process_list, + pid_out, + &birth, + &y_out, + &height, + &hashed_process_data_out); + drawing_insert_square( event_request->control_flow_data->drawing, y_out, height); + } + + g_free(name); + + /* Find process pid_in in the list... */ + process_in = lttv_state_find_process(tfs, pid_in); + g_critical("in : %s",g_quark_to_string(process_in->state->s)); + + birth = process_in->creation_time; + name = strdup(g_quark_to_string(process_in->name)); + HashedProcessData *hashed_process_data_in = NULL; + + if(processlist_get_process_pixels(process_list, + pid_in, + &birth, + &y_in, + &height, + &hashed_process_data_in) == 1) + { + /* Process not present */ + processlist_add(process_list, + pid_in, + &birth, + name, + &pl_height, + &hashed_process_data_in); + processlist_get_process_pixels(process_list, + pid_in, + &birth, + &y_in, + &height, + &hashed_process_data_in); + + drawing_insert_square( event_request->control_flow_data->drawing, y_in, height); + } + g_free(name); + + + /* Find pixels corresponding to time of the event. If the time does + * not fit in the window, show a warning, not supposed to happend. */ + guint x = 0; + guint width = control_flow_data->drawing->drawing_area->allocation.width; + + LttTime time = ltt_event_time(e); + + LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, + control_flow_data->time_window.start_time); + + + convert_time_to_pixels( + control_flow_data->time_window.start_time, + window_end, + time, + width, + &x); + + assert(x <= width); + + /* draw what represents the event for outgoing process. */ + + DrawContext *draw_context_out = hashed_process_data_out->draw_context; + draw_context_out->current->modify_over->x = x; + draw_context_out->current->modify_over->y = y_out; + draw_context_out->drawable = control_flow_data->drawing->pixmap; + draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; + GtkWidget *widget = control_flow_data->drawing->drawing_area; + //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; + draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); + gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); + //draw_context_out->gc = widget->style->black_gc; + + //draw_arc((void*)&prop_arc, (void*)draw_context_out); + //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); + + GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 }; + GdkColor colorbg_out = { 0, 0xffff, 0xffff, 0xffff }; + PropertiesText prop_text_out; + prop_text_out.foreground = &colorfg_out; + prop_text_out.background = &colorbg_out; + prop_text_out.size = 10; + prop_text_out.position = OVER; + + /* Print status of the process : U, WF, WC, E, W, R */ + if(process_out->state->s == LTTV_STATE_UNNAMED) + prop_text_out.text = "U"; + else if(process_out->state->s == LTTV_STATE_WAIT_FORK) + prop_text_out.text = "WF"; + else if(process_out->state->s == LTTV_STATE_WAIT_CPU) + prop_text_out.text = "WC"; + else if(process_out->state->s == LTTV_STATE_EXIT) + prop_text_out.text = "E"; + else if(process_out->state->s == LTTV_STATE_WAIT) + prop_text_out.text = "W"; + else if(process_out->state->s == LTTV_STATE_RUN) + prop_text_out.text = "R"; + else + prop_text_out.text = "U"; + + draw_text((void*)&prop_text_out, (void*)draw_context_out); + gdk_gc_unref(draw_context_out->gc); + + /* Draw the line of the out process */ + if(draw_context_out->previous->middle->x == -1) + { + draw_context_out->previous->middle->x = event_request->x_begin; + g_critical("out middle x_beg : %u",event_request->x_begin); + } + + draw_context_out->current->middle->x = x; + draw_context_out->current->middle->y = y_out + height/2; + draw_context_out->previous->middle->y = y_out + height/2; + draw_context_out->drawable = control_flow_data->drawing->pixmap; + draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; + //draw_context_out->gc = widget->style->black_gc; + draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); + gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); + + PropertiesLine prop_line_out; + prop_line_out.color = g_new(GdkColor,1); + prop_line_out.line_width = 4; + prop_line_out.style = GDK_LINE_SOLID; + prop_line_out.position = MIDDLE; + + /* color of line : status of the process */ + if(process_out->state->s == LTTV_STATE_UNNAMED) + { + prop_line_out.color->red = 0x0000; + prop_line_out.color->green = 0x0000; + prop_line_out.color->blue = 0x0000; + } + else if(process_out->state->s == LTTV_STATE_WAIT_FORK) + { + prop_line_out.color->red = 0x0fff; + prop_line_out.color->green = 0x0000; + prop_line_out.color->blue = 0x0fff; + } + else if(process_out->state->s == LTTV_STATE_WAIT_CPU) + { + prop_line_out.color->red = 0x0fff; + prop_line_out.color->green = 0x0fff; + prop_line_out.color->blue = 0x0000; + } + else if(process_out->state->s == LTTV_STATE_EXIT) + { + prop_line_out.color->red = 0xffff; + prop_line_out.color->green = 0x0000; + prop_line_out.color->blue = 0xffff; + } + else if(process_out->state->s == LTTV_STATE_WAIT) + { + prop_line_out.color->red = 0xffff; + prop_line_out.color->green = 0x0000; + prop_line_out.color->blue = 0x0000; + } + else if(process_out->state->s == LTTV_STATE_RUN) + { + prop_line_out.color->red = 0x0000; + prop_line_out.color->green = 0xffff; + prop_line_out.color->blue = 0x0000; + } + else + { + prop_line_out.color->red = 0x0000; + prop_line_out.color->green = 0x0000; + prop_line_out.color->blue = 0x0000; + } + + draw_line((void*)&prop_line_out, (void*)draw_context_out); + g_free(prop_line_out.color); + gdk_gc_unref(draw_context_out->gc); + /* Note : finishing line will have to be added when trace read over. */ + + /* Finally, update the drawing context of the pid_in. */ + + DrawContext *draw_context_in = hashed_process_data_in->draw_context; + draw_context_in->current->modify_over->x = x; + draw_context_in->current->modify_over->y = y_in; + draw_context_in->drawable = control_flow_data->drawing->pixmap; + draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; + widget = control_flow_data->drawing->drawing_area; + //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; + //draw_context_in->gc = widget->style->black_gc; + draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); + gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); + + //draw_arc((void*)&prop_arc, (void*)draw_context_in); + //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); + + GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 }; + GdkColor colorbg_in = { 0, 0xffff, 0xffff, 0xffff }; + PropertiesText prop_text_in; + prop_text_in.foreground = &colorfg_in; + prop_text_in.background = &colorbg_in; + prop_text_in.size = 10; + prop_text_in.position = OVER; + + /* Print status of the process : U, WF, WC, E, W, R */ + if(process_in->state->s == LTTV_STATE_UNNAMED) + prop_text_in.text = "U"; + else if(process_in->state->s == LTTV_STATE_WAIT_FORK) + prop_text_in.text = "WF"; + else if(process_in->state->s == LTTV_STATE_WAIT_CPU) + prop_text_in.text = "WC"; + else if(process_in->state->s == LTTV_STATE_EXIT) + prop_text_in.text = "E"; + else if(process_in->state->s == LTTV_STATE_WAIT) + prop_text_in.text = "W"; + else if(process_in->state->s == LTTV_STATE_RUN) + prop_text_in.text = "R"; + else + prop_text_in.text = "U"; + + draw_text((void*)&prop_text_in, (void*)draw_context_in); + gdk_gc_unref(draw_context_in->gc); + + /* Draw the line of the in process */ + if(draw_context_in->previous->middle->x == -1) + { + draw_context_in->previous->middle->x = event_request->x_begin; + g_critical("in middle x_beg : %u",event_request->x_begin); + } + + draw_context_in->current->middle->x = x; + draw_context_in->previous->middle->y = y_in + height/2; + draw_context_in->current->middle->y = y_in + height/2; + draw_context_in->drawable = control_flow_data->drawing->pixmap; + draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; + //draw_context_in->gc = widget->style->black_gc; + draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); + gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); + + PropertiesLine prop_line_in; + prop_line_in.color = g_new(GdkColor,1); + prop_line_in.line_width = 4; + prop_line_in.style = GDK_LINE_SOLID; + prop_line_in.position = MIDDLE; + + /* color of line : status of the process */ + if(process_in->state->s == LTTV_STATE_UNNAMED) + { + prop_line_in.color->red = 0x0000; + prop_line_in.color->green = 0x0000; + prop_line_in.color->blue = 0x0000; + } + else if(process_in->state->s == LTTV_STATE_WAIT_FORK) + { + prop_line_in.color->red = 0x0fff; + prop_line_in.color->green = 0x0000; + prop_line_in.color->blue = 0x0fff; + } + else if(process_in->state->s == LTTV_STATE_WAIT_CPU) + { + prop_line_in.color->red = 0x0fff; + prop_line_in.color->green = 0x0fff; + prop_line_in.color->blue = 0x0000; + } + else if(process_in->state->s == LTTV_STATE_EXIT) + { + prop_line_in.color->red = 0xffff; + prop_line_in.color->green = 0x0000; + prop_line_in.color->blue = 0xffff; + } + else if(process_in->state->s == LTTV_STATE_WAIT) + { + prop_line_in.color->red = 0xffff; + prop_line_in.color->green = 0x0000; + prop_line_in.color->blue = 0x0000; + } + else if(process_in->state->s == LTTV_STATE_RUN) + { + prop_line_in.color->red = 0x0000; + prop_line_in.color->green = 0xffff; + prop_line_in.color->blue = 0x0000; + } + else + { + prop_line_in.color->red = 0x0000; + prop_line_in.color->green = 0x0000; + prop_line_in.color->blue = 0x0000; + } + + draw_line((void*)&prop_line_in, (void*)draw_context_in); + g_free(prop_line_in.color); + gdk_gc_unref(draw_context_in->gc); + } + + return 0; + + /* Temp dump */ +#ifdef DONTSHOW + GString *string = g_string_new("");; + gboolean field_names = TRUE, state = TRUE; + + lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs); + g_string_append_printf(string,"\n"); + + if(state) { + g_string_append_printf(string, " %s", + g_quark_to_string(tfs->process->state->s)); + } + + g_info("%s",string->str); + + g_string_free(string, TRUE); + + /* End of text dump */ +#endif //DONTSHOW + +} + + +int draw_after_hook(void *hook_data, void *call_data) +{ + EventRequest *event_request = (EventRequest*)hook_data; + ControlFlowData *control_flow_data = event_request->control_flow_data; + + LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; + + LttvTracefileState *tfs = (LttvTracefileState *)call_data; + + + LttEvent *e; + e = tfc->e; + + if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) + { + g_critical("schedchange!"); + + /* Add process to process list (if not present) and get drawing "y" from + * process position */ + guint pid_out, pid_in; + LttvProcessState *process_out, *process_in; + LttTime birth; + guint y_in = 0, y_out = 0, height = 0, pl_height = 0; + + ProcessList *process_list = + guicontrolflow_get_process_list(event_request->control_flow_data); + + + LttField *f = ltt_event_field(e); + LttField *element; + element = ltt_field_member(f,0); + pid_out = ltt_event_get_long_unsigned(e,element); + element = ltt_field_member(f,1); + pid_in = ltt_event_get_long_unsigned(e,element); + g_critical("out : %u in : %u", pid_out, pid_in); + + + /* Find process pid_out in the list... */ + process_out = lttv_state_find_process(tfs, pid_out); + g_critical("out : %s",g_quark_to_string(process_out->state->s)); + + birth = process_out->creation_time; + gchar *name = strdup(g_quark_to_string(process_out->name)); + HashedProcessData *hashed_process_data_out = NULL; + + if(processlist_get_process_pixels(process_list, + pid_out, + &birth, + &y_out, + &height, + &hashed_process_data_out) == 1) + { + /* Process not present */ + processlist_add(process_list, + pid_out, + &birth, + name, + &pl_height, + &hashed_process_data_out); + processlist_get_process_pixels(process_list, + pid_out, + &birth, + &y_out, + &height, + &hashed_process_data_out); + drawing_insert_square( event_request->control_flow_data->drawing, y_out, height); + } + + g_free(name); + + /* Find process pid_in in the list... */ + process_in = lttv_state_find_process(tfs, pid_in); + g_critical("in : %s",g_quark_to_string(process_in->state->s)); + + birth = process_in->creation_time; + name = strdup(g_quark_to_string(process_in->name)); + HashedProcessData *hashed_process_data_in = NULL; + + if(processlist_get_process_pixels(process_list, + pid_in, + &birth, + &y_in, + &height, + &hashed_process_data_in) == 1) + { + /* Process not present */ + processlist_add(process_list, + pid_in, + &birth, + name, + &pl_height, + &hashed_process_data_in); + processlist_get_process_pixels(process_list, + pid_in, + &birth, + &y_in, + &height, + &hashed_process_data_in); + + drawing_insert_square( event_request->control_flow_data->drawing, y_in, height); + } + g_free(name); + + + /* Find pixels corresponding to time of the event. If the time does + * not fit in the window, show a warning, not supposed to happend. */ + //guint x = 0; + //guint width = control_flow_data->drawing->drawing_area->allocation.width; + + //LttTime time = ltt_event_time(e); + + //LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, + // control_flow_data->time_window.start_time); + + + //convert_time_to_pixels( + // control_flow_data->time_window.start_time, + // window_end, + // time, + // width, + // &x); + + //assert(x <= width); + + /* draw what represents the event for outgoing process. */ + + DrawContext *draw_context_out = hashed_process_data_out->draw_context; + //draw_context_out->current->modify_over->x = x; + draw_context_out->current->modify_over->y = y_out; + draw_context_out->drawable = control_flow_data->drawing->pixmap; + draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; + GtkWidget *widget = control_flow_data->drawing->drawing_area; + //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; + draw_context_out->gc = widget->style->black_gc; + + //draw_arc((void*)&prop_arc, (void*)draw_context_out); + //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); + + GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 }; + GdkColor colorbg_out = { 0, 0xffff, 0xffff, 0xffff }; + PropertiesText prop_text_out; + prop_text_out.foreground = &colorfg_out; + prop_text_out.background = &colorbg_out; + prop_text_out.size = 10; + prop_text_out.position = OVER; + + /* Print status of the process : U, WF, WC, E, W, R */ + if(process_out->state->s == LTTV_STATE_UNNAMED) + prop_text_out.text = "U"; + else if(process_out->state->s == LTTV_STATE_WAIT_FORK) + prop_text_out.text = "WF"; + else if(process_out->state->s == LTTV_STATE_WAIT_CPU) + prop_text_out.text = "WC"; + else if(process_out->state->s == LTTV_STATE_EXIT) + prop_text_out.text = "E"; + else if(process_out->state->s == LTTV_STATE_WAIT) + prop_text_out.text = "W"; + else if(process_out->state->s == LTTV_STATE_RUN) + prop_text_out.text = "R"; + else + prop_text_out.text = "U"; + + draw_text((void*)&prop_text_out, (void*)draw_context_out); + + draw_context_out->current->middle->y = y_out+height/2; + draw_context_out->current->status = process_out->state->s; + + /* for pid_out : remove previous, Prev = current, new current (default) */ + g_free(draw_context_out->previous->modify_under); + g_free(draw_context_out->previous->modify_middle); + g_free(draw_context_out->previous->modify_over); + g_free(draw_context_out->previous->under); + g_free(draw_context_out->previous->middle); + g_free(draw_context_out->previous->over); + g_free(draw_context_out->previous); + + draw_context_out->previous = draw_context_out->current; + + draw_context_out->current = g_new(DrawInfo,1); + draw_context_out->current->over = g_new(ItemInfo,1); + draw_context_out->current->over->x = -1; + draw_context_out->current->over->y = -1; + draw_context_out->current->middle = g_new(ItemInfo,1); + draw_context_out->current->middle->x = -1; + draw_context_out->current->middle->y = -1; + draw_context_out->current->under = g_new(ItemInfo,1); + draw_context_out->current->under->x = -1; + draw_context_out->current->under->y = -1; + draw_context_out->current->modify_over = g_new(ItemInfo,1); + draw_context_out->current->modify_over->x = -1; + draw_context_out->current->modify_over->y = -1; + draw_context_out->current->modify_middle = g_new(ItemInfo,1); + draw_context_out->current->modify_middle->x = -1; + draw_context_out->current->modify_middle->y = -1; + draw_context_out->current->modify_under = g_new(ItemInfo,1); + draw_context_out->current->modify_under->x = -1; + draw_context_out->current->modify_under->y = -1; + draw_context_out->current->status = LTTV_STATE_UNNAMED; + + /* Finally, update the drawing context of the pid_in. */ + + DrawContext *draw_context_in = hashed_process_data_in->draw_context; + //draw_context_in->current->modify_over->x = x; + draw_context_in->current->modify_over->y = y_in; + draw_context_in->drawable = control_flow_data->drawing->pixmap; + draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; + widget = control_flow_data->drawing->drawing_area; + //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; + draw_context_in->gc = widget->style->black_gc; + + //draw_arc((void*)&prop_arc, (void*)draw_context_in); + //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); + + GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 }; + GdkColor colorbg_in = { 0, 0xffff, 0xffff, 0xffff }; + PropertiesText prop_text_in; + prop_text_in.foreground = &colorfg_in; + prop_text_in.background = &colorbg_in; + prop_text_in.size = 10; + prop_text_in.position = OVER; + + /* Print status of the process : U, WF, WC, E, W, R */ + if(process_in->state->s == LTTV_STATE_UNNAMED) + prop_text_in.text = "U"; + else if(process_in->state->s == LTTV_STATE_WAIT_FORK) + prop_text_in.text = "WF"; + else if(process_in->state->s == LTTV_STATE_WAIT_CPU) + prop_text_in.text = "WC"; + else if(process_in->state->s == LTTV_STATE_EXIT) + prop_text_in.text = "E"; + else if(process_in->state->s == LTTV_STATE_WAIT) + prop_text_in.text = "W"; + else if(process_in->state->s == LTTV_STATE_RUN) + prop_text_in.text = "R"; + else + prop_text_in.text = "U"; + + draw_text((void*)&prop_text_in, (void*)draw_context_in); + + draw_context_in->current->middle->y = y_in+height/2; + draw_context_in->current->status = process_in->state->s; + + /* for pid_in : remove previous, Prev = current, new current (default) */ + g_free(draw_context_in->previous->modify_under); + g_free(draw_context_in->previous->modify_middle); + g_free(draw_context_in->previous->modify_over); + g_free(draw_context_in->previous->under); + g_free(draw_context_in->previous->middle); + g_free(draw_context_in->previous->over); + g_free(draw_context_in->previous); + + draw_context_in->previous = draw_context_in->current; + + draw_context_in->current = g_new(DrawInfo,1); + draw_context_in->current->over = g_new(ItemInfo,1); + draw_context_in->current->over->x = -1; + draw_context_in->current->over->y = -1; + draw_context_in->current->middle = g_new(ItemInfo,1); + draw_context_in->current->middle->x = -1; + draw_context_in->current->middle->y = -1; + draw_context_in->current->under = g_new(ItemInfo,1); + draw_context_in->current->under->x = -1; + draw_context_in->current->under->y = -1; + draw_context_in->current->modify_over = g_new(ItemInfo,1); + draw_context_in->current->modify_over->x = -1; + draw_context_in->current->modify_over->y = -1; + draw_context_in->current->modify_middle = g_new(ItemInfo,1); + draw_context_in->current->modify_middle->x = -1; + draw_context_in->current->modify_middle->y = -1; + draw_context_in->current->modify_under = g_new(ItemInfo,1); + draw_context_in->current->modify_under->x = -1; + draw_context_in->current->modify_under->y = -1; + draw_context_in->current->status = LTTV_STATE_UNNAMED; + + } + + return 0; +} + + + + +gint update_time_window_hook(void *hook_data, void *call_data) +{ + ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; + TimeWindow *old_time_window = + guicontrolflow_get_time_window(control_flow_data); + TimeWindow *new_time_window = ((TimeWindow*)call_data); + + /* Two cases : zoom in/out or scrolling */ + + /* In order to make sure we can reuse the old drawing, the scale must + * be the same and the new time interval being partly located in the + * currently shown time interval. (reuse is only for scrolling) + */ + + g_info("Old time window HOOK : %u, %u to %u, %u", + old_time_window->start_time.tv_sec, + old_time_window->start_time.tv_nsec, + old_time_window->time_width.tv_sec, + old_time_window->time_width.tv_nsec); + + g_info("New time window HOOK : %u, %u to %u, %u", + new_time_window->start_time.tv_sec, + new_time_window->start_time.tv_nsec, + new_time_window->time_width.tv_sec, + new_time_window->time_width.tv_nsec); + + if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec + && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec) + { + /* Same scale (scrolling) */ + g_info("scrolling"); + LttTime *ns = &new_time_window->start_time; + LttTime *os = &old_time_window->start_time; + LttTime old_end = ltt_time_add(old_time_window->start_time, + old_time_window->time_width); + LttTime new_end = ltt_time_add(new_time_window->start_time, + new_time_window->time_width); + //if(nsdrawing->drawing_area->allocation.width; + convert_time_to_pixels( + *os, + old_end, + *ns, + width, + &x); + + /* Copy old data to new location */ + gdk_draw_drawable (control_flow_data->drawing->pixmap, + control_flow_data->drawing->drawing_area->style->white_gc, + control_flow_data->drawing->pixmap, + x, 0, + 0, 0, + -1, -1); + + convert_time_to_pixels( + *ns, + new_end, + old_end, + width, + &x); + + *old_time_window = *new_time_window; + /* Clear the data request background, but not SAFETY */ + gdk_draw_rectangle (control_flow_data->drawing->pixmap, + control_flow_data->drawing->drawing_area->style->white_gc, + TRUE, + x+SAFETY, 0, + control_flow_data->drawing->width - x, // do not overlap + control_flow_data->drawing->height+SAFETY); + /* Get new data for the rest. */ + drawing_data_request(control_flow_data->drawing, + &control_flow_data->drawing->pixmap, + x, 0, + control_flow_data->drawing->width - x, + control_flow_data->drawing->height); + + drawing_refresh(control_flow_data->drawing, + 0, 0, + control_flow_data->drawing->width, + control_flow_data->drawing->height); + + + } else { + //if(nsdrawing->drawing_area->allocation.width; + convert_time_to_pixels( + *ns, + new_end, + *os, + width, + &x); + + /* Copy old data to new location */ + gdk_draw_drawable (control_flow_data->drawing->pixmap, + control_flow_data->drawing->drawing_area->style->white_gc, + control_flow_data->drawing->pixmap, + 0, 0, + x, 0, + -1, -1); + + *old_time_window = *new_time_window; + + /* Clean the data request background */ + gdk_draw_rectangle (control_flow_data->drawing->pixmap, + control_flow_data->drawing->drawing_area->style->white_gc, + TRUE, + 0, 0, + x, // do not overlap + control_flow_data->drawing->height+SAFETY); + /* Get new data for the rest. */ + drawing_data_request(control_flow_data->drawing, + &control_flow_data->drawing->pixmap, + 0, 0, + x, + control_flow_data->drawing->height); + + drawing_refresh(control_flow_data->drawing, + 0, 0, + control_flow_data->drawing->width, + control_flow_data->drawing->height); + + } else { + g_info("scrolling far"); + /* Cannot reuse any part of the screen : far jump */ + *old_time_window = *new_time_window; + + + gdk_draw_rectangle (control_flow_data->drawing->pixmap, + control_flow_data->drawing->drawing_area->style->white_gc, + TRUE, + 0, 0, + control_flow_data->drawing->width+SAFETY, // do not overlap + control_flow_data->drawing->height+SAFETY); + + drawing_data_request(control_flow_data->drawing, + &control_flow_data->drawing->pixmap, + 0, 0, + control_flow_data->drawing->width, + control_flow_data->drawing->height); + + drawing_refresh(control_flow_data->drawing, + 0, 0, + control_flow_data->drawing->width, + control_flow_data->drawing->height); + } + } + } else { + /* Different scale (zoom) */ + g_info("zoom"); + + *old_time_window = *new_time_window; + + gdk_draw_rectangle (control_flow_data->drawing->pixmap, + control_flow_data->drawing->drawing_area->style->white_gc, + TRUE, + 0, 0, + control_flow_data->drawing->width+SAFETY, // do not overlap + control_flow_data->drawing->height+SAFETY); + + + drawing_data_request(control_flow_data->drawing, + &control_flow_data->drawing->pixmap, + 0, 0, + control_flow_data->drawing->width, + control_flow_data->drawing->height); + + drawing_refresh(control_flow_data->drawing, + 0, 0, + control_flow_data->drawing->width, + control_flow_data->drawing->height); + } + + return 0; +} + +gint update_current_time_hook(void *hook_data, void *call_data) +{ + ControlFlowData *control_flow_data = (ControlFlowData*)hook_data; + + LttTime* current_time = + guicontrolflow_get_current_time(control_flow_data); + *current_time = *((LttTime*)call_data); + + TimeWindow time_window; + + LttTime time_begin = control_flow_data->time_window.start_time; + LttTime width = control_flow_data->time_window.time_width; + LttTime half_width = ltt_time_div(width,2.0); + LttTime time_end = ltt_time_add(time_begin, width); + + LttvTracesetContext * tsc = + get_traceset_context(control_flow_data->mw); + + LttTime trace_start = tsc->Time_Span->startTime; + LttTime trace_end = tsc->Time_Span->endTime; + + g_info("New current time HOOK : %u, %u", current_time->tv_sec, + current_time->tv_nsec); + + + + /* If current time is inside time interval, just move the highlight + * bar */ + + /* Else, we have to change the time interval. We have to tell it + * to the main window. */ + /* The time interval change will take care of placing the current + * time at the center of the visible area, or nearest possible if we are + * at one end of the trace. */ + + + if(ltt_time_compare(*current_time, time_begin) == -1) + { + if(ltt_time_compare(*current_time, + ltt_time_add(trace_start,half_width)) == -1) + time_begin = trace_start; + else + time_begin = ltt_time_sub(*current_time,half_width); + + time_window.start_time = time_begin; + time_window.time_width = width; + + set_time_window(control_flow_data->mw, &time_window); + } + else if(ltt_time_compare(*current_time, time_end) == 1) + { + if(ltt_time_compare(*current_time, ltt_time_sub(trace_end, half_width)) == 1) + time_begin = ltt_time_sub(trace_end,width); + else + time_begin = ltt_time_sub(*current_time,half_width); + + time_window.start_time = time_begin; + time_window.time_width = width; + + set_time_window(control_flow_data->mw, &time_window); + + } + gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); + + return 0; +} + +typedef struct _ClosureData { + EventRequest *event_request; + LttvTraceState *ts; +} ClosureData; + + +void draw_closure(gpointer key, gpointer value, gpointer user_data) +{ + ProcessInfo *process_info = (ProcessInfo*)key; + HashedProcessData *hashed_process_data = (HashedProcessData*)value; + ClosureData *closure_data = (ClosureData*)user_data; + + ControlFlowData *control_flow_data = + closure_data->event_request->control_flow_data; + + GtkWidget *widget = control_flow_data->drawing->drawing_area; + + /* Get y position of process */ + gint y=0, height=0; + + processlist_get_pixels_from_data( control_flow_data->process_list, + process_info, + hashed_process_data, + &y, + &height); + /* Get last state of process */ + LttvTraceContext *tc = + (LttvTraceContext *)closure_data->ts; + + LttvTraceState *ts = closure_data->ts; + LttvProcessState *process; + + process = lttv_state_find_process((LttvTracefileState*)ts, process_info->pid); + + /* Draw the closing line */ + DrawContext *draw_context = hashed_process_data->draw_context; + if(draw_context->previous->middle->x == -1) + { + draw_context->previous->middle->x = closure_data->event_request->x_begin; + g_critical("out middle x_beg : %u",closure_data->event_request->x_begin); + } + + draw_context->current->middle->x = closure_data->event_request->x_end; + draw_context->current->middle->y = y + height/2; + draw_context->previous->middle->y = y + height/2; + draw_context->drawable = control_flow_data->drawing->pixmap; + draw_context->pango_layout = control_flow_data->drawing->pango_layout; + //draw_context->gc = widget->style->black_gc; + draw_context->gc = gdk_gc_new(control_flow_data->drawing->pixmap); + gdk_gc_copy(draw_context->gc, widget->style->black_gc); + + PropertiesLine prop_line; + prop_line.color = g_new(GdkColor,1); + prop_line.line_width = 6; + prop_line.style = GDK_LINE_SOLID; + prop_line.position = MIDDLE; + + /* color of line : status of the process */ + if(process->state->s == LTTV_STATE_UNNAMED) + { + prop_line.color->red = 0x0000; + prop_line.color->green = 0x0000; + prop_line.color->blue = 0x0000; + } + else if(process->state->s == LTTV_STATE_WAIT_FORK) + { + prop_line.color->red = 0x0fff; + prop_line.color->green = 0x0000; + prop_line.color->blue = 0x0fff; + } + else if(process->state->s == LTTV_STATE_WAIT_CPU) + { + prop_line.color->red = 0x0fff; + prop_line.color->green = 0x0fff; + prop_line.color->blue = 0x0000; + } + else if(process->state->s == LTTV_STATE_EXIT) + { + prop_line.color->red = 0xffff; + prop_line.color->green = 0x0000; + prop_line.color->blue = 0xffff; + } + else if(process->state->s == LTTV_STATE_WAIT) + { + prop_line.color->red = 0xffff; + prop_line.color->green = 0x0000; + prop_line.color->blue = 0x0000; + } + else if(process->state->s == LTTV_STATE_RUN) + { + prop_line.color->red = 0x0000; + prop_line.color->green = 0xffff; + prop_line.color->blue = 0x0000; + } + else + { + prop_line.color->red = 0x0000; + prop_line.color->green = 0x0000; + prop_line.color->blue = 0x0000; + } + + draw_line((void*)&prop_line, (void*)draw_context); + g_free(prop_line.color); + gdk_gc_unref(draw_context->gc); + + /* Reset draw_context of the process for next request */ + + hashed_process_data->draw_context->drawable = NULL; + hashed_process_data->draw_context->gc = NULL; + hashed_process_data->draw_context->pango_layout = NULL; + hashed_process_data->draw_context->current->over->x = -1; + hashed_process_data->draw_context->current->over->y = -1; + hashed_process_data->draw_context->current->middle->x = -1; + hashed_process_data->draw_context->current->middle->y = -1; + hashed_process_data->draw_context->current->under->x = -1; + hashed_process_data->draw_context->current->under->y = -1; + hashed_process_data->draw_context->current->modify_over->x = -1; + hashed_process_data->draw_context->current->modify_over->y = -1; + hashed_process_data->draw_context->current->modify_middle->x = -1; + hashed_process_data->draw_context->current->modify_middle->y = -1; + hashed_process_data->draw_context->current->modify_under->x = -1; + hashed_process_data->draw_context->current->modify_under->y = -1; + hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED; + hashed_process_data->draw_context->previous->over->x = -1; + hashed_process_data->draw_context->previous->over->y = -1; + hashed_process_data->draw_context->previous->middle->x = -1; + hashed_process_data->draw_context->previous->middle->y = -1; + hashed_process_data->draw_context->previous->under->x = -1; + hashed_process_data->draw_context->previous->under->y = -1; + hashed_process_data->draw_context->previous->modify_over->x = -1; + hashed_process_data->draw_context->previous->modify_over->y = -1; + hashed_process_data->draw_context->previous->modify_middle->x = -1; + hashed_process_data->draw_context->previous->modify_middle->y = -1; + hashed_process_data->draw_context->previous->modify_under->x = -1; + hashed_process_data->draw_context->previous->modify_under->y = -1; + hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED; + + +} + +/* + * for each process + * draw closing line + * new default prev and current + */ +int after_data_request(void *hook_data, void *call_data) +{ + EventRequest *event_request = (EventRequest*)hook_data; + ControlFlowData *control_flow_data = event_request->control_flow_data; + + ProcessList *process_list = + guicontrolflow_get_process_list(event_request->control_flow_data); + + ClosureData closure_data; + closure_data.event_request = (EventRequest*)hook_data; + closure_data.ts = (LttvTraceState*)call_data; + + g_hash_table_foreach(process_list->process_hash, draw_closure, + (void*)&closure_data); + +} + diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/eventhooks.h b/ltt/branches/poly/lttv/modules/gui/ControlFlow/eventhooks.h new file mode 100644 index 00000000..d9f35605 --- /dev/null +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/eventhooks.h @@ -0,0 +1,85 @@ +/* eventhooks.c defines the hooks that are given to processTrace as parameter. + * These hooks call the drawing API to draw the information on the screen, + * using information from Context, but mostly state (running, waiting...). + */ + + +#ifndef _EVENT_HOOKS_H +#define _EVENT_HOOKS_H + +#include +#include +#include + +#include "processlist.h" +#include "drawing.h" +#include "cfv.h" + + +/* Structure used to store and use information relative to one events refresh + * request. Typically filled in by the expose event callback, then passed to the + * library call, then used by the drawing hooks. Then, once all the events are + * sent, it is freed by the hook called after the reading. + */ +typedef struct _EventRequest +{ + ControlFlowData *control_flow_data; + LttTime time_begin, time_end; + gint x_begin, x_end; + /* Fill the Events_Context during the initial expose, before calling for + * events. + */ + //GArray Events_Context; //FIXME +} EventRequest ; + + + + + +void send_test_data(ProcessList *process_list, Drawing_t *drawing); + +GtkWidget *h_guicontrolflow(MainWindow *mw, LttvTracesetSelector * s, char * key); + +int event_selected_hook(void *hook_data, void *call_data); + +/* Hook called before drawing. Gets the initial context at the beginning of the + * drawing interval and copy it to the context in event_request. + */ +int draw_before_hook(void *hook_data, void *call_data); + +/* + * The draw event hook is called by the reading API to have a + * particular event drawn on the screen. + * @param hook_data ControlFlowData structure of the viewer. + * @param call_data Event context. + * + * This function basically draw lines and icons. Two types of lines are drawn : + * one small (3 pixels?) representing the state of the process and the second + * type is thicker (10 pixels?) representing on which CPU a process is running + * (and this only in running state). + * + * Extremums of the lines : + * x_min : time of the last event context for this process kept in memory. + * x_max : time of the current event. + * y : middle of the process in the process list. The process is found in the + * list, therefore is it's position in pixels. + * + * The choice of lines'color is defined by the context of the last event for this + * process. + */ +int draw_event_hook(void *hook_data, void *call_data); + +int draw_after_hook(void *hook_data, void *call_data); + +void draw_closure(gpointer key, gpointer value, gpointer user_data); + +int after_data_request(void *hook_data, void *call_data); + + +gint update_time_window_hook(void *hook_data, void *call_data); +gint update_current_time_hook(void *hook_data, void *call_data); + + + + +#endif // _EVENT_HOOKS_H diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/module.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/module.c index 216688fb..aec5aab0 100644 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/module.c +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/module.c @@ -25,10 +25,10 @@ #include #include -#include "CFV.h" -#include "Event_Hooks.h" +#include "cfv.h" +#include "eventhooks.h" - #include "../icons/hGuiControlFlowInsert.xpm" +#include "../icons/hGuiControlFlowInsert.xpm" static LttvModule *Main_Win_Module; diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/process-list.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/process-list.c deleted file mode 100644 index c695fb15..00000000 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/process-list.c +++ /dev/null @@ -1,510 +0,0 @@ - -#include -#include -#include "Process_List.h" -#include "Draw_Item.h" - -/***************************************************************************** - * Methods to synchronize process list * - *****************************************************************************/ - -/* Enumeration of the columns */ -enum -{ - PROCESS_COLUMN, - PID_COLUMN, - BIRTH_S_COLUMN, - BIRTH_NS_COLUMN, - N_COLUMNS -}; - - -gint process_sort_func ( GtkTreeModel *model, - GtkTreeIter *it_a, - GtkTreeIter *it_b, - gpointer user_data) -{ - GValue a, b; - - memset(&a, 0, sizeof(GValue)); - memset(&b, 0, sizeof(GValue)); - - /* Order by PID */ - gtk_tree_model_get_value( model, - it_a, - PID_COLUMN, - &a); - - gtk_tree_model_get_value( model, - it_b, - PID_COLUMN, - &b); - - if(G_VALUE_TYPE(&a) == G_TYPE_UINT - && G_VALUE_TYPE(&b) == G_TYPE_UINT ) - { - if(g_value_get_uint(&a) > g_value_get_uint(&b)) - { - g_value_unset(&a); - g_value_unset(&b); - return 1; - } - if(g_value_get_uint(&a) < g_value_get_uint(&b)) - { - g_value_unset(&a); - g_value_unset(&b); - return 0; - } - } - - g_value_unset(&a); - g_value_unset(&b); - - - /* Order by birth second */ - gtk_tree_model_get_value( model, - it_a, - BIRTH_S_COLUMN, - &a); - - gtk_tree_model_get_value( model, - it_b, - BIRTH_S_COLUMN, - &b); - - - if(G_VALUE_TYPE(&a) == G_TYPE_ULONG - && G_VALUE_TYPE(&b) == G_TYPE_ULONG ) - { - if(g_value_get_ulong(&a) > g_value_get_ulong(&b)) - { - g_value_unset(&a); - g_value_unset(&b); - return 1; - } - if(g_value_get_ulong(&a) < g_value_get_ulong(&b)) - { - g_value_unset(&a); - g_value_unset(&b); - return 0; - } - - } - - g_value_unset(&a); - g_value_unset(&b); - - /* Order by birth nanosecond */ - gtk_tree_model_get_value( model, - it_a, - BIRTH_NS_COLUMN, - &a); - - gtk_tree_model_get_value( model, - it_b, - BIRTH_NS_COLUMN, - &b); - - - if(G_VALUE_TYPE(&a) == G_TYPE_ULONG - && G_VALUE_TYPE(&b) == G_TYPE_ULONG ) - { - if(g_value_get_ulong(&a) > g_value_get_ulong(&b)) - { - g_value_unset(&a); - g_value_unset(&b); - return 1; - } - // Final condition - //if(g_value_get_ulong(&a) < g_value_get_ulong(&b)) - //{ - // g_value_unset(&a); - // g_value_unset(&b); - // return 0; - //} - - } - - g_value_unset(&a); - g_value_unset(&b); - - return 0; - -} - -guint hash_fct(gconstpointer key) -{ - return ((ProcessInfo*)key)->pid; -} - -gboolean equ_fct(gconstpointer a, gconstpointer b) -{ - if(((ProcessInfo*)a)->pid != ((ProcessInfo*)b)->pid) - return 0; -// g_critical("compare %u and %u",((ProcessInfo*)a)->pid,((ProcessInfo*)b)->pid); - if(((ProcessInfo*)a)->birth.tv_sec != ((ProcessInfo*)b)->birth.tv_sec) - return 0; -// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec); - - if(((ProcessInfo*)a)->birth.tv_nsec != ((ProcessInfo*)b)->birth.tv_nsec) - return 0; -// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec); - - return 1; -} - -void destroy_hash_key(gpointer key); - -void destroy_hash_data(gpointer data); - - - - -ProcessList *processlist_construct(void) -{ - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - - ProcessList* process_list = g_new(ProcessList,1); - - process_list->number_of_process = 0; - - /* Create the Process list */ - process_list->list_store = gtk_list_store_new ( N_COLUMNS, - G_TYPE_STRING, - G_TYPE_UINT, - G_TYPE_ULONG, - G_TYPE_ULONG); - - - process_list->process_list_widget = - gtk_tree_view_new_with_model - (GTK_TREE_MODEL (process_list->list_store)); - - g_object_unref (G_OBJECT (process_list->list_store)); - - gtk_tree_sortable_set_sort_func( - GTK_TREE_SORTABLE(process_list->list_store), - PID_COLUMN, - process_sort_func, - NULL, - NULL); - - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(process_list->list_store), - PID_COLUMN, - GTK_SORT_ASCENDING); - - process_list->process_hash = g_hash_table_new_full( - hash_fct, equ_fct, - destroy_hash_key, destroy_hash_data - ); - - - gtk_tree_view_set_headers_visible( - GTK_TREE_VIEW(process_list->process_list_widget), FALSE); - - /* Create a column, associating the "text" attribute of the - * cell_renderer to the first column of the model */ - /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */ - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ( "Process", - renderer, - "text", - PROCESS_COLUMN, - NULL); - gtk_tree_view_column_set_alignment (column, 0.0); - gtk_tree_view_column_set_fixed_width (column, 45); - gtk_tree_view_append_column ( - GTK_TREE_VIEW (process_list->process_list_widget), column); - - column = gtk_tree_view_column_new_with_attributes ( "PID", - renderer, - "text", - PID_COLUMN, - NULL); - gtk_tree_view_append_column ( - GTK_TREE_VIEW (process_list->process_list_widget), column); - - - column = gtk_tree_view_column_new_with_attributes ( "Birth sec", - renderer, - "text", - BIRTH_S_COLUMN, - NULL); - gtk_tree_view_append_column ( - GTK_TREE_VIEW (process_list->process_list_widget), column); - - //gtk_tree_view_column_set_visible(column, 0); - // - column = gtk_tree_view_column_new_with_attributes ( "Birth nsec", - renderer, - "text", - BIRTH_NS_COLUMN, - NULL); - gtk_tree_view_append_column ( - GTK_TREE_VIEW (process_list->process_list_widget), column); - - //gtk_tree_view_column_set_visible(column, 0); - - g_object_set_data_full( - G_OBJECT(process_list->process_list_widget), - "process_list_Data", - process_list, - (GDestroyNotify)processlist_destroy); - - return process_list; -} -void processlist_destroy(ProcessList *process_list) -{ - g_hash_table_destroy(process_list->process_hash); - process_list->process_hash = NULL; - - g_free(process_list); -} - -GtkWidget *processlist_get_widget(ProcessList *process_list) -{ - return process_list->process_list_widget; -} - - - -gint get_cell_height(GtkTreeView *tree_view) -{ - gint height; - GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0); - //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column); - //GtkCellRenderer *Renderer = g_list_first(Render_List)->data; - - //g_list_free(Render_List); - gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, &height); - //g_critical("cell 0 height : %u",height); - - return height; -} - -void destroy_hash_key(gpointer key) -{ - g_free(key); -} - -void destroy_hash_data(gpointer data) -{ - g_free(data); -} - -int processlist_add( ProcessList *process_list, - guint pid, - LttTime *birth, - gchar *name, - guint *height, - HashedProcessData **pm_hashed_process_data) -{ - GtkTreeIter iter ; - ProcessInfo *Process_Info = g_new(ProcessInfo, 1); - HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1); - *pm_hashed_process_data = hashed_process_data; - - Process_Info->pid = pid; - Process_Info->birth = *birth; - - hashed_process_data->draw_context = g_new(DrawContext, 1); - hashed_process_data->draw_context->drawable = NULL; - hashed_process_data->draw_context->gc = NULL; - hashed_process_data->draw_context->pango_layout = NULL; - hashed_process_data->draw_context->current = g_new(DrawInfo,1); - hashed_process_data->draw_context->current->over = g_new(ItemInfo,1); - hashed_process_data->draw_context->current->over->x = -1; - hashed_process_data->draw_context->current->over->y = -1; - hashed_process_data->draw_context->current->middle = g_new(ItemInfo,1); - hashed_process_data->draw_context->current->middle->x = -1; - hashed_process_data->draw_context->current->middle->y = -1; - hashed_process_data->draw_context->current->under = g_new(ItemInfo,1); - hashed_process_data->draw_context->current->under->x = -1; - hashed_process_data->draw_context->current->under->y = -1; - hashed_process_data->draw_context->current->modify_over = g_new(ItemInfo,1); - hashed_process_data->draw_context->current->modify_over->x = -1; - hashed_process_data->draw_context->current->modify_over->y = -1; - hashed_process_data->draw_context->current->modify_middle = g_new(ItemInfo,1); - hashed_process_data->draw_context->current->modify_middle->x = -1; - hashed_process_data->draw_context->current->modify_middle->y = -1; - hashed_process_data->draw_context->current->modify_under = g_new(ItemInfo,1); - hashed_process_data->draw_context->current->modify_under->x = -1; - hashed_process_data->draw_context->current->modify_under->y = -1; - hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED; - hashed_process_data->draw_context->previous = g_new(DrawInfo,1); - hashed_process_data->draw_context->previous->over = g_new(ItemInfo,1); - hashed_process_data->draw_context->previous->over->x = -1; - hashed_process_data->draw_context->previous->over->y = -1; - hashed_process_data->draw_context->previous->middle = g_new(ItemInfo,1); - hashed_process_data->draw_context->previous->middle->x = -1; - hashed_process_data->draw_context->previous->middle->y = -1; - hashed_process_data->draw_context->previous->under = g_new(ItemInfo,1); - hashed_process_data->draw_context->previous->under->x = -1; - hashed_process_data->draw_context->previous->under->y = -1; - hashed_process_data->draw_context->previous->modify_over = g_new(ItemInfo,1); - hashed_process_data->draw_context->previous->modify_over->x = -1; - hashed_process_data->draw_context->previous->modify_over->y = -1; - hashed_process_data->draw_context->previous->modify_middle = g_new(ItemInfo,1); - hashed_process_data->draw_context->previous->modify_middle->x = -1; - hashed_process_data->draw_context->previous->modify_middle->y = -1; - hashed_process_data->draw_context->previous->modify_under = g_new(ItemInfo,1); - hashed_process_data->draw_context->previous->modify_under->x = -1; - hashed_process_data->draw_context->previous->modify_under->y = -1; - hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED; - - /* Add a new row to the model */ - gtk_list_store_append ( process_list->list_store, &iter); - //g_critical ( "iter before : %s", gtk_tree_path_to_string ( - // gtk_tree_model_get_path ( - // GTK_TREE_MODEL(process_list->list_store), - // &iter))); - gtk_list_store_set ( process_list->list_store, &iter, - PROCESS_COLUMN, name, - PID_COLUMN, pid, - BIRTH_S_COLUMN, birth->tv_sec, - BIRTH_NS_COLUMN, birth->tv_nsec, - -1); - hashed_process_data->row_ref = gtk_tree_row_reference_new ( - GTK_TREE_MODEL(process_list->list_store), - gtk_tree_model_get_path( - GTK_TREE_MODEL(process_list->list_store), - &iter)); - g_hash_table_insert( process_list->process_hash, - (gpointer)Process_Info, - (gpointer)hashed_process_data); - - //g_critical ( "iter after : %s", gtk_tree_path_to_string ( - // gtk_tree_model_get_path ( - // GTK_TREE_MODEL(process_list->list_store), - // &iter))); - process_list->number_of_process++; - - *height = get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget)) - * process_list->number_of_process ; - - - return 0; - -} - -int processlist_remove( ProcessList *process_list, - guint pid, - LttTime *birth) -{ - ProcessInfo Process_Info; - gint *path_indices; - HashedProcessData *hashed_process_data; - GtkTreeIter iter; - - Process_Info.pid = pid; - Process_Info.birth = *birth; - - - if(hashed_process_data = - (HashedProcessData*)g_hash_table_lookup( - process_list->process_hash, - &Process_Info)) - { - gtk_tree_model_get_iter ( - GTK_TREE_MODEL(process_list->list_store), - &iter, - gtk_tree_row_reference_get_path( - (GtkTreeRowReference*)hashed_process_data->row_ref) - ); - - gtk_list_store_remove (process_list->list_store, &iter); - - g_free(hashed_process_data->draw_context->previous->modify_under); - g_free(hashed_process_data->draw_context->previous->modify_middle); - g_free(hashed_process_data->draw_context->previous->modify_over); - g_free(hashed_process_data->draw_context->previous->under); - g_free(hashed_process_data->draw_context->previous->middle); - g_free(hashed_process_data->draw_context->previous->over); - g_free(hashed_process_data->draw_context->previous); - g_free(hashed_process_data->draw_context->current->modify_under); - g_free(hashed_process_data->draw_context->current->modify_middle); - g_free(hashed_process_data->draw_context->current->modify_over); - g_free(hashed_process_data->draw_context->current->under); - g_free(hashed_process_data->draw_context->current->middle); - g_free(hashed_process_data->draw_context->current->over); - g_free(hashed_process_data->draw_context->current); - g_free(hashed_process_data->draw_context); - g_free(hashed_process_data); - - g_hash_table_remove(process_list->process_hash, - &Process_Info); - - process_list->number_of_process--; - - return 0; - } else { - return 1; - } -} - - -guint processlist_get_height(ProcessList *process_list) -{ - return get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget)) - * process_list->number_of_process ; -} - - -gint processlist_get_process_pixels( ProcessList *process_list, - guint pid, LttTime *birth, - guint *y, - guint *height, - HashedProcessData **pm_hashed_process_data) -{ - ProcessInfo Process_Info; - gint *path_indices; - GtkTreePath *tree_path; - HashedProcessData *hashed_process_data = NULL; - - Process_Info.pid = pid; - Process_Info.birth = *birth; - - if(hashed_process_data = - (HashedProcessData*)g_hash_table_lookup( - process_list->process_hash, - &Process_Info)) - { - tree_path = gtk_tree_row_reference_get_path( - hashed_process_data->row_ref); - path_indices = gtk_tree_path_get_indices (tree_path); - - *height = get_cell_height( - GTK_TREE_VIEW(process_list->process_list_widget)); - *y = *height * path_indices[0]; - *pm_hashed_process_data = hashed_process_data; - return 0; - } else { - *pm_hashed_process_data = hashed_process_data; - return 1; - } - -} - - -gint processlist_get_pixels_from_data( ProcessList *process_list, - ProcessInfo *process_info, - HashedProcessData *hashed_process_data, - guint *y, - guint *height) -{ - gint *path_indices; - GtkTreePath *tree_path; - - tree_path = gtk_tree_row_reference_get_path( - hashed_process_data->row_ref); - path_indices = gtk_tree_path_get_indices (tree_path); - - *height = get_cell_height( - GTK_TREE_VIEW(process_list->process_list_widget)); - *y = *height * path_indices[0]; - - return 0; - -} diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/process-list.h b/ltt/branches/poly/lttv/modules/gui/ControlFlow/process-list.h deleted file mode 100644 index d3272160..00000000 --- a/ltt/branches/poly/lttv/modules/gui/ControlFlow/process-list.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef _PROCESS_LIST_H -#define _PROCESS_LIST_H - -#include -#include -#include -#include "Draw_Item.h" - -/* The process list - * - * Tasks : - * Create a process list - * contains the data for the process list - * tells the height of the process list widget - * provides methods to add/remove process from the list - * note : the sync with drawing is left to the caller. - * provides helper function to convert a process unique identifier to - * pixels (in height). - * - * //FIXME : connect the scrolled window adjustment with the list. - */ - -typedef struct _ProcessInfo { - - guint pid; - LttTime birth; - -} ProcessInfo; - -typedef struct _HashedProcessData { - - GtkTreeRowReference *row_ref; - DrawContext *draw_context; - -} HashedProcessData; - -struct _ProcessList { - - GtkWidget *process_list_widget; - GtkListStore *list_store; - - /* A hash table by PID to speed up process position find in the list */ - GHashTable *process_hash; - - guint number_of_process; -}; - - -typedef struct _ProcessList ProcessList; - -ProcessList *processlist_construct(void); -void processlist_destroy(ProcessList *process_list); -GtkWidget *processlist_get_widget(ProcessList *process_list); - -// out : success (0) and height -int processlist_add(ProcessList *process_list, guint pid, LttTime *birth, - gchar *name, guint *height, HashedProcessData **hashed_process_data); -// out : success (0) and height -int processlist_remove(ProcessList *process_list, guint pid, LttTime *birth); - -guint processlist_get_height(ProcessList *process_list); - -// Returns 0 on success -gint processlist_get_process_pixels(ProcessList *process_list, - guint pid, LttTime *birth, - guint *y, guint *height, - HashedProcessData **hashed_process_data); - -gint processlist_get_pixels_from_data( ProcessList *process_list, - ProcessInfo *process_info, - HashedProcessData *hashed_process_data, - guint *y, - guint *height); - -#endif // _PROCESS_LIST_H diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/processlist.c b/ltt/branches/poly/lttv/modules/gui/ControlFlow/processlist.c new file mode 100644 index 00000000..a1d03ac3 --- /dev/null +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/processlist.c @@ -0,0 +1,511 @@ + +#include +#include + +#include "processlist.h" +#include "drawitem.h" + +/***************************************************************************** + * Methods to synchronize process list * + *****************************************************************************/ + +/* Enumeration of the columns */ +enum +{ + PROCESS_COLUMN, + PID_COLUMN, + BIRTH_S_COLUMN, + BIRTH_NS_COLUMN, + N_COLUMNS +}; + + +gint process_sort_func ( GtkTreeModel *model, + GtkTreeIter *it_a, + GtkTreeIter *it_b, + gpointer user_data) +{ + GValue a, b; + + memset(&a, 0, sizeof(GValue)); + memset(&b, 0, sizeof(GValue)); + + /* Order by PID */ + gtk_tree_model_get_value( model, + it_a, + PID_COLUMN, + &a); + + gtk_tree_model_get_value( model, + it_b, + PID_COLUMN, + &b); + + if(G_VALUE_TYPE(&a) == G_TYPE_UINT + && G_VALUE_TYPE(&b) == G_TYPE_UINT ) + { + if(g_value_get_uint(&a) > g_value_get_uint(&b)) + { + g_value_unset(&a); + g_value_unset(&b); + return 1; + } + if(g_value_get_uint(&a) < g_value_get_uint(&b)) + { + g_value_unset(&a); + g_value_unset(&b); + return 0; + } + } + + g_value_unset(&a); + g_value_unset(&b); + + + /* Order by birth second */ + gtk_tree_model_get_value( model, + it_a, + BIRTH_S_COLUMN, + &a); + + gtk_tree_model_get_value( model, + it_b, + BIRTH_S_COLUMN, + &b); + + + if(G_VALUE_TYPE(&a) == G_TYPE_ULONG + && G_VALUE_TYPE(&b) == G_TYPE_ULONG ) + { + if(g_value_get_ulong(&a) > g_value_get_ulong(&b)) + { + g_value_unset(&a); + g_value_unset(&b); + return 1; + } + if(g_value_get_ulong(&a) < g_value_get_ulong(&b)) + { + g_value_unset(&a); + g_value_unset(&b); + return 0; + } + + } + + g_value_unset(&a); + g_value_unset(&b); + + /* Order by birth nanosecond */ + gtk_tree_model_get_value( model, + it_a, + BIRTH_NS_COLUMN, + &a); + + gtk_tree_model_get_value( model, + it_b, + BIRTH_NS_COLUMN, + &b); + + + if(G_VALUE_TYPE(&a) == G_TYPE_ULONG + && G_VALUE_TYPE(&b) == G_TYPE_ULONG ) + { + if(g_value_get_ulong(&a) > g_value_get_ulong(&b)) + { + g_value_unset(&a); + g_value_unset(&b); + return 1; + } + // Final condition + //if(g_value_get_ulong(&a) < g_value_get_ulong(&b)) + //{ + // g_value_unset(&a); + // g_value_unset(&b); + // return 0; + //} + + } + + g_value_unset(&a); + g_value_unset(&b); + + return 0; + +} + +guint hash_fct(gconstpointer key) +{ + return ((ProcessInfo*)key)->pid; +} + +gboolean equ_fct(gconstpointer a, gconstpointer b) +{ + if(((ProcessInfo*)a)->pid != ((ProcessInfo*)b)->pid) + return 0; +// g_critical("compare %u and %u",((ProcessInfo*)a)->pid,((ProcessInfo*)b)->pid); + if(((ProcessInfo*)a)->birth.tv_sec != ((ProcessInfo*)b)->birth.tv_sec) + return 0; +// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec); + + if(((ProcessInfo*)a)->birth.tv_nsec != ((ProcessInfo*)b)->birth.tv_nsec) + return 0; +// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec); + + return 1; +} + +void destroy_hash_key(gpointer key); + +void destroy_hash_data(gpointer data); + + + + +ProcessList *processlist_construct(void) +{ + GtkTreeViewColumn *column; + GtkCellRenderer *renderer; + + ProcessList* process_list = g_new(ProcessList,1); + + process_list->number_of_process = 0; + + /* Create the Process list */ + process_list->list_store = gtk_list_store_new ( N_COLUMNS, + G_TYPE_STRING, + G_TYPE_UINT, + G_TYPE_ULONG, + G_TYPE_ULONG); + + + process_list->process_list_widget = + gtk_tree_view_new_with_model + (GTK_TREE_MODEL (process_list->list_store)); + + g_object_unref (G_OBJECT (process_list->list_store)); + + gtk_tree_sortable_set_sort_func( + GTK_TREE_SORTABLE(process_list->list_store), + PID_COLUMN, + process_sort_func, + NULL, + NULL); + + gtk_tree_sortable_set_sort_column_id( + GTK_TREE_SORTABLE(process_list->list_store), + PID_COLUMN, + GTK_SORT_ASCENDING); + + process_list->process_hash = g_hash_table_new_full( + hash_fct, equ_fct, + destroy_hash_key, destroy_hash_data + ); + + + gtk_tree_view_set_headers_visible( + GTK_TREE_VIEW(process_list->process_list_widget), FALSE); + + /* Create a column, associating the "text" attribute of the + * cell_renderer to the first column of the model */ + /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */ + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ( "Process", + renderer, + "text", + PROCESS_COLUMN, + NULL); + gtk_tree_view_column_set_alignment (column, 0.0); + gtk_tree_view_column_set_fixed_width (column, 45); + gtk_tree_view_append_column ( + GTK_TREE_VIEW (process_list->process_list_widget), column); + + column = gtk_tree_view_column_new_with_attributes ( "PID", + renderer, + "text", + PID_COLUMN, + NULL); + gtk_tree_view_append_column ( + GTK_TREE_VIEW (process_list->process_list_widget), column); + + + column = gtk_tree_view_column_new_with_attributes ( "Birth sec", + renderer, + "text", + BIRTH_S_COLUMN, + NULL); + gtk_tree_view_append_column ( + GTK_TREE_VIEW (process_list->process_list_widget), column); + + //gtk_tree_view_column_set_visible(column, 0); + // + column = gtk_tree_view_column_new_with_attributes ( "Birth nsec", + renderer, + "text", + BIRTH_NS_COLUMN, + NULL); + gtk_tree_view_append_column ( + GTK_TREE_VIEW (process_list->process_list_widget), column); + + //gtk_tree_view_column_set_visible(column, 0); + + g_object_set_data_full( + G_OBJECT(process_list->process_list_widget), + "process_list_Data", + process_list, + (GDestroyNotify)processlist_destroy); + + return process_list; +} +void processlist_destroy(ProcessList *process_list) +{ + g_hash_table_destroy(process_list->process_hash); + process_list->process_hash = NULL; + + g_free(process_list); +} + +GtkWidget *processlist_get_widget(ProcessList *process_list) +{ + return process_list->process_list_widget; +} + + + +gint get_cell_height(GtkTreeView *tree_view) +{ + gint height; + GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0); + //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column); + //GtkCellRenderer *Renderer = g_list_first(Render_List)->data; + + //g_list_free(Render_List); + gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, &height); + //g_critical("cell 0 height : %u",height); + + return height; +} + +void destroy_hash_key(gpointer key) +{ + g_free(key); +} + +void destroy_hash_data(gpointer data) +{ + g_free(data); +} + +int processlist_add( ProcessList *process_list, + guint pid, + LttTime *birth, + gchar *name, + guint *height, + HashedProcessData **pm_hashed_process_data) +{ + GtkTreeIter iter ; + ProcessInfo *Process_Info = g_new(ProcessInfo, 1); + HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1); + *pm_hashed_process_data = hashed_process_data; + + Process_Info->pid = pid; + Process_Info->birth = *birth; + + hashed_process_data->draw_context = g_new(DrawContext, 1); + hashed_process_data->draw_context->drawable = NULL; + hashed_process_data->draw_context->gc = NULL; + hashed_process_data->draw_context->pango_layout = NULL; + hashed_process_data->draw_context->current = g_new(DrawInfo,1); + hashed_process_data->draw_context->current->over = g_new(ItemInfo,1); + hashed_process_data->draw_context->current->over->x = -1; + hashed_process_data->draw_context->current->over->y = -1; + hashed_process_data->draw_context->current->middle = g_new(ItemInfo,1); + hashed_process_data->draw_context->current->middle->x = -1; + hashed_process_data->draw_context->current->middle->y = -1; + hashed_process_data->draw_context->current->under = g_new(ItemInfo,1); + hashed_process_data->draw_context->current->under->x = -1; + hashed_process_data->draw_context->current->under->y = -1; + hashed_process_data->draw_context->current->modify_over = g_new(ItemInfo,1); + hashed_process_data->draw_context->current->modify_over->x = -1; + hashed_process_data->draw_context->current->modify_over->y = -1; + hashed_process_data->draw_context->current->modify_middle = g_new(ItemInfo,1); + hashed_process_data->draw_context->current->modify_middle->x = -1; + hashed_process_data->draw_context->current->modify_middle->y = -1; + hashed_process_data->draw_context->current->modify_under = g_new(ItemInfo,1); + hashed_process_data->draw_context->current->modify_under->x = -1; + hashed_process_data->draw_context->current->modify_under->y = -1; + hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED; + hashed_process_data->draw_context->previous = g_new(DrawInfo,1); + hashed_process_data->draw_context->previous->over = g_new(ItemInfo,1); + hashed_process_data->draw_context->previous->over->x = -1; + hashed_process_data->draw_context->previous->over->y = -1; + hashed_process_data->draw_context->previous->middle = g_new(ItemInfo,1); + hashed_process_data->draw_context->previous->middle->x = -1; + hashed_process_data->draw_context->previous->middle->y = -1; + hashed_process_data->draw_context->previous->under = g_new(ItemInfo,1); + hashed_process_data->draw_context->previous->under->x = -1; + hashed_process_data->draw_context->previous->under->y = -1; + hashed_process_data->draw_context->previous->modify_over = g_new(ItemInfo,1); + hashed_process_data->draw_context->previous->modify_over->x = -1; + hashed_process_data->draw_context->previous->modify_over->y = -1; + hashed_process_data->draw_context->previous->modify_middle = g_new(ItemInfo,1); + hashed_process_data->draw_context->previous->modify_middle->x = -1; + hashed_process_data->draw_context->previous->modify_middle->y = -1; + hashed_process_data->draw_context->previous->modify_under = g_new(ItemInfo,1); + hashed_process_data->draw_context->previous->modify_under->x = -1; + hashed_process_data->draw_context->previous->modify_under->y = -1; + hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED; + + /* Add a new row to the model */ + gtk_list_store_append ( process_list->list_store, &iter); + //g_critical ( "iter before : %s", gtk_tree_path_to_string ( + // gtk_tree_model_get_path ( + // GTK_TREE_MODEL(process_list->list_store), + // &iter))); + gtk_list_store_set ( process_list->list_store, &iter, + PROCESS_COLUMN, name, + PID_COLUMN, pid, + BIRTH_S_COLUMN, birth->tv_sec, + BIRTH_NS_COLUMN, birth->tv_nsec, + -1); + hashed_process_data->row_ref = gtk_tree_row_reference_new ( + GTK_TREE_MODEL(process_list->list_store), + gtk_tree_model_get_path( + GTK_TREE_MODEL(process_list->list_store), + &iter)); + g_hash_table_insert( process_list->process_hash, + (gpointer)Process_Info, + (gpointer)hashed_process_data); + + //g_critical ( "iter after : %s", gtk_tree_path_to_string ( + // gtk_tree_model_get_path ( + // GTK_TREE_MODEL(process_list->list_store), + // &iter))); + process_list->number_of_process++; + + *height = get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget)) + * process_list->number_of_process ; + + + return 0; + +} + +int processlist_remove( ProcessList *process_list, + guint pid, + LttTime *birth) +{ + ProcessInfo Process_Info; + gint *path_indices; + HashedProcessData *hashed_process_data; + GtkTreeIter iter; + + Process_Info.pid = pid; + Process_Info.birth = *birth; + + + if(hashed_process_data = + (HashedProcessData*)g_hash_table_lookup( + process_list->process_hash, + &Process_Info)) + { + gtk_tree_model_get_iter ( + GTK_TREE_MODEL(process_list->list_store), + &iter, + gtk_tree_row_reference_get_path( + (GtkTreeRowReference*)hashed_process_data->row_ref) + ); + + gtk_list_store_remove (process_list->list_store, &iter); + + g_free(hashed_process_data->draw_context->previous->modify_under); + g_free(hashed_process_data->draw_context->previous->modify_middle); + g_free(hashed_process_data->draw_context->previous->modify_over); + g_free(hashed_process_data->draw_context->previous->under); + g_free(hashed_process_data->draw_context->previous->middle); + g_free(hashed_process_data->draw_context->previous->over); + g_free(hashed_process_data->draw_context->previous); + g_free(hashed_process_data->draw_context->current->modify_under); + g_free(hashed_process_data->draw_context->current->modify_middle); + g_free(hashed_process_data->draw_context->current->modify_over); + g_free(hashed_process_data->draw_context->current->under); + g_free(hashed_process_data->draw_context->current->middle); + g_free(hashed_process_data->draw_context->current->over); + g_free(hashed_process_data->draw_context->current); + g_free(hashed_process_data->draw_context); + g_free(hashed_process_data); + + g_hash_table_remove(process_list->process_hash, + &Process_Info); + + process_list->number_of_process--; + + return 0; + } else { + return 1; + } +} + + +guint processlist_get_height(ProcessList *process_list) +{ + return get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget)) + * process_list->number_of_process ; +} + + +gint processlist_get_process_pixels( ProcessList *process_list, + guint pid, LttTime *birth, + guint *y, + guint *height, + HashedProcessData **pm_hashed_process_data) +{ + ProcessInfo Process_Info; + gint *path_indices; + GtkTreePath *tree_path; + HashedProcessData *hashed_process_data = NULL; + + Process_Info.pid = pid; + Process_Info.birth = *birth; + + if(hashed_process_data = + (HashedProcessData*)g_hash_table_lookup( + process_list->process_hash, + &Process_Info)) + { + tree_path = gtk_tree_row_reference_get_path( + hashed_process_data->row_ref); + path_indices = gtk_tree_path_get_indices (tree_path); + + *height = get_cell_height( + GTK_TREE_VIEW(process_list->process_list_widget)); + *y = *height * path_indices[0]; + *pm_hashed_process_data = hashed_process_data; + return 0; + } else { + *pm_hashed_process_data = hashed_process_data; + return 1; + } + +} + + +gint processlist_get_pixels_from_data( ProcessList *process_list, + ProcessInfo *process_info, + HashedProcessData *hashed_process_data, + guint *y, + guint *height) +{ + gint *path_indices; + GtkTreePath *tree_path; + + tree_path = gtk_tree_row_reference_get_path( + hashed_process_data->row_ref); + path_indices = gtk_tree_path_get_indices (tree_path); + + *height = get_cell_height( + GTK_TREE_VIEW(process_list->process_list_widget)); + *y = *height * path_indices[0]; + + return 0; + +} diff --git a/ltt/branches/poly/lttv/modules/gui/ControlFlow/processlist.h b/ltt/branches/poly/lttv/modules/gui/ControlFlow/processlist.h new file mode 100644 index 00000000..2ed7b343 --- /dev/null +++ b/ltt/branches/poly/lttv/modules/gui/ControlFlow/processlist.h @@ -0,0 +1,76 @@ +#ifndef _PROCESS_LIST_H +#define _PROCESS_LIST_H + +#include +#include +#include + +#include "drawitem.h" + +/* The process list + * + * Tasks : + * Create a process list + * contains the data for the process list + * tells the height of the process list widget + * provides methods to add/remove process from the list + * note : the sync with drawing is left to the caller. + * provides helper function to convert a process unique identifier to + * pixels (in height). + * + * //FIXME : connect the scrolled window adjustment with the list. + */ + +typedef struct _ProcessInfo { + + guint pid; + LttTime birth; + +} ProcessInfo; + +typedef struct _HashedProcessData { + + GtkTreeRowReference *row_ref; + DrawContext *draw_context; + +} HashedProcessData; + +struct _ProcessList { + + GtkWidget *process_list_widget; + GtkListStore *list_store; + + /* A hash table by PID to speed up process position find in the list */ + GHashTable *process_hash; + + guint number_of_process; +}; + + +typedef struct _ProcessList ProcessList; + +ProcessList *processlist_construct(void); +void processlist_destroy(ProcessList *process_list); +GtkWidget *processlist_get_widget(ProcessList *process_list); + +// out : success (0) and height +int processlist_add(ProcessList *process_list, guint pid, LttTime *birth, + gchar *name, guint *height, HashedProcessData **hashed_process_data); +// out : success (0) and height +int processlist_remove(ProcessList *process_list, guint pid, LttTime *birth); + +guint processlist_get_height(ProcessList *process_list); + +// Returns 0 on success +gint processlist_get_process_pixels(ProcessList *process_list, + guint pid, LttTime *birth, + guint *y, guint *height, + HashedProcessData **hashed_process_data); + +gint processlist_get_pixels_from_data( ProcessList *process_list, + ProcessInfo *process_info, + HashedProcessData *hashed_process_data, + guint *y, + guint *height); + +#endif // _PROCESS_LIST_H