Skip to content

Commit 2e84f08

Browse files
authored
Configure GA for memory screen. (#4705)
1 parent 919938c commit 2e84f08

33 files changed

+427
-179
lines changed

packages/devtools_app/lib/src/analytics/_analytics_stub.dart

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:async';
66

7-
import '../primitives/utils.dart';
87
import 'analytics_common.dart';
98

109
Future<void> setAnalyticsEnabled(bool value) async {}
@@ -42,11 +41,7 @@ void timeSync(
4241
}) {
4342
// Execute the operation here so that the desktop app still functions without
4443
// the real analytics call.
45-
try {
46-
syncOperation();
47-
} on ProcessCancelledException catch (_) {
48-
// Do nothing for instances of [ProcessCancelledException].
49-
}
44+
syncOperation();
5045
}
5146

5247
Future<void> timeAsync(
@@ -57,11 +52,7 @@ Future<void> timeAsync(
5752
}) async {
5853
// Execute the operation here so that the desktop app still functions without
5954
// the real analytics call.
60-
try {
61-
await asyncOperation();
62-
} on ProcessCancelledException catch (_) {
63-
// Do nothing for instances of [ProcessCancelledException].
64-
}
55+
await asyncOperation();
6556
}
6657

6758
void select(

packages/devtools_app/lib/src/analytics/_analytics_web.dart

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import '../shared/globals.dart';
2323
import '../ui/gtags.dart';
2424
import 'analytics_common.dart';
2525
import 'constants.dart' as analytics_constants;
26+
import 'metrics.dart';
2627

2728
// Dimensions1 AppType values:
2829
const String appTypeFlutter = 'flutter';
@@ -99,6 +100,10 @@ class GtagEventDevTools extends GtagEvent {
99100
int? cpu_stack_depth, // metric5
100101
// Performance screen metric. See [PerformanceScreenMetrics].
101102
int? trace_event_count, // metric6
103+
// Memory screen metric. See [MemoryScreenMetrics].
104+
int? heap_diff_objects_before, // metric7
105+
int? heap_diff_objects_after, // metric8
106+
int? heap_objects_total, // metric9
102107
});
103108

104109
@override
@@ -154,6 +159,12 @@ class GtagEventDevTools extends GtagEvent {
154159
external int? get cpu_stack_depth;
155160

156161
external int? get trace_event_count;
162+
163+
external int? get heap_diff_objects_before;
164+
165+
external int? get heap_diff_objects_after;
166+
167+
external int? get heap_objects_total;
157168
}
158169

