When running on multiple hosts with output coalesced, it is useful to
be able to isolate messages from individual processes.  This patch adds
the string "[hostname:pid] " to all messages emitted by libhugetlbfs.

This change uses a GNU extension of CPP that will eat a preceeding
comma when using ##__VA_ARGS__ and __VA_ARGS__ is empty.

Signed-off-by: Dean Luick <[EMAIL PROTECTED]> on behalf of Cray Inc.
---
Changes since V1:
The extra information is always printed.  Removed error checking on
call to gethostname() -- it was not really necessary.

I have tested this on x86_64.

Dean Luick
Cray Inc.


 debug.c                 |    7 +++++--
 libhugetlbfs_internal.h |   13 +++++++------
 2 files changed, 12 insertions(+), 8 deletions(-)


diff -ruNp libhugetlbfs-dev-20080319/debug.c 
libhugetlbfs-dev-20080319.modified/debug.c
--- libhugetlbfs-dev-20080319/debug.c   2008-03-19 10:25:28.000000000 -0500
+++ libhugetlbfs-dev-20080319.modified/debug.c  2008-04-09 11:04:25.000000000 
-0500
@@ -19,8 +19,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <malloc.h>
-#include <sys/mman.h>
+#include <unistd.h>
+#include <string.h>
 #include <errno.h>
 
 #include "hugetlbfs.h"
@@ -29,6 +29,7 @@
 
 int __hugetlbfs_verbose = 1;
 int __hugetlbfs_debug = 0;
+char __hugetlbfs_hostname[64];
 
 static int initialized;
 
@@ -47,6 +48,8 @@ static void __hugetlbfs_init_debug(void)
        if (env)
                __hugetlbfs_debug = 1;
 
+       gethostname(__hugetlbfs_hostname, sizeof(__hugetlbfs_hostname)-1);
+
        initialized = 1;
 }
 
diff -ruNp libhugetlbfs-dev-20080319/libhugetlbfs_internal.h 
libhugetlbfs-dev-20080319.modified/libhugetlbfs_internal.h
--- libhugetlbfs-dev-20080319/libhugetlbfs_internal.h   2008-03-19 
10:25:28.000000000 -0500
+++ libhugetlbfs-dev-20080319.modified/libhugetlbfs_internal.h  2008-04-09 
11:09:07.000000000 -0500
@@ -45,27 +45,28 @@ extern int __hugetlbfs_debug;
 extern void __hugetlbfs_setup_elflink();
 extern void __hugetlbfs_setup_morecore();
 extern void __hugetlbfs_setup_debug();
+extern char __hugetlbfs_hostname[];
 
-#define ERROR(...) \
+#define ERROR(format, ...) \
        do { \
                if (__hugetlbfs_debug || __hugetlbfs_verbose >= 1) { \
-                       fprintf(stderr, "libhugetlbfs: ERROR: " __VA_ARGS__); \
+                       fprintf(stderr, "libhugetlbfs [%s:%d]: ERROR: " format, 
__hugetlbfs_hostname, getpid(), ##__VA_ARGS__); \
                        fflush(stderr); \
                } \
        } while (0)
 
-#define WARNING(...) \
+#define WARNING(format, ...) \
        do { \
                if (__hugetlbfs_debug || __hugetlbfs_verbose >= 2) { \
-                       fprintf(stderr, "libhugetlbfs: WARNING: " __VA_ARGS__); 
\
+                       fprintf(stderr, "libhugetlbfs [%s:%d]: WARNING: " 
format, __hugetlbfs_hostname, getpid(), ##__VA_ARGS__); \
                        fflush(stderr); \
                } \
        } while (0)
 
-#define DEBUG(...) \
+#define DEBUG(format, ...) \
        do { \
                if (__hugetlbfs_debug || __hugetlbfs_verbose >= 3) { \
-                       fprintf(stderr, "libhugetlbfs: " __VA_ARGS__); \
+                       fprintf(stderr, "libhugetlbfs [%s:%d]: " format, 
__hugetlbfs_hostname, getpid(), ##__VA_ARGS__); \
                        fflush(stderr); \
                } \
        } while (0)

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to