dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.2k stars 1.57k forks source link

Expose more memory related metrics. #53134

Open polina-c opened 1 year ago

polina-c commented 1 year ago

Currently only memory numbers that is exposed to dart isolate are rss numbers:

ProcessInfo.currentRss
ProcessInfo.maxRss

It would be good to get more cheaply accessible numbers, like like currentIsolateHeap, totalHeap and whatever else is easy to expose in ProcessInfo.

It is needed to measure how a change in the code impacts memory consumption, by running the same test on the same machine 1000 times before change and after change, and recording the numbers.

I do not know which numbers will help. To run experiments that will show it, I need access to the numbers in a cheap way.

This is what my prototype outputs based on currentRss:

initialValue: 172.7 MB - 172.1 MB = 576 KB (0.33%)
deltaAvg: 49.7 MB - 49.9 MB = -266 KB (-0.52%)
deltaMax: 74.4 MB - 72.9 MB = 1.4 MB (1.97%)
absAvg: 222.4 MB - 222.1 MB = 310 KB (0.14%)
absMax: 247.1 MB - 245.1 MB = 2.0 MB (0.82%)
samples: 4245 - 4245 = 0

To set baseline, copy this code as parameter of MemoryBaselining:
      baseline: MemoryBaseline(
        rss: ValueSampler(initialValue: 181075968, deltaAvg: 52092107.835100144, deltaMax: 77987840, absAvg: 233155807.32171452, absMax: 259063808, samples: 4245,),
      )

See PR: https://github.com/dart-lang/leak_tracker/pull/114

polina-c commented 1 year ago

@bkonyi

a-siva commented 11 months ago

@polina-c would it make sense to implement this functionality in dart:developer similar to how we added reachabilityBarrier. Also to clarify we can provide this information only per isolate group and not for individual isolates in the isolate group.

polina-c commented 11 months ago

dart:developer is a good place

What is relation between isolate group and process? If a process may contain many isolate groups, I want also to be able to get all of them and total. It is because I want to be able to see how dart vm numbers relate to process monitor numbers on the device.

a-siva commented 11 months ago

What is relation between isolate group and process? If a process may contain many isolate groups, I want also to be able to get all of them and total. It is because I want to be able to see how dart vm numbers relate to process monitor numbers on the device.

It is possible to have multiple isolate groups in a process and multiple isolates in one isolate group. We could provide information about the group in which the current isolate exists. IsolateGroups is exposed at the Dart level only through vm-service. we would be able to surface the number only for the current isolate in dart:developer.

polina-c commented 11 months ago

Is it possible at least to get number of isolate groups in the process? Then, if the number is 1, I know I can compare the memory totals with numbers in activity monitor, that may help to understand how these numbers relate to each other.