159170
// This cannot be a factory constructor in the [GtagEventDevTools] class due to
@@ -183,6 +194,7 @@ GtagEventDevTools _gtagEvent({
183194
is_external_build: isExternalBuild.toString(),
184195
is_embedded: ideTheme.embed.toString(),
185196
g3_username: devToolsExtensionPoints.username(),
197+
// [PerformanceScreenMetrics]
186198
ui_duration_micros: screenMetrics is PerformanceScreenMetrics
187199
? screenMetrics.uiDuration?.inMicroseconds
188200
: null,
@@ -193,14 +205,25 @@ GtagEventDevTools _gtagEvent({
193205
screenMetrics is PerformanceScreenMetrics
194206
? screenMetrics.shaderCompilationDuration?.inMicroseconds
195207
: null,
208+
trace_event_count: screenMetrics is PerformanceScreenMetrics
209+
? screenMetrics.traceEventCount
210+
: null,
211+
// [ProfilerScreenMetrics]
196212
cpu_sample_count: screenMetrics is ProfilerScreenMetrics
197213
? screenMetrics.cpuSampleCount
198214
: null,
199215
cpu_stack_depth: screenMetrics is ProfilerScreenMetrics
200216
? screenMetrics.cpuStackDepth
201217
: null,
202-
trace_event_count: screenMetrics is PerformanceScreenMetrics
203-
? screenMetrics.traceEventCount
218+
// [MemoryScreenMetrics]
219+
heap_diff_objects_before: screenMetrics is MemoryScreenMetrics
220+
? screenMetrics.heapDiffObjectsBefore
221+
: null,
222+
heap_diff_objects_after: screenMetrics is MemoryScreenMetrics
223+
? screenMetrics.heapDiffObjectsAfter
224+
: null,
225+
heap_objects_total: screenMetrics is MemoryScreenMetrics
226+
? screenMetrics.heapObjectsTotal
204227
: null,
205228
);
206229
}
@@ -226,24 +249,36 @@ GtagExceptionDevTools _gtagException(
226249
is_external_build: isExternalBuild.toString(),
227250
is_embedded: ideTheme.embed.toString(),
228251
g3_username: devToolsExtensionPoints.username(),
252+
// [PerformanceScreenMetrics]
229253
ui_duration_micros: screenMetrics is PerformanceScreenMetrics
230254
? screenMetrics.uiDuration?.inMicroseconds
231255
: null,
232256
raster_duration_micros: screenMetrics is PerformanceScreenMetrics
233257
? screenMetrics.rasterDuration?.inMicroseconds
234258
: null,
259+
trace_event_count: screenMetrics is PerformanceScreenMetrics
260+
? screenMetrics.traceEventCount
261+
: null,
235262
shader_compilation_duration_micros:
236263
screenMetrics is PerformanceScreenMetrics
237264
? screenMetrics.shaderCompilationDuration?.inMicroseconds
238265
: null,
266+
// [ProfilerScreenMetrics]
239267
cpu_sample_count: screenMetrics is ProfilerScreenMetrics
240268
? screenMetrics.cpuSampleCount
241269
: null,
242270
cpu_stack_depth: screenMetrics is ProfilerScreenMetrics
243271
? screenMetrics.cpuStackDepth
244272
: null,
245-
trace_event_count: screenMetrics is PerformanceScreenMetrics
246-
? screenMetrics.traceEventCount
273+
// [MemoryScreenMetrics]
274+
heap_diff_objects_before: screenMetrics is MemoryScreenMetrics
275+
? screenMetrics.heapDiffObjectsBefore
276+
: null,
277+
heap_diff_objects_after: screenMetrics is MemoryScreenMetrics
278+
? screenMetrics.heapDiffObjectsAfter
279+
: null,
280+
heap_objects_total: screenMetrics is MemoryScreenMetrics
281+
? screenMetrics.heapObjectsTotal
247282
: null,
248283
);
249284
}
@@ -279,6 +314,10 @@ class GtagExceptionDevTools extends GtagException {
279314
int? cpu_stack_depth, // metric5
280315
// Performance screen metric. See [PerformanceScreenMetrics].
281316
int? trace_event_count, // metric6
317+
// Memory screen metric. See [MemoryScreenMetrics].
318+
int? heap_diff_objects_before, // metric7
319+
int? heap_diff_objects_after, // metric8
320+
int? heap_objects_total, // metric9
282321
});
283322

284323
@override
@@ -321,6 +360,12 @@ class GtagExceptionDevTools extends GtagException {
321360
external int? get cpu_stack_depth;
322361

323362
external int? get trace_event_count;
363+
364+
external int? get heap_diff_objects_before;
365+
366+
external int? get heap_diff_objects_after;
367+
368+
external int? get heap_objects_total;
324369
}
325370

326371
/// Request DevTools property value 'enabled' (GA enabled) stored in the file
@@ -431,7 +476,7 @@ void timeSync(
431476
'because an exception was thrown:\n$e\n$st',
432477
LogLevel.warning,
433478
);
434-
return;
479+
rethrow;
435480
}
436481
final endTime = DateTime.now();
437482
final durationMicros =
@@ -462,7 +507,7 @@ Future<void> timeAsync(
462507
'because an exception was thrown:\n$e\n$st',
463508
LogLevel.warning,
464509
);
465-
return;
510+
rethrow;
466511
}
467512
final endTime = DateTime.now();
468513
final durationMicros =

packages/devtools_app/lib/src/analytics/constants.dart

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// Type of events (event_category):
6-
75
import '../screens/inspector/inspector_screen.dart';
86
import '../screens/logging/logging_screen.dart';
97
import '../screens/memory/memory_screen.dart';
108
import '../screens/network/network_screen.dart';
119
import '../screens/performance/performance_screen.dart';
1210
import '../screens/profiler/profiler_screen.dart';
1311

12+
// Type of events (event_category):
1413
const screenViewEvent = 'screen'; // Active screen (tab selected).
1514
const selectEvent = 'select'; // User selected something.
1615
const timingEvent = 'timing'; // Timed operation.
@@ -95,24 +94,6 @@ const profileAppStartUp = 'profileAppStartUp';
9594
const cpuProfileFlameChartHelp = 'cpuProfileFlameChartHelp';
9695
const cpuProfileProcessingTime = 'cpuProfileProcessingTime';
9796

