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 {
});
}
// 'W/ActivityManager: '
static final RegExp _logFormat = new RegExp(r'^[VDIWEF]\/.{8,}:\s');
// 'W/ActivityManager(pid): '
static final RegExp _logFormat = new RegExp(r'^[VDIWEF]\/.*?\(\s*(\d+)\):\s');
static final List<RegExp> _whitelistedTags = <RegExp>[
new RegExp(r'^[VDIWEF]\/flutter[^:]*:\s+', caseSensitive: false),
......@@ -657,14 +657,19 @@ class _AdbLogReader extends DeviceLogReader {
}
// Chop off the time.
line = line.substring(timeMatch.end + 1);
if (_logFormat.hasMatch(line)) {
// Filter on approved names and levels.
for (RegExp regex in _whitelistedTags) {
if (regex.hasMatch(line)) {
_acceptedLastLine = true;
_linesController.add(line);
return;
}
final Match logMatch = _logFormat.firstMatch(line);
if (logMatch != null) {
bool acceptLine = false;
if (appPid != null && int.parse(logMatch.group(1)) == appPid) {
acceptLine = true;
} else {
// Filter on approved names and levels.
acceptLine = _whitelistedTags.any((RegExp re) => re.hasMatch(line));
}
if (acceptLine) {
_acceptedLastLine = true;
_linesController.add(line);
return;
}
_acceptedLastLine = false;
} else if (line == '--------- beginning of system' ||
......
......@@ -374,6 +374,9 @@ abstract class DeviceLogReader {
@override
String toString() => name;
/// Process ID of the app on the deivce.
int appPid;
}
/// Describes an app running on the device.
......
......@@ -114,6 +114,7 @@ class ColdRunner extends ResidentRunner {
printTrace('Application running.');
if (vmService != null) {
device.getLogReader(app: package).appPid = vmService.vm.pid;
await vmService.vm.refreshViews();
printTrace('Connected to ${vmService.vm.firstView}\.');
}
......
......@@ -101,6 +101,8 @@ class HotRunner extends ResidentRunner {
return 2;
}
device.getLogReader(app: package).appPid = vmService.vm.pid;
try {
final Uri baseUri = await _initDevFS();
if (connectionInfoCompleter != null) {
......
......@@ -507,6 +507,7 @@ class VM extends ServiceObjectOwner {
_loaded = true;
// TODO(johnmccutchan): Extract any properties we care about here.
_pid = map['pid'];
// Remove any isolates which are now dead from the isolate cache.
_removeDeadIsolates(map['isolates']);
......@@ -521,6 +522,11 @@ class VM extends ServiceObjectOwner {
/// The set of live views.
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) {
final DateTime aStart = a.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