Skip to content

Commit

Permalink
Migration for HotEvent for Flutter hot runner (#137717)
Browse files Browse the repository at this point in the history
Related to tracker issue:
- flutter/flutter#128251

For this migration, the `HotEvent` was being referenced in 2 additional files outside of `lib/src/reporting/events.dart`, shown below in the screenshot

<img width="257" alt="image" src="https://github.com/flutter/flutter/assets/42216813/97986f89-2253-4db1-9deb-bbced6321a16">
  • Loading branch information
eliasyishak authored Nov 6, 2023
1 parent 925f3ee commit 17e0fe1
Show file tree
Hide file tree
Showing 16 changed files with 394 additions and 17 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_tools/lib/src/commands/attach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:async';

import 'package:unified_analytics/unified_analytics.dart';
import 'package:vm_service/vm_service.dart';

import '../android/android_device.dart';
Expand Down Expand Up @@ -538,6 +539,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
dillOutputPath: stringArg('output-dill'),
ipv6: usesIpv6,
flutterProject: flutterProject,
analytics: analytics,
)
: ColdRunner(
flutterDevices,
Expand Down Expand Up @@ -570,6 +572,7 @@ class HotRunnerFactory {
bool stayResident = true,
bool ipv6 = false,
FlutterProject? flutterProject,
required Analytics analytics,
}) => HotRunner(
devices,
target: target,
Expand All @@ -581,5 +584,6 @@ class HotRunnerFactory {
dillOutputPath: dillOutputPath,
stayResident: stayResident,
ipv6: ipv6,
analytics: analytics,
);
}
2 changes: 2 additions & 0 deletions packages/flutter_tools/lib/src/commands/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ class AppDomain extends Domain {
urlTunneller: options.webEnableExposeUrl! ? daemon.daemonDomain.exposeUrl : null,
machine: machine,
usage: globals.flutterUsage,
analytics: globals.analytics,
systemClock: globals.systemClock,
logger: globals.logger,
fileSystem: globals.fs,
Expand All @@ -561,6 +562,7 @@ class AppDomain extends Domain {
multidexEnabled: multidexEnabled,
hostIsIde: true,
machine: machine,
analytics: globals.analytics,
);
} else {
runner = ColdRunner(
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_tools/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ class RunCommand extends RunCommandBase {
stayResident: stayResident,
ipv6: ipv6 ?? false,
multidexEnabled: boolArg('multidex'),
analytics: globals.analytics,
);
} else if (webMode) {
return webRunnerFactory!.createWebRunner(
Expand All @@ -608,6 +609,7 @@ class RunCommand extends RunCommandBase {
stayResident: stayResident,
fileSystem: globals.fs,
usage: globals.flutterUsage,
analytics: globals.analytics,
logger: globals.logger,
systemClock: globals.systemClock,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class WebDriverService extends DriverService {
flutterProject: FlutterProject.current(),
fileSystem: globals.fs,
usage: globals.flutterUsage,
analytics: globals.analytics,
logger: _logger,
systemClock: globals.systemClock,
);
Expand Down
18 changes: 17 additions & 1 deletion packages/flutter_tools/lib/src/isolated/resident_web_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:async';
// ignore: import_of_legacy_library_into_null_safe
import 'package:dwds/dwds.dart';
import 'package:package_config/package_config.dart';
import 'package:unified_analytics/unified_analytics.dart';
import 'package:vm_service/vm_service.dart' as vmservice;
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
hide StackTrace;
Expand Down Expand Up @@ -57,6 +58,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
required FileSystem fileSystem,
required SystemClock systemClock,
required Usage usage,
required Analytics analytics,
bool machine = false,
}) {
return ResidentWebRunner(
Expand All @@ -69,6 +71,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
urlTunneller: urlTunneller,
machine: machine,
usage: usage,
analytics: analytics,
systemClock: systemClock,
fileSystem: fileSystem,
logger: logger,
Expand All @@ -93,12 +96,14 @@ class ResidentWebRunner extends ResidentRunner {
required Logger logger,
required SystemClock systemClock,
required Usage usage,
required Analytics analytics,
UrlTunneller? urlTunneller,
ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler,
}) : _fileSystem = fileSystem,
_logger = logger,
_systemClock = systemClock,
_usage = usage,
_analytics = analytics,
_urlTunneller = urlTunneller,
super(
<FlutterDevice>[device],
Expand All @@ -114,6 +119,7 @@ class ResidentWebRunner extends ResidentRunner {
final Logger _logger;
final SystemClock _systemClock;
final Usage _usage;
final Analytics _analytics;
final UrlTunneller? _urlTunneller;

@override
Expand Down Expand Up @@ -441,15 +447,25 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
// Don't track restart times for dart2js builds or web-server devices.
if (debuggingOptions.buildInfo.isDebug && deviceIsDebuggable) {
_usage.sendTiming('hot', 'web-incremental-restart', elapsed);
final String sdkName = await device!.device!.sdkNameAndVersion;
HotEvent(
'restart',
targetPlatform: getNameForTargetPlatform(TargetPlatform.web_javascript),
sdkName: await device!.device!.sdkNameAndVersion,
sdkName: sdkName,
emulator: false,
fullRestart: true,
reason: reason,
overallTimeInMs: elapsed.inMilliseconds,
).send();
_analytics.send(Event.hotRunnerInfo(
label: 'restart',
targetPlatform: getNameForTargetPlatform(TargetPlatform.web_javascript),
sdkName: sdkName,
emulator: false,
fullRestart: true,
reason: reason,
overallTimeInMs: elapsed.inMilliseconds
));
}
return OperationResult.ok;
}
Expand Down
115 changes: 102 additions & 13 deletions packages/flutter_tools/lib/src/run_hot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:async';
import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
import 'package:pool/pool.dart';
import 'package:unified_analytics/unified_analytics.dart';
import 'package:vm_service/vm_service.dart' as vm_service;

import 'base/context.dart';
Expand Down Expand Up @@ -94,17 +95,20 @@ class HotRunner extends ResidentRunner {
ReloadSourcesHelper reloadSourcesHelper = defaultReloadSourcesHelper,
ReassembleHelper reassembleHelper = _defaultReassembleHelper,
NativeAssetsBuildRunner? buildRunner,
}) : _stopwatchFactory = stopwatchFactory,
_reloadSourcesHelper = reloadSourcesHelper,
_reassembleHelper = reassembleHelper,
required Analytics analytics,
}) : _stopwatchFactory = stopwatchFactory,
_reloadSourcesHelper = reloadSourcesHelper,
_reassembleHelper = reassembleHelper,
_buildRunner = buildRunner,
super(
_analytics = analytics,
super(
hotMode: true,
);

final StopwatchFactory _stopwatchFactory;
final ReloadSourcesHelper _reloadSourcesHelper;
final ReassembleHelper _reassembleHelper;
final Analytics _analytics;

final bool benchmarkMode;
final File? applicationBinary;
Expand Down Expand Up @@ -429,15 +433,29 @@ class HotRunner extends ResidentRunner {
}));
}