98-
// Memory UX actions:
99-
const gc = 'gc';
100-
const memoryLegend = 'memoryLegend';
101-
const memorySettings = 'memorySettings';
102-
const androidChart = 'androidChart';
103-
const autoSnapshot = 'autoSnapshot';
104-
const showChart = 'showChart';
105-
const hideChart = 'hideChart';
106-
const groupByPrefix = 'groupBy';
107-
const trackAllocations = 'trackAllocations';
108-
const resetAllocationAccumulators = 'resetAllocationAccumulators';
109-
const autoCompleteSearchSelect = 'autoCompleteSearchSelect';
110-
const takeSnapshot = 'takeSnapshot';
111-
const snapshotFilterDialog = 'snapshotFilterDialog';
112-
const sourcesDropDown = 'sourcesDropDown';
113-
const memoryDisplayInterval = 'chartInterval';
114-
const treemapToggle = 'treemap';
115-
11697
// Logging UX actions:
11798
const structuredErrors = 'structuredErrors';
11899
const trackRebuildWidgets = 'trackRebuildWidgets';
@@ -158,47 +139,55 @@ String topicDocumentationButton(String topic) => '${topic}DocumentationButton';
158139
String topicDocumentationLink(String topic) => '${topic}DocumentationLink';
159140

160141
/// Analytic time constants specific for memory screen.
161-
class MemoryTimeAnalytics {
142+
class MemoryTime {
162143
static const adaptSnapshot = 'adaptSnapshot';
144+
static const calculateDiff = 'calculateDiff';
163145
static const updateValues = 'updateValues';
164146
}
165147

166148
/// Analytic event constants specific for memory screen.
167-
class MemoryEventAnalytics {
149+
class MemoryEvent {
168150
static const gc = 'gc';
169151
static const settings = 'settings';
152+
static const autoSnapshot = 'autoSnapshot';
153+
154+
static const chartLegend = 'memoryLegend';
155+
static const chartAndroid = 'androidChart';
170156

171-
static const chartExpand = 'chartExpand';
172-
static const chartCollapse = 'chartCollapse';
157+
static const showChart = 'showChart';
158+
static const hideChart = 'hideChart';
159+
static const chartInterval = 'chartInterval';
173160

174161
static const profileDownloadCsv = 'profileDownloadCsv';
175162
static const profileRefreshManual = 'profileRefreshManual';
176163
static const profileRefreshOnGc = 'profileRefreshOnGc';
164+
static const profileHelp = 'memoryProfileHelp';
177165

178-
static const allocationClear = 'allocationClear';
179-
static const allocationRefresh = 'allocationRefresh';
180-
static const allocationFilter = 'allocationFilter';
181-
static const allocationTrace = 'allocationTrace';
182-
static const allocationHelp = 'allocationHelp';
166+
static const tracingClear = 'tracingClear';
167+
static const tracingRefresh = 'tracingRefresh';
168+
static const tracingClassFilter = 'tracingClassFilter';
169+
static const tracingTraceCheck = 'tracingTraceCheck';
170+
static const tracingHelp = 'memoryTracingHelp';
183171

184-
static const diffTakeSnapshot = 'diffTakeSnapshot';
172+
static const diffTakeSnapshotControlPane = 'diffTakeSnapshotControlPane';
173+
static const diffTakeSnapshotAfterHelp = 'diffTakeSnapshotAfterHelp';
185174
static const diffClearSnapshots = 'diffClearSnapshots';
186175

187-
static const diffSnapshotDiff = 'diffSnapshotDiff';
176+
static const diffSnapshotDiffSelect = 'diffSnapshotDiffSelect';
177+
static const diffSnapshotDiffOff = 'diffSnapshotDiffSelectOff';
188178
static const diffSnapshotFilter = 'diffSnapshotFilter';
189179
static const diffSnapshotDownloadCsv = 'diffSnapshotDownloadCsv';
190180
static const diffSnapshotDelete = 'diffSnapshotDelete';
191181

192-
static const diffClassSelect = 'diffClassSelect';
182+
static const diffClassDiffSelect = 'diffClassDiffSelect';
183+
static const diffClassSingleSelect = 'diffClassSingleSelect';
193184
static const diffPathSelect = 'diffPathSelect';
185+
static const diffClassDiffCopy = 'diffClassDiffCopy';
186+
static const diffClassSingleCopy = 'diffClassSingleCopy';
194187
static const diffPathCopy = 'diffPathCopy';
195188
static const diffPathFilter = 'diffPathFilter';
196-
static const diffPathUnfilter = 'diffPathUnfilter';
197-
static const diffPathRevert = 'diffPathRevert';
198-
static const diffPathUnrevert = 'diffPathUnrevert';
189+
static const diffPathInvert = 'diffPathInvert';
199190

200-
static const diffSnapshotFilterAll = 'diffSnapshotFilterAll';
201-
static const diffSnapshotFilterExcept = 'diffSnapshotFilterExcept';
202-
static const diffSnapshotFilterOnly = 'diffSnapshotFilterOnly';
191+
static const diffSnapshotFilterType = 'diffSnapshotFilterType';
203192
static const diffSnapshotFilterReset = 'diffSnapshotFilterReset';
204193
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2022 The Chromium 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 'analytics_common.dart';
6+
7+
// TODO(polina-c): move other subclasses of ScreenAnalyticsMetrics here.
8+
9+
class MemoryScreenMetrics extends ScreenAnalyticsMetrics {
10+
MemoryScreenMetrics({
11+
this.heapObjectsTotal,
12+
this.heapDiffObjectsBefore,
13+
this.heapDiffObjectsAfter,
14+
});
15+
16+
final int? heapDiffObjectsBefore;
17+
final int? heapDiffObjectsAfter;
18+
final int? heapObjectsTotal;
19+
}

packages/devtools_app/lib/src/screens/memory/memory_heap_tree_view.dart

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
279279
});
280280

281281
addAutoDisposeListener(controller.searchAutoCompleteNotifier, () {
282-
ga.select(
283-
analytics_constants.memory,
284-
analytics_constants.snapshotFilterDialog,
285-
);
286282
controller.handleAutoCompleteOverlay(
287283
context: context,
288284
searchFieldKey: memorySearchFieldKey,
@@ -606,10 +602,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
606602
onChanged: (String? newValue) {
607603
setState(
608604
() {
609-
ga.select(
610-
analytics_constants.memory,
611-
'${analytics_constants.groupByPrefix}$newValue',
612-
);
613605
controller.selectedLeaf = null;
614606
controller.groupingBy.value = newValue!;
615607
if (controller.snapshots.isNotEmpty) {
@@ -643,11 +635,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
643635
value: treeMapVisible,
644636
onChanged: controller.snapshotByLibraryData != null
645637
? (value) {
646-
ga.select(
647-
analytics_constants.memory,
648-
'${analytics_constants.treemapToggle}-'
649-
'${value ? 'show' : 'hide'}',
650-
);
651638
controller.toggleTreeMapVisible(value);
652639
}
653640
: null,
@@ -796,11 +783,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
796783

797784
/// Match, found, select it and process via ValueNotifiers.
798785
void selectTheMatch(String foundName) {
799-
ga.select(
800-
analytics_constants.memory,
801-
analytics_constants.autoCompleteSearchSelect,
802-
);
803-
804786
setState(() {
805787
if (snapshotDisplay is MemoryHeapTable) {
806788
controller.groupByTreeTable.dataRoots.every((element) {
@@ -845,11 +827,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
845827
// TODO: Much of the logic for _takeHeapSnapshot() might want to move into the
846828
// controller.
847829
void _takeHeapSnapshot({bool userGenerated = true}) async {
848-
ga.select(
849-
analytics_constants.memory,
850-
analytics_constants.takeSnapshot,
851-
);
852-
853830
// VmService not available (disconnected/crashed).
854831
if (serviceManager.service == null) return;
855832

@@ -947,10 +924,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
947924
}
948925

949926
void _filter() {
950-
ga.select(
951-
analytics_constants.memory,
952-
analytics_constants.snapshotFilterDialog,
953-
);
954927
// TODO(terry): Remove barrierDismissble and make clicking outside
955928
// dialog same as cancel.
956929
// Dialog isn't dismissed by clicking outside the dialog (modal).

0 commit comments

Comments
 (0)