Add a devicelab test that captures memory usage metrics on Android (#7120)
This commit is contained in:
@@ -81,6 +81,12 @@ abstract class Device {
|
||||
///
|
||||
/// Assumes the device doesn't have a secure unlock pattern.
|
||||
Future<Null> unlock();
|
||||
|
||||
/// Read memory statistics for a process.
|
||||
Future<Map<String, dynamic>> getMemoryStats(String packageName);
|
||||
|
||||
/// Stop a process.
|
||||
Future<Null> stop(String packageName);
|
||||
}
|
||||
|
||||
class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
@@ -248,6 +254,20 @@ class AndroidDevice implements Device {
|
||||
Future<String> shellEval(String command, List<String> arguments, {Map<String, String> env}) {
|
||||
return eval(adbPath, <String>['shell', command]..addAll(arguments), env: env, canFail: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getMemoryStats(String packageName) async {
|
||||
String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]);
|
||||
Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo);
|
||||
return <String, dynamic>{
|
||||
'total_kb': int.parse(match.group(1)),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> stop(String packageName) async {
|
||||
return shellExec('am', <String>['force-stop', packageName]);
|
||||
}
|
||||
}
|
||||
|
||||
class IosDeviceDiscovery implements DeviceDiscovery {
|
||||
@@ -344,6 +364,14 @@ class IosDevice implements Device {
|
||||
|
||||
@override
|
||||
Future<Null> unlock() async {}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getMemoryStats(String packageName) async {
|
||||
throw 'Not implemented';
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> stop(String packageName) async {}
|
||||
}
|
||||
|
||||
/// Path to the `adb` executable.
|
||||
|
||||
@@ -28,7 +28,7 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
if (!file(taskExecutable).existsSync())
|
||||
throw 'Executable Dart file not found: $taskExecutable';
|
||||
|
||||
int vmServicePort = await _findAvailablePort();
|
||||
int vmServicePort = await findAvailablePort();
|
||||
Process runner = await startProcess(dartBin, <String>[
|
||||
'--enable-vm-service=$vmServicePort',
|
||||
'--no-pause-isolates-on-exit',
|
||||
@@ -118,17 +118,3 @@ Future<VMIsolate> _connectToRunnerIsolate(int vmServicePort) async {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> _findAvailablePort() async {
|
||||
int port = 20000;
|
||||
while (true) {
|
||||
try {
|
||||
ServerSocket socket =
|
||||
await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, port);
|
||||
await socket.close();
|
||||
return port;
|
||||
} catch (_) {
|
||||
port++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,10 +231,10 @@ Future<String> eval(String executable, List<String> arguments,
|
||||
}
|
||||
|
||||
Future<int> flutter(String command,
|
||||
{List<String> options: const <String>[], bool canFail: false}) {
|
||||
{List<String> options: const <String>[], bool canFail: false, Map<String, String> env}) {
|
||||
List<String> args = <String>[command]..addAll(options);
|
||||
return exec(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
canFail: canFail);
|
||||
canFail: canFail, env: env);
|
||||
}
|
||||
|
||||
String get dartBin =>
|
||||
@@ -404,3 +404,18 @@ Future<Null> runAndCaptureAsyncStacks(Future<Null> callback()) {
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/// Return an unused TCP port number.
|
||||
Future<int> findAvailablePort() async {
|
||||
int port = 20000;
|
||||
while (true) {
|
||||
try {
|
||||
ServerSocket socket =
|
||||
await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, port);
|
||||
await socket.close();
|
||||
return port;
|
||||
} catch (_) {
|
||||
port++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user