Reduce noise on the memory benchmarks (#19630)
- Check memory usage in release builds, not profile. - Use multiple runs and average the results.
This commit is contained in:
@@ -83,9 +83,18 @@ abstract class Device {
|
||||
/// Assumes the device doesn't have a secure unlock pattern.
|
||||
Future<Null> unlock();
|
||||
|
||||
/// Emulate a tap on the touch screen.
|
||||
Future<Null> tap(int x, int y);
|
||||
|
||||
/// Read memory statistics for a process.
|
||||
Future<Map<String, dynamic>> getMemoryStats(String packageName);
|
||||
|
||||
/// Stream the system log from the device.
|
||||
///
|
||||
/// Flutter applications' `print` statements end up in this log
|
||||
/// with some prefix.
|
||||
Stream<String> get logcat;
|
||||
|
||||
/// Stop a process.
|
||||
Future<Null> stop(String packageName);
|
||||
}
|
||||
@@ -237,6 +246,11 @@ class AndroidDevice implements Device {
|
||||
await shellExec('input', const <String>['keyevent', '82']);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> tap(int x, int y) async {
|
||||
await shellExec('input', <String>['tap', '$x', '$y']);
|
||||
}
|
||||
|
||||
/// Retrieves device's wakefulness state.
|
||||
///
|
||||
/// See: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/PowerManagerInternal.java
|
||||
@@ -271,6 +285,63 @@ class AndroidDevice implements Device {
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<String> get logcat {
|
||||
final Completer<void> stdoutDone = new Completer<void>();
|
||||
final Completer<void> stderrDone = new Completer<void>();
|
||||
final Completer<void> processDone = new Completer<void>();
|
||||
final Completer<void> abort = new Completer<void>();
|
||||
bool aborted = false;
|
||||
StreamController<String> stream;
|
||||
stream = new StreamController<String>(
|
||||
onListen: () async {
|
||||
await adb(<String>['logcat', '--clear']);
|
||||
final Process process = await startProcess(adbPath, <String>['-s', deviceId, 'logcat']);
|
||||
process.stdout
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) {
|
||||
print('adb logcat: $line');
|
||||
stream.sink.add(line);
|
||||
}, onDone: () { stdoutDone.complete(); });
|
||||
process.stderr
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) {
|
||||
print('adb logcat stderr: $line');
|
||||
}, onDone: () { stderrDone.complete(); });
|
||||
process.exitCode.then((int exitCode) {
|
||||
print('adb logcat process terminated with exit code $exitCode');
|
||||
if (!aborted) {
|
||||
stream.addError(BuildFailedError('adb logcat failed with exit code $exitCode.'));
|
||||
processDone.complete();
|
||||
}
|
||||
});
|
||||
await Future.any<dynamic>(<Future<dynamic>>[
|
||||
Future.wait<void>(<Future<void>>[
|
||||
stdoutDone.future,
|
||||
stderrDone.future,
|
||||
processDone.future,
|
||||
]),
|
||||
abort.future,
|
||||
]);
|
||||
aborted = true;
|
||||
print('terminating adb logcat');
|
||||
process.kill();
|
||||
print('closing logcat stream');
|
||||
await stream.close();
|
||||
},
|
||||
onCancel: () {
|
||||
if (!aborted) {
|
||||
print('adb logcat aborted');
|
||||
aborted = true;
|
||||
abort.complete();
|
||||
}
|
||||
},
|
||||
);
|
||||
return stream.stream;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> stop(String packageName) async {
|
||||
return shellExec('am', <String>['force-stop', packageName]);
|
||||
@@ -371,11 +442,21 @@ class IosDevice implements Device {
|
||||
@override
|
||||
Future<Null> unlock() async {}
|
||||
|
||||
@override
|
||||
Future<Null> tap(int x, int y) async {
|
||||
throw 'Not implemented';
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getMemoryStats(String packageName) async {
|
||||
throw 'Not implemented';
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<String> get logcat {
|
||||
throw 'Not implemented';
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> stop(String packageName) async {}
|
||||
}
|
||||
|
||||
@@ -81,12 +81,15 @@ class _TaskRunner {
|
||||
Future<TaskResult> run(Duration taskTimeout) async {
|
||||
try {
|
||||
_taskStarted = true;
|
||||
print('Running task.');
|
||||
final TaskResult result = await _performTask().timeout(taskTimeout);
|
||||
_completer.complete(result);
|
||||
return result;
|
||||
} on TimeoutException catch (_) {
|
||||
print('Task timed out after $taskTimeout.');
|
||||
return new TaskResult.failure('Task timed out after $taskTimeout');
|
||||
} finally {
|
||||
print('Cleaning up after task...');
|
||||
await forceQuitRunningProcesses();
|
||||
_closeKeepAlivePort();
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ Future<Null> forceQuitRunningProcesses() async {
|
||||
|
||||
// Whatever's left, kill it.
|
||||
for (ProcessInfo p in _runningProcesses) {
|
||||
print('Force quitting process:\n$p');
|
||||
print('Force-quitting process:\n$p');
|
||||
if (!p.process.kill()) {
|
||||
print('Failed to force quit process');
|
||||
}
|
||||
@@ -528,8 +528,6 @@ int parseServicePort(String line, {
|
||||
// e.g. "An Observatory debugger and profiler on ... is available at: http://127.0.0.1:8100/"
|
||||
final RegExp pattern = new RegExp('$prefix(\\S+:(\\d+)/\\S*)\$', multiLine: multiLine);
|
||||
final Match match = pattern.firstMatch(line);
|
||||
print(pattern);
|
||||
print(match);
|
||||
return match == null ? null : int.parse(match.group(2));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user