Skip to content

Commit 33f4107

Browse files
Reset default UserTag at the time of the first flutter frame (flutter#86516)
* Reset default UserTag at the time of the first flutter frame
1 parent cd78190 commit 33f4107

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/flutter/lib/src/widgets/binding.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,11 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
859859
firstFrameCallback = (List<FrameTiming> timings) {
860860
assert(sendFramesToEngine);
861861
if (!kReleaseMode) {
862+
// Change the current user tag back to the default tag. At this point,
863+
// the user tag should be set to "AppStartUp" (originally set in the
864+
// engine), so we need to change it back to the default tag to mark
865+
// the end of app start up for CPU profiles.
866+
developer.UserTag.defaultTag.makeCurrent();
862867
developer.Timeline.instantSync('Rasterized first useful frame');
863868
developer.postEvent('Flutter.FirstFrame', <String, dynamic>{});
864869
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
import 'dart:developer' as developer;
6+
import 'dart:ui';
7+
8+
import 'package:flutter/material.dart';
9+
import 'package:flutter_test/flutter_test.dart';
10+
11+
void main() {
12+
test('first frame callback sets the default UserTag', () {
13+
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
14+
15+
expect(developer.getCurrentTag().label, equals('Default'));
16+
developer.UserTag('test tag').makeCurrent();
17+
expect(developer.getCurrentTag().label, equals('test tag'));
18+
19+
binding.drawFrame();
20+
// Simulates the engine again.
21+
binding.window.onReportTimings!(<FrameTiming>[]);
22+
23+
expect(developer.getCurrentTag().label, equals('Default'));
24+
});
25+
}

0 commit comments

Comments
 (0)