performance_overlay.dart 3.08 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/rendering.dart';
6

Adam Barth's avatar
Adam Barth committed
7
import 'framework.dart';
8

9
/// Displays performance statistics.
10
class PerformanceOverlay extends LeafRenderObjectWidget {
11 12
  // TODO(abarth): We should have a page on the web site with a screenshot and
  // an explanation of all the various readouts.
13

14
  /// Create a performance overlay that only displays specific statistics. The
15 16
  /// mask is created by shifting 1 by the index of the specific
  /// [StatisticOption] to enable.
17
  PerformanceOverlay({ this.optionsMask, this.rasterizerThreshold: 0, Key key }) : super(key: key);
18

19 20
  /// Create a performance overlay that displays all available statistics
  PerformanceOverlay.allEnabled({ Key key, this.rasterizerThreshold: 0 })
Hixie's avatar
Hixie committed
21
    : optionsMask = (
22 23 24 25
        1 << PerformanceOverlayOption.displayRasterizerStatistics.index |
        1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index |
        1 << PerformanceOverlayOption.displayEngineStatistics.index |
        1 << PerformanceOverlayOption.visualizeEngineStatistics.index
Hixie's avatar
Hixie committed
26 27
      ),
      super(key: key);
28 29

  final int optionsMask;
30 31 32

  /// The rasterizer threshold is an integer specifying the number of frame
  /// intervals that the rasterizer must miss before it decides that the frame
Devon Carew's avatar
Devon Carew committed
33
  /// is suitable for capturing an SkPicture trace for further analysis.
34 35 36 37 38 39 40 41 42
  ///
  /// For example, if you want a trace of all pictures that could not be
  /// renderered by the rasterizer within the frame boundary (and hence caused
  /// jank), specify 1. Specifying 2 will trace all pictures that took more
  /// more than 2 frame intervals to render. Adjust this value to only capture
  /// the particularly expensive pictures while skipping the others. Specifying
  /// 0 disables all capture.
  ///
  /// Captured traces are placed on your device in the application documents
43
  /// directory in this form "trace_<collection_time>.skp". These can
44 45 46 47 48 49 50 51 52 53
  /// be viewed in the Skia debugger.
  ///
  /// Notes:
  /// The rasterizer only takes into account the time it took to render
  /// the already constructed picture. This include the Skia calls (which is
  /// also why an SkPicture trace is generated) but not any of the time spent in
  /// dart to construct that picture. To profile that part of your code, use
  /// the instrumentation available in observatory.
  ///
  /// To decide what threshold interval to use, count the number of horizontal
54
  /// lines displayed in the performance overlay for the rasterizer (not the
55 56
  /// engine). That should give an idea of how often frames are skipped (and by
  /// how many frame intervals).
57
  final int rasterizerThreshold;
58

59
  RenderPerformanceOverlay createRenderObject() => new RenderPerformanceOverlay(
60 61 62
    optionsMask: optionsMask,
    rasterizerThreshold: rasterizerThreshold
  );
63

64
  void updateRenderObject(RenderPerformanceOverlay renderObject, RenderObjectWidget oldWidget) {
65
    renderObject.optionsMask = optionsMask;
66
    renderObject.rasterizerThreshold = rasterizerThreshold;
67 68
  }
}