diff --git a/mozglue/baseprofiler/core/platform.cpp b/mozglue/baseprofiler/core/platform.cpp index 2023dfc9e6a7..bd7442985581 100644 --- a/mozglue/baseprofiler/core/platform.cpp +++ b/mozglue/baseprofiler/core/platform.cpp @@ -150,7 +150,7 @@ namespace baseprofiler { using detail::RacyFeatures; -bool BaseProfilerLogTest(int aLevelToTest) { +bool LogTest(int aLevelToTest) { static const int maxLevel = getenv("MOZ_BASE_PROFILER_VERBOSE_LOGGING") ? 5 @@ -160,6 +160,17 @@ bool BaseProfilerLogTest(int aLevelToTest) { return aLevelToTest <= maxLevel; } +void PrintToConsole(const char* aFmt, ...) { + va_list args; + va_start(args, aFmt); +# if defined(ANDROID) + __android_log_vprint(ANDROID_LOG_INFO, "Gecko", aFmt, args); +# else + vfprintf(stderr, aFmt, args); +# endif + va_end(args); +} + // Return all features that are available on this platform. static uint32_t AvailableFeatures() { uint32_t features = 0; diff --git a/mozglue/baseprofiler/core/platform.h b/mozglue/baseprofiler/core/platform.h index 5915eaf9d2fb..ef6f8a2acf43 100644 --- a/mozglue/baseprofiler/core/platform.h +++ b/mozglue/baseprofiler/core/platform.h @@ -41,39 +41,47 @@ #include #include -bool BaseProfilerLogTest(int aLevelToTest); +namespace mozilla { +namespace baseprofiler { +bool LogTest(int aLevelToTest); +void PrintToConsole(const char* aFmt, ...) MOZ_FORMAT_PRINTF(1, 2); +} // namespace baseprofiler +} // namespace mozilla // These are for MOZ_BASE_PROFILER_LOGGING and above. It's the default logging // level for the profiler, and should be used sparingly. -#define LOG_TEST BaseProfilerLogTest(3) -#define LOG(arg, ...) \ - do { \ - if (LOG_TEST) { \ - fprintf(stderr, "[I %d/%d] " arg "\n", profiler_current_process_id(), \ - profiler_current_thread_id(), ##__VA_ARGS__); \ - } \ +#define LOG_TEST ::mozilla::baseprofiler::LogTest(3) +#define LOG(arg, ...) \ + do { \ + if (LOG_TEST) { \ + ::mozilla::baseprofiler::PrintToConsole( \ + "[I %d/%d] " arg "\n", profiler_current_process_id(), \ + profiler_current_thread_id(), ##__VA_ARGS__); \ + } \ } while (0) // These are for MOZ_BASE_PROFILER_DEBUG_LOGGING. It should be used for logging // that is somewhat more verbose than LOG. -#define DEBUG_LOG_TEST BaseProfilerLogTest(4) -#define DEBUG_LOG(arg, ...) \ - do { \ - if (DEBUG_LOG_TEST) { \ - fprintf(stderr, "[D %d/%d] " arg "\n", profiler_current_process_id(), \ - profiler_current_thread_id(), ##__VA_ARGS__); \ - } \ +#define DEBUG_LOG_TEST ::mozilla::baseprofiler::LogTest(4) +#define DEBUG_LOG(arg, ...) \ + do { \ + if (DEBUG_LOG_TEST) { \ + ::mozilla::baseprofiler::PrintToConsole( \ + "[D %d/%d] " arg "\n", profiler_current_process_id(), \ + profiler_current_thread_id(), ##__VA_ARGS__); \ + } \ } while (0) // These are for MOZ_BASE_PROFILER_VERBOSE_LOGGING. It should be used for // logging that is somewhat more verbose than DEBUG_LOG. -#define VERBOSE_LOG_TEST BaseProfilerLogTest(5) -#define VERBOSE_LOG(arg, ...) \ - do { \ - if (VERBOSE_LOG_TEST) { \ - fprintf(stderr, "[V %d/%d] " arg "\n", profiler_current_process_id(), \ - profiler_current_thread_id(), ##__VA_ARGS__); \ - } \ +#define VERBOSE_LOG_TEST ::mozilla::baseprofiler::LogTest(5) +#define VERBOSE_LOG(arg, ...) \ + do { \ + if (VERBOSE_LOG_TEST) { \ + ::mozilla::baseprofiler::PrintToConsole( \ + "[V %d/%d] " arg "\n", profiler_current_process_id(), \ + profiler_current_thread_id(), ##__VA_ARGS__); \ + } \ } while (0) namespace mozilla {