frame_timing_summarizer_test.dart 2.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui';

import 'package:flutter_test/flutter_test.dart';

void main() {
  test('Test FrameTimingSummarizer', () {
11 12 13
    List<int> vsyncTimes = <int>[
      for (int i = 0; i < 100; i += 1) 100 * (i + 1),
    ];
14
    List<int> buildTimes = <int>[
15
      for (int i = 0; i < 100; i += 1) vsyncTimes[i] + 1000 * (i + 1),
16 17
    ];
    List<int> rasterTimes = <int>[
18
      for (int i = 0; i < 100; i += 1) 1000 * (i + 1) + 1000,
19
    ];
20 21
    // reversed to make sure sort is working.
    buildTimes = buildTimes.reversed.toList();
22
    rasterTimes = rasterTimes.reversed.toList();
23
    vsyncTimes = vsyncTimes.reversed.toList();
24 25 26 27
    final List<FrameTiming> inputData = <FrameTiming>[
      for (int i = 0; i < 100; i += 1)
        FrameTiming(
          vsyncStart: 0,
28
          buildStart: vsyncTimes[i],
29 30 31 32 33
          buildFinish: buildTimes[i],
          rasterStart: 500,
          rasterFinish: rasterTimes[i],
        ),
    ];
34

35 36 37 38 39 40 41 42 43 44 45 46 47
    final FrameTimingSummarizer summary = FrameTimingSummarizer(inputData);
    expect(summary.averageFrameBuildTime.inMicroseconds, 50500);
    expect(summary.p90FrameBuildTime.inMicroseconds, 90000);
    expect(summary.p99FrameBuildTime.inMicroseconds, 99000);
    expect(summary.worstFrameBuildTime.inMicroseconds, 100000);
    expect(summary.missedFrameBuildBudget, 84);

    expect(summary.averageFrameRasterizerTime.inMicroseconds, 51000);
    expect(summary.p90FrameRasterizerTime.inMicroseconds, 90500);
    expect(summary.p99FrameRasterizerTime.inMicroseconds, 99500);
    expect(summary.worstFrameRasterizerTime.inMicroseconds, 100500);
    expect(summary.missedFrameRasterizerBudget, 85);
    expect(summary.frameBuildTime.length, 100);
48 49 50 51 52

    expect(summary.averageVsyncOverhead.inMicroseconds, 5050);
    expect(summary.p90VsyncOverhead.inMicroseconds, 9000);
    expect(summary.p99VsyncOverhead.inMicroseconds, 9900);
    expect(summary.worstVsyncOverhead.inMicroseconds, 10000);
53 54
  });
}