Skip to content

Commit 840e109

Browse files
authored
Improve tracing (#93086)
1 parent 14cf445 commit 840e109

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1166
-133
lines changed

.ci.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ targets:
398398
{"dependency": "goldctl"},
399399
{"dependency": "clang"},
400400
{"dependency": "cmake"},
401-
{"dependency": "ninja"}
401+
{"dependency": "ninja"},
402+
{"dependency": "open_jdk"},
403+
{"dependency": "android_sdk", "version": "version:29.0"}
402404
]
403405
shard: framework_tests
404406
subshard: misc
@@ -2108,7 +2110,9 @@ targets:
21082110
[
21092111
{"dependency": "goldctl"},
21102112
{"dependency": "xcode"},
2111-
{"dependency": "gems"}
2113+
{"dependency": "gems"},
2114+
{"dependency": "open_jdk"},
2115+
{"dependency": "android_sdk", "version": "version:29.0"}
21122116
]
21132117
shard: framework_tests
21142118
subshard: misc
@@ -3642,7 +3646,9 @@ targets:
36423646
dependencies: >-
36433647
[
36443648
{"dependency": "goldctl"},
3645-
{"dependency": "vs_build", "version": "version:vs2019"}
3649+
{"dependency": "vs_build", "version": "version:vs2019"},
3650+
{"dependency": "open_jdk"},
3651+
{"dependency": "android_sdk", "version": "version:29.0"}
36463652
]
36473653
shard: framework_tests
36483654
subshard: misc

dev/bots/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ dependencies:
1515
platform: 3.1.0
1616
process: 4.2.4
1717
test: 1.19.5
18+
archive: 3.1.6
1819

1920
_discoveryapis_commons: 1.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
2021
_fe_analyzer_shared: 31.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
2122
analyzer: 2.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
22-
archive: 3.1.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
2323
async: 2.8.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
2424
boolean_selector: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
2525
charcode: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"

dev/bots/test.dart

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import 'dart:async';
66
import 'dart:convert';
77
import 'dart:io';
88
import 'dart:math' as math;
9+
import 'dart:typed_data';
910

11+
import 'package:archive/archive.dart';
1012
import 'package:file/file.dart' as fs;
1113
import 'package:file/local.dart';
1214
import 'package:path/path.dart' as path;
@@ -744,6 +746,89 @@ Future<void> _runFrameworkTests() async {
744746
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'), options: soundNullSafetyOptions);
745747
}
746748

