authors in about
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / callbacks.c
index 3659ae58a693d9e4ea590ada618e60d1f6c50171..c101c9c6c792d2624db211943c42fca489ab98c6 100644 (file)
@@ -238,31 +238,38 @@ void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor)
 
 int SetTraceset(Tab * tab, LttvTraceset *traceset)
 {
-  LttvHooks * tmp;
-  LttvAttributeValue value;
-  gint retval = 0;
-
-  g_assert( lttv_iattribute_find_by_path(tab->attributes,
-     "hooks/updatetraceset", LTTV_POINTER, &value));
-
-  tmp = (LttvHooks*)*(value.v_pointer);
-  if(tmp == NULL) retval = 1;
-  else lttv_hooks_call(tmp,traceset);
-
-  /* Set scrollbar */
   LttvTracesetContext *tsc =
         LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
   TimeInterval time_span = tsc->time_span;
+
+  /* Set the tab's time window and current time if
+   * out of bounds */
+  if(ltt_time_compare(tab->time_window.start_time, time_span.start_time) < 0
+     || ltt_time_compare(  ltt_time_add(tab->time_window.start_time,
+                                        tab->time_window.time_width),
+                           time_span.end_time) > 0) {
+    tab->time_window.start_time = time_span.start_time;
+    tab->current_time = time_span.start_time;
+    
+    LttTime tmp_time;
+
+    if(DEFAULT_TIME_WIDTH_S < time_span.end_time.tv_sec)
+      tmp_time.tv_sec = DEFAULT_TIME_WIDTH_S;
+    else
+      tmp_time.tv_sec = time_span.end_time.tv_sec;
+    tmp_time.tv_nsec = 0;
+    tab->time_window.time_width = tmp_time ;
+  }
+  
+  /* Set scrollbar */
   GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
+  LttTime upper = ltt_time_sub(time_span.end_time, time_span.start_time);
       
   g_object_set(G_OBJECT(adjustment),
                "lower",
-               ltt_time_to_double(time_span.start_time) 
-                 * NANOSECONDS_PER_SECOND, /* lower */
+                 0.0, /* lower */
                "upper",
-               ltt_time_to_double(time_span.end_time
+               ltt_time_to_double(upper
                  * NANOSECONDS_PER_SECOND, /* upper */
                "step_increment",
                ltt_time_to_double(tab->time_window.time_width)
@@ -279,11 +286,26 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
 
   g_object_set(G_OBJECT(adjustment),
                "value",
-               ltt_time_to_double(tab->time_window.start_time) 
-                 * NANOSECONDS_PER_SECOND, /* value */
+               ltt_time_to_double(
+                ltt_time_sub(tab->time_window.start_time, time_span.start_time))
+                   * NANOSECONDS_PER_SECOND, /* value */
                NULL);
   gtk_adjustment_value_changed(adjustment);
-  
+
+  /* Finally, call the update hooks of the viewers */
+  LttvHooks * tmp;
+  LttvAttributeValue value;
+  gint retval = 0;
+
+  g_assert( lttv_iattribute_find_by_path(tab->attributes,
+     "hooks/updatetraceset", LTTV_POINTER, &value));
+
+  tmp = (LttvHooks*)*(value.v_pointer);
+  if(tmp == NULL) retval = 1;
+  else lttv_hooks_call(tmp,traceset);
+
   return retval;
 }
 
@@ -740,10 +762,13 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
 
   
   /* Events processing algorithm implementation */
+  /* Warning : the gtk_events_pending takes a LOT of cpu time. So what we do
+   * instead is to leave the control to GTK and take it back.
+   */
   /* A. Servicing loop */
-  while( (g_slist_length(list_in) != 0 || g_slist_length(list_out) != 0)) {
-     /*    && !gtk_events_pending() )  */
-
+  //while( (g_slist_length(list_in) != 0 || g_slist_length(list_out) != 0)) {
+  if((g_slist_length(list_in) != 0 || g_slist_length(list_out) != 0)) {
+    /* Servicing */
     /* 1. If list_in is empty (need a seek) */
     if( g_slist_length(list_in) ==  0 ) {
 
@@ -1011,7 +1036,7 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
                                              events_request->event,
                                              events_request->event_by_id);
           }
+
           /* Go to next */
           if(remove)
           {
@@ -1113,8 +1138,11 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
       count = lttv_process_traceset_middle(tsc, end_time, end_nb_events, end_position);
 
       tfc = lttv_traceset_context_get_current_tfc(tsc);
-      g_debug("Context time after middle : %lu, %lu", tfc->timestamp.tv_sec,
+      if(tfc != NULL)
+        g_debug("Context time after middle : %lu, %lu", tfc->timestamp.tv_sec,
                                                         tfc->timestamp.tv_nsec);
+      else
+        g_debug("End of trace reached after middle.");
 
     }
     {
@@ -1231,9 +1259,10 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
         }
       }
     }
-
-    if(gtk_events_pending()) break;
   }
+  /* End of removed servicing loop : leave control to GTK instead. */
+  //  if(gtk_events_pending()) break;
+  //}
 
   /* B. When interrupted between chunks */
 
@@ -1384,9 +1413,10 @@ static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
 {
   LttvTraceset *traceset = tab->traceset_info->traceset;
   guint i;
+  guint num_traces = lttv_traceset_number(traceset);
 
  //Verify if trace is already present.
-  for(i=0; i<lttv_traceset_number(traceset); i++)
+  for(i=0; i<num_traces; i++)
   {
     LttvTrace * trace = lttv_traceset_get(traceset, i);
     if(trace == trace_v)
@@ -1419,36 +1449,7 @@ static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
                                       traceset_context),
             traceset); 
 
-  /* Set the tab's time window and current time if
-   * out of bounds */
-  TimeInterval time_span = 
-    LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->time_span;
-  if(ltt_time_compare(tab->time_window.start_time, time_span.start_time) < 0
-     || ltt_time_compare(  ltt_time_add(tab->time_window.start_time,
-                                        tab->time_window.time_width),
-                           time_span.end_time) > 0) {
-    tab->time_window.start_time = 
-        LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
-                               time_span.start_time;
-    tab->current_time = 
-       LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
-                             time_span.start_time;
-    
-    LttTime tmp_time;
 
-    if(DEFAULT_TIME_WIDTH_S <
-            LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
-                           time_span.end_time.tv_sec)
-      tmp_time.tv_sec = DEFAULT_TIME_WIDTH_S;
-    else
-      tmp_time.tv_sec =
-              LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
-                           time_span.end_time.tv_sec;
-    tmp_time.tv_nsec = 0;
-    tab->time_window.time_width = tmp_time ;
-    
-  }
   //add state update hooks
   lttv_state_add_event_hooks(
   (LttvTracesetState*)tab->traceset_info->traceset_context);
@@ -1633,17 +1634,18 @@ void remove_trace(GtkWidget *widget, gpointer user_data)
 
     trace_v = lttv_traceset_get(traceset, index);
 
-    if(lttv_trace_get_ref_number(trace_v) <= 2) {
-      /* ref 2 : traceset, local */
-      lttvwindowtraces_remove_trace(trace_v);
-      ltt_trace_close(lttv_trace(trace_v));
-    }
-    
     lttv_traceset_remove(traceset, index);
     lttv_trace_unref(trace_v);  // Remove local reference
 
-    if(!lttv_trace_get_ref_number(trace_v))
-       lttv_trace_destroy(trace_v);
+    if(lttv_trace_get_ref_number(trace_v) <= 1) {
+      /* ref 1 : lttvwindowtraces only*/
+      ltt_trace_close(lttv_trace(trace_v));
+      /* lttvwindowtraces_remove_trace takes care of destroying
+       * the traceset linked with the trace_v and also of destroying
+       * the trace_v at the same time.
+       */
+      lttvwindowtraces_remove_trace(trace_v);
+    }
     
     tab->traceset_info->traceset_context =
       g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
@@ -1987,15 +1989,15 @@ void zoom(GtkWidget * widget, double size)
   //
   //
 
+ LttTime rel_time =
+       ltt_time_sub(new_time_window.start_time, time_span.start_time); 
  if(   ltt_time_to_double(new_time_window.time_width)
                              * NANOSECONDS_PER_SECOND
                              / SCROLL_STEP_PER_PAGE/* step increment */
        +
-       ltt_time_to_double(new_time_window.start_time)
-                             * NANOSECONDS_PER_SECOND /* page size */
+       ltt_time_to_double(rel_time) * NANOSECONDS_PER_SECOND /* page size */
                     == 
-       ltt_time_to_double(new_time_window.start_time)
-                             * NANOSECONDS_PER_SECOND /* page size */
+       ltt_time_to_double(rel_time) * NANOSECONDS_PER_SECOND /* page size */
        ) {
     g_warning("Can not zoom that far due to scrollbar precision");
  } else if(
@@ -2015,10 +2017,10 @@ void zoom(GtkWidget * widget, double size)
                  //ltt_time_to_double(new_time_window.start_time) 
                  //  * NANOSECONDS_PER_SECOND, /* value */
                  "lower",
-                 ltt_time_to_double(time_span.start_time) 
-                   * NANOSECONDS_PER_SECOND, /* lower */
+                   0.0, /* lower */
                  "upper",
-                 ltt_time_to_double(time_span.end_time) 
+                 ltt_time_to_double(
+                   ltt_time_sub(time_span.end_time, time_span.start_time))
                    * NANOSECONDS_PER_SECOND, /* upper */
                  "step_increment",
                  ltt_time_to_double(new_time_window.time_width)
@@ -2036,7 +2038,8 @@ void zoom(GtkWidget * widget, double size)
     //gtk_adjustment_value_changed(adjustment);
     g_object_set(G_OBJECT(adjustment),
                  "value",
-                 ltt_time_to_double(new_time_window.start_time) 
+                 ltt_time_to_double(
+                   ltt_time_sub(new_time_window.start_time, time_span.start_time))
                    * NANOSECONDS_PER_SECOND, /* value */
                  NULL);
     gtk_adjustment_value_changed(adjustment);
@@ -2720,9 +2723,9 @@ on_unload_module_activate              (GtkMenuItem     *menuitem,
     GPtrArray *name;
     guint nb,i;
     gchar *module_name;
+    nb = lttv_library_module_number(library);
     LttvModuleInfo *module_info = g_new(LttvModuleInfo,nb);
     name = g_ptr_array_new();
-    nb = lttv_library_module_number(library);
     /* ask for the module name */
 
     for(i=0;i<nb;i++){
@@ -2854,11 +2857,90 @@ on_content_activate                    (GtkMenuItem     *menuitem,
 }
 
 
+static void 
+on_about_close_activate                (GtkButton       *button,
+                                        gpointer         user_data)
+{
+  GtkWidget *about_widget = GTK_WIDGET(user_data);
+
+  gtk_widget_destroy(about_widget);
+}
+
 void
 on_about_activate                      (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-  g_printf("About...\n");
+  MainWindow *main_window = get_window_data_struct(GTK_WIDGET(menuitem));
+  GtkWidget *window_widget = main_window->mwindow;
+  GtkWidget *about_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  GtkWindow *about_window = GTK_WINDOW(about_widget);
+  gint window_width, window_height;
+  
+  gtk_window_set_title(about_window, "About Linux Trace Toolkit");
+
+  gtk_window_set_resizable(about_window, FALSE);
+  gtk_window_set_transient_for(GTK_WINDOW(window_widget), about_window);
+  gtk_window_set_destroy_with_parent(about_window, TRUE);
+  gtk_window_set_modal(about_window, FALSE);
+
+  /* Put the about window at the center of the screen */
+  gtk_window_get_size(about_window, &window_width, &window_height);
+  gtk_window_move (about_window,
+                   (gdk_screen_width() - window_width)/2,
+                   (gdk_screen_height() - window_height)/2);
+  GtkWidget *vbox = gtk_vbox_new(FALSE, 1);
+
+  gtk_container_add(GTK_CONTAINER(about_widget), vbox);
+
+    
+  /* Text to show */
+  GtkWidget *label1 = gtk_label_new("");
+  gtk_misc_set_padding(GTK_MISC(label1), 10, 20);
+  gtk_label_set_markup(GTK_LABEL(label1), "\
+<big>Linux Trace Toolkit</big>");
+  gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_CENTER);
+  
+  GtkWidget *label2 = gtk_label_new("");
+  gtk_misc_set_padding(GTK_MISC(label2), 10, 20);
+  gtk_label_set_markup(GTK_LABEL(label2), "\
+Project author: Karim Yaghmour\n\
+\n\
+Contributors :\n\
+\n\
+Michel Dagenais (New trace format, lttv main)\n\
+Mathieu Desnoyers (Directory structure, build with automake/conf,\n\
+                   lttv gui, control flow view, gui green threads\n\
+                   with interruptible foreground and background computation,\n\
+                   detailed event list)\n\
+Benoit Des Ligneris (Cluster adaptation)\n\
+Xang-Xiu Yang (new trace reading library and converter, lttv gui, \n\
+               detailed event list and statistics view)\n\
+Tom Zanussi (RelayFS)");
+
+  GtkWidget *label3 = gtk_label_new("");
+  gtk_label_set_markup(GTK_LABEL(label3), "\
+Linux Trace Toolkit, Copyright (C) 2004  Karim Yaghmour\n\
+Linux Trace Toolkit comes with ABSOLUTELY NO WARRANTY.\n\
+This is free software, and you are welcome to redistribute it\n\
+under certain conditions. See COPYING for details.");
+  gtk_misc_set_padding(GTK_MISC(label3), 10, 20);
+
+  gtk_box_pack_start_defaults(GTK_BOX(vbox), label1);
+  gtk_box_pack_start_defaults(GTK_BOX(vbox), label2);
+  gtk_box_pack_start_defaults(GTK_BOX(vbox), label3);
+
+  GtkWidget *hbox = gtk_hbox_new(TRUE, 0);
+  gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+  GtkWidget *close_button = gtk_button_new_with_mnemonic("_Close");
+  gtk_box_pack_end(GTK_BOX(hbox), close_button, FALSE, FALSE, 0);
+  gtk_container_set_border_width(GTK_CONTAINER(close_button), 20);
+
+  g_signal_connect(G_OBJECT(close_button), "clicked",
+      G_CALLBACK(on_about_close_activate),
+      (gpointer)about_widget);
+  
+  gtk_widget_show_all(about_widget);
 }
 
 
@@ -3081,26 +3163,26 @@ void scroll_value_changed_cb(GtkWidget *scrollbar,
 {
   Tab *tab = (Tab *)user_data;
   TimeWindow time_window;
-  TimeInterval *time_span;
   LttTime time;
   GtkAdjustment *adjust = gtk_range_get_adjustment(GTK_RANGE(scrollbar));
   gdouble value = gtk_adjustment_get_value(adjust);
   gdouble upper, lower, ratio, page_size;
   LttvTracesetContext * tsc = 
     LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
+  TimeInterval time_span = tsc->time_span;
 
   //time_window = tab->time_window;
 
-  time_span = &tsc->time_span ;
   lower = adjust->lower;
   upper = adjust->upper;
   ratio = (value - lower) / (upper - lower);
-  g_critical("lower %lu, upper %lu, value %lu, ratio %lu", lower, upper, value, ratio);
+  g_info("lower %lu, upper %lu, value %lu, ratio %lu", lower, upper, value, ratio);
   
   //time = ltt_time_sub(time_span->end_time, time_span->start_time);
   //time = ltt_time_mul(time, (float)ratio);
   //time = ltt_time_add(time_span->start_time, time);
-  time = ltt_time_from_double(value/NANOSECONDS_PER_SECOND);
+  time = ltt_time_add(ltt_time_from_double(value/NANOSECONDS_PER_SECOND),
+                      time_span.start_time);
 
   time_window.start_time = time;
   
@@ -3108,7 +3190,7 @@ void scroll_value_changed_cb(GtkWidget *scrollbar,
 
   time_window.time_width = 
     ltt_time_from_double(page_size/NANOSECONDS_PER_SECOND);
-  //time = ltt_time_sub(time_span->end_time, time);
+  //time = ltt_time_sub(time_span.end_time, time);
   //if(ltt_time_compare(time,time_window.time_width) < 0){
   //  time_window.time_width = time;
   //}
@@ -3625,9 +3707,13 @@ void construct_main_window(MainWindow * parent)
     new_tab = create_tab(new_m_window, parent_tab, notebook, "Traceset");
   } else {
     new_tab = create_tab(new_m_window, NULL, notebook, "Traceset");
+    /* First window, use command line trace */
     if(g_init_trace != NULL){
       lttvwindow_add_trace(new_tab,
                            g_init_trace);
+
+      LttvTraceset *traceset = new_tab->traceset_info->traceset;
+      SetTraceset(new_tab, traceset);
     }
   }
 
@@ -3703,12 +3789,13 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
     tab->traceset_info->traceset = lttv_traceset_new();
   }
 
-//FIXME : this is g_debug level
+#ifdef DEBUG
   lttv_attribute_write_xml(
       lttv_traceset_attribute(tab->traceset_info->traceset),
       stdout,
       0, 4);
   fflush(stdout);
+#endif //DEBUG
 
 
   //FIXME copy not implemented in lower level
@@ -3750,8 +3837,8 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
   tab->attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
   tab->interrupted_state = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
  
-  tab->vbox = gtk_vbox_new(FALSE, 0);
-  tab->viewer_container = gtk_vbox_new(TRUE, 0);
+  tab->vbox = gtk_vbox_new(FALSE, 2);
+  tab->viewer_container = gtk_vbox_new(TRUE, 2);
   tab->scrollbar = gtk_hscrollbar_new(NULL);
   //tab->multivpaned = gtk_multi_vpaned_new();
   
This page took 0.026915 seconds and 4 git commands to generate.