Skip to content

Commit 7970d69

Browse files
author
Stewart Miles
committed
Added measurement of iOS resolver operations.
Instrumented the iOS Resolver with events to track operations performed by the module. This change logs: - Settings values and interaction with the settings dialog. - Documentation views. - iOS target SDK updates. - Cocoapods tool installation and error reporting. - Podfile generation and error reporting. - Cocoapods installation steps and error reporting. In addition, the settings window will now render analytics options if EditorAnalytics.GloballyEnabled is set to "true". Bug: 112723334 Change-Id: I98cef612732e31974996fa7648f3f3b3b15b77fb
1 parent d4933f5 commit 7970d69

File tree

2 files changed

+106
-4
lines changed

2 files changed

+106
-4
lines changed

source/IOSResolver/src/IOSResolver.cs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ exception is TypeInitializationException ||
723723
/// </summary>
724724
[MenuItem("Assets/Play Services Resolver/iOS Resolver/Documentation")]
725725
public static void OpenDocumentation() {
726-
Application.OpenURL(VersionHandlerImpl.DocumentationUrl("#ios-resolver-usage"));
726+
analytics.OpenUrl(VersionHandlerImpl.DocumentationUrl("#ios-resolver-usage"), "Usage");
727727
}
728728

729729
// Display the iOS resolver settings menu.
@@ -777,6 +777,7 @@ public static void RemapXcodeExtension() {
777777
/// </summary>
778778
internal static void RestoreDefaultSettings() {
779779
settings.DeleteKeys(PREFERENCE_KEYS);
780+
analytics.RestoreDefaultSettings();
780781
}
781782

782783
/// <summary>
@@ -984,6 +985,16 @@ private delegate void LogMessageDelegate(string message, bool verbose = false,
984985

985986
private static Google.Logger logger = new Google.Logger();
986987

988+
// Analytics reporter.
989+
internal static EditorMeasurement analytics = new EditorMeasurement(
990+
settings, logger, VersionHandlerImpl.GA_TRACKING_ID,
991+
"com.google.unity.oss.play_services_resolver", "iOS Resolver", "",
992+
VersionHandlerImpl.PRIVACY_POLICY) {
993+
BasePath = "/iosresolver/",
994+
BaseQuery = String.Format("version={0}", IOSResolverVersionNumber.Value.ToString()),
995+
BaseReportName = "iOS Resolver: "
996+
};
997+
987998
/// <summary>
988999
/// Log a message.
9891000
/// </summary>
@@ -1181,6 +1192,8 @@ public static bool UpdateTargetSdk(bool runningBuild) {
11811192
").\n" +
11821193
"Would you like to update the target SDK version?",
11831194
"Yes", cancel: "No");
1195+
analytics.Report("updatetargetsdk/" + (update ? "apply" : "cancel"),
1196+
"Update Target SDK");
11841197
if (update) {
11851198
TargetSdkVersion = minVersionAndPodNames.Key;
11861199
if (runningBuild) {
@@ -1467,7 +1480,9 @@ public static void InstallCocoapods(bool interactive, string workingDirectory,
14671480
"For more information see:\n" +
14681481
" https://guides.cocoapods.org/using/getting-started.html\n\n";
14691482

1470-
// Log the set of install pods.
1483+
analytics.Report("installpodtool/querygems", "Install Pod Tool Query Ruby Gems");
1484+
1485+
// Log the set of install gems.
14711486
RunCommand(GEM_EXECUTABLE, "list");
14721487

14731488
// Gem is being executed in an RVM directory it's already configured to perform a
@@ -1491,6 +1506,7 @@ public static void InstallCocoapods(bool interactive, string workingDirectory,
14911506
installArgs += " --verbose";
14921507
}
14931508

1509+
analytics.Report("installpodtool/installgems", "Install Pod Tool Ruby Gem");
14941510
var commandList = new List<CommandItem>();
14951511
if (!QueryGemInstalled("activesupport", logMessage: logMessage)) {
14961512
// Workaround activesupport (dependency of the CocoaPods gem) requiring
@@ -1515,6 +1531,9 @@ public static void InstallCocoapods(bool interactive, string workingDirectory,
15151531
var lastCommand = commands[commandIndex];
15161532
commandIndex += 1;
15171533
if (result.exitCode != 0) {
1534+
analytics.Report("installpodtool/failed",
1535+
String.Format("Install Pod Tool Ruby Gem Failed {0}",
1536+
result.exitCode));
15181537
logMessage(String.Format(
15191538
"Failed to install CocoaPods for the current user.\n\n" +
15201539
"{0}\n" +
@@ -1535,15 +1554,20 @@ public static void InstallCocoapods(bool interactive, string workingDirectory,
15351554
"'{0} {1}' succeeded but the {2} tool cannot be found.\n\n" +
15361555
"{3}\n", lastCommand.Command, lastCommand.Arguments,
15371556
POD_EXECUTABLE, commonInstallErrorMessage), level: LogLevel.Error);
1557+
analytics.Report("installpodtool/failedmissing",
1558+
"Install Pod Tool Ruby Gem Succeeded, Missing Tool");
15381559
complete.Set();
15391560
return -1;
15401561
}
15411562
if (dialog != null) {
1563+
analytics.Report("installpodtool/downloadrepo",
1564+
"Install Pod Tool Download Cocoapods Repo");
15421565
dialog.bodyText += ("\n\nDownloading CocoaPods Master Repository\n" +
15431566
"(this can take a while)\n");
15441567
}
15451568
commands[commandIndex].Command = podToolPath;
15461569
} else if (commandIndex == commands.Length) {
1570+
analytics.Report("installpodtool/success", "Install Pod Tool Succeeded");
15471571
complete.Set();
15481572
logMessage("CocoaPods tools successfully installed.");
15491573
cocoapodsToolsInstallPresent = true;
@@ -1839,6 +1863,7 @@ private static string GeneratePodfileSourcesSection() {
18391863
// processing step.
18401864
public static void GenPodfile(BuildTarget buildTarget,
18411865
string pathToBuiltProject) {
1866+
analytics.Report("generatepodfile", "Generate Podfile");
18421867
string podfilePath = GetPodfilePath(pathToBuiltProject);
18431868

18441869
string unityPodfile = FindExistingUnityPodfile(podfilePath);
@@ -1858,6 +1883,7 @@ public static void GenPodfile(BuildTarget buildTarget,
18581883
(CocoapodsWorkspaceIntegrationEnabled ? "Xcode workspace" :
18591884
(CocoapodsProjectIntegrationEnabled ? "Xcode project" : "no target"))),
18601885
verbose: true);
1886+
18611887
using (StreamWriter file = new StreamWriter(podfilePath)) {
18621888
file.WriteLine(GeneratePodfileSourcesSection() +
18631889
String.Format("platform :ios, '{0}'\n", TargetSdk));
@@ -1869,6 +1895,38 @@ public static void GenPodfile(BuildTarget buildTarget,
18691895
file.WriteLine("end");
18701896
}
18711897
}
1898+
1899+
int versionCount = 0;
1900+
int localPathCount = 0;
1901+
int targetSdkCount = 0;
1902+
int maxProperties = 0;
1903+
int maxSources = Pod.Sources.Count;
1904+
int fromXmlFileCount = 0;
1905+
foreach (var pod in pods.Values) {
1906+
maxProperties = Math.Max(maxProperties, pod.propertiesByName.Count);
1907+
maxSources = Math.Max(maxSources, pod.sources.Count);
1908+
if (!String.IsNullOrEmpty(pod.version)) versionCount++;
1909+
if (!String.IsNullOrEmpty(pod.minTargetSdk)) targetSdkCount++;
1910+
if (!String.IsNullOrEmpty(pod.LocalPath)) localPathCount++;
1911+
if (pod.fromXmlFile) fromXmlFileCount++;
1912+
}
1913+
analytics.Report("generatepodfile/podinfo",
1914+
new KeyValuePair<string, string>[] {
1915+
new KeyValuePair<string, string>("numPods", pods.Count.ToString()),
1916+
new KeyValuePair<string, string>("numPodsWithVersions",
1917+
versionCount.ToString()),
1918+
new KeyValuePair<string, string>("numLocalPods",
1919+
localPathCount.ToString()),
1920+
new KeyValuePair<string, string>("numMinTargetSdk",
1921+
targetSdkCount.ToString()),
1922+
new KeyValuePair<string, string>("maxNumProperties",
1923+
maxProperties.ToString()),
1924+
new KeyValuePair<string, string>("maxNumSources",
1925+
maxSources.ToString()),
1926+
new KeyValuePair<string, string>("numFromXmlFiles",
1927+
fromXmlFileCount.ToString())
1928+
},
1929+
"Generate Podfile Pods Section");
18721930
}
18731931

18741932
/// <summary>
@@ -2219,6 +2277,7 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
22192277
if (UnityCanLoadWorkspace &&
22202278
CocoapodsIntegrationMethodPref == CocoapodsIntegrationMethod.Workspace &&
22212279
SkipPodInstallWhenUsingWorkspaceIntegration) {
2280+
analytics.Report("installpods/disabled", "Pod Install Disabled");
22222281
Log("Skipping pod install.", level: LogLevel.Warning);
22232282
return;
22242283
}
@@ -2227,9 +2286,14 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
22272286
CommandLine.Result result;
22282287
result = RunPodCommand("--version", pathToBuiltProject);
22292288
if (result.exitCode == 0) podsVersion = result.stdout.Trim();
2289+
var cocoapodsVersionParameters = new KeyValuePair<string, string>[] {
2290+
new KeyValuePair<string, string>("cocoapodsVersion", podsVersion)
2291+
};
22302292

22312293
if (result.exitCode != 0 ||
22322294
(!String.IsNullOrEmpty(podsVersion) && podsVersion[0] == '0')) {
2295+
analytics.Report("installpods/outofdate", cocoapodsVersionParameters,
2296+
"Pod Install, Tool Out Of Date");
22332297
Log("Error running CocoaPods. Please ensure you have at least " +
22342298
"version 1.0.0. " + COCOAPOD_INSTALL_INSTRUCTIONS + "\n\n" +
22352299
"'" + POD_EXECUTABLE + " --version' returned status: " +
@@ -2239,16 +2303,21 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
22392303
return;
22402304
}
22412305

2306+
analytics.Report("installpods/install", cocoapodsVersionParameters, "Pod Install");
22422307
result = RunPodCommand("install", pathToBuiltProject);
22432308

22442309
// If pod installation failed it may be due to an out of date pod repo.
22452310
// We'll attempt to resolve the error by updating the pod repo -
22462311
// which is a slow operation - and retrying pod installation.
22472312
if (result.exitCode != 0) {
2313+
analytics.Report("installpods/repoupdate", cocoapodsVersionParameters,
2314+
"Pod Install Repo Update");
22482315
CommandLine.Result repoUpdateResult =
22492316
RunPodCommand("repo update", pathToBuiltProject);
22502317
bool repoUpdateSucceeded = repoUpdateResult.exitCode == 0;
22512318

2319+
analytics.Report("installpods/install2", cocoapodsVersionParameters,
2320+
"Pod Install Attempt 2");
22522321
// Second attempt result.
22532322
// This is isolated in case it fails, so we can just report the
22542323
// original failure.
@@ -2257,6 +2326,8 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
22572326

22582327
// If the repo update still didn't fix the problem...
22592328
if (result2.exitCode != 0) {
2329+
analytics.Report("installpods/failed", cocoapodsVersionParameters,
2330+
"Pod Install Failed");
22602331
Log("iOS framework addition failed due to a " +
22612332
"CocoaPods installation failure. This will will likely " +
22622333
"result in an non-functional Xcode project.\n\n" +
@@ -2305,6 +2376,7 @@ public static void UpdateProjectDeps(
23052376
// failed.
23062377
var podsDir = Path.Combine(pathToBuiltProject, PODS_DIR);
23072378
if (!Directory.Exists(podsDir)) return;
2379+
analytics.Report("injectpodsintoxcproj", "Inject Pods Into xcproj");
23082380

23092381
// If Unity can load workspaces, and one has been generated, yet we're still
23102382
// trying to patch the project file, then we have to actually get rid of the workspace

source/IOSResolver/src/IOSResolverSettingsDialog.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace Google {
1818

1919
using System;
20+
using System.Collections.Generic;
2021
using System.IO;
2122
using UnityEditor;
2223
using UnityEngine;
@@ -36,6 +37,7 @@ private class Settings {
3637
internal bool verboseLoggingEnabled;
3738
internal int cocoapodsIntegrationMenuIndex;
3839
internal bool useProjectSettings;
40+
internal EditorMeasurement.Settings analyticsSettings;
3941

4042
/// <summary>
4143
/// Load settings into the dialog.
@@ -48,6 +50,7 @@ internal Settings() {
4850
cocoapodsIntegrationMenuIndex = FindIndexFromCocoapodsIntegrationMethod(
4951
IOSResolver.CocoapodsIntegrationMethodPref);
5052
useProjectSettings = IOSResolver.UseProjectSettings;
53+
analyticsSettings = new EditorMeasurement.Settings(IOSResolver.analytics);
5154
}
5255

5356
/// <summary>
@@ -61,6 +64,7 @@ internal void Save() {
6164
IOSResolver.CocoapodsIntegrationMethodPref =
6265
integrationMapping[cocoapodsIntegrationMenuIndex];
6366
IOSResolver.UseProjectSettings = useProjectSettings;
67+
analyticsSettings.Save();
6468
}
6569
}
6670

@@ -91,7 +95,7 @@ private static int FindIndexFromCocoapodsIntegrationMethod(
9195
}
9296

9397
public void Initialize() {
94-
minSize = new Vector2(400, 360);
98+
minSize = new Vector2(400, 400);
9599
position = new Rect(UnityEngine.Screen.width / 3, UnityEngine.Screen.height / 3,
96100
minSize.x, minSize.y);
97101
}
@@ -170,6 +174,8 @@ public void OnGUI() {
170174
"Assets > Play Services Resolver > iOS Resolver > Install Cocoapods");
171175
}
172176

177+
settings.analyticsSettings.RenderGui();
178+
173179
GUILayout.BeginHorizontal();
174180
GUILayout.Label("Verbose Logging", EditorStyles.boldLabel);
175181
settings.verboseLoggingEnabled = EditorGUILayout.Toggle(settings.verboseLoggingEnabled);
@@ -187,15 +193,39 @@ public void OnGUI() {
187193
// saved preferences.
188194
var backupSettings = new Settings();
189195
IOSResolver.RestoreDefaultSettings();
196+
IOSResolver.analytics.Report("settings/reset", "Settings Reset");
190197
LoadSettings();
191198
backupSettings.Save();
192199
}
193200

194201
GUILayout.BeginHorizontal();
195202
bool closeWindow = GUILayout.Button("Cancel");
203+
if (closeWindow) IOSResolver.analytics.Report("settings/cancel", "Settings Cancel");
196204
bool ok = GUILayout.Button("OK");
197205
closeWindow |= ok;
198-
if (ok) settings.Save();
206+
if (ok) {
207+
IOSResolver.analytics.Report(
208+
"settings/save",
209+
new KeyValuePair<string, string>[] {
210+
new KeyValuePair<string, string>(
211+
"podfileGenerationEnabled",
212+
IOSResolver.PodfileGenerationEnabled.ToString()),
213+
new KeyValuePair<string, string>(
214+
"podToolExecutionViaShellEnabled",
215+
IOSResolver.PodToolExecutionViaShellEnabled.ToString()),
216+
new KeyValuePair<string, string>(
217+
"autoPodToolInstallInEditorEnabled",
218+
IOSResolver.AutoPodToolInstallInEditorEnabled.ToString()),
219+
new KeyValuePair<string, string>(
220+
"verboseLoggingEnabled",
221+
IOSResolver.VerboseLoggingEnabled.ToString()),
222+
new KeyValuePair<string, string>(
223+
"cocoapodsIntegrationMethod",
224+
IOSResolver.CocoapodsIntegrationMethodPref.ToString()),
225+
},
226+
"Settings Save");
227+
settings.Save();
228+
}
199229
if (closeWindow) Close();
200230
GUILayout.EndHorizontal();
201231
GUILayout.EndVertical();

0 commit comments

Comments
 (0)