[nautilus] Add profiling support



commit d1a5b063f58b93f01a1415ee3b547256ba7d61b7
Author: William Jon McCann <jmccann redhat com>
Date:   Tue Aug 7 17:16:48 2012 -0400

    Add profiling support
    
    Can now be profiled like so:
    strace -ttt -f -o /tmp/logfile.strace nautilus
    python plot-timeline.py -o prettygraph.png /tmp/logfile.strace
    
    See: http://www.gnome.org/~federico/news-2006-03.html#09

 configure.in                           |   14 +++++++
 libnautilus-private/Makefile.am        |    2 +
 libnautilus-private/nautilus-profile.c |   65 ++++++++++++++++++++++++++++++++
 libnautilus-private/nautilus-profile.h |   58 ++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+), 0 deletions(-)
---
diff --git a/configure.in b/configure.in
index cde9321..f4dc089 100644
--- a/configure.in
+++ b/configure.in
@@ -85,6 +85,19 @@ else
 fi
 
 dnl ==========================================================================
+dnl Enable Profiling
+
+AC_ARG_ENABLE(profiling,
+        [AC_HELP_STRING([--enable-profiling],
+        [turn on profiling])],
+        , enable_profiling=yes)
+
+if test "x$enable_profiling" = "xyes"; then
+    AC_DEFINE(ENABLE_PROFILING,1,[enable profiling])
+fi
+
+
+dnl ==========================================================================
 
 AC_CHECK_PROGS(PERL, perl5 perl)
 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
@@ -342,6 +355,7 @@ nautilus-$VERSION:
 	Tracker support:	$enable_tracker
 
         debugging support:      ${enable_debug}
+        profiling support:      ${enable_profiling}
 	nautilus-extension documentation: ${enable_gtk_doc}
 	nautilus-extension introspection: ${found_introspection}
 "
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 6c8c48b..cdd481f 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -142,6 +142,8 @@ libnautilus_private_la_SOURCES = \
 	nautilus-module.h \
 	nautilus-monitor.c \
 	nautilus-monitor.h \
+	nautilus-profile.c \
+	nautilus-profile.h \
 	nautilus-progress-info.c \
 	nautilus-progress-info.h \
 	nautilus-progress-info-manager.c \
diff --git a/libnautilus-private/nautilus-profile.c b/libnautilus-private/nautilus-profile.c
new file mode 100644
index 0000000..8c8d284
--- /dev/null
+++ b/libnautilus-private/nautilus-profile.c
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2005 William Jon McCann <mccann jhu edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors: William Jon McCann <mccann jhu edu>
+ *
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <signal.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
+#include "nautilus-profile.h"
+
+void
+_nautilus_profile_log (const char *func,
+                       const char *note,
+                       const char *format,
+                       ...)
+{
+        va_list args;
+        char   *str;
+        char   *formatted;
+
+        if (format == NULL) {
+                formatted = g_strdup ("");
+        } else {
+                va_start (args, format);
+                formatted = g_strdup_vprintf (format, args);
+                va_end (args);
+        }
+
+        if (func != NULL) {
+                str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname(), func, note ? note : "", formatted);
+        } else {
+                str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname(), note ? note : "", formatted);
+        }
+
+        g_free (formatted);
+
+        g_access (str, F_OK);
+        g_free (str);
+}
diff --git a/libnautilus-private/nautilus-profile.h b/libnautilus-private/nautilus-profile.h
new file mode 100644
index 0000000..c8c7704
--- /dev/null
+++ b/libnautilus-private/nautilus-profile.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2005 William Jon McCann <mccann jhu edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors: William Jon McCann <mccann jhu edu>
+ *
+ * Can be profiled like so:
+ *       strace -ttt -f -o /tmp/logfile.strace nautilus
+ *       python plot-timeline.py -o prettygraph.png /tmp/logfile.strace
+ *
+ *       See: http://www.gnome.org/~federico/news-2006-03.html#09
+ */
+
+#ifndef __NAUTILUS_PROFILE_H
+#define __NAUTILUS_PROFILE_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#ifdef ENABLE_PROFILING
+#ifdef G_HAVE_ISO_VARARGS
+#define nautilus_profile_start(...) _nautilus_profile_log (G_STRFUNC, "start", __VA_ARGS__)
+#define nautilus_profile_end(...)   _nautilus_profile_log (G_STRFUNC, "end", __VA_ARGS__)
+#define nautilus_profile_msg(...)   _nautilus_profile_log (NULL, NULL, __VA_ARGS__)
+#elif defined(G_HAVE_GNUC_VARARGS)
+#define nautilus_profile_start(format...) _nautilus_profile_log (G_STRFUNC, "start", format)
+#define nautilus_profile_end(format...)   _nautilus_profile_log (G_STRFUNC, "end", format)
+#define nautilus_profile_msg(format...)   _nautilus_profile_log (NULL, NULL, format)
+#endif
+#else
+#define nautilus_profile_start(...)
+#define nautilus_profile_end(...)
+#define nautilus_profile_msg(...)
+#endif
+
+void            _nautilus_profile_log    (const char *func,
+                                          const char *note,
+                                          const char *format,
+                                          ...) G_GNUC_PRINTF (3, 4);
+
+G_END_DECLS
+
+#endif /* __NAUTILUS_PROFILE_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]