Reduce noise on the memory benchmarks (#19630)
- Check memory usage in release builds, not profile. - Use multiple runs and average the results.
This commit is contained in:
@@ -363,7 +363,7 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
|
||||
? const Text('Flutter gallery')
|
||||
: new Text(_category.name),
|
||||
),
|
||||
frontHeading: widget.testMode ? null: new Container(height: 24.0),
|
||||
frontHeading: widget.testMode ? null : new Container(height: 24.0),
|
||||
frontLayer: new AnimatedSwitcher(
|
||||
duration: _kFrontLayerSwitchDuration,
|
||||
switchOutCurve: switchOutCurve,
|
||||
|
||||
@@ -44,7 +44,7 @@ Future<Null> main() async {
|
||||
fail('Unrecognized demo names in _kSkippedDemoTitles: $_kSkippedDemoTitles');
|
||||
|
||||
runApp(const GalleryApp(testMode: true));
|
||||
final _LiveWidgetController controller = new _LiveWidgetController();
|
||||
final _LiveWidgetController controller = new _LiveWidgetController(WidgetsBinding.instance);
|
||||
for (GalleryDemoCategory category in kAllGalleryDemoCategories) {
|
||||
await controller.tap(find.text(category.name));
|
||||
for (GalleryDemo demo in kGalleryCategoryToDemos[category]) {
|
||||
@@ -73,9 +73,8 @@ Future<Null> main() async {
|
||||
}
|
||||
}
|
||||
|
||||
class _LiveWidgetController {
|
||||
|
||||
final WidgetController _controller = new WidgetController(WidgetsBinding.instance);
|
||||
class _LiveWidgetController extends LiveWidgetController {
|
||||
_LiveWidgetController(WidgetsBinding binding) : super(binding);
|
||||
|
||||
/// With [frameSync] enabled, Flutter Driver will wait to perform an action
|
||||
/// until there are no pending frames in the app under test.
|
||||
@@ -107,8 +106,9 @@ class _LiveWidgetController {
|
||||
return finder;
|
||||
}
|
||||
|
||||
Future<Null> tap(Finder finder) async {
|
||||
await _controller.tap(await _waitForElement(finder));
|
||||
@override
|
||||
Future<Null> tap(Finder finder, { int pointer }) async {
|
||||
await tap(await _waitForElement(finder), pointer: pointer);
|
||||
}
|
||||
|
||||
Future<Null> scrollIntoView(Finder finder, {double alignment}) async {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
import 'package:flutter_driver/driver_extension.dart';
|
||||
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
enableFlutterDriverExtension();
|
||||
// As in lib/main.dart: overriding https://github.com/flutter/flutter/issues/13736
|
||||
// for better visual effect at the cost of performance.
|
||||
MaterialPageRoute.debugEnableFadingRoutes = true; // ignore: deprecated_member_use
|
||||
runApp(const GalleryApp(testMode: true));
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import 'package:flutter_driver/flutter_driver.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('flutter gallery transitions', () {
|
||||
FlutterDriver driver;
|
||||
setUpAll(() async {
|
||||
driver = await FlutterDriver.connect();
|
||||
});
|
||||
|
||||
tearDownAll(() async {
|
||||
if (driver != null)
|
||||
await driver.close();
|
||||
});
|
||||
|
||||
test('navigation', () async {
|
||||
await driver.tap(find.text('Material'));
|
||||
|
||||
final SerializableFinder demoList = find.byValueKey('GalleryDemoList');
|
||||
final SerializableFinder demoItem = find.text('Text fields');
|
||||
await driver.scrollUntilVisible(demoList, demoItem,
|
||||
dyScroll: -300.0,
|
||||
alignment: 0.5,
|
||||
timeout: const Duration(minutes: 1),
|
||||
);
|
||||
for (int i = 0; i < 15; i++) {
|
||||
await driver.tap(demoItem);
|
||||
await driver.tap(find.byTooltip('Back'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
37
examples/flutter_gallery/test_memory/back_button.dart
Normal file
37
examples/flutter_gallery/test_memory/back_button.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// See //dev/devicelab/bin/tasks/flutter_gallery__memory_nav.dart
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Future<void> endOfAnimation() async {
|
||||
do {
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
} while (SchedulerBinding.instance.hasScheduledFrame);
|
||||
}
|
||||
|
||||
int iteration = 0;
|
||||
|
||||
class LifecycleObserver extends WidgetsBindingObserver {
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
debugPrint('==== MEMORY BENCHMARK ==== $state ====');
|
||||
debugPrint('This was lifecycle event number $iteration in this instance');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> main() async {
|
||||
MaterialPageRoute.debugEnableFadingRoutes = true; // ignore: deprecated_member_use
|
||||
runApp(const GalleryApp());
|
||||
await endOfAnimation();
|
||||
await new Future<Null>.delayed(const Duration(milliseconds: 50));
|
||||
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
|
||||
WidgetsBinding.instance.addObserver(new LifecycleObserver());
|
||||
}
|
||||
72
examples/flutter_gallery/test_memory/memory_nav.dart
Normal file
72
examples/flutter_gallery/test_memory/memory_nav.dart
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// See //dev/devicelab/bin/tasks/flutter_gallery__memory_nav.dart
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Future<void> endOfAnimation() async {
|
||||
do {
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
} while (SchedulerBinding.instance.hasScheduledFrame);
|
||||
}
|
||||
|
||||
Future<void> main() async {
|
||||
MaterialPageRoute.debugEnableFadingRoutes = true; // ignore: deprecated_member_use
|
||||
final Completer<void> ready = new Completer<void>();
|
||||
runApp(new GestureDetector(
|
||||
onTap: () {
|
||||
debugPrint('Received tap.');
|
||||
ready.complete();
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const IgnorePointer(
|
||||
ignoring: true,
|
||||
child: GalleryApp(testMode: true),
|
||||
),
|
||||
));
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
await new Future<Null>.delayed(const Duration(milliseconds: 50));
|
||||
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
|
||||
|
||||
await ready.future;
|
||||
debugPrint('Continuing...');
|
||||
|
||||
// remove onTap handler, enable pointer events for app
|
||||
runApp(new GestureDetector(
|
||||
child: const IgnorePointer(
|
||||
ignoring: false,
|
||||
child: GalleryApp(testMode: true),
|
||||
),
|
||||
));
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
|
||||
final WidgetController controller = new LiveWidgetController(WidgetsBinding.instance);
|
||||
|
||||
debugPrint('Navigating...');
|
||||
await controller.tap(find.text('Material'));
|
||||
await new Future<Null>.delayed(const Duration(milliseconds: 150));
|
||||
final Finder demoList = find.byKey(const Key('GalleryDemoList'));
|
||||
final Finder demoItem = find.text('Text fields');
|
||||
do {
|
||||
await controller.drag(demoList, const Offset(0.0, -300.0));
|
||||
await new Future<Null>.delayed(const Duration(milliseconds: 20));
|
||||
} while (!demoItem.precache());
|
||||
|
||||
for (int iteration = 0; iteration < 15; iteration += 1) {
|
||||
debugPrint('Tapping... (iteration $iteration)');
|
||||
await controller.tap(demoItem);
|
||||
await endOfAnimation();
|
||||
debugPrint('Backing out...');
|
||||
await controller.tap(find.byTooltip('Back').last);
|
||||
await endOfAnimation();
|
||||
}
|
||||
|
||||
debugPrint('==== MEMORY BENCHMARK ==== DONE ====');
|
||||
}
|
||||
Reference in New Issue
Block a user