Repository navigation
Register memory info command on vmservice for Android devices - #45568
Conversation
| Device _device; | ||
| set device(Device device) { | ||
| _device = device; | ||
| _peer.registerMethod('flutterRss', (rpc.Parameters params) async { |
There was a problem hiding this comment.
TBD: good method name
There was a problem hiding this comment.
Updated to flutterMemoryInfo
| vmServices = <VMService>[service]; | ||
| device.getLogReader(app: package).connectedVMServices = vmServices; | ||
| vmService = service; | ||
| service.device = device; |
There was a problem hiding this comment.
This is where the vmservice learns about the device type.
There was a problem hiding this comment.
Could you pass the device to VMService.connect ?
| } | ||
|
|
||
|
|
||
| const String _kJavaHeapKey = 'Java Heap'; |
There was a problem hiding this comment.
The string 'Java Heap' isn't in the example below or in the linked docs.
There was a problem hiding this comment.
Updated to full example
| for (String line in input.split('\n')) { | ||
| line = line.trim(); | ||
| if (line.startsWith(_kJavaHeapKey)) { | ||
| result[_kJavaHeapKey] = int.tryParse(line.split(':').last.trim()); |
There was a problem hiding this comment.
There are no colons in the example above or in the linked documentation.
There was a problem hiding this comment.
Parsing of 'TOTAL:' would be a little different because of 'TOTAL SWAP PSS:' on the same line I would ignore 'TOTAL:' as the other 7 will add up to this anyway.
Since the only data we care about is the App Summary. It might be safer to limit parsing - only calling int.tryParse in the App Summary section e.g.,
- start parsing after 'App Summary' is encountered
- stop parsing after 'Objects' is encountered
| Unknown 43971 43968 0 1 | ||
| TOTAL 95085 61120 31392 62 23108 13495 9612 | ||
|
|
||
| App Summary |
There was a problem hiding this comment.
This section is missing from the documentation. Do different Android versions output different info?
There was a problem hiding this comment.
Added to documentation. Not that I know of
There was a problem hiding this comment.
Limiting the parsing to just the 'App Summary' section might help with different versions. The only differences I've seen have to do with older Android version 7 I think.
Older (Android 7 I think)
Dalvik Heap 5110(3) 0 4136 4988(3) 0 0 9168 8958(6) 210
This is the modern output for a few years:
Dalvik Heap 34340 33816 0 0 62436 53883 8553
But I only care about the App Summary section.
| } | ||
|
|
||
| @override | ||
| Future<Map<String, Object>> queryRss() async { |
There was a problem hiding this comment.
Instead of returning a Map, consider promoting the return type here to a class with platform agnostic fields from a base class and android-specific fields from an inherited class.
Then, instead of naming this method queryRss you can name it queryBaseClass since it's really doing a lot more than just grabbing Rss.
There was a problem hiding this comment.
I would be converting that back to JSON almost immediately though, so it would be a fairly short-lived object.
I'll wait for terry to chime in with what information we actually need from this dumpinfo first.
There was a problem hiding this comment.
When adding support for this to a new platform, it will be good to have support from the language/type-system ensuring that the expected info is filled in.
There was a problem hiding this comment.
Jonah I was hopping to get all information in the App Summary section:
Java Heap:
Native Heap:
Code::
Stack:
Graphics:
Private Other:
System:
TOTAL:
these numbers seem the most useful for Android users (or at least its what Android Studio reports in their memory profiler).
At some point, we we'll probably hookup to dumpsys battery and dumpsys network stats too. These might be passed as a row(s) or data instead of lots of parsing (but that's in the future). The JSON/Map seems fine for me as it will be coming via a service call.
| final Device device; | ||
| final ResidentCompiler generator; | ||
| Stream<Uri> observatoryUris; | ||
| List<VMService> vmServices; |
There was a problem hiding this comment.
Maybe this cleanup should go in a separate PR.
| vmServices = <VMService>[service]; | ||
| device.getLogReader(app: package).connectedVMServices = vmServices; | ||
| vmService = service; | ||
| service.device = device; |
There was a problem hiding this comment.
Could you pass the device to VMService.connect ?
|
|
||
| /// The connected physical device instance. | ||
| Device _device; | ||
| set device(Device device) { |
There was a problem hiding this comment.
If you pass the device to VMService.connect, then maybe you don't need this complicated setter, and you can set up the extension in the constructor with all the other extensions.
| targetModel: TargetModel.dartdevc, | ||
| experimentalFlags: experimentalFlags, | ||
| platformDill: artifacts.getArtifactPath(Artifact.webPlatformKernelDill, mode: buildMode), | ||
| platformDill: fs.file(artifacts |
There was a problem hiding this comment.
This is an unrelated change, will revert
terrylucas
left a comment
There was a problem hiding this comment.
Thanks Jonah this is exactly what I needed. Added a few suggestions and comments.
|
I've updated the example with the fields Java Heap, Native Heap, Code, Stack, Graphics, Private Other, System, and Total. This is provided via the vmservice method In the case where I fail to parse a field, I'm defaulting it to 0. |
| .takeWhile((String line) => !line.contains('TOTAL')); | ||
| final AndroidMemoryInfo androidMemoryInfo = AndroidMemoryInfo(); | ||
| for (String line in lines) { | ||
| if (!line.contains(':')) { |
There was a problem hiding this comment.
To avoid mixing styles:
Maybe move to after the takeWhile, like .where((String line) => line.contains(':'))
Then you can .forEach((String line) {...}) instead of a for loop.
Description
Allows the Device sub-classes to provide a
queryRssmethod which is connected to the vmservice. implements this on AndroidDevice by calling #41225 and parsing the results.Also cleans up flutter device to support a single vmservice instance.
Fixes #41225
cc @terrylucas to determine what specific fields we need.