Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Integration Test で パフォーマンス計測する

kumamotone
December 08, 2023

Integration Test で パフォーマンス計測する

Flutter の Integration Test で パフォーマンス計測をしてみた話です

2023/12/08 YOUTRUST x ゆめみ Flutter LT会 #4
https://yumemi.connpass.com/event/299538/

kumamotone/flutter_performance_profiling
https://github.com/kumamotone/flutter_performance_profiling

Performance profiling - flutter.dev
https://docs.flutter.dev/cookbook/testing/integration/profiling

動画
https://share.cleanshot.com/R0pnjJwH

kumamotone

December 08, 2023
Tweet

More Decks by kumamotone

Other Decks in Technology

Transcript

  1. • CA. fl utter #1 ͱ͍͏ΠϕϯτͰɺIntegration TestͰฏۉϑϨʔϜϏϧ υ࣌ؒͳͲΛܭଌ͍ͯ͠Δͱ͍͏࿩Λฉ͍ͨ • ࢼͯ͠ΈͨͷͰͪΐͬͱ۷ΓԼ͛ͯΈ·͢

    ࠓճͷ࿩ CA. fl utter #1 ʹࢀՃ͠·ͨ͠ - kumamotone’s blog https://kumamotone.hatenadiary.jp/entry/2023/11/14/202304
  2. औΕΔ΋ͷ { "average_frame_build_time_millis": 0.7377550000000005, "90th_percentile_frame_build_time_millis": 1.265, "99th_percentile_frame_build_time_millis": 3.401, "worst_frame_build_time_millis": 5.096,

    "missed_frame_build_budget_count": 0, "average_frame_rasterizer_time_millis": 1.9002878787878796, "90th_percentile_frame_rasterizer_time_millis": 3.648, "99th_percentile_frame_rasterizer_time_millis": 4.868, "worst_frame_rasterizer_time_millis": 6.207, "missed_frame_rasterizer_budget_count": 0, "frame_count": 200, "frame_rasterizer_count": 198, "new_gen_gc_count": 14, "old_gen_gc_count": 0, "frame_build_times": [ 715, …
  3. • main.dart • ܭଌ͍ͨ͠ΞϓϦ • integration_test/scrolling_test.dart • integration_test • test_driver/perf_driver.dart

    • driver • ςετΛ࣮ߦͨ͠ࡍʹɺͲ͜ʹܭଌ݁ՌΛग़ྗ͢Δ͔౳Λࢦఆ͢Δ ༻ҙ͢Δ΋ͷ
  4. integration_test/scrolling_test.dart import 'package:flutter/material.dart'; import 'package:flutter_application_integration_perf/main.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; void

    main() { final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); testWidgets('Perform scrolling', (WidgetTester tester) async { await tester.pumpWidget(MyApp()); await binding.traceAction( () async { final gesture = await tester .startGesture(tester.getCenter(find.byType(Scrollable))); final startTime = DateTime.now(); while (DateTime.now().difference(startTime) < const Duration(seconds: 10)) { await gesture.moveBy(const Offset(0, -10)); await Future.delayed(const Duration(milliseconds: 16)); // ը໘ϦϑϨογϡϨʔτ } // εΫϩʔϧऴྃ await gesture.up(); }, reportKey: 'scrolling_timeline', ); }); } ඵؒɺNT͝ͱʹ εΫϩʔϧ͠ଓ͚Δςετ
  5. test_driver/perf_driver.dart import 'package:flutter_driver/flutter_driver.dart' as driver; import 'package:integration_test/integration_test_driver.dart'; import 'package:intl/intl.dart'; Future<void>

    main() { return integrationDriver( responseDataCallback: (data) async { if (data != null) { final timeline = driver.Timeline.fromJson( data['scrolling_timeline'] as Map<String, dynamic>, ); DateTime now = DateTime.now(); // ೔࣌ΛϑΥʔϚοτ String formattedDate = DateFormat('yyyy-MM-dd_hh-mm-ss').format(now); // ϑΝΠϧ໊ʹ૊ΈࠐΉ String fileName = 'scrolling_$formattedDate'; // λΠϜϥΠϯΛɺಡΈ΍͘͢ཧղ͠΍͍͢λΠϜϥΠϯαϚϦʔʹม׵ final summary = driver.TimelineSummary.summarize(timeline); await summary.writeTimelineToFile( fileName, pretty: true, ); } }, ); } ϑΝΠϧʹग़ྗ͢Δ σϑΥϧτͩͱCVJMEʹग़·͢