Mesa (master): util: add GALLIUM_LOG_FILE option for logging output to a file
Brian Paul
brianp at kemper.freedesktop.org
Fri May 25 16:03:05 UTC 2012
Module: Mesa
Branch: master
Commit: 9c8568743935f0892bb5bd33f5a5210bae53b8d3
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9c8568743935f0892bb5bd33f5a5210bae53b8d3
Author: Brian Paul <brianp at vmware.com>
Date: Tue May 22 09:32:50 2012 -0600
util: add GALLIUM_LOG_FILE option for logging output to a file
Useful for logging different runs to files and diffing, etc.
---
src/gallium/auxiliary/os/os_misc.c | 25 ++++++++++++++++++++++---
src/gallium/auxiliary/util/u_debug.c | 6 +++---
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/src/gallium/auxiliary/os/os_misc.c b/src/gallium/auxiliary/os/os_misc.c
index 5744dd5..447e720 100644
--- a/src/gallium/auxiliary/os/os_misc.c
+++ b/src/gallium/auxiliary/os/os_misc.c
@@ -50,16 +50,35 @@
void
os_log_message(const char *message)
{
+ /* If the GALLIUM_LOG_FILE environment variable is set to a valid filename,
+ * write all messages to that file.
+ */
+ static FILE *fout = NULL;
+
+ if (!fout) {
+ /* one-time init */
+ const char *filename = os_get_option("GALLIUM_LOG_FILE");
+ if (filename)
+ fout = fopen(filename, "w");
+ if (!fout)
+ fout = stderr;
+ }
+
#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
OutputDebugStringA(message);
if(GetConsoleWindow() && !IsDebuggerPresent()) {
fflush(stdout);
- fputs(message, stderr);
- fflush(stderr);
+ fputs(message, fout);
+ fflush(fout);
+ }
+ else if (fout != stderr) {
+ fputs(message, fout);
+ fflush(fout);
}
#else /* !PIPE_SUBSYSTEM_WINDOWS */
fflush(stdout);
- fputs(message, stderr);
+ fputs(message, fout);
+ fflush(fout);
#endif
}
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index df1d8e6..0a350ca 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -48,9 +48,9 @@
void _debug_vprintf(const char *format, va_list ap)
{
+ static char buf[4096] = {'\0'};
#if defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_EMBEDDED)
/* We buffer until we find a newline. */
- static char buf[4096] = {'\0'};
size_t len = strlen(buf);
int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
@@ -58,8 +58,8 @@ void _debug_vprintf(const char *format, va_list ap)
buf[0] = '\0';
}
#else
- /* Just print as-is to stderr */
- vfprintf(stderr, format, ap);
+ util_vsnprintf(buf, sizeof(buf), format, ap);
+ os_log_message(buf);
#endif
}
More information about the mesa-commit
mailing list