[vm] buffer size based log flushing

Useful when debugging on Android, since adb logcat
truncates messages that are "too long" (and always
flushing would result in too many short messages).

Change-Id: I51978b4e352d65c9074ab1d830b042f68e06710d
Reviewed-on: https://dart-review.googlesource.com/70740
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Aart Bik <ajcbik@google.com>
This commit is contained in:
Aart Bik 2018-08-20 22:47:31 +00:00 committed by commit-bot@chromium.org
parent dec1da2437
commit 7f88b64e0a
2 changed files with 19 additions and 1 deletions

View file

@ -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();
}

View file

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