From 95c4497bd4ba7a4f072a5e7ffd7fd97560715c87 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 6 Feb 2018 15:49:26 -0800 Subject: [PATCH] adb: don't spew to logcat when tracing is enabled. When persist.adb.trace_mask is used to enable verbose logging, avoid exponential logging when a user runs `adb logcat`. As a side-effect, set the minimum logging level to include everything when ADB_TRACE is used on the client (which is something we want anyway). Bug: http://b/72971016 Test: `adb shell 'setprop persist.adb.trace_mask; killall adbd'; adb logcat` Change-Id: Id4bca1f3933a920345499dbeaeb103c8a2e220cd --- adb/adb_trace.cpp | 12 ++++++++++-- adb/adb_trace.h | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/adb/adb_trace.cpp b/adb/adb_trace.cpp index eac923d4d..a8ec5fb12 100644 --- a/adb/adb_trace.cpp +++ b/adb/adb_trace.cpp @@ -42,7 +42,11 @@ void AdbLogger(android::base::LogId id, android::base::LogSeverity severity, const char* message) { android::base::StderrLogger(id, severity, tag, file, line, message); #if !ADB_HOST - gLogdLogger(id, severity, tag, file, line, message); + // Only print logs of INFO or higher to logcat, so that `adb logcat` with adbd tracing on + // doesn't result in exponential logging. + if (severity >= android::base::INFO) { + gLogdLogger(id, severity, tag, file, line, message); + } #endif } @@ -137,11 +141,15 @@ static void setup_trace_mask() { // -1 is used for the special values "1" and "all" that enable all // tracing. adb_trace_mask = ~0; - return; + break; } else { adb_trace_mask |= 1 << flag->second; } } + + if (adb_trace_mask != 0) { + android::base::SetMinimumLogSeverity(android::base::VERBOSE); + } } void adb_trace_init(char** argv) { diff --git a/adb/adb_trace.h b/adb/adb_trace.h index fc6560cfb..1d2c8c704 100644 --- a/adb/adb_trace.h +++ b/adb/adb_trace.h @@ -43,11 +43,11 @@ enum AdbTrace { #define VLOG_IS_ON(TAG) \ ((adb_trace_mask & (1 << (TAG))) != 0) -#define VLOG(TAG) \ +#define VLOG(TAG) \ if (LIKELY(!VLOG_IS_ON(TAG))) \ - ; \ - else \ - LOG(INFO) + ; \ + else \ + LOG(DEBUG) // You must define TRACE_TAG before using this macro. #define D(...) \