continuedGrowthSlope static method

  1. @visibleForTesting
double continuedGrowthSlope(
  1. List<HeapSample> samples
)

The slowest growth rate across samples, in bytes/sec, over the whole window and over each half split at its time midpoint. Each rate is the lower of the native and RSS regressions. Zero while a half holds fewer than nativeMinSamplesPerHalf samples.

Native growth must show in the RSS itself. When RSS keeps the pages of freed Dart objects, a heap drop raises RSS minus the heap without moving RSS; a drop of about 25 MB or more read above 1 MiB/s for longer than 10 s.

Growth must also continue through the window. A one-time jump of D bytes in the middle of a 30 s window reads about 1.5 D / 30 s as one slope, so a screen that allocated 25 MB once read as growth for more than 10 s. A jump leaves one half flat. Growth that arrives in chunks more than about 15 s apart can leave a half flat too and is not reported.

Implementation

@visibleForTesting
static double continuedGrowthSlope(List<HeapSample> samples) {
  double rate(List<HeapSample> part) => math.min(
    _slopeBytesPerSec(part, (s) => s.nativeBytes!),
    _slopeBytesPerSec(part, (s) => s.rssBytes!),
  );
  final start = samples.first.timestamp;
  final middle = start.add(samples.last.timestamp.difference(start) ~/ 2);
  final split = samples.indexWhere((s) => !s.timestamp.isBefore(middle));
  if (split < nativeMinSamplesPerHalf ||
      samples.length - split < nativeMinSamplesPerHalf) {
    return 0;
  }
  return [
    rate(samples),
    rate(samples.sublist(0, split)),
    rate(samples.sublist(split)),
  ].reduce(math.min);
}