-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bf44e0
commit fbc2291
Showing
5 changed files
with
275 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
PerformanceTests/UnityPerformanceBenchmark/Assets/Tests/PlaymodeMetadataCollector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
#if UNITY_2018_1_OR_NEWER | ||
using System; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
using Unity.PerformanceTesting; | ||
using Unity.PerformanceTesting.Runtime; | ||
using UnityEngine; | ||
using UnityEngine.Networking; | ||
using UnityEngine.TestTools; | ||
#if ENABLE_VR | ||
using UnityEngine.XR; | ||
#endif | ||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
#endif | ||
|
||
[Category("Performance")] | ||
public class PlaymodeMetadataCollector : IPrebuildSetup | ||
{ | ||
private PerformanceTestRun m_TestRun; | ||
|
||
private string m_TestRunPath | ||
{ | ||
get { return Path.Combine(Application.streamingAssetsPath, "PerformanceTestRunInfo.json"); } | ||
} | ||
|
||
[UnityTest, Order(0), PrebuildSetup(typeof(RenderPerformancePrebuildStep))] | ||
public IEnumerator GetPlayerSettingsTest() | ||
{ | ||
yield return ReadPerformanceTestRunJsonAsync(); | ||
m_TestRun.PlayerSystemInfo = GetSystemInfo(); | ||
m_TestRun.QualitySettings = GetQualitySettings(); | ||
m_TestRun.ScreenSettings = GetScreenSettings(); | ||
m_TestRun.TestSuite = "Playmode"; | ||
m_TestRun.BuildSettings.Platform = Application.platform.ToString(); | ||
|
||
TestContext.Out.Write("##performancetestruninfo:" + JsonUtility.ToJson(m_TestRun)); | ||
} | ||
|
||
private PerformanceTestRun ReadPerformanceTestRunJson() | ||
{ | ||
try | ||
{ | ||
string json; | ||
if (Application.platform == RuntimePlatform.Android) | ||
{ | ||
UnityWebRequest reader = new UnityWebRequest("jar:file://" + m_TestRunPath); | ||
while (!reader.isDone) | ||
{ | ||
Thread.Sleep(1); | ||
} | ||
|
||
json = reader.downloadHandler.text; | ||
} | ||
else | ||
{ | ||
json = File.ReadAllText(m_TestRunPath); | ||
} | ||
|
||
return JsonUtility.FromJson<PerformanceTestRun>(json); | ||
} | ||
catch | ||
{ | ||
return new PerformanceTestRun { PlayerSettings = new Unity.PerformanceTesting.PlayerSettings() }; | ||
} | ||
} | ||
|
||
|
||
private IEnumerator ReadPerformanceTestRunJsonAsync() | ||
{ | ||
string json; | ||
if (Application.platform == RuntimePlatform.Android) | ||
{ | ||
var path = m_TestRunPath; | ||
UnityWebRequest reader = UnityWebRequest.Get(path); | ||
yield return reader.SendWebRequest(); | ||
|
||
while (!reader.isDone) | ||
{ | ||
yield return null; | ||
} | ||
|
||
json = reader.downloadHandler.text; | ||
} | ||
else | ||
{ | ||
if (!File.Exists(m_TestRunPath)) | ||
{ | ||
m_TestRun = new PerformanceTestRun { PlayerSettings = new Unity.PerformanceTesting.PlayerSettings() }; | ||
yield break; | ||
} | ||
json = File.ReadAllText(m_TestRunPath); | ||
} | ||
|
||
m_TestRun = JsonUtility.FromJson<PerformanceTestRun>(json); | ||
} | ||
|
||
private static PlayerSystemInfo GetSystemInfo() | ||
{ | ||
return new PlayerSystemInfo | ||
{ | ||
OperatingSystem = SystemInfo.operatingSystem, | ||
DeviceModel = SystemInfo.deviceModel, | ||
DeviceName = SystemInfo.deviceName, | ||
ProcessorType = SystemInfo.processorType, | ||
ProcessorCount = SystemInfo.processorCount, | ||
XrModel = XRDevice.model, | ||
GraphicsDeviceName = SystemInfo.graphicsDeviceName, | ||
SystemMemorySize = SystemInfo.systemMemorySize, | ||
#if ENABLE_VR | ||
XrDevice = XRSettings.loadedDeviceName | ||
#endif | ||
}; | ||
} | ||
|
||
private static Unity.PerformanceTesting.QualitySettings GetQualitySettings() | ||
{ | ||
return new Unity.PerformanceTesting.QualitySettings() | ||
{ | ||
Vsync = UnityEngine.QualitySettings.vSyncCount, | ||
AntiAliasing = UnityEngine.QualitySettings.antiAliasing, | ||
ColorSpace = UnityEngine.QualitySettings.activeColorSpace.ToString(), | ||
AnisotropicFiltering = UnityEngine.QualitySettings.anisotropicFiltering.ToString(), | ||
BlendWeights = UnityEngine.QualitySettings.blendWeights.ToString() | ||
}; | ||
} | ||
|
||
private static ScreenSettings GetScreenSettings() | ||
{ | ||
return new ScreenSettings | ||
{ | ||
ScreenRefreshRate = Screen.currentResolution.refreshRate, | ||
ScreenWidth = Screen.currentResolution.width, | ||
ScreenHeight = Screen.currentResolution.height, | ||
Fullscreen = Screen.fullScreen | ||
}; | ||
} | ||
|
||
public void Setup() | ||
{ | ||
#if UNITY_EDITOR | ||
m_TestRun = ReadPerformanceTestRunJson(); | ||
m_TestRun.EditorVersion = GetEditorInfo(); | ||
m_TestRun.PlayerSettings = GetPlayerSettings(m_TestRun.PlayerSettings); | ||
m_TestRun.BuildSettings = GetPlayerBuildInfo(); | ||
m_TestRun.StartTime = Utils.DateToInt(DateTime.Now); | ||
|
||
CreateStreamingAssetsFolder(); | ||
CreatePerformanceTestRunJson(); | ||
} | ||
|
||
private static EditorVersion GetEditorInfo() | ||
{ | ||
return new EditorVersion | ||
{ | ||
FullVersion = UnityEditorInternal.InternalEditorUtility.GetFullUnityVersion(), | ||
DateSeconds = int.Parse(UnityEditorInternal.InternalEditorUtility.GetUnityVersionDate().ToString()), | ||
Branch = GetEditorBranch(), | ||
RevisionValue = int.Parse(UnityEditorInternal.InternalEditorUtility.GetUnityRevision().ToString()) | ||
}; | ||
} | ||
|
||
private static string GetEditorBranch() | ||
{ | ||
foreach (var method in typeof(UnityEditorInternal.InternalEditorUtility).GetMethods()) | ||
{ | ||
if (method.Name.Contains("GetUnityBuildBranch")) | ||
{ | ||
return (string)method.Invoke(null, null); | ||
} | ||
} | ||
|
||
return "null"; | ||
} | ||
|
||
private static Unity.PerformanceTesting.PlayerSettings GetPlayerSettings( | ||
Unity.PerformanceTesting.PlayerSettings playerSettings) | ||
{ | ||
playerSettings.VrSupported = UnityEditor.PlayerSettings.virtualRealitySupported; | ||
playerSettings.MtRendering = UnityEditor.PlayerSettings.MTRendering; | ||
playerSettings.GpuSkinning = UnityEditor.PlayerSettings.gpuSkinning; | ||
playerSettings.GraphicsJobs = UnityEditor.PlayerSettings.graphicsJobs; | ||
playerSettings.GraphicsApi = | ||
UnityEditor.PlayerSettings.GetGraphicsAPIs(EditorUserBuildSettings.activeBuildTarget)[0] | ||
.ToString(); | ||
playerSettings.ScriptingBackend = UnityEditor.PlayerSettings | ||
.GetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup) | ||
.ToString(); | ||
playerSettings.ScriptingRuntimeVersion = UnityEditor.PlayerSettings.scriptingRuntimeVersion.ToString(); | ||
playerSettings.StereoRenderingPath = UnityEditor.PlayerSettings.stereoRenderingPath.ToString(); | ||
playerSettings.RenderThreadingMode = UnityEditor.PlayerSettings.graphicsJobs ? "GraphicsJobs" : | ||
UnityEditor.PlayerSettings.MTRendering ? "MultiThreaded" : "SingleThreaded"; | ||
playerSettings.AndroidMinimumSdkVersion = UnityEditor.PlayerSettings.Android.minSdkVersion.ToString(); | ||
playerSettings.AndroidTargetSdkVersion = UnityEditor.PlayerSettings.Android.targetSdkVersion.ToString(); | ||
playerSettings.Batchmode = UnityEditorInternal.InternalEditorUtility.inBatchMode.ToString(); | ||
return playerSettings; | ||
// Currently no API on 2018.1 | ||
//playerSettings.StaticBatching = TODO | ||
//playerSettings.DynamicBatching = TODO | ||
//PlayerSettings.GetBatchingForPlatform(EditorUserBuildSettings.activeBuildTarget, out pbi.staticBatching, out pbi.dynamicBatching); | ||
} | ||
|
||
private static BuildSettings GetPlayerBuildInfo() | ||
{ | ||
var buildSettings = new BuildSettings | ||
{ | ||
BuildTarget = EditorUserBuildSettings.activeBuildTarget.ToString(), | ||
DevelopmentPlayer = EditorUserBuildSettings.development, | ||
AndroidBuildSystem = EditorUserBuildSettings.androidBuildSystem.ToString() | ||
}; | ||
return buildSettings; | ||
} | ||
|
||
private void CreateStreamingAssetsFolder() | ||
{ | ||
if (!Directory.Exists(Application.streamingAssetsPath)) | ||
{ | ||
AssetDatabase.CreateFolder("Assets", "StreamingAssets"); | ||
} | ||
} | ||
|
||
private void CreatePerformanceTestRunJson() | ||
{ | ||
string json = JsonUtility.ToJson(m_TestRun, true); | ||
File.WriteAllText(m_TestRunPath, json); | ||
AssetDatabase.Refresh(); | ||
#endif | ||
} | ||
} | ||
#endif |
11 changes: 11 additions & 0 deletions
11
PerformanceTests/UnityPerformanceBenchmark/Assets/Tests/PlaymodeMetadataCollector.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.