Commit 67b3871e authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Filter Android logs by the pid of the remote process (#9293)

Fixes https://github.com/flutter/flutter/issues/6849
parent 8bcf302e
...@@ -621,8 +621,8 @@ class _AdbLogReader extends DeviceLogReader { ...@@ -621,8 +621,8 @@ class _AdbLogReader extends DeviceLogReader {
}); });
} }
// 'W/ActivityManager: ' // 'W/ActivityManager(pid): '
static final RegExp _logFormat = new RegExp(r'^[VDIWEF]\/.{8,}:\s'); static final RegExp _logFormat = new RegExp(r'^[VDIWEF]\/.*?\(\s*(\d+)\):\s');
static final List<RegExp> _whitelistedTags = <RegExp>[ static final List<RegExp> _whitelistedTags = <RegExp>[
new RegExp(r'^[VDIWEF]\/flutter[^:]*:\s+', caseSensitive: false), new RegExp(r'^[VDIWEF]\/flutter[^:]*:\s+', caseSensitive: false),
...@@ -657,14 +657,19 @@ class _AdbLogReader extends DeviceLogReader { ...@@ -657,14 +657,19 @@ class _AdbLogReader extends DeviceLogReader {
} }
// Chop off the time. // Chop off the time.
line = line.substring(timeMatch.end + 1); line = line.substring(timeMatch.end + 1);
if (_logFormat.hasMatch(line)) { final Match logMatch = _logFormat.firstMatch(line);
// Filter on approved names and levels. if (logMatch != null) {
for (RegExp regex in _whitelistedTags) { bool acceptLine = false;
if (regex.hasMatch(line)) { if (appPid != null && int.parse(logMatch.group(1)) == appPid) {
_acceptedLastLine = true; acceptLine = true;
_linesController.add(line); } else {
return; // Filter on approved names and levels.
} acceptLine = _whitelistedTags.any((RegExp re) => re.hasMatch(line));
}
if (acceptLine) {
_acceptedLastLine = true;
_linesController.add(line);
return;
} }
_acceptedLastLine = false; _acceptedLastLine = false;
} else if (line == '--------- beginning of system' || } else if (line == '--------- beginning of system' ||
......
...@@ -374,6 +374,9 @@ abstract class DeviceLogReader { ...@@ -374,6 +374,9 @@ abstract class DeviceLogReader {
@override @override
String toString() => name; String toString() => name;
/// Process ID of the app on the deivce.
int appPid;
} }
/// Describes an app running on the device. /// Describes an app running on the device.
......
...@@ -114,6 +114,7 @@ class ColdRunner extends ResidentRunner { ...@@ -114,6 +114,7 @@ class ColdRunner extends ResidentRunner {
printTrace('Application running.'); printTrace('Application running.');
if (vmService != null) { if (vmService != null) {
device.getLogReader(app: package).appPid = vmService.vm.pid;
await vmService.vm.refreshViews(); await vmService.vm.refreshViews();
printTrace('Connected to ${vmService.vm.firstView}\.'); printTrace('Connected to ${vmService.vm.firstView}\.');
} }
......
...@@ -101,6 +101,8 @@ class HotRunner extends ResidentRunner { ...@@ -101,6 +101,8 @@ class HotRunner extends ResidentRunner {
return 2; return 2;
} }
device.getLogReader(app: package).appPid = vmService.vm.pid;
try { try {
final Uri baseUri = await _initDevFS(); final Uri baseUri = await _initDevFS();
if (connectionInfoCompleter != null) { if (connectionInfoCompleter != null) {
......
...@@ -507,6 +507,7 @@ class VM extends ServiceObjectOwner { ...@@ -507,6 +507,7 @@ class VM extends ServiceObjectOwner {
_loaded = true; _loaded = true;
// TODO(johnmccutchan): Extract any properties we care about here. // TODO(johnmccutchan): Extract any properties we care about here.
_pid = map['pid'];
// Remove any isolates which are now dead from the isolate cache. // Remove any isolates which are now dead from the isolate cache.
_removeDeadIsolates(map['isolates']); _removeDeadIsolates(map['isolates']);
...@@ -521,6 +522,11 @@ class VM extends ServiceObjectOwner { ...@@ -521,6 +522,11 @@ class VM extends ServiceObjectOwner {
/// The set of live views. /// The set of live views.
final Map<String, FlutterView> _viewCache = <String, FlutterView>{}; final Map<String, FlutterView> _viewCache = <String, FlutterView>{};
/// The pid of the VM's process.
int _pid;
int get pid => _pid;
int _compareIsolates(Isolate a, Isolate b) { int _compareIsolates(Isolate a, Isolate b) {
final DateTime aStart = a.startTime; final DateTime aStart = a.startTime;
final DateTime bStart = b.startTime; final DateTime bStart = b.startTime;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment