Unverified Commit 1b4d321b authored by Terry Lucas's avatar Terry Lucas Committed by GitHub

Fix Flutter tool to use correct adb parameter and collect Realtime value. (#49701)

* Fix parameter to adb to be _package.id instead of package._launchActivity.
parent 22fc2152
...@@ -659,9 +659,10 @@ class AndroidDevice extends Device { ...@@ -659,9 +659,10 @@ class AndroidDevice extends Device {
'shell', 'shell',
'dumpsys', 'dumpsys',
'meminfo', 'meminfo',
_package.launchActivity, _package.id,
'-d', '-d',
])); ]));
if (runResult.exitCode != 0) { if (runResult.exitCode != 0) {
return const MemoryInfo.empty(); return const MemoryInfo.empty();
} }
...@@ -801,8 +802,15 @@ Map<String, String> parseAdbDeviceProperties(String str) { ...@@ -801,8 +802,15 @@ Map<String, String> parseAdbDeviceProperties(String str) {
@visibleForTesting @visibleForTesting
AndroidMemoryInfo parseMeminfoDump(String input) { AndroidMemoryInfo parseMeminfoDump(String input) {
final AndroidMemoryInfo androidMemoryInfo = AndroidMemoryInfo(); final AndroidMemoryInfo androidMemoryInfo = AndroidMemoryInfo();
input
.split('\n') final List<String> lines = input.split('\n');
final String timelineData = lines.firstWhere((String line) =>
line.startsWith('${AndroidMemoryInfo._kUpTimeKey}: '));
final List<String> times = timelineData.trim().split('${AndroidMemoryInfo._kRealTimeKey}:');
androidMemoryInfo.realTime = int.tryParse(times.last.trim()) ?? 0;
lines
.skipWhile((String line) => !line.contains('App Summary')) .skipWhile((String line) => !line.contains('App Summary'))
.takeWhile((String line) => !line.contains('TOTAL')) .takeWhile((String line) => !line.contains('TOTAL'))
.where((String line) => line.contains(':')) .where((String line) => line.contains(':'))
...@@ -863,6 +871,8 @@ List<AndroidDevice> getAdbDevices() { ...@@ -863,6 +871,8 @@ List<AndroidDevice> getAdbDevices() {
/// Android specific implementation of memory info. /// Android specific implementation of memory info.
class AndroidMemoryInfo extends MemoryInfo { class AndroidMemoryInfo extends MemoryInfo {
static const String _kUpTimeKey = 'Uptime';
static const String _kRealTimeKey = 'Realtime';
static const String _kJavaHeapKey = 'Java Heap'; static const String _kJavaHeapKey = 'Java Heap';
static const String _kNativeHeapKey = 'Native Heap'; static const String _kNativeHeapKey = 'Native Heap';
static const String _kCodeKey = 'Code'; static const String _kCodeKey = 'Code';
...@@ -872,6 +882,10 @@ class AndroidMemoryInfo extends MemoryInfo { ...@@ -872,6 +882,10 @@ class AndroidMemoryInfo extends MemoryInfo {
static const String _kSystemKey = 'System'; static const String _kSystemKey = 'System';
static const String _kTotalKey = 'Total'; static const String _kTotalKey = 'Total';
// Realtime is time since the system was booted includes deep sleep. Clock
// is monotonic, and ticks even when the CPU is in power saving modes.
int realTime = 0;
// Each measurement has KB as a unit. // Each measurement has KB as a unit.
int javaHeap = 0; int javaHeap = 0;
int nativeHeap = 0; int nativeHeap = 0;
...@@ -885,6 +899,7 @@ class AndroidMemoryInfo extends MemoryInfo { ...@@ -885,6 +899,7 @@ class AndroidMemoryInfo extends MemoryInfo {
Map<String, Object> toJson() { Map<String, Object> toJson() {
return <String, Object>{ return <String, Object>{
'platform': 'Android', 'platform': 'Android',
_kRealTimeKey: realTime,
_kJavaHeapKey: javaHeap, _kJavaHeapKey: javaHeap,
_kNativeHeapKey: nativeHeap, _kNativeHeapKey: nativeHeap,
_kCodeKey: code, _kCodeKey: code,
......
...@@ -818,6 +818,7 @@ Uptime: 441088659 Realtime: 521464097 ...@@ -818,6 +818,7 @@ Uptime: 441088659 Realtime: 521464097
final AndroidMemoryInfo result = parseMeminfoDump(exampleOutput); final AndroidMemoryInfo result = parseMeminfoDump(exampleOutput);
// Parses correctly // Parses correctly
expect(result.realTime, 521464097);
expect(result.javaHeap, 4296); expect(result.javaHeap, 4296);
expect(result.nativeHeap, 8620); expect(result.nativeHeap, 8620);
expect(result.code, 11288); expect(result.code, 11288);
...@@ -829,6 +830,7 @@ Uptime: 441088659 Realtime: 521464097 ...@@ -829,6 +830,7 @@ Uptime: 441088659 Realtime: 521464097
// toJson works correctly // toJson works correctly
final Map<String, Object> json = result.toJson(); final Map<String, Object> json = result.toJson();
expect(json, containsPair('Realtime', 521464097));
expect(json, containsPair('Java Heap', 4296)); expect(json, containsPair('Java Heap', 4296));
expect(json, containsPair('Native Heap', 8620)); expect(json, containsPair('Native Heap', 8620));
expect(json, containsPair('Code', 11288)); expect(json, containsPair('Code', 11288));
......
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