Unverified Commit d5b67035 authored by Elias Yishak's avatar Elias Yishak Committed by GitHub

Unified analytics migration for `CodeSizeAnalysis` (#138351)

Part of tracker issue:
- https://github.com/flutter/flutter/issues/128251

This migrates the event being sent when the "--analyze-size" is used in a flutter invocation

The only file that had this event being sent from is `packages/flutter_tools/lib/src/base/analyze_size.dart`
parent 44990867
......@@ -608,6 +608,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
fileSystem: _fileSystem,
logger: _logger,
flutterUsage: _usage,
analytics: _analytics,
);
final String archName = androidBuildInfo.targetArchs.single.archName;
final BuildInfo buildInfo = androidBuildInfo.buildInfo;
......
......@@ -5,6 +5,7 @@
import 'package:archive/archive.dart';
import 'package:archive/archive_io.dart';
import 'package:meta/meta.dart';
import 'package:unified_analytics/unified_analytics.dart';
import 'package:vm_snapshot_analysis/treemap.dart';
import '../convert.dart';
......@@ -20,8 +21,10 @@ class SizeAnalyzer {
required FileSystem fileSystem,
required Logger logger,
required Usage flutterUsage,
required Analytics analytics,
Pattern appFilenamePattern = 'libapp.so',
}) : _flutterUsage = flutterUsage,
_analytics = analytics,
_fileSystem = fileSystem,
_logger = logger,
_appFilenamePattern = appFilenamePattern;
......@@ -30,6 +33,7 @@ class SizeAnalyzer {
final Logger _logger;
final Pattern _appFilenamePattern;
final Usage _flutterUsage;
final Analytics _analytics;
String? _appFilename;
static const String aotSnapshotFileName = 'aot-snapshot.json';
......@@ -88,6 +92,7 @@ class SizeAnalyzer {
assert(_appFilename != null);
CodeSizeEvent(type, flutterUsage: _flutterUsage).send();
_analytics.send(Event.codeSizeAnalysis(platform: type));
return apkAnalysisJson;
}
......@@ -141,6 +146,7 @@ class SizeAnalyzer {
precompilerTrace: json.decode(precompilerTrace.readAsStringSync()) as Map<String, Object?>? ?? <String, Object?>{},
);
CodeSizeEvent(kind, flutterUsage: _flutterUsage).send();
_analytics.send(Event.codeSizeAnalysis(platform: kind));
return apkAnalysisJson;
}
......
......@@ -680,6 +680,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
fileSystem: globals.fs,
logger: globals.logger,
flutterUsage: globals.flutterUsage,
analytics: analytics,
appFilenamePattern: 'App'
);
// Only support 64bit iOS code size analysis.
......
......@@ -94,6 +94,7 @@ class BuildLinuxCommand extends BuildSubCommand {
fileSystem: globals.fs,
logger: logger,
flutterUsage: globals.flutterUsage,
analytics: analytics,
),
needCrossBuild: needCrossBuild,
targetPlatform: targetPlatform,
......
......@@ -70,6 +70,7 @@ class BuildMacosCommand extends BuildSubCommand {
logger: globals.logger,
appFilenamePattern: 'App',
flutterUsage: globals.flutterUsage,
analytics: analytics,
),
);
return FlutterCommandResult.success();
......
......@@ -63,6 +63,7 @@ class BuildWindowsCommand extends BuildSubCommand {
logger: globals.logger,
appFilenamePattern: 'app.so',
flutterUsage: globals.flutterUsage,
analytics: analytics,
),
);
return FlutterCommandResult.success();
......
......@@ -543,6 +543,9 @@ void main() {
expect(usage.events, contains(
const TestUsageEvent('code-size-analysis', 'ios'),
));
expect(fakeAnalytics.sentEvents, contains(
Event.codeSizeAnalysis(platform: 'ios')
));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
Logger: () => logger,
......@@ -550,6 +553,7 @@ void main() {
Platform: () => macosPlatform,
FileSystemUtils: () => FileSystemUtils(fileSystem: fileSystem, platform: macosPlatform),
Usage: () => usage,
Analytics: () => fakeAnalytics,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
......
......@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/base/analyze_size.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../../src/common.dart';
......@@ -66,6 +67,7 @@ void main() {
logger: logger,
appFilenamePattern: RegExp(r'lib.*app\.so'),
flutterUsage: TestUsage(),
analytics: NoOpAnalytics(),
);
final Archive archive = Archive()
......@@ -150,6 +152,7 @@ void main() {
logger: logger,
appFilenamePattern: RegExp(r'lib.*app\.so'),
flutterUsage: TestUsage(),
analytics: NoOpAnalytics(),
);
final Archive archive = Archive()
......@@ -192,6 +195,7 @@ void main() {
logger: logger,
appFilenamePattern: RegExp(r'lib.*app\.so'),
flutterUsage: TestUsage(),
analytics: NoOpAnalytics(),
);
final Directory outputDirectory = fileSystem.directory('example/out/foo.app')
......@@ -235,6 +239,7 @@ void main() {
logger: logger,
appFilenamePattern: RegExp(r'lib.*app\.so'),
flutterUsage: TestUsage(),
analytics: NoOpAnalytics(),
);
final Directory outputDirectory = fileSystem.directory('example/out/foo.app')..createSync(recursive: true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment