Skip to content

Configure GA for memory screen. #4705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions packages/devtools_app/lib/src/analytics/_analytics_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:async';

import '../primitives/utils.dart';
import 'analytics_common.dart';

Future<void> setAnalyticsEnabled(bool value) async {}
Expand Down Expand Up @@ -42,11 +41,7 @@ void timeSync(
}) {
// Execute the operation here so that the desktop app still functions without
// the real analytics call.
try {
syncOperation();
} on ProcessCancelledException catch (_) {
// Do nothing for instances of [ProcessCancelledException].
}
syncOperation();
}

Future<void> timeAsync(
Expand All @@ -57,11 +52,7 @@ Future<void> timeAsync(
}) async {
// Execute the operation here so that the desktop app still functions without
// the real analytics call.
try {
await asyncOperation();
} on ProcessCancelledException catch (_) {
// Do nothing for instances of [ProcessCancelledException].
}
await asyncOperation();
}

void select(
Expand Down
57 changes: 51 additions & 6 deletions packages/devtools_app/lib/src/analytics/_analytics_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import '../shared/globals.dart';
import '../ui/gtags.dart';
import 'analytics_common.dart';
import 'constants.dart' as analytics_constants;
import 'metrics.dart';

// Dimensions1 AppType values:
const String appTypeFlutter = 'flutter';
Expand Down Expand Up @@ -99,6 +100,10 @@ class GtagEventDevTools extends GtagEvent {
int? cpu_stack_depth, // metric5
// Performance screen metric. See [PerformanceScreenMetrics].
int? trace_event_count, // metric6
// Memory screen metric. See [MemoryScreenMetrics].
int? heap_diff_objects_before, // metric7
int? heap_diff_objects_after, // metric8
int? heap_objects_total, // metric9
});

@override
Expand Down Expand Up @@ -154,6 +159,12 @@ class GtagEventDevTools extends GtagEvent {
external int? get cpu_stack_depth;

external int? get trace_event_count;

external int? get heap_diff_objects_before;

external int? get heap_diff_objects_after;

external int? get heap_objects_total;
}

// This cannot be a factory constructor in the [GtagEventDevTools] class due to
Expand Down Expand Up @@ -183,6 +194,7 @@ GtagEventDevTools _gtagEvent({
is_external_build: isExternalBuild.toString(),
is_embedded: ideTheme.embed.toString(),
g3_username: devToolsExtensionPoints.username(),
// [PerformanceScreenMetrics]
ui_duration_micros: screenMetrics is PerformanceScreenMetrics
? screenMetrics.uiDuration?.inMicroseconds
: null,
Expand All @@ -193,14 +205,25 @@ GtagEventDevTools _gtagEvent({
screenMetrics is PerformanceScreenMetrics
? screenMetrics.shaderCompilationDuration?.inMicroseconds
: null,
trace_event_count: screenMetrics is PerformanceScreenMetrics
? screenMetrics.traceEventCount
: null,
// [ProfilerScreenMetrics]
cpu_sample_count: screenMetrics is ProfilerScreenMetrics
? screenMetrics.cpuSampleCount
: null,
cpu_stack_depth: screenMetrics is ProfilerScreenMetrics
? screenMetrics.cpuStackDepth
: null,
trace_event_count: screenMetrics is PerformanceScreenMetrics
? screenMetrics.traceEventCount
// [MemoryScreenMetrics]
heap_diff_objects_before: screenMetrics is MemoryScreenMetrics
? screenMetrics.heapDiffObjectsBefore
: null,
heap_diff_objects_after: screenMetrics is MemoryScreenMetrics
? screenMetrics.heapDiffObjectsAfter
: null,
heap_objects_total: screenMetrics is MemoryScreenMetrics
? screenMetrics.heapObjectsTotal
: null,
);
}
Expand All @@ -226,24 +249,36 @@ GtagExceptionDevTools _gtagException(
is_external_build: isExternalBuild.toString(),
is_embedded: ideTheme.embed.toString(),
g3_username: devToolsExtensionPoints.username(),
// [PerformanceScreenMetrics]
ui_duration_micros: screenMetrics is PerformanceScreenMetrics
? screenMetrics.uiDuration?.inMicroseconds
: null,
raster_duration_micros: screenMetrics is PerformanceScreenMetrics
? screenMetrics.rasterDuration?.inMicroseconds
: null,
trace_event_count: screenMetrics is PerformanceScreenMetrics
? screenMetrics.traceEventCount
: null,
shader_compilation_duration_micros:
screenMetrics is PerformanceScreenMetrics
? screenMetrics.shaderCompilationDuration?.inMicroseconds
: null,
// [ProfilerScreenMetrics]
cpu_sample_count: screenMetrics is ProfilerScreenMetrics
? screenMetrics.cpuSampleCount
: null,
cpu_stack_depth: screenMetrics is ProfilerScreenMetrics
? screenMetrics.cpuStackDepth
: null,
trace_event_count: screenMetrics is PerformanceScreenMetrics
? screenMetrics.traceEventCount
// [MemoryScreenMetrics]
heap_diff_objects_before: screenMetrics is MemoryScreenMetrics
? screenMetrics.heapDiffObjectsBefore
: null,
heap_diff_objects_after: screenMetrics is MemoryScreenMetrics
? screenMetrics.heapDiffObjectsAfter
: null,
heap_objects_total: screenMetrics is MemoryScreenMetrics
? screenMetrics.heapObjectsTotal
: null,
);
}
Expand Down Expand Up @@ -279,6 +314,10 @@ class GtagExceptionDevTools extends GtagException {
int? cpu_stack_depth, // metric5
// Performance screen metric. See [PerformanceScreenMetrics].
int? trace_event_count, // metric6
// Memory screen metric. See [MemoryScreenMetrics].
int? heap_diff_objects_before, // metric7
int? heap_diff_objects_after, // metric8
int? heap_objects_total, // metric9
});

