Skip to content

Commit 6ad3691

Browse files
authored
Added new event enum + constructor for hot runner (#193)
* Added new event enum + constructor for hot runner * Bump `eventsAccountedForInTests` * Add `label` for each hot event * Add TODO for enhancing dartdocs for new constructor
1 parent dd91cb6 commit 6ad3691

File tree

6 files changed

+115
-3
lines changed

6 files changed

+115
-3
lines changed

pkgs/unified_analytics/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 5.2.0
2+
3+
- Added the `Event.hotRunnerInfo` constructor
4+
15
## 5.1.0
26

37
- Added the `Event.flutterBuildInfo` constructor

pkgs/unified_analytics/lib/src/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const int kLogFileLength = 2500;
8282
const String kLogFileName = 'dart-flutter-telemetry.log';
8383

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

8787
/// The minimum length for a session.
8888
const int kSessionDurationMinutes = 30;

pkgs/unified_analytics/lib/src/enums.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ enum DashEvent {
6161
description: 'Hot reload duration',
6262
toolOwner: DashTool.flutterTool,
6363
),
64+
hotRunnerInfo(
65+
label: 'hot_runner_info',
66+
description: 'Information related to the Flutter hot runner',
67+
toolOwner: DashTool.flutterTool,
68+
),
6469

6570
// Events for language_server below
6671

pkgs/unified_analytics/lib/src/event.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,64 @@ final class Event {
266266
if (error != null) 'error': error,
267267
};
268268

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

275+
// TODO: eliasyishak, add better dartdocs to explain each param
276+
/// Events to be sent for the Flutter Hot Runner.
277+
Event.hotRunnerInfo({
278+
required String label,
279+
required String targetPlatform,
280+
required String sdkName,
281+
required bool emulator,
282+
required bool fullRestart,
283+
String? reason,
284+
int? finalLibraryCount,
285+
int? syncedLibraryCount,
286+
int? syncedClassesCount,
287+
int? syncedProceduresCount,
288+
int? syncedBytes,
289+
int? invalidatedSourcesCount,
290+
int? transferTimeInMs,
291+
int? overallTimeInMs,
292+
int? compileTimeInMs,
293+
int? findInvalidatedTimeInMs,
294+
int? scannedSourcesCount,
295+
int? reassembleTimeInMs,
296+
int? reloadVMTimeInMs,
297+
}) : eventName = DashEvent.hotRunnerInfo,
298+
eventData = {
299+
'label': label,
300+
'targetPlatform': targetPlatform,
301+
'sdkName': sdkName,
302+
'emulator': emulator,
303+
'fullRestart': fullRestart,
304+
if (reason != null) 'reason': reason,
305+
if (finalLibraryCount != null) 'finalLibraryCount': finalLibraryCount,
306+
if (syncedLibraryCount != null)
307+
'syncedLibraryCount': syncedLibraryCount,
308+
if (syncedClassesCount != null)
309+
'syncedClassesCount': syncedClassesCount,
310+
if (syncedProceduresCount != null)
311+
'syncedProceduresCount': syncedProceduresCount,
312+
if (syncedBytes != null) 'syncedBytes': syncedBytes,
313+
if (invalidatedSourcesCount != null)
314+
'invalidatedSourcesCount': invalidatedSourcesCount,
315+
if (transferTimeInMs != null) 'transferTimeInMs': transferTimeInMs,
316+
if (overallTimeInMs != null) 'overallTimeInMs': overallTimeInMs,
317+
if (compileTimeInMs != null) 'compileTimeInMs': compileTimeInMs,
318+
if (findInvalidatedTimeInMs != null)
319+
'findInvalidatedTimeInMs': findInvalidatedTimeInMs,
320+
if (scannedSourcesCount != null)
321+
'scannedSourcesCount': scannedSourcesCount,
322+
if (reassembleTimeInMs != null)
323+
'reassembleTimeInMs': reassembleTimeInMs,
324+
if (reloadVMTimeInMs != null) 'reloadVMTimeInMs': reloadVMTimeInMs,
325+
};
326+
273327
/// Event that is emitted periodically to report the number of times each lint
274328
/// has been enabled.
275329
///

pkgs/unified_analytics/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >-
44
to Google Analytics.
55
# When updating this, keep the version consistent with the changelog and the
66
# value in lib/src/constants.dart.
7-
version: 5.1.0
7+
version: 5.2.0
88
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics
99

1010
environment:

pkgs/unified_analytics/test/event_test.dart

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,55 @@ void main() {
332332
expect(constructedEvent.eventData.length, 5);
333333
});
334334

