Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[integration_test] Add watchPerformance #3116

Merged
merged 6 commits into from Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/integration_test/CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.9.2

* Add `watchPerformance` for performance test.

## 0.9.1

* Keep handling deprecated Android v1 classes for backward compatibility.
Expand Down
31 changes: 31 additions & 0 deletions packages/integration_test/lib/integration_test.dart
Expand Up @@ -4,6 +4,7 @@

import 'dart:async';
import 'dart:developer' as developer;
import 'dart:ui';

import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -81,6 +82,10 @@ class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding

Size _surfaceSize;

// This flag is used to print warning messages when tracking performance
// under debug mode.
static bool _firstRun = false;

/// Artificially changes the surface size to `size` on the Widget binding,
/// then flushes microtasks.
///
Expand Down Expand Up @@ -282,4 +287,30 @@ class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding
reportData ??= <String, dynamic>{};
reportData[reportKey] = timeline.toJson();
}

/// Watches the [FrameTiming] during `action` and report it to the binding
/// with key `reportKey`.
///
/// This can be used to implement performance tests previously using
/// [traceAction] and [TimelineSummary] from [flutter_driver]
Future<void> watchPerformance(
Future<void> action(), {
String reportKey = 'performance',
}) async {
assert(() {
if (_firstRun) {
debugPrint(kDebugWarning);
_firstRun = false;
}
return true;
}());
final List<FrameTiming> frameTimings = <FrameTiming>[];
final TimingsCallback watcher = frameTimings.addAll;
addTimingsCallback(watcher);
await action();
removeTimingsCallback(watcher);
final FrameTimingSummarizer frameTimes = FrameTimingSummarizer(frameTimings);
reportData ??= <String, dynamic>{};
reportData[reportKey] = frameTimes.summary;
}
}
2 changes: 1 addition & 1 deletion packages/integration_test/pubspec.yaml
@@ -1,6 +1,6 @@
name: integration_test
description: Runs tests that use the flutter_test API as integration tests.
version: 0.9.1
version: 0.9.2
homepage: https://github.com/flutter/plugins/tree/master/packages/integration_test

environment:
Expand Down