summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2012-11-15 23:06:14 +0400
committerIvan Maidanski <ivmai@mail.ru>2012-11-15 23:06:14 +0400
commit1862047925292f4b84b8dc0d392b61ffc1b039da (patch)
tree444e4baa890cdb589cfd447448f89e3f75219213
parent2abed50383046d18d556cd5acb6896de4bb7db7f (diff)
downloadbdwgc-1862047925292f4b84b8dc0d392b61ffc1b039da.tar.gz
Improve logging for Android differentiating messages by log level
* include/private/gc_priv.h (VERBOSE): Move definition to be upper than GC_print_stats. * include/private/gc_priv.h (GC_print_stats): Define as macro (to VERBOSE) if GC_ANDROID_LOG. * include/private/gc_priv.h (GC_real_print_stats): New macro defined to GC_print_stats if not GC_ANDROID_LOG otherwise declared as global variable replacing GC_print_stats. * include/private/gc_priv.h (GC_stats_log_printf, GC_verbose_log_printf): Declare as GC_INNER function instead of macro if GC_ANDROID_LOG. * misc.c (GC_print_stats): Replace to GC_real_print_stats. * misc.c (GC_init): Set GC_real_print_stats instead of GC_print_stats. * misc.c (GC_log_printf): Use DEBUG log level instead of INFO (only if GC_ANDROID_LOG). * misc.c (GC_warn_printf): New macro (if not GC_ANDROID_LOG) or static routine (that writes to Android log at WARN level). * misc.c (GC_stats_log_printf, GC_verbose_log_printf): New GC_INNER function definition (only if GC_ANDROID_LOG) using INFO/VERBOSE Android log levels. * misc.c (GC_default_warn_proc): Use GC_warn_printf instead of GC_err_printf.
-rw-r--r--include/private/gc_priv.h20
-rw-r--r--misc.c36
2 files changed, 48 insertions, 8 deletions
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index 4ea9cf8e..146ccfb6 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -1885,16 +1885,25 @@ GC_EXTERN GC_bool GC_have_errors; /* We saw a smashed or leaked object. */
/* occasionally. It is ok to read it */
/* without acquiring the lock. */
+#define VERBOSE 2
#ifndef SMALL_CONFIG
/* GC_print_stats should be visible to extra/MacOS.c. */
- extern int GC_print_stats; /* Nonzero generates basic GC log. */
+# ifndef GC_ANDROID_LOG
+ extern int GC_print_stats; /* Nonzero generates basic GC log. */
/* VERBOSE generates add'l messages. */
+# define GC_real_print_stats GC_print_stats
+# else
+# ifndef GC_print_stats
+# define GC_print_stats VERBOSE
+# endif
+ extern int GC_real_print_stats;
+ /* Influences logging only if redirected to a file. */
+# endif
#else /* SMALL_CONFIG */
# define GC_print_stats 0
/* Will this remove the message character strings from the executable? */
/* With a particular level of optimizations, it should... */
#endif
-#define VERBOSE 2
#ifdef KEEP_BACK_PTRS
GC_EXTERN long GC_backtraces;
@@ -2040,10 +2049,17 @@ GC_API_PRIV void GC_log_printf(const char * format, ...)
}
#endif
+#ifndef GC_ANDROID_LOG
/* GC_stats_log_printf should be called only if GC_print_stats. */
# define GC_stats_log_printf GC_log_printf
/* GC_verbose_log_printf is called only if GC_print_stats is VERBOSE. */
# define GC_verbose_log_printf GC_log_printf
+#else
+ GC_INNER void GC_stats_log_printf(const char *format, ...)
+ GC_ATTR_FORMAT_PRINTF(1, 2);
+ GC_INNER void GC_verbose_log_printf(const char *format, ...)
+ GC_ATTR_FORMAT_PRINTF(1, 2);
+#endif /* GC_ANDROID_LOG */
/* Convenient macros for GC_stats/verbose_log_printf invocation. */
#define GC_COND_LOG_PRINTF if (!GC_print_stats) {} else GC_stats_log_printf
diff --git a/misc.c b/misc.c
index 77c78ce8..2c197ff6 100644
--- a/misc.c
+++ b/misc.c
@@ -91,7 +91,7 @@ int GC_dont_precollect = FALSE;
GC_bool GC_quiet = 0; /* used also in pcr_interface.c */
#ifndef SMALL_CONFIG
- int GC_print_stats = 0;
+ int GC_real_print_stats = 0;
#endif
#ifdef GC_PRINT_BACK_HEIGHT
@@ -860,12 +860,12 @@ GC_API void GC_CALL GC_init(void)
# ifdef GC_PRINT_VERBOSE_STATS
/* This is useful for debugging and profiling on platforms with */
/* missing getenv() (like WinCE). */
- GC_print_stats = VERBOSE;
+ GC_real_print_stats = VERBOSE;
# else
if (0 != GETENV("GC_PRINT_VERBOSE_STATS")) {
- GC_print_stats = VERBOSE;
+ GC_real_print_stats = VERBOSE;
} else if (0 != GETENV("GC_PRINT_STATS")) {
- GC_print_stats = 1;
+ GC_real_print_stats = 1;
}
# endif
# if defined(UNIX_LIKE) || defined(CYGWIN32) || defined(SYMBIAN)
@@ -1514,6 +1514,8 @@ void GC_err_printf(const char *format, ...)
ABORT("write to GC log failed");
}
+# define GC_warn_printf GC_err_printf
+
#else
# define GC_LOG_PRINTF_IMPL(loglevel, fileLogCond, format) \
@@ -1528,7 +1530,29 @@ void GC_err_printf(const char *format, ...)
void GC_log_printf(const char *format, ...)
{
- GC_LOG_PRINTF_IMPL(ANDROID_LOG_INFO, TRUE, format);
+ GC_LOG_PRINTF_IMPL(ANDROID_LOG_DEBUG, TRUE, format);
+ }
+
+ GC_INNER void GC_stats_log_printf(const char *format, ...)
+ {
+ GC_LOG_PRINTF_IMPL(ANDROID_LOG_INFO, GC_real_print_stats != 0, format);
+ }
+
+ GC_INNER void GC_verbose_log_printf(const char *format, ...)
+ {
+ GC_LOG_PRINTF_IMPL(ANDROID_LOG_VERBOSE, GC_real_print_stats == VERBOSE,
+ format);
+ }
+
+ STATIC void GC_warn_printf(const char *format, ...)
+ {
+ char buf[BUFSZ + 1];
+
+ GC_PRINTF_FILLBUF(buf, format);
+ __android_log_write(ANDROID_LOG_WARN, GC_ANDROID_LOG_TAG, buf);
+ if (GC_real_print_stats && GC_stderr != GC_DEFAULT_STDERR_FD
+ && WRITE(GC_stderr, buf, strlen(buf)) < 0)
+ ABORT("write to stderr failed");
}
#endif /* GC_ANDROID_LOG */
@@ -1546,7 +1570,7 @@ void GC_err_puts(const char *s)
STATIC void GC_CALLBACK GC_default_warn_proc(char *msg, GC_word arg)
{
/* TODO: Add assertion on arg comply with msg (format). */
- GC_err_printf(msg, arg);
+ GC_warn_printf(msg, arg);
}
GC_INNER GC_warn_proc GC_current_warn_proc = GC_default_warn_proc;