@override
Expand Down Expand Up @@ -321,6 +360,12 @@ class GtagExceptionDevTools extends GtagException {
external int? get cpu_stack_depth;

external int? get trace_event_count;

external int? get heap_diff_objects_before;

external int? get heap_diff_objects_after;

external int? get heap_objects_total;
}

/// Request DevTools property value 'enabled' (GA enabled) stored in the file
Expand Down Expand Up @@ -431,7 +476,7 @@ void timeSync(
'because an exception was thrown:\n$e\n$st',
LogLevel.warning,
);
return;
rethrow;
}
final endTime = DateTime.now();
final durationMicros =
Expand Down Expand Up @@ -462,7 +507,7 @@ Future<void> timeAsync(
'because an exception was thrown:\n$e\n$st',
LogLevel.warning,
);
return;
rethrow;
}
final endTime = DateTime.now();
final durationMicros =
Expand Down
65 changes: 27 additions & 38 deletions packages/devtools_app/lib/src/analytics/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Type of events (event_category):

import '../screens/inspector/inspector_screen.dart';
import '../screens/logging/logging_screen.dart';
import '../screens/memory/memory_screen.dart';
import '../screens/network/network_screen.dart';
import '../screens/performance/performance_screen.dart';
import '../screens/profiler/profiler_screen.dart';

// Type of events (event_category):
const screenViewEvent = 'screen'; // Active screen (tab selected).
const selectEvent = 'select'; // User selected something.
const timingEvent = 'timing'; // Timed operation.
Expand Down Expand Up @@ -95,24 +94,6 @@ const profileAppStartUp = 'profileAppStartUp';
const cpuProfileFlameChartHelp = 'cpuProfileFlameChartHelp';
const cpuProfileProcessingTime = 'cpuProfileProcessingTime';

// Memory UX actions:
const gc = 'gc';
const memoryLegend = 'memoryLegend';
const memorySettings = 'memorySettings';
const androidChart = 'androidChart';
const autoSnapshot = 'autoSnapshot';
const showChart = 'showChart';
const hideChart = 'hideChart';
const groupByPrefix = 'groupBy';
const trackAllocations = 'trackAllocations';
const resetAllocationAccumulators = 'resetAllocationAccumulators';
const autoCompleteSearchSelect = 'autoCompleteSearchSelect';
const takeSnapshot = 'takeSnapshot';
const snapshotFilterDialog = 'snapshotFilterDialog';
const sourcesDropDown = 'sourcesDropDown';
const memoryDisplayInterval = 'chartInterval';
const treemapToggle = 'treemap';

// Logging UX actions:
const structuredErrors = 'structuredErrors';
const trackRebuildWidgets = 'trackRebuildWidgets';
Expand Down Expand Up @@ -158,47 +139,55 @@ String topicDocumentationButton(String topic) => '${topic}DocumentationButton';
String topicDocumentationLink(String topic) => '${topic}DocumentationLink';