unawaited(appStartedCompleter?.future.then((_) => HotEvent('reload-ready',
targetPlatform: _targetPlatform!,
sdkName: _sdkName!,
emulator: _emulator!,
fullRestart: false,
overallTimeInMs: appStartedTimer.elapsed.inMilliseconds,
compileTimeInMs: totalCompileTime.inMilliseconds,
transferTimeInMs: totalLaunchAppTime.inMilliseconds,
).send()));
unawaited(appStartedCompleter?.future.then((_) {
HotEvent(
'reload-ready',
targetPlatform: _targetPlatform!,
sdkName: _sdkName!,
emulator: _emulator!,
fullRestart: false,
overallTimeInMs: appStartedTimer.elapsed.inMilliseconds,
compileTimeInMs: totalCompileTime.inMilliseconds,
transferTimeInMs: totalLaunchAppTime.inMilliseconds,
).send();

_analytics.send(Event.hotRunnerInfo(
label: 'reload-ready',
targetPlatform: _targetPlatform!,
sdkName: _sdkName!,
emulator: _emulator!,
fullRestart: false,
overallTimeInMs: appStartedTimer.elapsed.inMilliseconds,
compileTimeInMs: totalCompileTime.inMilliseconds,
transferTimeInMs: totalLaunchAppTime.inMilliseconds,
));
}));

