[Gnucash-changes] Chris Shoemaker's gnc-trace patch.

Derek Atkins warlord at cvs.gnucash.org
Fri Dec 31 17:50:40 EST 2004


Log Message:
-----------
Chris Shoemaker's gnc-trace patch.

	* src/engine/gnc-trace.[ch]:
	  - Recent use of malloc in gnc-trace breaks my compile, use g_malloc
	  - Fix leak of filename mem
	  - add indenting of trace file according to ENTER/LEAVE stack depth
	  - have ENTER report file name of function along with function name

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/engine:
        gnc-trace.c
        gnc-trace.h

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1872
retrieving revision 1.1873
diff -LChangeLog -LChangeLog -u -r1.1872 -r1.1873
--- ChangeLog
+++ ChangeLog
@@ -2,6 +2,13 @@
 
 	John Ellson's patch to fix some gcc4 warnings (bug #162582).
 
+	Chris Shoemaker's gnc-trace patch.
+	* src/engine/gnc-trace.[ch]:
+	  - Recent use of malloc in gnc-trace breaks my compile, use g_malloc
+	  - Fix leak of filename mem
+	  - add indenting of trace file according to ENTER/LEAVE stack depth
+	  - have ENTER report file name of function along with function name
+
 2004-12-29  Christian Stimming  <stimming at tuhh.de>
 
 	* src/tax/us/txf-de_DE.scm: Add Tax TXF categories for the de_DE
Index: gnc-trace.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-trace.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lsrc/engine/gnc-trace.c -Lsrc/engine/gnc-trace.c -u -r1.12 -r1.13
--- src/engine/gnc-trace.c
+++ src/engine/gnc-trace.c
@@ -72,14 +72,21 @@
 static FILE *fout = NULL;
 static const int MAX_TRACE_FILENAME = 100;
 
+/* Don't be fooled: gnc_trace_num_spaces has external linkage and
+   static storage, but can't be defined with 'extern' because it has
+   an initializer, and can't be declared with 'static' because that
+   would give it internal linkage. */
+gint __attribute__ ((unused)) gnc_trace_num_spaces = 0;
+
 static void
 fh_printer (const gchar   *log_domain,
             GLogLevelFlags    log_level,
             const gchar   *message,
             gpointer    user_data)
 {
+  extern gint gnc_trace_num_spaces;
   FILE *fh = user_data;
-  fprintf (fh, "%s\n", message);
+  fprintf (fh, "%*s%s\n", gnc_trace_num_spaces, "", message);
   fflush(fh);
 }
 
@@ -90,9 +97,11 @@
 
    fout = fopen ("/tmp/gnucash.trace", "w");
 
-   if(!fout && (filename = (char *)malloc(MAX_TRACE_FILENAME))) {
-      snprintf(filename, MAX_TRACE_FILENAME-1, "/tmp/gnucash.trace.%d", getpid());
+   if(!fout && (filename = (char *)g_malloc(MAX_TRACE_FILENAME))) {
+      snprintf(filename, MAX_TRACE_FILENAME-1, "/tmp/gnucash.trace.%d", 
+	       getpid());
       fout = fopen (filename, "w");
+      g_free(filename);
    }
 
    if(!fout)
Index: gnc-trace.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-trace.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lsrc/engine/gnc-trace.h -Lsrc/engine/gnc-trace.h -u -r1.12 -r1.13
--- src/engine/gnc-trace.h
+++ src/engine/gnc-trace.h
@@ -82,6 +82,8 @@
 
 //extern gncLogLevel gnc_log_modules[MOD_LAST + 1];
 
+#define GNC_TRACE_INDENT_WIDTH 4
+
 /** Initialize the error logging subsystem */
 void gnc_log_init (void);
 
@@ -104,7 +106,7 @@
 const char * gnc_log_prettify (const char *name);
 
 /* We want logging decisions to be made inline, rather than through
- * a CPU-cucking subroutine call. Thus, this is a #define, not a
+ * a CPU-sucking subroutine call. Thus, this is a #define, not a
  * subroutine call.  The prototype would have been:
  * gboolean gnc_should_log (gncModuleType module, gncLogLevel log_level); 
  *
@@ -159,7 +161,8 @@
 #define PINFO(format, args...) {                   \
   if (gnc_should_log (module, GNC_LOG_INFO)) {     \
     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO,         \
-      "Info: %s(): " format, FUNK , ## args);      \
+      "Info: %s(): " format,                       \
+      FUNK , ## args);                             \
   }                                                \
 }
 
@@ -167,23 +170,30 @@
 #define DEBUG(format, args...) {                   \
   if (gnc_should_log (module, GNC_LOG_DEBUG)) {    \
     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,        \
-      "Debug: %s(): " format, FUNK , ## args);     \
+      "Debug: %s(): " format,                      \
+      FUNK , ## args);                             \
   }                                                \
 }
 
 /** Print an function entry debugging message */
 #define ENTER(format, args...) {                   \
+  extern gint gnc_trace_num_spaces;                \
   if (gnc_should_log (module, GNC_LOG_DEBUG)) {    \
     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,        \
-      "Enter: %s" format, FUNK , ## args);         \
+      "Enter in %s: %s()" format, __FILE__,        \
+      FUNK , ## args);                             \
+    gnc_trace_num_spaces += GNC_TRACE_INDENT_WIDTH;\
   }                                                \
 }
 
 /** Print an function exit debugging message */
 #define LEAVE(format, args...) {                   \
+  extern gint gnc_trace_num_spaces;                \
   if (gnc_should_log (module, GNC_LOG_DEBUG)) {    \
+    gnc_trace_num_spaces -= GNC_TRACE_INDENT_WIDTH;\
     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,        \
-      "Leave: %s" format, FUNK , ## args);         \
+      "Leave: %s()" format,                        \
+      FUNK , ## args);                             \
   }                                                \
 }
 


More information about the gnucash-changes mailing list