[Mesa-dev] [RFC 4/7] android: print debug info to logcat

Chih-Wei Huang cwhuang at android-x86.org
Thu Apr 28 07:34:57 UTC 2016


From: WuZhen <wuzhen at jidemail.com>

Redirect logs printed to stderr to logcat.

NO_REF_TASK
tested: local run

Change-Id: I58e3966a608af361b86c54b4c95a92561b711968
Signed-off-by: Chih-Wei Huang <cwhuang at linux.org.tw>
---
 src/gallium/auxiliary/os/os_misc.c   | 12 ++++++++++--
 src/gallium/auxiliary/util/u_debug.c |  2 +-
 src/gallium/targets/dri/Android.mk   |  1 +
 src/mesa/main/errors.c               | 12 ++++++++++++
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/os/os_misc.c b/src/gallium/auxiliary/os/os_misc.c
index d6b83e9..08c438e 100644
--- a/src/gallium/auxiliary/os/os_misc.c
+++ b/src/gallium/auxiliary/os/os_misc.c
@@ -46,8 +46,10 @@
 
 #endif
 
-
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_CYGWIN) || defined(PIPE_OS_SOLARIS)
+#if defined(PIPE_OS_ANDROID)
+#  define LOG_TAG "gallium"
+#  include <log/log.h>
+#elif defined(PIPE_OS_LINUX) || defined(PIPE_OS_CYGWIN) || defined(PIPE_OS_SOLARIS)
 #  include <unistd.h>
 #elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD)
 #  include <sys/sysctl.h>
@@ -89,6 +91,12 @@ os_log_message(const char *message)
       fflush(fout);
    }
 #else /* !PIPE_SUBSYSTEM_WINDOWS */
+#if defined(PIPE_OS_ANDROID)
+   if (fout == stderr) {
+      ALOGD(message);
+      return;
+   }
+#endif
    fflush(stdout);
    fputs(message, fout);
    fflush(fout);
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index db66357..12ceada 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -55,7 +55,7 @@ void
 _debug_vprintf(const char *format, va_list ap)
 {
    static char buf[4096] = {'\0'};
-#if defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_EMBEDDED)
+#if defined(PIPE_OS_WINDOWS) || defined(PIPE_OS_ANDROID) || defined(PIPE_SUBSYSTEM_EMBEDDED)
    /* We buffer until we find a newline. */
    size_t len = strlen(buf);
    int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
diff --git a/src/gallium/targets/dri/Android.mk b/src/gallium/targets/dri/Android.mk
index 03c3795..a14d449 100644
--- a/src/gallium/targets/dri/Android.mk
+++ b/src/gallium/targets/dri/Android.mk
@@ -46,6 +46,7 @@ LOCAL_CFLAGS :=
 
 LOCAL_SHARED_LIBRARIES := \
 	libdl \
+	liblog \
 	libglapi \
 	libexpat \
 
diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 9932b4a..1bdd668 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -42,6 +42,10 @@
 #include "util/hash_table.h"
 #include "util/simple_list.h"
 
+#if defined(ANDROID)
+#  define LOG_TAG "mesa"
+#  include <log/log.h>
+#endif
 
 static FILE *LogFile = NULL;
 
@@ -87,6 +91,14 @@ output_if_debug(const char *prefixString, const char *outputString,
          fprintf(LogFile, "\n");
       fflush(LogFile);
 
+#if defined(ANDROID)
+      {
+         char buf[4096];
+         _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
+         ALOGD(buf);
+      }
+#endif
+
 #if defined(_WIN32)
       /* stderr from windows applications without console is not usually 
        * visible, so communicate with the debugger instead */ 
-- 
1.9.1



More information about the mesa-dev mailing list