Skip to content

Commit 3e21ae9

Browse files
authored
Event Constructor added for devtools event (#258)
* Constructor added for the one devtools event * Relabel enum value * Update eventData with correct types * Update event constructor name * Add test for new event * Prep for publishing
1 parent d86ea23 commit 3e21ae9

File tree

6 files changed

+170
-3
lines changed

6 files changed

+170
-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+
## 6.1.0
2+
3+
- Added new event constructor `Event.devtoolsEvent` for the single devtools event with a new enum value `DashEvent.devtoolsEvent`
4+
15
## 6.0.0
26

37
- Consolidate `Session` functionality into `UserProperty` to prevent race condition crash where session logic crashed before initializing `UserProperty`

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 = '6.0.0';
85+
const String kPackageVersion = '6.1.0';
8686

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

pkgs/unified_analytics/lib/src/enums.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ enum DashEvent {
5656
toolOwner: DashTool.dartTool,
5757
),
5858

59+
// Events for Flutter devtools
60+
61+
devtoolsEvent(
62+
label: 'devtools_event',
63+
description: 'Information for various devtools events',
64+
toolOwner: DashTool.devtools,
65+
),
66+
5967
// Events for the Flutter CLI
6068

6169
appleUsageEvent(

pkgs/unified_analytics/lib/src/event.dart

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,96 @@ final class Event {
356356
if (exitCode != null) 'exitCode': exitCode,
357357
};
358358

359+
/// Event that is sent from devtools for various different actions as
360+
/// indicated by the [eventCategory].
361+
Event.devtoolsEvent({
362+
required String eventCategory,
363+
required String label,
364+
required int value,
365+
366+
// Defaulted values
367+
bool userInitiatedInteraction = true,
368+
369+
// Optional parameters
370+
String? g3Username,
371+
String? userApp,
372+
String? userBuild,
373+
String? userPlatform,
374+
String? devtoolsPlatform,
375+
String? devtoolsChrome,
376+
String? devtoolsVersion,
377+
String? ideLaunched,
378+
String? isExternalBuild,
379+
String? isEmbedded,
380+
String? ideLaunchedFeature,
381+
382+
// PerformanceScreenMetrics
383+
int? uiDurationMicros,
384+
int? rasterDurationMicros,
385+
int? shaderCompilationDurationMicros,
386+
int? traceEventCount,
387+
388+
// ProfilerScreenMetrics
389+
int? cpuSampleCount,
390+
int? cpuStackDepth,
391+
392+
// MemoryScreenMetrics
393+
int? heapDiffObjectsBefore,
394+
int? heapDiffObjectsAfter,
395+
int? heapObjectsTotal,
396+
397+
// InspectorScreenMetrics
398+
int? rootSetCount,
399+
int? rowCount,
400+
int? inspectorTreeControllerId,
401+
}) : eventName = DashEvent.devtoolsEvent,
402+
eventData = {
403+
'eventCategory': eventCategory,
404+
'label': label,
405+
'value': value,
406+
407+
'userInitiatedInteraction': userInitiatedInteraction,
408+
409+
// Optional parameters
410+
if (g3Username != null) 'g3Username': g3Username,
411+
if (userApp != null) 'userApp': userApp,
412+
if (userBuild != null) 'userBuild': userBuild,
413+
if (userPlatform != null) 'userPlatform': userPlatform,
414+
if (devtoolsPlatform != null) 'devtoolsPlatform': devtoolsPlatform,
415+
if (devtoolsChrome != null) 'devtoolsChrome': devtoolsChrome,
416+
if (devtoolsVersion != null) 'devtoolsVersion': devtoolsVersion,
417+
if (ideLaunched != null) 'ideLaunched': ideLaunched,
418+
if (isExternalBuild != null) 'isExternalBuild': isExternalBuild,
419+
if (isEmbedded != null) 'isEmbedded': isEmbedded,
420+
if (ideLaunchedFeature != null)
421+
'ideLaunchedFeature': ideLaunchedFeature,
422+
423+
// PerformanceScreenMetrics
424+
if (uiDurationMicros != null) 'uiDurationMicros': uiDurationMicros,
425+
if (rasterDurationMicros != null)
426+
'rasterDurationMicros': rasterDurationMicros,
427+
if (shaderCompilationDurationMicros != null)
428+
'shaderCompilationDurationMicros': shaderCompilationDurationMicros,
429+
if (traceEventCount != null) 'traceEventCount': traceEventCount,
430+
431+
// ProfilerScreenMetrics
432+
if (cpuSampleCount != null) 'cpuSampleCount': cpuSampleCount,
433+
if (cpuStackDepth != null) 'cpuStackDepth': cpuStackDepth,
434+
435+
// MemoryScreenMetrics
436+
if (heapDiffObjectsBefore != null)
437+
'heapDiffObjectsBefore': heapDiffObjectsBefore,
438+
if (heapDiffObjectsAfter != null)
439+
'heapDiffObjectsAfter': heapDiffObjectsAfter,
440+
if (heapObjectsTotal != null) 'heapObjectsTotal': heapObjectsTotal,
441+
442+
// InspectorScreenMetrics
443+
if (rootSetCount != null) 'rootSetCount': rootSetCount,
444+
if (rowCount != null) 'rowCount': rowCount,
445+
if (inspectorTreeControllerId != null)
446+
'inspectorTreeControllerId': inspectorTreeControllerId,
447+
};
448+
359449
/// Event that contains the results for a specific doctor validator.
360450
///
361451
/// [validatorName] - the name for the doctor validator.

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: 6.0.0
7+
version: 6.1.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: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,71 @@ void main() {
553553
expect(constructedEvent.eventData.length, 3);
554554
});
555555

556+
test('Event.devtoolsEvent constructed', () {
557+
Event generateEvent() => Event.devtoolsEvent(
558+
eventCategory: 'eventCategory',
559+
label: 'label',
560+
value: 1,
561+
userInitiatedInteraction: true,
562+
g3Username: 'g3Username',
563+
userApp: 'userApp',
564+
userBuild: 'userBuild',
565+
userPlatform: 'userPlatform',
566+
devtoolsPlatform: 'devtoolsPlatform',
567+
devtoolsChrome: 'devtoolsChrome',
568+
devtoolsVersion: 'devtoolsVersion',
569+
ideLaunched: 'ideLaunched',
570+
isExternalBuild: 'isExternalBuild',
571+
isEmbedded: 'isEmbedded',
572+
ideLaunchedFeature: 'ideLaunchedFeature',
573+
uiDurationMicros: 123,
574+
rasterDurationMicros: 123,
575+
shaderCompilationDurationMicros: 123,
576+
traceEventCount: 123,
577+
cpuSampleCount: 123,
578+
cpuStackDepth: 123,
579+
heapDiffObjectsBefore: 123,
580+
heapDiffObjectsAfter: 123,
581+
heapObjectsTotal: 123,
582+
rootSetCount: 123,
583+
rowCount: 123,
584+
inspectorTreeControllerId: 123,
585+
);
586+
587+
final constructedEvent = generateEvent();
588+
589+
expect(generateEvent, returnsNormally);
590+
expect(constructedEvent.eventData['eventCategory'], 'eventCategory');
591+
expect(constructedEvent.eventData['label'], 'label');
592+
expect(constructedEvent.eventData['value'], 1);
593+
expect(constructedEvent.eventData['userInitiatedInteraction'], true);
594+
expect(constructedEvent.eventData['g3Username'], 'g3Username');
595+
expect(constructedEvent.eventData['userApp'], 'userApp');
596+
expect(constructedEvent.eventData['userBuild'], 'userBuild');
597+
expect(constructedEvent.eventData['userPlatform'], 'userPlatform');
598+
expect(constructedEvent.eventData['devtoolsPlatform'], 'devtoolsPlatform');
599+
expect(constructedEvent.eventData['devtoolsChrome'], 'devtoolsChrome');
600+
expect(constructedEvent.eventData['devtoolsVersion'], 'devtoolsVersion');
601+
expect(constructedEvent.eventData['ideLaunched'], 'ideLaunched');
602+
expect(constructedEvent.eventData['isExternalBuild'], 'isExternalBuild');
603+
expect(constructedEvent.eventData['isEmbedded'], 'isEmbedded');
604+
expect(
605+
constructedEvent.eventData['ideLaunchedFeature'], 'ideLaunchedFeature');
606+
expect(constructedEvent.eventData['uiDurationMicros'], 123);
607+
expect(constructedEvent.eventData['rasterDurationMicros'], 123);
608+
expect(constructedEvent.eventData['shaderCompilationDurationMicros'], 123);
609+
expect(constructedEvent.eventData['traceEventCount'], 123);
610+
expect(constructedEvent.eventData['cpuSampleCount'], 123);
611+
expect(constructedEvent.eventData['cpuStackDepth'], 123);
612+
expect(constructedEvent.eventData['heapDiffObjectsBefore'], 123);
613+
expect(constructedEvent.eventData['heapDiffObjectsAfter'], 123);
614+
expect(constructedEvent.eventData['heapObjectsTotal'], 123);
615+
expect(constructedEvent.eventData['rootSetCount'], 123);
616+
expect(constructedEvent.eventData['rowCount'], 123);
617+
expect(constructedEvent.eventData['inspectorTreeControllerId'], 123);
618+
expect(constructedEvent.eventData.length, 27);
619+
});
620+
556621
test('Confirm all constructors were checked', () {
557622
var constructorCount = 0;
558623
for (var declaration in reflectClass(Event).declarations.keys) {
@@ -563,7 +628,7 @@ void main() {
563628

564629
// Change this integer below if your PR either adds or removes
565630
// an Event constructor
566-
final eventsAccountedForInTests = 26;
631+
final eventsAccountedForInTests = 27;
567632
expect(eventsAccountedForInTests, constructorCount,
568633
reason: 'If you added or removed an event constructor, '
569634
'ensure you have updated '

0 commit comments

Comments
 (0)