X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fmodules%2Fgui%2Flttvwindow%2Flttvwindow%2Flttvwindowtraces.c;h=87beead611324da1cad41ae51eb60b5320159f80;hb=b91e751bfd4702dd0e73008727b38d9043f609c5;hp=1ce869990fe2e10ee69ad30f18e4b7773daf913d;hpb=3710295e1cd7cd1d4ec53bd4950f0f078914b7e0;p=lttv.git diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c index 1ce86999..87beead6 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c @@ -20,9 +20,14 @@ /* Here is the implementation of the API */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include +#include #include #include @@ -33,13 +38,17 @@ #include #include #include // for CHUNK_NUM_EVENTS +#include /* for main window structure */ +extern GSList * g_main_window_list; typedef struct _BackgroundRequest { LttvAttributeName module_name; /* Hook path in global attributes, where all standard hooks under computation/. i.e. modulename */ LttvTrace *trace; /* trace concerned */ + GtkWidget *dialog; /* Dialog linked with the request, may be NULL */ + GtkWidget *parent_window; /* Parent window the dialog must be transient for */ } BackgroundRequest; typedef struct _BackgroundNotify { @@ -65,7 +74,6 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace); LttvTrace *lttvwindowtraces_get_trace_by_name(gchar *path) { - LttvAttribute *attribute = lttv_global_attributes(); guint i; for(i=0;i= 0); + snprintf(attribute_path, PATH_MAX, "%llu:%llu", buf.st_dev, buf.st_ino) >= 0); g_assert(attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute), @@ -157,6 +167,7 @@ void lttvwindowtraces_add_trace(LttvTrace *trace) /* create new traceset and tracesetcontext */ LttvTraceset *ts; LttvTracesetStats *tss; + //LttvTracesetContextPosition *sync_position; attribute = lttv_trace_attribute(trace); g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute), @@ -176,7 +187,15 @@ void lttvwindowtraces_add_trace(LttvTrace *trace) *(value.v_pointer) = tss; lttv_context_init(LTTV_TRACESET_CONTEXT(tss), ts); +#if 0 + g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute), + LTTV_COMPUTATION_SYNC_POSITION, + LTTV_POINTER, + &value)); + sync_position = lttv_traceset_context_position_new(); + *(value.v_pointer) = sync_position; +#endif //0 value = lttv_attribute_add(attribute, LTTV_REQUESTS_QUEUE, LTTV_POINTER); @@ -192,7 +211,6 @@ void lttvwindowtraces_add_trace(LttvTrace *trace) value = lttv_attribute_add(attribute, LTTV_NOTIFY_CURRENT, LTTV_POINTER); - } /* Remove a trace from the global attributes */ @@ -220,9 +238,10 @@ void lttvwindowtraces_remove_trace(LttvTrace *trace) /* Found */ LttvAttribute *l_attribute; - /* create new traceset and tracesetcontext */ + /* destroy traceset and tracesetcontext */ LttvTraceset *ts; LttvTracesetStats *tss; + //LttvTracesetContextPosition *sync_position; l_attribute = lttv_trace_attribute(trace); @@ -244,7 +263,18 @@ void lttvwindowtraces_remove_trace(LttvTrace *trace) LTTV_POINTER, &value)); ts = (LttvTraceset*)*(value.v_pointer); - +#if 0 + g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(l_attribute), + LTTV_COMPUTATION_SYNC_POSITION, + LTTV_POINTER, + &value)); + sync_position = (LttvTracesetContextPosition*)*(value.v_pointer); + lttv_traceset_context_position_destroy(sync_position); + + lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute), + LTTV_COMPUTATION_SYNC_POSITION); + +#endif //0 g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(l_attribute), LTTV_COMPUTATION_TRACESET_CONTEXT, LTTV_POINTER, @@ -255,9 +285,10 @@ void lttvwindowtraces_remove_trace(LttvTrace *trace) g_object_unref(tss); lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute), LTTV_COMPUTATION_TRACESET_CONTEXT); - lttv_traceset_destroy(ts); lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute), LTTV_COMPUTATION_TRACESET); + /* Destroy the traceset and the trace also */ + lttv_traceset_destroy(ts); /* finally, remove the global attribute */ lttv_attribute_remove(attribute, i); @@ -267,19 +298,26 @@ void lttvwindowtraces_remove_trace(LttvTrace *trace) } } +static void destroy_dialog(BackgroundRequest *bg_req) +{ + gtk_widget_destroy(bg_req->dialog); + bg_req->dialog = NULL; +} + /** * Function to request data from a specific trace * * The memory allocated for the request will be managed by the API. * + * @param widget the current Window * @param trace the trace to compute * @param module_name the name of the module which registered global computation * hooks. */ void lttvwindowtraces_background_request_queue - (LttvTrace *trace, gchar *module_name) + (GtkWidget *widget, LttvTrace *trace, gchar *module_name) { BackgroundRequest *bg_req; LttvAttribute *attribute = lttv_trace_attribute(trace); @@ -323,7 +361,25 @@ void lttvwindowtraces_background_request_queue trace, NULL); /* FIXME : show message in status bar, need context and message id */ - g_info("Background computation started for trace %p", trace); + g_info("Background computation for %s started for trace %p", module_name, + trace); + GtkWidget *dialog = + gtk_message_dialog_new( + GTK_WINDOW(widget), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, GTK_BUTTONS_OK, + "Background computation for %s started for trace %s", + module_name, + g_quark_to_string(ltt_trace_name(lttv_trace(trace)))); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(widget)); + g_signal_connect_swapped (dialog, "response", + G_CALLBACK (destroy_dialog), + bg_req); + bg_req->dialog = dialog; + /* the parent window might vanish : only use this pointer for a + * comparison with existing windows */ + bg_req->parent_window = gtk_widget_get_toplevel(widget); + gtk_widget_show(dialog); } /** @@ -372,6 +428,37 @@ void lttvwindowtraces_background_request_remove } } +/** + * Find a background request in a trace + * + */ + +gboolean lttvwindowtraces_background_request_find + (LttvTrace *trace, gchar *module_name) +{ + LttvAttribute *attribute = lttv_trace_attribute(trace); + LttvAttributeValue value; + GSList *iter = NULL; + GSList **slist; + + g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute), + LTTV_REQUESTS_QUEUE, + LTTV_POINTER, + &value)); + slist = (GSList**)(value.v_pointer); + + for(iter=*slist;iter!=NULL;) { + BackgroundRequest *bg_req = + (BackgroundRequest *)iter->data; + + if(bg_req->module_name == g_quark_from_string(module_name)) { + return TRUE; + } else { + iter=g_slist_next(iter); + } + } + return FALSE; +} /** * Register a callback to be called when requested data is passed in the next @@ -402,6 +489,11 @@ void lttvwindowtraces_background_notify_queue &value)); slist = (GSList**)(value.v_pointer); + g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute), + LTTV_COMPUTATION_TRACESET_CONTEXT, + LTTV_POINTER, + &value)); + LttvTracesetContext *tsc = (LttvTracesetContext*)(value.v_pointer); bg_notify = g_new(BackgroundNotify,1); @@ -409,7 +501,7 @@ void lttvwindowtraces_background_notify_queue bg_notify->trace = trace; bg_notify->notify_time = notify_time; if(notify_position != NULL) { - bg_notify->notify_position = lttv_traceset_context_position_new(); + bg_notify->notify_position = lttv_traceset_context_position_new(tsc); lttv_traceset_context_position_copy(bg_notify->notify_position, notify_position); } else { @@ -451,13 +543,20 @@ void lttvwindowtraces_background_notify_current &value)); slist = (GSList**)(value.v_pointer); + g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute), + LTTV_COMPUTATION_TRACESET_CONTEXT, + LTTV_POINTER, + &value)); + LttvTracesetContext *tsc = (LttvTracesetContext*)(value.v_pointer); + + bg_notify = g_new(BackgroundNotify,1); bg_notify->owner = owner; bg_notify->trace = trace; bg_notify->notify_time = notify_time; if(notify_position!= NULL) { - bg_notify->notify_position = lttv_traceset_context_position_new(); + bg_notify->notify_position = lttv_traceset_context_position_new(tsc); lttv_traceset_context_position_copy(bg_notify->notify_position, notify_position); } else { @@ -548,7 +647,66 @@ void lttvwindowtraces_background_notify_remove(gpointer owner) /* Background processing helper functions */ void lttvwindowtraces_add_computation_hooks(LttvAttributeName module_name, - LttvTracesetContext *tsc) + LttvTracesetContext *tsc, + LttvHooks *hook_adder) +{ + LttvAttribute *g_attribute = lttv_global_attributes(); + LttvAttribute *module_attribute; + LttvAttributeType type; + LttvAttributeValue value; + + + g_assert(module_attribute = + LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute), + LTTV_COMPUTATION))); + + g_assert(module_attribute = + LTTV_ATTRIBUTE(lttv_iattribute_find_subdir( + LTTV_IATTRIBUTE(module_attribute), + module_name))); + + /* Call the module's hook adder */ + type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute), + LTTV_HOOK_ADDER, + &value); + if(type == LTTV_POINTER) { + //lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss); + if(hook_adder != NULL) + lttv_hooks_add_list(hook_adder, (LttvHooks*)*(value.v_pointer)); + } +} + +void lttvwindowtraces_remove_computation_hooks(LttvAttributeName module_name, + LttvTracesetContext *tsc, + LttvHooks *hook_remover) +{ + LttvAttribute *g_attribute = lttv_global_attributes(); + LttvAttribute *module_attribute; + LttvAttributeType type; + LttvAttributeValue value; + + g_assert(module_attribute = + LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute), + LTTV_COMPUTATION))); + + g_assert(module_attribute = + LTTV_ATTRIBUTE(lttv_iattribute_find_subdir( + LTTV_IATTRIBUTE(module_attribute), + module_name))); + + /* Call the module's hook remover */ + type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute), + LTTV_HOOK_REMOVER, + &value); + if(type == LTTV_POINTER) { + //lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss); + if(hook_remover != NULL) + lttv_hooks_add_list(hook_remover, (LttvHooks*)*(value.v_pointer)); + } +} + +void lttvwindowtraces_call_before_chunk(LttvAttributeName module_name, + LttvTracesetContext *tsc) { LttvAttribute *g_attribute = lttv_global_attributes(); LttvAttribute *module_attribute; @@ -606,27 +764,18 @@ void lttvwindowtraces_add_computation_hooks(LttvAttributeName module_name, event_hook_by_id = (LttvHooksById*)*(value.v_pointer); } - /* Call the module's hook adder */ - type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute), - LTTV_HOOK_ADDER, - &value); - if(type == LTTV_POINTER) { - lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss); - } - - - lttv_process_traceset_begin(tsc, before_chunk_traceset, before_chunk_trace, before_chunk_tracefile, event_hook, event_hook_by_id); - } - -void lttvwindowtraces_remove_computation_hooks(LttvAttributeName module_name, - LttvTracesetContext *tsc) + + + +void lttvwindowtraces_call_after_chunk(LttvAttributeName module_name, + LttvTracesetContext *tsc) { LttvAttribute *g_attribute = lttv_global_attributes(); LttvAttribute *module_attribute; @@ -690,13 +839,6 @@ void lttvwindowtraces_remove_computation_hooks(LttvAttributeName module_name, event_hook, event_hook_by_id); - /* Call the module's hook remover */ - type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute), - LTTV_HOOK_REMOVER, - &value); - if(type == LTTV_POINTER) { - lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss); - } } @@ -802,6 +944,12 @@ gboolean lttvwindowtraces_get_ready(LttvAttributeName module_name, return TRUE; } +static gint find_window_widget(MainWindow *a, GtkWidget *b) +{ + if(a->mwindow == b) return 0; + else return -1; +} + /* lttvwindowtraces_process_pending_requests * @@ -816,16 +964,18 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) LttvTracesetContext *tsc; LttvTracesetStats *tss; LttvTraceset *ts; + //LttvTracesetContextPosition *sync_position; LttvAttribute *attribute; LttvAttribute *g_attribute = lttv_global_attributes(); GSList **list_out, **list_in, **notify_in, **notify_out; LttvAttributeValue value; LttvAttributeType type; gboolean ret_val; - LttvHooks *before_request, *after_request; if(trace == NULL) return FALSE; + + if(lttvwindow_preempt_count > 0) return TRUE; attribute = lttv_trace_attribute(trace); @@ -867,10 +1017,15 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) tss = (LttvTracesetStats*)*(value.v_pointer); g_assert(LTTV_IS_TRACESET_CONTEXT(tsc)); g_assert(LTTV_IS_TRACESET_STATS(tss)); - +#if 0 + type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute), + LTTV_COMPUTATION_SYNC_POSITION, + &value); + g_assert(type == LTTV_POINTER); + sync_position = (LttvTracesetContextPosition*)*(value.v_pointer); +#endif //0 /* There is no events requests pending : we should never have been called! */ g_assert(g_slist_length(*list_out) != 0 || g_slist_length(*list_in) != 0); - /* 0.1 Lock traces */ { guint iter_trace=0; @@ -886,8 +1041,8 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) } } /* 0.2 Sync tracefiles */ + //g_assert(lttv_process_traceset_seek_position(tsc, sync_position) == 0); lttv_process_traceset_synchronize_tracefiles(tsc); - /* 1. Before processing */ { /* if list_in is empty */ @@ -950,7 +1105,6 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) &value); g_assert(type == LTTV_POINTER); LttvHooks *before_request = (LttvHooks*)*(value.v_pointer); - if(before_request != NULL) lttv_hooks_call(before_request, tsc); @@ -993,6 +1147,24 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) } } } + { + GSList *iter = *list_in; + LttvHooks *hook_adder = lttv_hooks_new(); + /* - for each request in list_in */ + while(iter != NULL) { + + BackgroundRequest *bg_req = (BackgroundRequest*)iter->data; + /*- add hooks to context*/ + lttvwindowtraces_add_computation_hooks(bg_req->module_name, + tsc, + hook_adder); + iter = g_slist_next(iter); + } + lttv_hooks_call(hook_adder,tsc); + lttv_hooks_destroy(hook_adder); + } + + } { @@ -1002,18 +1174,17 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) BackgroundRequest *bg_req = (BackgroundRequest*)iter->data; /*- Call before chunk hooks for list_in*/ - /*- add hooks to context*/ - lttvwindowtraces_add_computation_hooks(bg_req->module_name, + lttvwindowtraces_call_before_chunk(bg_req->module_name, tsc); iter = g_slist_next(iter); } } - } + } /* 2. call process traceset middle for a chunk */ { /*(assert list_in is not empty! : should not even be called in that case)*/ - LttTime end = { G_MAXUINT, G_MAXUINT }; + LttTime end = ltt_time_infinite; g_assert(g_slist_length(*list_in) != 0); lttv_process_traceset_middle(tsc, end, CHUNK_NUM_EVENTS, NULL); @@ -1029,8 +1200,7 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) BackgroundRequest *bg_req = (BackgroundRequest*)iter->data; /* - Call after chunk hooks for list_in */ - /* - remove hooks from context */ - lttvwindowtraces_remove_computation_hooks(bg_req->module_name, + lttvwindowtraces_call_after_chunk(bg_req->module_name, tsc); iter = g_slist_next(iter); } @@ -1089,7 +1259,24 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec); if(tfc == NULL || ltt_time_compare(tfc->timestamp, tsc->time_span.end_time) > 0) { - + + { + GSList *iter = *list_in; + LttvHooks *hook_remover = lttv_hooks_new(); + /* - for each request in list_in */ + while(iter != NULL) { + + BackgroundRequest *bg_req = (BackgroundRequest*)iter->data; + /* - remove hooks from context */ + lttvwindowtraces_remove_computation_hooks(bg_req->module_name, + tsc, + hook_remover); + iter = g_slist_next(iter); + } + lttv_hooks_call(hook_remover,tsc); + lttv_hooks_destroy(hook_remover); + } + /* - for each request in list_in */ { GSList *iter = *list_in; @@ -1125,8 +1312,39 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) &value); g_assert(type == LTTV_POINTER); LttvHooks *after_request = (LttvHooks*)*(value.v_pointer); + { + struct sum_traceset_closure t_closure; + t_closure.tss = (LttvTracesetStats*)tsc; + t_closure.current_time = ltt_time_infinite; + if(after_request != NULL) lttv_hooks_call(after_request, + &t_closure); + } + + if(bg_req->dialog != NULL) + gtk_widget_destroy(bg_req->dialog); + GtkWidget *parent_window; + if(g_slist_find_custom(g_main_window_list, + bg_req->parent_window, + (GCompareFunc)find_window_widget)) + parent_window = GTK_WIDGET(bg_req->parent_window); + else + parent_window = NULL; + + GtkWidget *dialog = + gtk_message_dialog_new(GTK_WINDOW(parent_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, GTK_BUTTONS_OK, + "Background computation %s finished for trace %s", + g_quark_to_string(bg_req->module_name), + g_quark_to_string(ltt_trace_name(lttv_trace(bg_req->trace)))); + if(parent_window != NULL) + gtk_window_set_transient_for(GTK_WINDOW(dialog), + GTK_WINDOW(parent_window)); + g_signal_connect_swapped (dialog, "response", + G_CALLBACK (gtk_widget_destroy), + dialog); + gtk_widget_show(dialog); - if(after_request != NULL) lttv_hooks_call(after_request, tsc); /* - remove request */ remove = TRUE; free_data = TRUE; @@ -1174,12 +1392,18 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) } } } + { + /* - reset the context */ + LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->fini(tsc); + LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->init(tsc,ts); + } /* - if list_out is empty */ if(g_slist_length(*list_out) == 0) { /* - return FALSE (scheduler stopped) */ g_debug("Background computation scheduler stopped"); g_info("Background computation finished for trace %p", trace); /* FIXME : remove status bar info, need context id and message id */ + ret_val = FALSE; } else { ret_val = TRUE; @@ -1194,7 +1418,8 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace) } /* 4. Unlock traces */ { - //lttv_process_traceset_get_sync_data(tsc); + lttv_process_traceset_get_sync_data(tsc); + //lttv_traceset_context_position_save(tsc, sync_position); guint iter_trace; for(iter_trace=0;