Skip to content

Commit

Permalink
Added new event enum + constructor for hot runner (#193)
Browse files Browse the repository at this point in the history
* Added new event enum + constructor for hot runner

* Bump `eventsAccountedForInTests`

* Add `label` for each hot event

* Add TODO for enhancing dartdocs for new constructor
  • Loading branch information
eliasyishak authored Nov 2, 2023
1 parent dd91cb6 commit 6ad3691
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.2.0

- Added the `Event.hotRunnerInfo` constructor

## 5.1.0

- Added the `Event.flutterBuildInfo` constructor
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const int kLogFileLength = 2500;
const String kLogFileName = 'dart-flutter-telemetry.log';

/// The current version of the package, should be in line with pubspec version.
const String kPackageVersion = '5.1.0';
const String kPackageVersion = '5.2.0';

/// The minimum length for a session.
const int kSessionDurationMinutes = 30;
Expand Down
5 changes: 5 additions & 0 deletions pkgs/unified_analytics/lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ enum DashEvent {
description: 'Hot reload duration',
toolOwner: DashTool.flutterTool,
),
hotRunnerInfo(
label: 'hot_runner_info',
description: 'Information related to the Flutter hot runner',
toolOwner: DashTool.flutterTool,
),

// Events for language_server below

Expand Down
54 changes: 54 additions & 0 deletions pkgs/unified_analytics/lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,64 @@ final class Event {
if (error != null) 'error': error,
};

// TODO: eliasyishak, remove this or replace once we have a generic
// timing event that can be used by potentially more than one DashTool
Event.hotReloadTime({required int timeMs})
: eventName = DashEvent.hotReloadTime,
eventData = {'timeMs': timeMs};

// TODO: eliasyishak, add better dartdocs to explain each param
/// Events to be sent for the Flutter Hot Runner.
Event.hotRunnerInfo({
required String label,
required String targetPlatform,
required String sdkName,
required bool emulator,
required bool fullRestart,
String? reason,
int? finalLibraryCount,
int? syncedLibraryCount,
int? syncedClassesCount,
int? syncedProceduresCount,
int? syncedBytes,
int? invalidatedSourcesCount,
int? transferTimeInMs,
int? overallTimeInMs,
int? compileTimeInMs,
int? findInvalidatedTimeInMs,
int? scannedSourcesCount,
int? reassembleTimeInMs,
int? reloadVMTimeInMs,
}) : eventName = DashEvent.hotRunnerInfo,
eventData = {
'label': label,
'targetPlatform': targetPlatform,
'sdkName': sdkName,
'emulator': emulator,
'fullRestart': fullRestart,
if (reason != null) 'reason': reason,
if (finalLibraryCount != null) 'finalLibraryCount': finalLibraryCount,
if (syncedLibraryCount != null)
'syncedLibraryCount': syncedLibraryCount,
if (syncedClassesCount != null)
'syncedClassesCount': syncedClassesCount,
if (syncedProceduresCount != null)
'syncedProceduresCount': syncedProceduresCount,
if (syncedBytes != null) 'syncedBytes': syncedBytes,
if (invalidatedSourcesCount != null)
'invalidatedSourcesCount': invalidatedSourcesCount,
if (transferTimeInMs != null) 'transferTimeInMs': transferTimeInMs,
if (overallTimeInMs != null) 'overallTimeInMs': overallTimeInMs,
if (compileTimeInMs != null) 'compileTimeInMs': compileTimeInMs,
if (findInvalidatedTimeInMs != null)
'findInvalidatedTimeInMs': findInvalidatedTimeInMs,
if (scannedSourcesCount != null)
'scannedSourcesCount': scannedSourcesCount,
if (reassembleTimeInMs != null)
'reassembleTimeInMs': reassembleTimeInMs,
if (reloadVMTimeInMs != null) 'reloadVMTimeInMs': reloadVMTimeInMs,
};

/// Event that is emitted periodically to report the number of times each lint
/// has been enabled.
///
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: >-
to Google Analytics.
# When updating this, keep the version consistent with the changelog and the
# value in lib/src/constants.dart.
version: 5.1.0
version: 5.2.0
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics

environment:
Expand Down
51 changes: 50 additions & 1 deletion pkgs/unified_analytics/test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,55 @@ void main() {
expect(constructedEvent.eventData.length, 5);
});

test('Event.hotRunnerInfo constructed', () {
Event generateEvent() => Event.hotRunnerInfo(
label: 'label',
targetPlatform: 'targetPlatform',
sdkName: 'sdkName',
emulator: false,
fullRestart: true,
reason: 'reason',
finalLibraryCount: 5,
syncedLibraryCount: 6,
syncedClassesCount: 7,
syncedProceduresCount: 8,
syncedBytes: 9,
invalidatedSourcesCount: 10,
transferTimeInMs: 11,
overallTimeInMs: 12,
compileTimeInMs: 13,
findInvalidatedTimeInMs: 14,
scannedSourcesCount: 15,
reassembleTimeInMs: 16,
reloadVMTimeInMs: 17,
);

final constructedEvent = generateEvent();

expect(generateEvent, returnsNormally);
expect(constructedEvent.eventName, DashEvent.hotRunnerInfo);
expect(constructedEvent.eventData['label'], 'label');
expect(constructedEvent.eventData['targetPlatform'], 'targetPlatform');
expect(constructedEvent.eventData['sdkName'], 'sdkName');
expect(constructedEvent.eventData['emulator'], false);
expect(constructedEvent.eventData['fullRestart'], true);
expect(constructedEvent.eventData['reason'], 'reason');
expect(constructedEvent.eventData['finalLibraryCount'], 5);
expect(constructedEvent.eventData['syncedLibraryCount'], 6);
expect(constructedEvent.eventData['syncedClassesCount'], 7);
expect(constructedEvent.eventData['syncedProceduresCount'], 8);
expect(constructedEvent.eventData['syncedBytes'], 9);
expect(constructedEvent.eventData['invalidatedSourcesCount'], 10);
expect(constructedEvent.eventData['transferTimeInMs'], 11);
expect(constructedEvent.eventData['overallTimeInMs'], 12);
expect(constructedEvent.eventData['compileTimeInMs'], 13);
expect(constructedEvent.eventData['findInvalidatedTimeInMs'], 14);
expect(constructedEvent.eventData['scannedSourcesCount'], 15);
expect(constructedEvent.eventData['reassembleTimeInMs'], 16);
expect(constructedEvent.eventData['reloadVMTimeInMs'], 17);
expect(constructedEvent.eventData.length, 19);
});

test('Confirm all constructors were checked', () {
var constructorCount = 0;
for (var declaration in reflectClass(Event).declarations.keys) {
Expand All @@ -340,7 +389,7 @@ void main() {

// Change this integer below if your PR either adds or removes
// an Event constructor
final eventsAccountedForInTests = 18;
final eventsAccountedForInTests = 19;
expect(eventsAccountedForInTests, constructorCount,
reason: 'If you added or removed an event constructor, '
'ensure you have updated '
Expand Down

0 comments on commit 6ad3691

Please sign in to comment.