This commit is contained in:
Rares Sebastian Popa 2020-06-16 11:58:00 +02:00
Родитель 068d771b17
Коммит fdfcf976aa
3 изменённых файлов: 72 добавлений и 39 удалений

Просмотреть файл

@ -37,18 +37,22 @@ namespace UnityEditor.EditorIterationProfiler
internal enum ExportStatus internal enum ExportStatus
{ {
Started, Started,
Finished Finished,
Error
} }
internal enum ExportType internal enum ExportType
{ {
Selected, Selected,
MultiWindow,
Multi, Multi,
Captured Captured,
CapturedAll
} }
struct ExportEventData struct ExportEventData
{ {
public string guid;
public string format; public string format;
public string type; public string type;
public string status; public string status;
@ -58,9 +62,12 @@ namespace UnityEditor.EditorIterationProfiler
{ {
public bool eipState; public bool eipState;
public bool isPlaying; public bool isPlaying;
public bool deepProfile;
public bool flatten;
public bool userCode;
} }
public static void SendExportEvent(string format, string type, string status) public static void SendExportEvent(string format, string type, string status, string guid)
{ {
if (!UnityEngine.Analytics.Analytics.enabled || !EnableAnalytics()) if (!UnityEngine.Analytics.Analytics.enabled || !EnableAnalytics())
{ {
@ -71,13 +78,14 @@ namespace UnityEditor.EditorIterationProfiler
{ {
format = format, format = format,
type = type, type = type,
status = status status = status,
guid = guid
}; };
EditorAnalytics.SendEventWithLimit(k_ExportEventName, data); EditorAnalytics.SendEventWithLimit(k_ExportEventName, data);
} }
public static void SendInteractionEvent(bool state, bool isPlaying) public static void SendInteractionEvent(bool state, bool isPlaying, bool deepProfile, bool flatten, bool userCode)
{ {
if (!UnityEngine.Analytics.Analytics.enabled || !EnableAnalytics()) if (!UnityEngine.Analytics.Analytics.enabled || !EnableAnalytics())
{ {
@ -87,7 +95,10 @@ namespace UnityEditor.EditorIterationProfiler
var data = new InteractionEventData() var data = new InteractionEventData()
{ {
eipState = state, eipState = state,
isPlaying = isPlaying isPlaying = isPlaying,
deepProfile = deepProfile,
flatten = flatten,
userCode = userCode
}; };
EditorAnalytics.SendEventWithLimit(k_InteractionEventName, data); EditorAnalytics.SendEventWithLimit(k_InteractionEventName, data);

Просмотреть файл

@ -8,8 +8,13 @@ using UnityEditor.ShortcutManagement;
using UnityEditorInternal; using UnityEditorInternal;
using UnityEngine; using UnityEngine;
using ExportType = UnityEditor.EditorIterationProfiler.EditorIterationProfilerAnalytics.ExportType;
using ExportStatus = UnityEditor.EditorIterationProfiler.EditorIterationProfilerAnalytics.ExportStatus;
namespace UnityEditor.EditorIterationProfiler namespace UnityEditor.EditorIterationProfiler
{ {
public class EditorIterationProfilerWindow : EditorWindow public class EditorIterationProfilerWindow : EditorWindow
{ {
internal static class Styles internal static class Styles
@ -95,14 +100,6 @@ namespace UnityEditor.EditorIterationProfiler
} }
} }
void OnDisable()
{
}
void OnDestroy()
{
}
void DrawToolbar() void DrawToolbar()
{ {
GUILayout.BeginHorizontal(EditorStyles.toolbar); GUILayout.BeginHorizontal(EditorStyles.toolbar);
@ -141,8 +138,7 @@ namespace UnityEditor.EditorIterationProfiler
foreach (var exporter in exporters) foreach (var exporter in exporters)
{ {
EditorIterationProfilerAnalytics.SendExportEvent(exporter.Name, EditorIterationProfilerAnalytics.ExportType.Captured.ToString(), EditorIterationProfilerAnalytics.ExportStatus.Started.ToString()); menu.AddItem(new GUIContent(exporter.Name), false, () => ReportExtension(exporter, EditorIterationProfilerIntegration.Instance.IterationList, ExportType.Captured));
menu.AddItem(new GUIContent(exporter.Name), false, () => ReportExtension(exporter, EditorIterationProfilerIntegration.Instance.IterationList));
} }
menu.AddSeparator(""); menu.AddSeparator("");
@ -172,7 +168,6 @@ namespace UnityEditor.EditorIterationProfiler
foreach (var exporter in exporters) foreach (var exporter in exporters)
{ {
EditorIterationProfilerAnalytics.SendExportEvent(exporter.Name, EditorIterationProfilerAnalytics.ExportType.Selected.ToString(), EditorIterationProfilerAnalytics.ExportStatus.Started.ToString());
menu.AddItem(new GUIContent("Selected Frame/" + exporter.Name), false, () => ReportSelectedFrame(exporter, currentFrameIndex)); menu.AddItem(new GUIContent("Selected Frame/" + exporter.Name), false, () => ReportSelectedFrame(exporter, currentFrameIndex));
} }
@ -182,7 +177,6 @@ namespace UnityEditor.EditorIterationProfiler
{ {
menu.AddItem(new GUIContent("Multiple Frames/" + exporter.Name), false, () => menu.AddItem(new GUIContent("Multiple Frames/" + exporter.Name), false, () =>
{ {
EditorIterationProfilerAnalytics.SendExportEvent(exporter.Name, EditorIterationProfilerAnalytics.ExportType.Multi.ToString(), EditorIterationProfilerAnalytics.ExportStatus.Started.ToString());
var window = GetWindow<ProfilerMultiFrameSelector>(); var window = GetWindow<ProfilerMultiFrameSelector>();
window.Initialize(exporter); window.Initialize(exporter);
}); });
@ -201,6 +195,8 @@ namespace UnityEditor.EditorIterationProfiler
if (m_TreeView.UserCodeOnly != userCodeOnly) if (m_TreeView.UserCodeOnly != userCodeOnly)
{ {
EditorIterationProfilerAnalytics.SendInteractionEvent(UnityProfiling.EditorProfilingEnabled, EditorApplication.isPlaying, ProfilerDriver.deepProfiling, EditorIterationProfilerIntegration.Instance.Settings.Flatten, EditorIterationProfilerIntegration.Instance.Settings.UserCode);
m_TreeView.UserCodeOnly = userCodeOnly; m_TreeView.UserCodeOnly = userCodeOnly;
EditorPrefs.SetBool(Styles.k_UserCodePref, m_TreeView.UserCodeOnly); EditorPrefs.SetBool(Styles.k_UserCodePref, m_TreeView.UserCodeOnly);
m_TreeView.Reload(); m_TreeView.Reload();
@ -208,6 +204,8 @@ namespace UnityEditor.EditorIterationProfiler
if (m_TreeView.Flatten != flatten) if (m_TreeView.Flatten != flatten)
{ {
EditorIterationProfilerAnalytics.SendInteractionEvent(UnityProfiling.EditorProfilingEnabled, EditorApplication.isPlaying, ProfilerDriver.deepProfiling, EditorIterationProfilerIntegration.Instance.Settings.Flatten, EditorIterationProfilerIntegration.Instance.Settings.UserCode);
m_TreeView.Flatten = flatten; m_TreeView.Flatten = flatten;
EditorPrefs.SetBool(Styles.k_FlattenPref, m_TreeView.Flatten); EditorPrefs.SetBool(Styles.k_FlattenPref, m_TreeView.Flatten);
m_TreeView.Reload(); m_TreeView.Reload();
@ -217,14 +215,17 @@ namespace UnityEditor.EditorIterationProfiler
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
public static void ReportMultipleFrames(IFileDataReporter reporter, int beginRange, int endRange) public static void ReportMultipleFrames(IFileDataReporter reporter, int beginRange, int endRange, string guid)
{ {
var exportType = ExportType.Multi;
if (beginRange == -1) if (beginRange == -1)
{ {
ReportSelectedFrame(reporter, beginRange); ReportSelectedFrame(reporter, beginRange, exportType, guid);
return; return;
} }
EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, exportType.ToString(), ExportStatus.Started.ToString(), guid);
var path = EditorUtility.SaveFolderPanel($"Export frames to folder", "", reporter.Extension); var path = EditorUtility.SaveFolderPanel($"Export frames to folder", "", reporter.Extension);
for (int i = beginRange - 1; i < endRange; ++i) for (int i = beginRange - 1; i < endRange; ++i)
@ -238,6 +239,7 @@ namespace UnityEditor.EditorIterationProfiler
if (!hfdv.valid) if (!hfdv.valid)
{ {
EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, exportType.ToString(), ExportStatus.Error.ToString(), guid);
Debug.LogError($"There was an issue getting the frame {i}"); Debug.LogError($"There was an issue getting the frame {i}");
return; return;
} }
@ -262,18 +264,23 @@ namespace UnityEditor.EditorIterationProfiler
if (path.Length != 0) if (path.Length != 0)
{ {
reporter.Report(list, Path.Combine(path, filename)); reporter.Report(list, Path.Combine(path, filename));
EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, EditorIterationProfilerAnalytics.ExportType.Multi.ToString(), EditorIterationProfilerAnalytics.ExportStatus.Finished.ToString());
} }
} }
if (path.Length != 0) if (path.Length != 0)
{ {
EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, EditorIterationProfilerAnalytics.ExportType.Multi.ToString(), EditorIterationProfilerAnalytics.ExportStatus.Finished.ToString()); EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, exportType.ToString(), ExportStatus.Finished.ToString(), guid);
} }
} }
static void ReportSelectedFrame(IFileDataReporter exporter, int currentFrameIndex) static void ReportSelectedFrame(IFileDataReporter reporter, int currentFrameIndex, ExportType exportType = ExportType.Selected, string guid = "")
{ {
if (string.IsNullOrEmpty(guid))
{
guid = Guid.NewGuid().ToString();
EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, exportType.ToString(), ExportStatus.Started.ToString(), guid);
}
var list = new IterationList(); var list = new IterationList();
var hfdv = UnityProfiling.GetFrame(currentFrameIndex, 0); var hfdv = UnityProfiling.GetFrame(currentFrameIndex, 0);
@ -283,6 +290,7 @@ namespace UnityEditor.EditorIterationProfiler
if (!hfdv.valid) if (!hfdv.valid)
{ {
EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, exportType.ToString(), ExportStatus.Error.ToString(), guid);
Debug.LogError($"There was an issue getting the frame {currentFrameIndex}"); Debug.LogError($"There was an issue getting the frame {currentFrameIndex}");
return; return;
} }
@ -302,28 +310,37 @@ namespace UnityEditor.EditorIterationProfiler
lastEvent.SetStartFinishTimeFromChildren(); lastEvent.SetStartFinishTimeFromChildren();
lastEvent.Identifier = $"Data (Frame {currentFrameIndex + 1})"; lastEvent.Identifier = $"Data (Frame {currentFrameIndex + 1})";
ReportExtension(exporter, list, isExportingProfilerSelectedFrame: true); ReportExtension(reporter, list, exportType, guid);
} }
static void ReportAllExtensions(IIterationList iterationList) static void ReportAllExtensions(IIterationList iterationList)
{ {
var guid = Guid.NewGuid().ToString();
var path = EditorUtility.SaveFolderPanel($"Export frames to folder", "", ""); var path = EditorUtility.SaveFolderPanel($"Export frames to folder", "", "");
var extensions = EditorIterationProfilerIntegration.Instance.DataReporterProvider.GetAllReporters<IFileDataReporter>(); var extensions = EditorIterationProfilerIntegration.Instance.DataReporterProvider.GetAllReporters<IFileDataReporter>();
foreach (var extension in extensions) foreach (var extension in extensions)
{ {
ReportExtension(extension, iterationList, path); ReportExtension(extension, iterationList, ExportType.CapturedAll, guid, path);
} }
} }
static void ReportExtension(IFileDataReporter fileReporterType, IIterationList iterationList, string folderPath = "", bool isExportingProfilerSelectedFrame = false) static void ReportExtension(IFileDataReporter fileReporterType, IIterationList iterationList, ExportType exportType, string guid = "", string folderPath = "")
{ {
if (string.IsNullOrEmpty(guid))
{
guid = Guid.NewGuid().ToString();
}
if(ExportType.Selected != exportType)
{
EditorIterationProfilerAnalytics.SendExportEvent(fileReporterType.Name, exportType.ToString(), ExportStatus.Started.ToString(), guid);
}
var reporter = EditorIterationProfilerIntegration.Instance.DataReporterProvider.TryGetReporter<IFileDataReporter>(fileReporterType.GetType()); var reporter = EditorIterationProfilerIntegration.Instance.DataReporterProvider.TryGetReporter<IFileDataReporter>(fileReporterType.GetType());
if (reporter == null) if (reporter == null)
{ {
#if DEVELOPMENT_BUILD
Debug.LogError($"Reporter is null! Check if type name \"{typeName}\" exists");
#endif
return; return;
} }
@ -343,14 +360,7 @@ namespace UnityEditor.EditorIterationProfiler
{ {
reporter.Report(iterationList, path); reporter.Report(iterationList, path);
if (isExportingProfilerSelectedFrame) EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, exportType.ToString(), ExportStatus.Finished.ToString(), guid);
{
EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, EditorIterationProfilerAnalytics.ExportType.Selected.ToString(), EditorIterationProfilerAnalytics.ExportStatus.Finished.ToString());
}
else
{
EditorIterationProfilerAnalytics.SendExportEvent(reporter.Name, EditorIterationProfilerAnalytics.ExportType.Captured.ToString(), EditorIterationProfilerAnalytics.ExportStatus.Finished.ToString());
}
} }
} }
@ -382,7 +392,7 @@ namespace UnityEditor.EditorIterationProfiler
void OnLostFocus() void OnLostFocus()
{ {
EditorIterationProfilerAnalytics.SendInteractionEvent(UnityProfiling.EditorProfilingEnabled, EditorApplication.isPlaying); EditorIterationProfilerAnalytics.SendInteractionEvent(UnityProfiling.EditorProfilingEnabled, EditorApplication.isPlaying, ProfilerDriver.deepProfiling, EditorIterationProfilerIntegration.Instance.Settings.Flatten, EditorIterationProfilerIntegration.Instance.Settings.UserCode);
} }
void OnGUI() void OnGUI()
@ -480,6 +490,8 @@ namespace UnityEditor.EditorIterationProfiler
int m_FirstRange = -1; int m_FirstRange = -1;
int m_SecondRange = -1; int m_SecondRange = -1;
string m_EventGuid;
static void OpenWindow() static void OpenWindow()
{ {
GetWindow<ProfilerMultiFrameSelector>(); GetWindow<ProfilerMultiFrameSelector>();
@ -488,6 +500,14 @@ namespace UnityEditor.EditorIterationProfiler
public void Initialize(IFileDataReporter exporter) public void Initialize(IFileDataReporter exporter)
{ {
m_Exporter = exporter; m_Exporter = exporter;
m_EventGuid = Guid.NewGuid().ToString();
EditorIterationProfilerAnalytics.SendExportEvent(exporter.Name, ExportType.MultiWindow.ToString(), ExportStatus.Started.ToString(), m_EventGuid);
}
public void OnDestroy()
{
EditorIterationProfilerAnalytics.SendExportEvent(m_Exporter.Name, ExportType.MultiWindow.ToString(), ExportStatus.Finished.ToString(), m_EventGuid);
} }
void OnEnable() void OnEnable()
@ -517,7 +537,7 @@ namespace UnityEditor.EditorIterationProfiler
if (GUILayout.Button("Export")) if (GUILayout.Button("Export"))
{ {
Debug.Log($"Exporting Frames [{m_FirstRange},{m_SecondRange}] ({Mathf.Abs(m_SecondRange) - Mathf.Abs(m_FirstRange) + 1} frames)"); Debug.Log($"Exporting Frames [{m_FirstRange},{m_SecondRange}] ({Mathf.Abs(m_SecondRange) - Mathf.Abs(m_FirstRange) + 1} frames)");
EditorIterationProfilerWindow.ReportMultipleFrames(m_Exporter, m_FirstRange, m_SecondRange); EditorIterationProfilerWindow.ReportMultipleFrames(m_Exporter, m_FirstRange, m_SecondRange, m_EventGuid);
Close(); Close();
} }

Просмотреть файл

@ -39,6 +39,8 @@ namespace UnityEditor.EditorIterationProfiler
if (doApply) if (doApply)
{ {
EditorIterationProfilerAnalytics.SendInteractionEvent(EditorProfilingEnabled, EditorApplication.isPlaying, ProfilerDriver.deepProfiling, EditorIterationProfilerIntegration.Instance.Settings.Flatten, EditorIterationProfilerIntegration.Instance.Settings.UserCode);
ProfilerDriver.deepProfiling = deep; ProfilerDriver.deepProfiling = deep;
EditorPrefs.SetBool(EditorIterationProfilerWindow.Styles.k_EnableDeepProfile, deep); EditorPrefs.SetBool(EditorIterationProfilerWindow.Styles.k_EnableDeepProfile, deep);
EditorIterationProfilerIntegration.Instance.Settings.DeepProfile = deep; EditorIterationProfilerIntegration.Instance.Settings.DeepProfile = deep;