When running on multiple hosts with output coalesced, it is useful to
be able to isolate messages from individual processes. This patch adds
the ability to add the string "[hostname:pid] " to all messages emitted
by libhugetlbfs. Display this additional information by setting the
environment variable HUGETLB_VERBOSE_ID to anything but "no".
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.
---
I have tested this on x86_64.
Dean Luick
Cray Inc.
HOWTO | 6 ++++++
debug.c | 23 +++++++++++++++++++++--
libhugetlbfs_internal.h | 18 ++++++++++++------
3 files changed, 39 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-07 17:01:12.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"
@@ -31,6 +31,17 @@ int __hugetlbfs_verbose = 1;
int __hugetlbfs_debug = 0;
static int initialized;
+static char hostname[64];
+
+char *__hugetlbfs_host_info(char *buf, int size)
+{
+ if (hostname[0] == 0) /* empty -- not set */
+ return "";
+
+ snprintf(buf, size, "[%s:%d] ", hostname, getpid());
+ buf[size-1] = 0; /* make sure it is null terminated */
+ return buf;
+}
static void __hugetlbfs_init_debug(void)
{
@@ -47,6 +58,14 @@ static void __hugetlbfs_init_debug(void)
if (env)
__hugetlbfs_debug = 1;
+ env = getenv("HUGETLB_VERBOSE_ID");
+ if (env && strcasecmp(env, "no") != 0) {
+ if (gethostname(hostname, sizeof(hostname)-1)) {
+ hostname[0] = 0;
+ DEBUG("Unable to get host name: %s", strerror(errno));
+ }
+ }
+
initialized = 1;
}
diff -ruNp libhugetlbfs-dev-20080319/HOWTO
libhugetlbfs-dev-20080319.modified/HOWTO
--- libhugetlbfs-dev-20080319/HOWTO 2008-03-19 10:25:28.000000000 -0500
+++ libhugetlbfs-dev-20080319.modified/HOWTO 2008-04-07 16:53:41.000000000
-0500
@@ -317,6 +317,9 @@ libhugetlbfs:
HUGETLB_VERBOSE
Specify the verbosity level of debugging output from 1
to 99 (default is 1)
+ HUGETLB_VERBOSE_ID
+ When not equal to "no", add "[hostname:pid] " in front of
+ all printed library output.
HUGETLB_PATH
Specify the path to the hugetlbfs mount point
HUGETLB_SHARE
@@ -442,6 +445,9 @@ exception is in cases where the library
happen if something goes wrong in the middle of unmapping and
remapping segments for the text/data/bss feature.
+Set the environment variable HUGETLB_VERBOSE_ID to anything but "no"
+to add "[hostname:pid] " in front of all library messages printed.
+
If an application fails to run, set the environment variable HUGETLB_DEBUG
to 1. This causes additional diagnostics to be run. This information should
be included when sending bug reports to the libhugetlbfs team.
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-03
11:22:13.000000000 -0500
@@ -45,27 +45,33 @@ extern int __hugetlbfs_debug;
extern void __hugetlbfs_setup_elflink();
extern void __hugetlbfs_setup_morecore();
extern void __hugetlbfs_setup_debug();
+extern char *__hugetlbfs_host_info(char *, int);
-#define ERROR(...) \
+#define HOST_BUF_SIZE 128
+
+#define ERROR(format, ...) \
do { \
if (__hugetlbfs_debug || __hugetlbfs_verbose >= 1) { \
- fprintf(stderr, "libhugetlbfs: ERROR: " __VA_ARGS__); \
+ char buf[HOST_BUF_SIZE]; \
+ fprintf(stderr, "%slibhugetlbfs: ERROR: " format,
__hugetlbfs_host_info(buf, HOST_BUF_SIZE), ##__VA_ARGS__); \
fflush(stderr); \
} \
} while (0)
-#define WARNING(...) \
+#define WARNING(format, ...) \
do { \
if (__hugetlbfs_debug || __hugetlbfs_verbose >= 2) { \
- fprintf(stderr, "libhugetlbfs: WARNING: " __VA_ARGS__);
\
+ char buf[HOST_BUF_SIZE]; \
+ fprintf(stderr, "%slibhugetlbfs: WARNING: " format,
__hugetlbfs_host_info(buf, HOST_BUF_SIZE), ##__VA_ARGS__); \
fflush(stderr); \
} \
} while (0)
-#define DEBUG(...) \
+#define DEBUG(format, ...) \
do { \
if (__hugetlbfs_debug || __hugetlbfs_verbose >= 3) { \
- fprintf(stderr, "libhugetlbfs: " __VA_ARGS__); \
+ char buf[HOST_BUF_SIZE]; \
+ fprintf(stderr, "%slibhugetlbfs: WARNING: " format,
__hugetlbfs_host_info(buf, HOST_BUF_SIZE), ##__VA_ARGS__); \
fflush(stderr); \
} \
} while (0)
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
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