X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fmodules%2FguiControlFlow%2FProcess_List.c;h=c695fb15f4e07c8a1bdcab8e2aa9e9015f4ad88c;hb=8d70e03bc0026687c050287b3dc9b3ec42281191;hp=6085a67232b89e68af3136a3f00a90c857450bc9;hpb=558aa01322f1af8be09fcfc086864da0373823c5;p=lttv.git diff --git a/ltt/branches/poly/lttv/modules/guiControlFlow/Process_List.c b/ltt/branches/poly/lttv/modules/guiControlFlow/Process_List.c index 6085a672..c695fb15 100644 --- a/ltt/branches/poly/lttv/modules/guiControlFlow/Process_List.c +++ b/ltt/branches/poly/lttv/modules/guiControlFlow/Process_List.c @@ -1,119 +1,510 @@ +#include +#include #include "Process_List.h" +#include "Draw_Item.h" /***************************************************************************** * Methods to synchronize process list * *****************************************************************************/ -typedef struct _ProcessList { - - GtkWidget *Process_List_VC; - GtkListStore *Store_M; - - guint Number_Of_Process; - -} ProcessList ; - - /* Enumeration of the columns */ enum { - PROCESS_COLUMN, - N_COLUMNS + PROCESS_COLUMN, + PID_COLUMN, + BIRTH_S_COLUMN, + BIRTH_NS_COLUMN, + N_COLUMNS }; -ProcessList *ProcessList_construct(void) +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) { - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - - ProcessList* Process_List = g_new(ProcessList,1); - - /* Create the Process list */ - Process_List->Store_M = gtk_list_store_new ( N_COLUMNS, - G_TYPE_STRING); - - - Process_List->Process_List_VC = - gtk_tree_view_new_with_model - (GTK_TREE_MODEL (Process_List->Store_M)); - - g_object_unref (G_OBJECT (Process_List->Store_M)); - - gtk_tree_view_set_headers_visible( - GTK_TREE_VIEW(Process_List->Process_List_VC), 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_VC), column); - - g_object_set_data_full( - G_OBJECT(Process_List->Process_List_VC), - "Process_List_Data", - Process_List, - ProcessList_destroy); - - - return Process_List; + return ((ProcessInfo*)key)->pid; } -void ProcessList_destroy(ProcessList *Process_List) +gboolean equ_fct(gconstpointer a, gconstpointer b) { - g_object_unref (G_OBJECT (Process_List->Process_List_VC)); + 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); - g_free(Process_List); + return 1; } -GtkWidget *ProcessList_getWidget(ProcessList *Process_List) +void destroy_hash_key(gpointer key); + +void destroy_hash_data(gpointer data); + + + + +ProcessList *processlist_construct(void) { - return Process_List->Process_List_VC; + 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); +} -gint get_cell_height(GtkTreeView *TreeView) +void destroy_hash_data(gpointer data) { - gint height, width; - GtkTreeViewColumn *Column = gtk_tree_view_get_column(TreeView, 0); - GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column); - GtkCellRenderer *Renderer = g_list_first(Render_List)->data; - - gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, &height); - g_critical("cell 0 height : %u",height); - - return height; + g_free(data); } -#ifdef 0 -int ProcessList_add(Process *myproc, ProcessList *Process_List, guint *height) +int processlist_add( ProcessList *process_list, + guint pid, + LttTime *birth, + gchar *name, + guint *height, + HashedProcessData **pm_hashed_process_data) { - // add proc to container + 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_VC)) - * Process_List->Number_Of_Process ; - - return 0; - + *height = get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget)) + * process_list->number_of_process ; + + + return 0; + } -int ProcessList_remove(Process *myproc, ProcessList *Process_List) +int processlist_remove( ProcessList *process_list, + guint pid, + LttTime *birth) { - // remove proc from container - - get_cell_height(GTK_TREE_VIEW(Process_List->Process_List_VC)) - * Process_List->Number_Of_Process ; - - return 0; + 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; + } -#endif