Add in some conditionally compiled hooks for turning callgrind on/off

via the menus.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12267 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton
2006-01-05 06:35:21 +00:00
parent fe6c5d827e
commit 9cb14afc99
3 changed files with 43 additions and 0 deletions

View File

@@ -1711,6 +1711,10 @@ AC_SUBST(enable_latex_docs)
BB_ENABLE_DOXYGEN
# check for callgrind
# ----------------------------------------------------------------------------
AC_CHECK_HEADERS(valgrind/callgrind.h)
### --------------------------------------------------------------------------
### Libraries
LIBS="$LIBS -lm"

View File

@@ -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_refresh (GtkAction *action, GncMainWindow *
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 @@ static GtkToggleActionEntry toggle_actions [] =
{ "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_insensitive_actions[] = {
static const gchar *always_hidden_actions[] = {
"ViewSortByAction",
"ViewFilterByAction",
#ifndef HAVE_VALGRIND_CALLGRIND_H
"ExtensionsCallgrindAction",
#endif
NULL
};
@@ -2721,6 +2731,34 @@ gnc_main_window_cmd_view_statusbar (GtkAction *action, GncMainWindow *window)
}
}
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)
{

View File

@@ -108,6 +108,7 @@
</menu>
<menu name="Extensions" action="ExtensionsAction">
<menuitem name="Callgrind" action="ExtensionsCallgrindAction"/>
<placeholder name="ExtensionsPlaceholder"/>
</menu>