diff --git a/runtime/vm/log.cc b/runtime/vm/log.cc index 83b99b20f07..c7c4c2ffe9a 100644 --- a/runtime/vm/log.cc +++ b/runtime/vm/log.cc @@ -12,6 +12,15 @@ namespace dart { DEFINE_FLAG(bool, force_log_flush, false, "Always flush log messages."); +// The following flag is useful when debugging on Android, since +// adb logcat truncates messages that are "too long" (and always +// flushing would result in too many short messages). +DEFINE_FLAG( + int, + force_log_flush_at_size, + 0, + "Flush log messages when buffer exceeds given size (disabled when 0)."); + DEFINE_FLAG(charp, isolate_log_filter, NULL, @@ -80,7 +89,7 @@ void Log::VPrint(const char* format, va_list args) { } free(buffer); - if ((manual_flush_ == 0) || FLAG_force_log_flush) { + if (ShouldFlush()) { Flush(); } } @@ -161,6 +170,12 @@ void Log::DisableManualFlush(const intptr_t cursor) { } } +bool Log::ShouldFlush() const { + return ((manual_flush_ == 0) || FLAG_force_log_flush || + ((FLAG_force_log_flush_at_size > 0) && + (cursor() > FLAG_force_log_flush_at_size))); +} + void LogBlock::Initialize() { log_->EnableManualFlush(); } diff --git a/runtime/vm/log.h b/runtime/vm/log.h index 8c851a436a2..c18d6f58673 100644 --- a/runtime/vm/log.h +++ b/runtime/vm/log.h @@ -54,6 +54,9 @@ class Log { void EnableManualFlush(); void DisableManualFlush(const intptr_t cursor); + // Returns true when flush is required. + bool ShouldFlush() const; + // Returns false if we should drop log messages related to 'isolate'. static bool ShouldLogForIsolate(const Isolate* isolate);