/// Analytic time constants specific for memory screen.
class MemoryTimeAnalytics {
class MemoryTime {
static const adaptSnapshot = 'adaptSnapshot';
static const calculateDiff = 'calculateDiff';
static const updateValues = 'updateValues';
}

/// Analytic event constants specific for memory screen.
class MemoryEventAnalytics {
class MemoryEvent {
static const gc = 'gc';
static const settings = 'settings';
static const autoSnapshot = 'autoSnapshot';

static const chartLegend = 'memoryLegend';
static const chartAndroid = 'androidChart';

static const chartExpand = 'chartExpand';
static const chartCollapse = 'chartCollapse';
static const showChart = 'showChart';
static const hideChart = 'hideChart';
static const chartInterval = 'chartInterval';

static const profileDownloadCsv = 'profileDownloadCsv';
static const profileRefreshManual = 'profileRefreshManual';
static const profileRefreshOnGc = 'profileRefreshOnGc';
static const profileHelp = 'memoryProfileHelp';

static const allocationClear = 'allocationClear';
static const allocationRefresh = 'allocationRefresh';
static const allocationFilter = 'allocationFilter';
static const allocationTrace = 'allocationTrace';
static const allocationHelp = 'allocationHelp';
static const tracingClear = 'tracingClear';
static const tracingRefresh = 'tracingRefresh';
static const tracingClassFilter = 'tracingClassFilter';
static const tracingTraceCheck = 'tracingTraceCheck';
static const tracingHelp = 'memoryTracingHelp';

static const diffTakeSnapshot = 'diffTakeSnapshot';
static const diffTakeSnapshotControlPane = 'diffTakeSnapshotControlPane';
static const diffTakeSnapshotAfterHelp = 'diffTakeSnapshotAfterHelp';
static const diffClearSnapshots = 'diffClearSnapshots';

static const diffSnapshotDiff = 'diffSnapshotDiff';
static const diffSnapshotDiffSelect = 'diffSnapshotDiffSelect';
static const diffSnapshotDiffOff = 'diffSnapshotDiffSelectOff';
static const diffSnapshotFilter = 'diffSnapshotFilter';
static const diffSnapshotDownloadCsv = 'diffSnapshotDownloadCsv';
static const diffSnapshotDelete = 'diffSnapshotDelete';

static const diffClassSelect = 'diffClassSelect';
static const diffClassDiffSelect = 'diffClassDiffSelect';
static const diffClassSingleSelect = 'diffClassSingleSelect';
static const diffPathSelect = 'diffPathSelect';
static const diffClassDiffCopy = 'diffClassDiffCopy';
static const diffClassSingleCopy = 'diffClassSingleCopy';
static const diffPathCopy = 'diffPathCopy';
static const diffPathFilter = 'diffPathFilter';
static const diffPathUnfilter = 'diffPathUnfilter';
static const diffPathRevert = 'diffPathRevert';
static const diffPathUnrevert = 'diffPathUnrevert';
static const diffPathInvert = 'diffPathInvert';

static const diffSnapshotFilterAll = 'diffSnapshotFilterAll';
static const diffSnapshotFilterExcept = 'diffSnapshotFilterExcept';
static const diffSnapshotFilterOnly = 'diffSnapshotFilterOnly';
static const diffSnapshotFilterType = 'diffSnapshotFilterType';
static const diffSnapshotFilterReset = 'diffSnapshotFilterReset';
}
19 changes: 19 additions & 0 deletions packages/devtools_app/lib/src/analytics/metrics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'analytics_common.dart';

// TODO(polina-c): move other subclasses of ScreenAnalyticsMetrics here.

class MemoryScreenMetrics extends ScreenAnalyticsMetrics {
MemoryScreenMetrics({
this.heapObjectsTotal,
this.heapDiffObjectsBefore,
this.heapDiffObjectsAfter,
});

final int? heapDiffObjectsBefore;
final int? heapDiffObjectsAfter;
final int? heapObjectsTotal;
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
});

addAutoDisposeListener(controller.searchAutoCompleteNotifier, () {
ga.select(
analytics_constants.memory,
analytics_constants.snapshotFilterDialog,
);
controller.handleAutoCompleteOverlay(
context: context,
searchFieldKey: memorySearchFieldKey,
Expand Down Expand Up @@ -606,10 +602,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
onChanged: (String? newValue) {
setState(
() {
ga.select(
analytics_constants.memory,
'${analytics_constants.groupByPrefix}$newValue',
);
controller.selectedLeaf = null;
controller.groupingBy.value = newValue!;
if (controller.snapshots.isNotEmpty) {
Expand Down Expand Up @@ -643,11 +635,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
value: treeMapVisible,
onChanged: controller.snapshotByLibraryData != null
? (value) {
ga.select(
analytics_constants.memory,
'${analytics_constants.treemapToggle}-'
'${value ? 'show' : 'hide'}',
);
controller.toggleTreeMapVisible(value);
}
: null,
Expand Down Expand Up @@ -796,11 +783,6 @@ class _HeapTreeViewState extends State<HeapTreeView>

/// Match, found, select it and process via ValueNotifiers.
void selectTheMatch(String foundName) {
ga.select(
analytics_constants.memory,
analytics_constants.autoCompleteSearchSelect,
);

setState(() {
if (snapshotDisplay is MemoryHeapTable) {
controller.groupByTreeTable.dataRoots.every((element) {
Expand Down Expand Up @@ -845,11 +827,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
// TODO: Much of the logic for _takeHeapSnapshot() might want to move into the
// controller.
void _takeHeapSnapshot({bool userGenerated = true}) async {
ga.select(
analytics_constants.memory,
analytics_constants.takeSnapshot,
);

// VmService not available (disconnected/crashed).
if (serviceManager.service == null) return;

Expand Down Expand Up @@ -947,10 +924,6 @@ class _HeapTreeViewState extends State<HeapTreeView>
}

void _filter() {
ga.select(
analytics_constants.memory,
analytics_constants.snapshotFilterDialog,
);
// TODO(terry): Remove barrierDismissble and make clicking outside
// dialog same as cancel.
// Dialog isn't dismissed by clicking outside the dialog (modal).
Expand Down
Loading