This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Provide a subset of adb logcat logs streaming during scenario_app testing
#50886
Merged
auto-submit
merged 7 commits into
flutter:main
from
matanlurey:filter-scenario_app-logging
Feb 23, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dcce941
Start working on filtering for adb logcat.
matanlurey 8b22b13
Refactor process management.
matanlurey f7e7647
Add basic filtering.
matanlurey eb84b3d
++
matanlurey c876adf
Format.
matanlurey 43cab82
Remove cat logcat.
matanlurey 90b68e6
++
matanlurey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /// Some notes about filtering `adb logcat` output, especially as a result of | ||
| /// running `adb shell` to instrument the app and test scripts, as it's | ||
| /// non-trivial and error-prone. | ||
| /// | ||
| /// 1. It's probably worth keeping `ActivityManager` lines unconditionally. | ||
| /// They are the most important ones, and they are not too verbose (for | ||
| /// example, they don't typically contain stack traces). | ||
| /// | ||
| /// 2. `ActivityManager` starts with the application name and process ID: | ||
| /// | ||
| /// ```txt | ||
| /// [stdout] 02-15 10:20:36.914 1735 1752 I ActivityManager: Start proc 6840:dev.flutter.scenarios/u0a98 for added application dev.flutter.scenarios | ||
| /// ``` | ||
| /// | ||
| /// The "application" comes from the file `android/app/build.gradle` under | ||
| /// `android > defaultConfig > applicationId`. | ||
| /// | ||
| /// 3. Once we have the process ID, we can filter the logcat output further: | ||
| /// | ||
| /// ```txt | ||
| /// [stdout] 02-15 10:20:37.430 6840 6840 E GeneratedPluginsRegister: Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@144d737) but could not find or invoke the GeneratedPluginRegistrant. | ||
| /// ``` | ||
| /// | ||
| /// A sample output of `adb logcat` command lives in `./sample_adb_logcat.txt`. | ||
| /// | ||
| /// See also: <https://developer.android.com/tools/logcat>. | ||
| library; | ||
|
|
||
| /// Represents a line of `adb logcat` output parsed into a structured form. | ||
| /// | ||
| /// For example the line: | ||
| /// ```txt | ||
| /// 02-22 13:54:39.839 549 3683 I ActivityManager: Force stopping dev.flutter.scenarios appid=10226 user=0: start instr | ||
| /// ``` | ||
| /// | ||
| /// ## Implementation notes | ||
| /// | ||
| /// The reason this is an extension type and not a class is partially to use the | ||
| /// language feature, and partially because extension types work really well | ||
| /// with lazy parsing. | ||
| extension type const AdbLogLine._(Match _match) { | ||
| // RegEx that parses into the following groups: | ||
| // 1. Everything up to the severity (I, W, E, etc.). | ||
| // In other words, any whitespace, numbers, hyphens, colons, and periods. | ||
| // 2. The severity (a single uppercase letter). | ||
| // 3. The name of the process (up to the colon). | ||
| // 4. The message (after the colon). | ||
| // | ||
| // This regex is simple versus being more precise. Feel free to improve it. | ||
| static final RegExp _pattern = RegExp(r'([^A-Z]*)([A-Z])\s([^:]*)\:\s(.*)'); | ||
|
|
||
| /// Parses the given [adbLogCatLine] into a structured form. | ||
| /// | ||
| /// Returns `null` if the line does not match the expected format. | ||
| static AdbLogLine? tryParse(String adbLogCatLine) { | ||
| final Match? match = _pattern.firstMatch(adbLogCatLine); | ||
| return match == null ? null : AdbLogLine._(match); | ||
| } | ||
|
|
||
| /// The full line of `adb logcat` output. | ||
| String get line => _match.group(0)!; | ||
|
|
||
| /// The process name, such as `ActivityManager`. | ||
| String get process => _match.group(3)!; | ||
|
|
||
| /// The actual log message. | ||
| String get message => _match.group(4)!; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this format documented? Not that this is a requirement, just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine. My only thought would be if this is TOO specific, and thus brittle to changes. But I'm inclined to say LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to make it fairly resilient, but it's not the best