The adb logcat filtering will continue until morale improves. (flutter/engine#51069)

Closes https://github.com/flutter/flutter/issues/144346.
This commit is contained in:
Matan Lurey
2024-02-28 19:10:17 -08:00
committed by GitHub
parent f1eec9b65f
commit b2b8311980
3 changed files with 42 additions and 14 deletions

View File

@@ -68,14 +68,20 @@ extension type const AdbLogLine._(Match _match) {
/// Tries to parse the process that was started, if the log line is about it.
String? tryParseProcess() {
if (name == 'ActivityManager' && message.startsWith('Start proc')) {
// Start proc 6840:d
final RegExpMatch? match = RegExp(r'Start proc (\d+):').firstMatch(message);
if (name == activityManagerTag && message.startsWith('Start proc')) {
// ActivityManager: Start proc 4475:dev.flutter.scenarios/u0a190 for added application ...
final RegExpMatch? match = RegExp('Start proc (\\d+):$flutterProcessName').firstMatch(message);
return match?.group(1);
}
return null;
}
@visibleForTesting
static const String activityManagerTag = 'ActivityManager';
@visibleForTesting
static const String flutterProcessName = 'dev.flutter.scenarios';
@visibleForTesting
static const Set<String> knownNoiseTags = <String>{
'CCodec',
@@ -95,7 +101,7 @@ extension type const AdbLogLine._(Match _match) {
@visibleForTesting
static const Set<String> knownUsefulTags = <String>{
'ActivityManager',
activityManagerTag
};
@visibleForTesting

View File

@@ -21,7 +21,7 @@ void main() {
test('should always retain fatal logs', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess process = logcat.withProcess();
final FakeAdbProcess process = logcat.process();
process.fatal('Something', 'A bad thing happened');
final Iterable<String> filtered = filter(logcat.drain());
@@ -31,7 +31,7 @@ void main() {
test('should never retain debug logs', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess process = logcat.withProcess();
final FakeAdbProcess process = logcat.process();
final String tag = AdbLogLine.knownNoiseTags.first;
process.debug(tag, 'A debug message');
@@ -41,7 +41,7 @@ void main() {
test('should never retain logs from known "noise" tags', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess process = logcat.withProcess();
final FakeAdbProcess process = logcat.process();
final String tag = AdbLogLine.knownNoiseTags.first;
process.info(tag, 'Flutter flutter flutter');
@@ -51,7 +51,7 @@ void main() {
test('should always retain logs from known "useful" tags', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess process = logcat.withProcess();
final FakeAdbProcess process = logcat.process();
final String tag = AdbLogLine.knownUsefulTags.first;
process.info(tag, 'A useful message');
@@ -62,7 +62,7 @@ void main() {
test('if a process ID is passed, retain the log', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess process = logcat.withProcess();
final FakeAdbProcess process = logcat.process();
process.info('SomeTag', 'A message');
final Iterable<String> filtered = filter(logcat.drain(), filterProcessId: process.processId);
@@ -72,7 +72,7 @@ void main() {
test('even if a process ID passed, retain logs containing "flutter"', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess process = logcat.withProcess();
final FakeAdbProcess process = logcat.process();
process.info('SomeTag', 'A message with flutter');
final Iterable<String> filtered = filter(logcat.drain(), filterProcessId: process.processId);
@@ -82,7 +82,7 @@ void main() {
test('should retain E-level flags from known "useful" error tags', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess process = logcat.withProcess();
final FakeAdbProcess process = logcat.process();
final String tag = AdbLogLine.knownUsefulErrorTags.first;
process.error(tag, 'An error message');
process.info(tag, 'An info message');
@@ -94,7 +94,7 @@ void main() {
test('should filter out error logs from unimportant processes', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess process = logcat.withProcess();
final FakeAdbProcess process = logcat.process();
// I hate this one.
const String tag = 'gs.intelligence';
@@ -103,4 +103,26 @@ void main() {
final Iterable<String> filtered = filter(logcat.drain());
expect(filtered, isEmpty);
});
test('should filter the flutter-launched process, not just any process', () {
final FakeAdbLogcat logcat = FakeAdbLogcat();
final FakeAdbProcess device = logcat.process();
final FakeAdbProcess unrelated = logcat.process();
final FakeAdbProcess flutter = logcat.process();
device.info(AdbLogLine.activityManagerTag, 'Start proc ${unrelated.processId}:com.example.unrelated');
List<String> rawLines = logcat.drain();
expect(rawLines, hasLength(1));
AdbLogLine parsedLogLine = AdbLogLine.tryParse(rawLines.single)!;
expect(parsedLogLine.tryParseProcess(), isNull);
device.info(AdbLogLine.activityManagerTag, 'Start proc ${flutter.processId}:${AdbLogLine.flutterProcessName}');
rawLines = logcat.drain();
expect(rawLines, hasLength(1));
parsedLogLine = AdbLogLine.tryParse(rawLines.single)!;
expect(parsedLogLine.tryParseProcess(), '${flutter.processId}');
});
}

View File

@@ -61,7 +61,7 @@ final class FakeAdbLogcat {
///
/// Optionally specify a [processId] to use for the process, otherwise a
/// simple default is used (sequential numbers starting from 1000).
FakeAdbProcess withProcess({int? processId}) {
FakeAdbProcess process({int? processId}) {
processId ??= 1000 + _processById.length;
return _processById.putIfAbsent(
processId,
@@ -76,7 +76,7 @@ final class FakeAdbLogcat {
/// A stateful fixture that represents a fake process writing to `adb logcat`.
///
/// See [FakeAdbLogcat.withProcess] for how to create this fixture.
/// See [FakeAdbLogcat.process] for how to create this fixture.
final class FakeAdbProcess {
const FakeAdbProcess._(
this._logcat, {