335+
test('Event.hotRunnerInfo constructed', () {
336+
Event generateEvent() => Event.hotRunnerInfo(
337+
label: 'label',
338+
targetPlatform: 'targetPlatform',
339+
sdkName: 'sdkName',
340+
emulator: false,
341+
fullRestart: true,
342+
reason: 'reason',
343+
finalLibraryCount: 5,
344+
syncedLibraryCount: 6,
345+
syncedClassesCount: 7,
346+
syncedProceduresCount: 8,
347+
syncedBytes: 9,
348+
invalidatedSourcesCount: 10,
349+
transferTimeInMs: 11,
350+
overallTimeInMs: 12,
351+
compileTimeInMs: 13,
352+
findInvalidatedTimeInMs: 14,
353+
scannedSourcesCount: 15,
354+
reassembleTimeInMs: 16,
355+
reloadVMTimeInMs: 17,
356+
);
357+
358+
final constructedEvent = generateEvent();
359+
360+
expect(generateEvent, returnsNormally);
361+
expect(constructedEvent.eventName, DashEvent.hotRunnerInfo);
362+
expect(constructedEvent.eventData['label'], 'label');
363+
expect(constructedEvent.eventData['targetPlatform'], 'targetPlatform');
364+
expect(constructedEvent.eventData['sdkName'], 'sdkName');
365+
expect(constructedEvent.eventData['emulator'], false);
366+
expect(constructedEvent.eventData['fullRestart'], true);
367+
expect(constructedEvent.eventData['reason'], 'reason');
368+
expect(constructedEvent.eventData['finalLibraryCount'], 5);
369+
expect(constructedEvent.eventData['syncedLibraryCount'], 6);
370+
expect(constructedEvent.eventData['syncedClassesCount'], 7);
371+
expect(constructedEvent.eventData['syncedProceduresCount'], 8);
372+
expect(constructedEvent.eventData['syncedBytes'], 9);
373+
expect(constructedEvent.eventData['invalidatedSourcesCount'], 10);
374+
expect(constructedEvent.eventData['transferTimeInMs'], 11);
375+
expect(constructedEvent.eventData['overallTimeInMs'], 12);
376+
expect(constructedEvent.eventData['compileTimeInMs'], 13);
377+
expect(constructedEvent.eventData['findInvalidatedTimeInMs'], 14);
378+
expect(constructedEvent.eventData['scannedSourcesCount'], 15);
379+
expect(constructedEvent.eventData['reassembleTimeInMs'], 16);
380+
expect(constructedEvent.eventData['reloadVMTimeInMs'], 17);
381+
expect(constructedEvent.eventData.length, 19);
382+
});
383+
335384
test('Confirm all constructors were checked', () {
336385
var constructorCount = 0;
337386
for (var declaration in reflectClass(Event).declarations.keys) {
@@ -340,7 +389,7 @@ void main() {
340389

341390
// Change this integer below if your PR either adds or removes
342391
// an Event constructor
343-
final eventsAccountedForInTests = 18;
392+
final eventsAccountedForInTests = 19;
344393
expect(eventsAccountedForInTests, constructorCount,
345394
reason: 'If you added or removed an event constructor, '
346395
'ensure you have updated '

0 commit comments

Comments
 (0)