linker: only generate log messages when logging is enabled

Avoids some unnecessary work during dlopen/dlclose/dlsym for most
cases.

Bug: 122471935
Test: fewer page faults during app startup
Change-Id: Ie886e1e671066af3c6f3a895f9a8126f209d6660
This commit is contained in:
Tim Murray 2019-01-17 11:35:18 -08:00 committed by Josh Gao
parent 1f6adf5863
commit a022034da2
2 changed files with 11 additions and 10 deletions

View File

@ -118,11 +118,7 @@ void LinkerLogger::ResetState() {
flags_ |= ParseProperty(debug_ld_app);
}
void LinkerLogger::Log(uint32_t type, const char* format, ...) {
if ((flags_ & type) == 0) {
return;
}
void LinkerLogger::Log(const char* format, ...) {
va_list ap;
va_start(ap, format);
async_safe_format_log_va_list(ANDROID_LOG_DEBUG, "linker", format, ap);

View File

@ -35,10 +35,10 @@
#include <android-base/macros.h>
#define LD_LOG(type, x...) \
{ \
g_linker_logger.Log(type, x); \
}
#define LD_LOG(type, x...) \
do { \
if (g_linker_logger.IsEnabled(type)) g_linker_logger.Log(x); \
} while (0)
constexpr const uint32_t kLogErrors = 1 << 0;
constexpr const uint32_t kLogDlopen = 1 << 1;
@ -49,7 +49,12 @@ class LinkerLogger {
LinkerLogger() : flags_(0) { }
void ResetState();
void Log(uint32_t type, const char* format, ...);
void Log(const char* format, ...);
uint32_t IsEnabled(uint32_t type) {
return flags_ & type;
}
private:
uint32_t flags_;