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