[Gnucash-changes] r12267 - gnucash/trunk - Add in some conditionally compiled hooks for turning callgrind on/off

David Hampton hampton at cvs.gnucash.org
Thu Jan 5 01:35:22 EST 2006


Author: hampton
Date: 2006-01-05 01:35:21 -0500 (Thu, 05 Jan 2006)
New Revision: 12267
Trac: http://svn.gnucash.org/trac/changeset/12267

Modified:
   gnucash/trunk/configure.in
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
   gnucash/trunk/src/gnome-utils/ui/gnc-main-window-ui.xml
Log:
Add in some conditionally compiled hooks for turning callgrind on/off
via the menus.


Modified: gnucash/trunk/configure.in
===================================================================
--- gnucash/trunk/configure.in	2006-01-05 06:33:10 UTC (rev 12266)
+++ gnucash/trunk/configure.in	2006-01-05 06:35:21 UTC (rev 12267)
@@ -1711,6 +1711,10 @@
 BB_ENABLE_DOXYGEN
 
 
+# check for callgrind
+# ----------------------------------------------------------------------------
+AC_CHECK_HEADERS(valgrind/callgrind.h)
+
 ### --------------------------------------------------------------------------
 ### Libraries
 LIBS="$LIBS -lm"

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2006-01-05 06:33:10 UTC (rev 12266)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2006-01-05 06:35:21 UTC (rev 12267)
@@ -40,6 +40,9 @@
 #ifndef HAVE_GLIB26
 #include "gkeyfile.h"
 #endif
+#ifdef HAVE_VALGRIND_CALLGRIND_H
+#include <valgrind/callgrind.h>
+#endif
 
 #include "gnc-plugin.h"
 #include "gnc-plugin-manager.h"
@@ -122,6 +125,7 @@
 static void gnc_main_window_cmd_view_toolbar (GtkAction *action, GncMainWindow *window);
 static void gnc_main_window_cmd_view_summary (GtkAction *action, GncMainWindow *window);
 static void gnc_main_window_cmd_view_statusbar (GtkAction *action, GncMainWindow *window);
+static void gnc_main_window_cmd_extensions_callgrind (GtkAction *action, GncMainWindow *window);
 static void gnc_main_window_cmd_actions_reset_warnings (GtkAction *action, GncMainWindow *window);
 static void gnc_main_window_cmd_actions_rename_page (GtkAction *action, GncMainWindow *window);
 static void gnc_main_window_cmd_window_new (GtkAction *action, GncMainWindow *window);
@@ -301,6 +305,9 @@
 	{ "ViewStatusbarAction", NULL, N_("Stat_us Bar"), NULL,
 	  N_("Show/hide the status bar on this window"),
 	  G_CALLBACK (gnc_main_window_cmd_view_statusbar), TRUE },
+	{ "ExtensionsCallgrindAction", NULL, "Use Callgrind", NULL,
+	  "Enable/disable the Valgrind/Callgrind profiling tool.",
+	  G_CALLBACK (gnc_main_window_cmd_extensions_callgrind), FALSE },
 };
 /** The number of toggle actions provided by the main window. */
 static guint n_toggle_actions = G_N_ELEMENTS (toggle_actions);
@@ -353,6 +360,9 @@
 static const gchar *always_hidden_actions[] = {
 	"ViewSortByAction",
 	"ViewFilterByAction",
+#ifndef HAVE_VALGRIND_CALLGRIND_H
+	"ExtensionsCallgrindAction",
+#endif
 	NULL
 };
 
@@ -2722,6 +2732,34 @@
 }
 
 static void
+gnc_main_window_cmd_extensions_callgrind (GtkAction *action, GncMainWindow *window)
+{
+#ifdef HAVE_VALGRIND_CALLGRIND_H
+	GncMainWindowPrivate *priv;
+	static struct timeval start, end;
+
+	priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
+	if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
+	  printf("Start timing.\n");
+	  gettimeofday(&start, NULL);
+	  CALLGRIND_START_INSTRUMENTATION();
+	  CALLGRIND_TOGGLE_COLLECT();
+	} else {
+	  CALLGRIND_TOGGLE_COLLECT();
+	  CALLGRIND_STOP_INSTRUMENTATION();
+	  gettimeofday(&end, NULL);
+	  if (start.tv_usec > end.tv_usec) {
+	    end.tv_usec += 1000000;
+	    end.tv_sec  -= 1;
+	  }
+	  printf("Callgrind enabled for %d.%6d seconds.\n",
+		 (int)(end.tv_sec - start.tv_sec),
+		 (int)(end.tv_usec - start.tv_usec));
+	}
+#endif
+}
+
+static void
 gnc_main_window_cmd_window_new (GtkAction *action, GncMainWindow *window)
 {
 	GncMainWindow *new_window;

Modified: gnucash/trunk/src/gnome-utils/ui/gnc-main-window-ui.xml
===================================================================
--- gnucash/trunk/src/gnome-utils/ui/gnc-main-window-ui.xml	2006-01-05 06:33:10 UTC (rev 12266)
+++ gnucash/trunk/src/gnome-utils/ui/gnc-main-window-ui.xml	2006-01-05 06:35:21 UTC (rev 12267)
@@ -108,6 +108,7 @@
     </menu>
 
     <menu name="Extensions" action="ExtensionsAction">
+      <menuitem name="Callgrind"      action="ExtensionsCallgrindAction"/>
       <placeholder name="ExtensionsPlaceholder"/>
     </menu>
 



More information about the gnucash-changes mailing list