try {
final List<bool> results = await Future.wait(startupTasks);
Expand Down Expand Up @@ -828,6 +846,21 @@ class HotRunner extends ResidentRunner {
findInvalidatedTimeInMs: result.updateFSReport?.findInvalidatedDuration.inMilliseconds,
scannedSourcesCount: result.updateFSReport?.scannedSourcesCount,
).send();
_analytics.send(Event.hotRunnerInfo(
label: 'restart',
targetPlatform: targetPlatform,
sdkName: sdkName,
emulator: emulator,
fullRestart: true,
reason: reason,
overallTimeInMs: restartTimer.elapsed.inMilliseconds,
syncedBytes: result.updateFSReport?.syncedBytes,
invalidatedSourcesCount: result.updateFSReport?.invalidatedSourcesCount,
transferTimeInMs: result.updateFSReport?.transferDuration.inMilliseconds,
compileTimeInMs: result.updateFSReport?.compileDuration.inMilliseconds,
findInvalidatedTimeInMs: result.updateFSReport?.findInvalidatedDuration.inMilliseconds,
scannedSourcesCount: result.updateFSReport?.scannedSourcesCount,
));
}
} on vm_service.SentinelException catch (err, st) {
restartEvent = 'exception';
Expand All @@ -846,6 +879,14 @@ class HotRunner extends ResidentRunner {
fullRestart: true,
reason: reason,
).send();
_analytics.send(Event.hotRunnerInfo(
label: restartEvent,
targetPlatform: targetPlatform,
sdkName: sdkName,
emulator: emulator,
fullRestart: true,
reason: reason,
));
}
status?.cancel();
}
Expand Down Expand Up @@ -895,6 +936,14 @@ class HotRunner extends ResidentRunner {
fullRestart: false,
reason: reason,
).send();
_analytics.send(Event.hotRunnerInfo(
label: 'reload-barred',
targetPlatform: targetPlatform,
sdkName: sdkName,
emulator: emulator,
fullRestart: false,
reason: reason,
));
} else {
HotEvent('exception',
targetPlatform: targetPlatform!,
Expand All @@ -903,6 +952,14 @@ class HotRunner extends ResidentRunner {
fullRestart: false,
reason: reason,
).send();
_analytics.send(Event.hotRunnerInfo(
label: 'exception',
targetPlatform: targetPlatform,
sdkName: sdkName,
emulator: emulator,
fullRestart: false,
reason: reason,
));
}
return OperationResult(errorCode, errorMessage, fatal: true);
} finally {
Expand Down Expand Up @@ -965,6 +1022,7 @@ class HotRunner extends ResidentRunner {
emulator,
reason,
globals.flutterUsage,
globals.analytics,
);
if (result.code != 0) {
return result;
Expand Down Expand Up @@ -1024,6 +1082,27 @@ class HotRunner extends ResidentRunner {
reassembleTimeInMs: reassembleTimer.elapsed.inMilliseconds,
reloadVMTimeInMs: reloadVMTimer.elapsed.inMilliseconds,
).send();
_analytics.send(Event.hotRunnerInfo(
label: 'reload',
targetPlatform: targetPlatform,
sdkName: sdkName,
emulator: emulator,
fullRestart: false,
reason: reason,
overallTimeInMs: reloadInMs,
finalLibraryCount: firstReloadDetails['finalLibraryCount'] as int? ?? 0,
syncedLibraryCount: firstReloadDetails['receivedLibraryCount'] as int? ?? 0,
syncedClassesCount: firstReloadDetails['receivedClassesCount'] as int? ?? 0,
syncedProceduresCount: firstReloadDetails['receivedProceduresCount'] as int? ?? 0,
syncedBytes: updatedDevFS.syncedBytes,
invalidatedSourcesCount: updatedDevFS.invalidatedSourcesCount,
transferTimeInMs: updatedDevFS.transferDuration.inMilliseconds,
compileTimeInMs: updatedDevFS.compileDuration.inMilliseconds,
findInvalidatedTimeInMs: updatedDevFS.findInvalidatedDuration.inMilliseconds,
scannedSourcesCount: updatedDevFS.scannedSourcesCount,
reassembleTimeInMs: reassembleTimer.elapsed.inMilliseconds,
reloadVMTimeInMs: reloadVMTimer.elapsed.inMilliseconds,
));

if (shouldReportReloadTime) {
globals.printTrace('Hot reload performed in ${getElapsedAsMilliseconds(reloadDuration)}.');
Expand Down Expand Up @@ -1186,6 +1265,7 @@ typedef ReloadSourcesHelper = Future<OperationResult> Function(
bool? emulator,
String? reason,
Usage usage,
Analytics analytics,
);

@visibleForTesting
Expand All @@ -1199,6 +1279,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
bool? emulator,
String? reason,
Usage usage,
Analytics analytics,
) async {
final Stopwatch vmReloadTimer = Stopwatch()..start();
const String entryPath = 'main.dart.incremental.dill';
Expand Down Expand Up @@ -1239,6 +1320,14 @@ Future<OperationResult> defaultReloadSourcesHelper(
reason: reason,
usage: usage,
).send();
analytics.send(Event.hotRunnerInfo(
label: 'reload-reject',
targetPlatform: targetPlatform,
sdkName: sdkName,
emulator: emulator,
fullRestart: false,
reason: reason,
));
// Reset devFS lastCompileTime to ensure the file will still be marked
// as dirty on subsequent reloads.
_resetDevFSCompileTime(flutterDevices);
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter_tools/lib/src/runner/flutter_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:args/command_runner.dart';
import 'package:file/file.dart';
import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart';
import 'package:unified_analytics/unified_analytics.dart';

import '../application_package.dart';
import '../base/common.dart';
Expand Down Expand Up @@ -223,6 +224,11 @@ abstract class FlutterCommand extends Command<void> {
bool _excludeDebug = false;
bool _excludeRelease = false;

/// Grabs the [Analytics] instance from the global context. It is defined
/// at the [FlutterCommand] level to enable any classes that extend it to
/// easily reference it or overwrite as necessary.
Analytics get analytics => globals.analytics;

void requiresPubspecYaml() {
_requiresPubspecYaml = true;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/flutter_tools/lib/src/web/web_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:unified_analytics/unified_analytics.dart';

import '../base/context.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
Expand Down Expand Up @@ -31,6 +33,7 @@ abstract class WebRunnerFactory {
required FileSystem fileSystem,
required SystemClock systemClock,
required Usage usage,
required Analytics analytics,
bool machine = false,
});
}
Loading

0 comments on commit 17e0fe1

Please sign in to comment.