1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-11 23:39:14 +00:00

Add web startup analyzer to material 3 demo (#2144)

This adds a tool to measure web app startup for the Material 3 demo.

Demo:
- [Example app](https://flutter-web-perf-experiments.web.app/)
- [Material
3](https://flutter-web-perf-experiments--material3-vswzldcy.web.app/)
(open console)

---------

Co-authored-by: Brett Morgan <brett.morgan@gmail.com>
Co-authored-by: Kevin Moore <kevmoo@google.com>
This commit is contained in:
John Ryan
2024-01-29 13:24:56 -08:00
committed by GitHub
parent dc37f37b5c
commit d96bb336b6
26 changed files with 670 additions and 17 deletions

View File

@@ -0,0 +1,43 @@
// Copyright 2021 The Flutter team. 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:async';
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
class FrameAnalyzer {
final WidgetsBinding _binding;
final Completer _onDone = Completer();
int _remainingFrames;
final int additionalFrames;
List<int> additionalFrameTimes = [];
FrameAnalyzer(this._binding, {this.additionalFrames = 10})
: _remainingFrames = additionalFrames;
Future captureAdditionalFrames() {
_binding.addTimingsCallback(_timingsCallback);
return _onDone.future;
}
_reportFrame(FrameTiming frameTiming) {
additionalFrameTimes.add(frameTiming.totalSpan.inMilliseconds);
}
_timingsCallback(timings) {
int i = 0;
while (_remainingFrames > 0 && i < timings.length) {
_reportFrame(timings[i]);
i++;
_remainingFrames--;
}
if (_remainingFrames <= 0) {
_binding.removeTimingsCallback(_timingsCallback);
_onDone.complete();
}
}
}

View File

@@ -0,0 +1,25 @@
// Copyright 2021 The Flutter team. 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:js_interop';
@JS()
@staticInterop
external FlutterWebStartupAnalyzer get flutterWebStartupAnalyzer;
@JS()
@staticInterop
class FlutterWebStartupAnalyzer {
external factory FlutterWebStartupAnalyzer();
}
extension FlutterWebStartupAnalyzerExtensions on FlutterWebStartupAnalyzer {
external JSObject get timings;
external void markStart(String name);
external void markFinished(String name);
external void capture(String name);
external void captureAll();
external void capturePaint();
external void report();
}