There are many ways to write a memory test for Flutter. In this article, we give 3 classes of example tests that are currently used by Flutter device lab. Memory performance is a high priority for Flutter so there are many new memory tools and test utilities in progress. We’ll add them in this doc in the future.
These memory tests use the MemoryTest class defined in the device lab perf_tests.dart to poll adb directly before and after an overridable useMemory
function. By default, useMemory
will just run an app in release and wait for a “done” message to be printed in logcat.
Examples include
To write a new MemoryTest case some_memory_perf
and add it to Flutter’s device lab so Flutter’s CI system can measure it for each Flutter commit, follow examples above to
main
function for the test app in a file named like test_memory/some_memory_perf.dart
.some_memory_perf
entry to manifest.yamlsome_memory_perf.dart
file to dev/devicelab/bin/tasks folder.The memory tests use DevTools to poll adb and Dart VM during a normal Flutter driver test run, which typically measures speed performance instead of memory performance. DevToolsMemoryTest handles most of the process so a new test only needs to specify the driver test location.
Examples include
To write a new DevTools memory test case some_memory_perf
and add it to Flutter’s device lab so Flutter’s CI system can measure it for each Flutter commit, follow examples above to
test_driver/some_memory_perf.dart
and test_driver/some_memory_perf_test.dart
.some_memory_perf
entry to manifest.yamlsome_memory_perf.dart
file to dev/devicelab/bin/tasks folder.The iOS embedding of Flutter supports sampling memory usage during runtime, which then writes metrics to the Dart timeline. After recording a timeline for the relevant portion of an application’s execution, the timeline can be analyzed to obtain memory related information from the profile.
Examples include
To write a new iOS memory test case some_memory_perf
and add it to Flutter’s device lab so Flutter’s CI system can measure it for each Flutter commit, follow examples above to
test_driver/some_memory_perf.dart
and test_driver/some_memory_perf_test.dart
.some_memory_perf
entry to manifest.yamlsome_memory_perf.dart
file to dev/devicelab/bin/tasks folder that specifies measureMemory: true
.