Bug 1618979 - Tweak base profiler logging. r=gerald

This fixes the declaration of (BaseProfiler)LogTest. It also makes it so that the logs show up on Android.
In xpcom we have printf_stderr which does something similar and also handles Windows.

Differential Revision: https://phabricator.services.mozilla.com/D64994

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2020-03-17 03:25:40 +00:00
Родитель e54247708a
Коммит e3cd7fc71c
2 изменённых файлов: 42 добавлений и 23 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -41,39 +41,47 @@
#include <stdint.h>
#include <string>
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 {