Skip to content

Register memory info command on vmservice for Android devices - #45568

Merged
jonahwilliams merged 8 commits into
flutter:masterfrom
jonahwilliams:wire_adb
Nov 26, 2019
Merged

jonahwilliams merged 8 commits into
flutter:masterfrom
jonahwilliams:wire_adb

Conversation

@jonahwilliams

@jonahwilliams jonahwilliams commented Nov 25, 2019 •

Copy link
Copy Markdown
Contributor

Description

Allows the Device sub-classes to provide a queryRss method 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.

@fluttergithubbot fluttergithubbot added tool Affects the "flutter" command-line tool. See also t: labels. work in progress; do not review labels Nov 25, 2019
Device _device;
set device(Device device) {
_device = device;
_peer.registerMethod('flutterRss', (rpc.Parameters params) async {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD: good method name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to flutterMemoryInfo

vmServices = <VMService>[service];
device.getLogReader(app: package).connectedVMServices = vmServices;
vmService = service;
service.device = device;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the vmservice learns about the device type.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pass the device to VMService.connect ?

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

FYI, @zanderso @jmagman

}


const String _kJavaHeapKey = 'Java Heap';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string 'Java Heap' isn't in the example below or in the linked docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no colons in the example above or in the linked documentation.

@terrylucas terrylucas Nov 26, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is missing from the documentation. Do different Android versions output different info?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to documentation. Not that I know of

@terrylucas terrylucas Nov 26, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this cleanup should go in a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

vmServices = <VMService>[service];
device.getLogReader(app: package).connectedVMServices = vmServices;
vmService = service;
service.device = device;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pass the device to VMService.connect ?


/// The connected physical device instance.
Device _device;
set device(Device device) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

targetModel: TargetModel.dartdevc,
experimentalFlags: experimentalFlags,
platformDill: artifacts.getArtifactPath(Artifact.webPlatformKernelDill, mode: buildMode),
platformDill: fs.file(artifacts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated change, will revert

@terrylucas terrylucas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jonah this is exactly what I needed. Added a few suggestions and comments.

@jonahwilliams jonahwilliams changed the title Register rss command on vmservice for Android devices Register memory info command on vmservice for Android devices Nov 26, 2019
@jonahwilliams

Copy link
Copy Markdown
Contributor Author

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 flutterMemoryInfo (taking better name suggestions). The map also contains an identifier for the platform returned.

In the case where I fail to parse a field, I'm defaulting it to 0.

@jonahwilliams
jonahwilliams marked this pull request as ready for review November 26, 2019 18:58

@zanderso zanderso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm w/ nit

.takeWhile((String line) => !line.contains('TOTAL'));
final AndroidMemoryInfo androidMemoryInfo = AndroidMemoryInfo();
for (String line in lines) {
if (!line.contains(':')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jonahwilliams
jonahwilliams merged commit 831163f into flutter:master Nov 26, 2019
@jonahwilliams
jonahwilliams deleted the wire_adb branch November 26, 2019 22:50
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Register additional Service Extensions to Flutter Tool for DevTools Profiling

5 participants