749+
Future<void> runTracingTests() async {
750+
final String tracingDirectory = path.join(flutterRoot, 'dev', 'tracing_tests');
751+
752+
// run the tests for debug mode
753+
await _runFlutterTest(tracingDirectory, options: <String>['--enable-vmservice']);
754+
755+
Future<List<String>> verifyTracingAppBuild({
756+
required String modeArgument,
757+
required String sourceFile,
758+
required Set<String> allowed,
759+
required Set<String> disallowed,
760+
}) async {
761+
await runCommand(
762+
flutter,
763+
<String>[
764+
'build', 'appbundle', '--$modeArgument', path.join('lib', sourceFile),
765+
],
766+
workingDirectory: tracingDirectory,
767+
);
768+
final Archive archive = ZipDecoder().decodeBytes(File(path.join(tracingDirectory, 'build', 'app', 'outputs', 'bundle', modeArgument, 'app-$modeArgument.aab')).readAsBytesSync());
769+
final ArchiveFile libapp = archive.findFile('base/lib/arm64-v8a/libapp.so')!;
770+
final Uint8List libappBytes = libapp.content as Uint8List; // bytes decompressed here
771+
final String libappStrings = utf8.decode(libappBytes, allowMalformed: true);
772+
await runCommand(flutter, <String>['clean'], workingDirectory: tracingDirectory);
773+
final List<String> results = <String>[];
774+
for (final String pattern in allowed) {
775+
if (!libappStrings.contains(pattern)) {
776+
results.add('When building with --$modeArgument, expected to find "$pattern" in libapp.so but could not find it.');
777+
}
778+
}
779+
for (final String pattern in disallowed) {
780+
if (libappStrings.contains(pattern)) {
781+
results.add('When building with --$modeArgument, expected to not find "$pattern" in libapp.so but did find it.');
782+
}
783+
}
784+
return results;
785+
}
786+
787+
final List<String> results = <String>[];
788+
results.addAll(await verifyTracingAppBuild(
789+
modeArgument: 'profile',
790+
sourceFile: 'control.dart', // this is the control, the other two below are the actual test
791+
allowed: <String>{
792+
'TIMELINE ARGUMENTS TEST CONTROL FILE',
793+
'toTimelineArguments used in non-debug build', // we call toTimelineArguments directly to check the message does exist
794+
},
795+
disallowed: <String>{
796+
'BUILT IN DEBUG MODE', 'BUILT IN RELEASE MODE',
797+
},
798+
));
799+
results.addAll(await verifyTracingAppBuild(
800+
modeArgument: 'profile',
801+
sourceFile: 'test.dart',
802+
allowed: <String>{
803+
'BUILT IN PROFILE MODE', 'RenderTest.performResize called', // controls
804+
'BUILD', 'LAYOUT', 'PAINT', // we output these to the timeline in profile builds
805+
// (LAYOUT and PAINT also exist because of NEEDS-LAYOUT and NEEDS-PAINT in RenderObject.toStringShort)
806+
},
807+
disallowed: <String>{
808+
'BUILT IN DEBUG MODE', 'BUILT IN RELEASE MODE',
809+
'TestWidget.debugFillProperties called', 'RenderTest.debugFillProperties called', // debug only
810+
'toTimelineArguments used in non-debug build', // entire function should get dropped by tree shaker
811+
},
812+
));
813+
results.addAll(await verifyTracingAppBuild(
814+
modeArgument: 'release',
815+
sourceFile: 'test.dart',
816+
allowed: <String>{
817+
'BUILT IN RELEASE MODE', 'RenderTest.performResize called', // controls
818+
},
819+
disallowed: <String>{
820+
'BUILT IN DEBUG MODE', 'BUILT IN PROFILE MODE',
821+
'BUILD', 'LAYOUT', 'PAINT', // these are only used in Timeline.startSync calls that should not appear in release builds
822+
'TestWidget.debugFillProperties called', 'RenderTest.debugFillProperties called', // debug only
823+
'toTimelineArguments used in non-debug build', // not included in release builds
824+
},
825+
));
826+
if (results.isNotEmpty) {
827+
print(results.join('\n'));
828+
exit(1);
829+
}
830+
}
831+
747832
Future<void> runFixTests() async {
748833
final List<String> args = <String>[
749834
'fix',
@@ -808,10 +893,7 @@ Future<void> _runFrameworkTests() async {
808893
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'), options: soundNullSafetyOptions);
809894
await _runFlutterTest(path.join(flutterRoot, 'packages', 'fuchsia_remote_debug_protocol'), options: soundNullSafetyOptions);
810895
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'non_nullable'), options: mixedModeNullSafetyOptions);
811-
await _runFlutterTest(
812-
path.join(flutterRoot, 'dev', 'tracing_tests'),
813-
options: <String>['--enable-vmservice'],
814-
);
896+
await runTracingTests();
815897
await runFixTests();
816898
await runPrivateTests();
817899
const String httpClientWarning =

dev/integration_tests/flutter_gallery/lib/demo/video_demo.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,12 @@ class _VideoDemoState extends State<VideoDemo> with SingleTickerProviderStateMix
382382
super.initState();
383383

384384
Future<void> initController(VideoPlayerController controller, String name) async {
385-
print('> VideoDemo initController "$name" ${isDisposed ? "DISPOSED" : ""}');
386385
controller.setLooping(true);
387386
controller.setVolume(0.0);
388387
controller.play();
389388
await connectedCompleter.future;
390389
await controller.initialize();
391390
if (mounted) {
392-
print('< VideoDemo initController "$name" done ${isDisposed ? "DISPOSED" : ""}');
393391
setState(() { });
394392
}
395393
}
@@ -403,11 +401,9 @@ class _VideoDemoState extends State<VideoDemo> with SingleTickerProviderStateMix
403401

404402
@override
405403
void dispose() {
406-
print('> VideoDemo dispose');
407404
isDisposed = true;
408405
butterflyController.dispose();
409406
beeController.dispose();
410-
print('< VideoDemo dispose');
411407
super.dispose();
412408
}
413409

dev/integration_tests/flutter_gallery/test/flutter_test_config.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,20 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
export 'package:flutter_goldens/flutter_goldens.dart' show testExecutable;
5+
import 'dart:async';
6+
7+
import 'package:flutter/rendering.dart';
8+
import 'package:flutter_goldens/flutter_goldens.dart' as flutter_goldens show testExecutable;
9+
import 'package:flutter_test/flutter_test.dart';
10+
11+
Future<void> testExecutable(FutureOr<void> Function() testMain) {
12+
// Enable extra checks since this package exercises a lot of the framework.
13+
debugCheckIntrinsicSizes = true;
14+
15+
// Make tap() et al fail if the given finder specifies a widget that would not
16+
// receive the event.
17+
WidgetController.hitTestWarningShouldBeFatal = true;
18+
19+
// Enable golden file testing using Skia Gold.
20+
return flutter_goldens.testExecutable(testMain);
21+
}

dev/integration_tests/flutter_gallery/test/smoke_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Future<void> smokeOptionsPage(WidgetTester tester) async {
118118
// Switch back to system theme setting: first menu button, choose 'System Default'
119119
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
120120
await tester.pumpAndSettle();
121-
await tester.tap(find.text('System Default').at(1));
121+
await tester.tap(find.text('System Default').at(1), warnIfMissed: false); // https://github.com/flutter/flutter/issues/82908
122122
await tester.pumpAndSettle();
123123

124124
// Switch text direction: first switch

dev/tracing_tests/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Tracing tests
22

3+
## "Application"
4+
5+
The `lib/test.dart` and `lib/control.dart` files in this directory are
6+
used by `dev/bots/test.dart`'s `runTracingTests` function to check
7+
whether aspects of the tracing logic in the framework get compiled out
8+
in profile and release builds. They're not meant to be run directly.
9+
10+
The strings in these files are used in `dev/bots/test.dart`.
11+
12+
## Tests
13+
314
The tests in this folder must be run with `flutter test --enable-vmservice`,
415
since they test that trace data is written to the timeline by connecting to
516
the observatory.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
12+
**/*.keystore
13+
**/*.jks
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
def localProperties = new Properties()
6+
def localPropertiesFile = rootProject.file('local.properties')
7+
if (localPropertiesFile.exists()) {
8+
localPropertiesFile.withReader('UTF-8') { reader ->
9+
localProperties.load(reader)
10+
}
11+
}
12+
13+
def flutterRoot = localProperties.getProperty('flutter.sdk')
14+
if (flutterRoot == null) {
15+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
16+
}
17+
18+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
19+
if (flutterVersionCode == null) {
20+
flutterVersionCode = '1'
21+
}
22+
23+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
24+
if (flutterVersionName == null) {
25+
flutterVersionName = '1.0'
26+
}
27+
28+
apply plugin: 'com.android.application'
29+
apply plugin: 'kotlin-android'
30+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
31+
32+
android {
33+
compileSdkVersion flutter.compileSdkVersion
34+
35+
compileOptions {
36+
sourceCompatibility JavaVersion.VERSION_1_8
37+
targetCompatibility JavaVersion.VERSION_1_8
38+
}
39+
40+
kotlinOptions {
41+
jvmTarget = '1.8'
42+
}
43+
44+
sourceSets {
45+
main.java.srcDirs += 'src/main/kotlin'
46+
}
47+
48+
defaultConfig {
49+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
50+
applicationId "com.example.tracing_tests"
51+
minSdkVersion flutter.minSdkVersion
52+
targetSdkVersion flutter.targetSdkVersion
53+
versionCode flutterVersionCode.toInteger()
54+
versionName flutterVersionName
55+
}
56+
57+
buildTypes {
58+
release {
59+
// TODO: Add your own signing config for the release build.
60+
// Signing with the debug keys for now, so `flutter run --release` works.
61+
signingConfig signingConfigs.debug
62+
}
63+
}
64+
}
65+
66+
flutter {
67+
source '../..'
68+
}
69+
70+
dependencies {
71+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
72+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2+
Use of this source code is governed by a BSD-style license that can be
3+
found in the LICENSE file. -->
4+
5+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
6+
package="com.example.tracing_tests">
7+
<!-- Flutter needs it to communicate with the running application
8+
to allow setting breakpoints, to provide hot reload, etc.
9+
-->
10+
<uses-permission android:name="android.permission.INTERNET"/>
11+
</manifest>

0 commit comments

Comments
 (0)