add unit tests for Extension Methods, update .css, roll up metadata validation results to the Test Environment Config sections. Update screenshot of web page for wiki.

This commit is contained in:
Sean Stolberg 2018-08-17 13:24:28 -07:00
Родитель 060832ec9a
Коммит 3a36bf7621
8 изменённых файлов: 601 добавлений и 71 удалений

Двоичные данные
UnityPerformanceBenchmarkReport.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 64 KiB

После

Ширина:  |  Высота:  |  Размер: 163 KiB

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

@ -22,8 +22,9 @@ namespace UnityPerformanceBenchmarkReporter
}
else
{
var newSigDigits = parts[1].Substring(0, (int) (digits == 0 ? digits : parts[1].Length - digits));
truncated = Convert.ToUInt32(parts[0] + newSigDigits);
var newSigDigits = parts[1].Substring(0, (int) digits);
var truncString = string.Format("{0}.{1}", parts[0], newSigDigits);
truncated = Convert.ToDouble(truncString);
}
}

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

@ -1,48 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityPerformanceBenchmarkReporter.Entities;
namespace UnityPerformanceBenchmarkReporter
{
internal class MetadataValidator
public class MetadataValidator
{
public void ValidatePlayerSystemInfo(PerformanceTestRun testRun1, PerformanceTestRun testRun2)
public string[] PlayerSystemInfoResultFiles = Array.Empty<string>();
public readonly Dictionary<string, Dictionary<string, string>> MismatchedPlayerSystemInfoValues = new Dictionary<string, Dictionary<string, string>>();
public string[] PlayerSettingsResultFiles = Array.Empty<string>();
public readonly Dictionary<string, Dictionary<string, string>> MismatchedPlayerSettingsValues = new Dictionary<string, Dictionary<string, string>>();
public string[] QualitySettingsResultFiles = Array.Empty<string>();
public readonly Dictionary<string, Dictionary<string, string>> MismatchedQualitySettingsValues = new Dictionary<string, Dictionary<string, string>>();
public string[] ScreenSettingsResultFiles = Array.Empty<string>();
public readonly Dictionary<string, Dictionary<string, string>> MismatchedScreenSettingsValues = new Dictionary<string, Dictionary<string, string>>();
public string[] BuildSettingsResultFiles = Array.Empty<string>();
public readonly Dictionary<string, Dictionary<string, string>> MismatchedBuildSettingsValues = new Dictionary<string, Dictionary<string, string>>();
public string[] EditorVersionResultFiles = Array.Empty<string>();
public readonly Dictionary<string, Dictionary<string, string>> MismatchedEditorVersionValues = new Dictionary<string, Dictionary<string, string>>();
public void ValidatePlayerSystemInfo(PerformanceTestRun testRun1, PerformanceTestRun testRun2, string firstTestRunResultPath, string xmlFileNamePath)
{
if (testRun1.PlayerSystemInfo.DeviceModel != testRun2.PlayerSystemInfo.DeviceModel)
{
WriteWarningMessage("Test results with mismatching PlayerSystemInfo.DeviceModeltestRun");
AddMismatchPlayerMetadata(
ref PlayerSystemInfoResultFiles,
MismatchedPlayerSystemInfoValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSystemInfo.DeviceModel),
testRun1.PlayerSystemInfo.DeviceModel,
testRun2.PlayerSystemInfo.DeviceModel);
}
if (testRun1.PlayerSystemInfo.GraphicsDeviceName != testRun2.PlayerSystemInfo.GraphicsDeviceName)
{
WriteWarningMessage("Test results with mismatching PlayerSystemInfo.GraphicsDeviceName");
AddMismatchPlayerMetadata(
ref PlayerSystemInfoResultFiles,
MismatchedPlayerSystemInfoValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSystemInfo.GraphicsDeviceName),
testRun1.PlayerSystemInfo.GraphicsDeviceName,
testRun2.PlayerSystemInfo.GraphicsDeviceName);
}
if (testRun1.PlayerSystemInfo.ProcessorCount != testRun2.PlayerSystemInfo.ProcessorCount)
{
WriteWarningMessage("Test results with mismatching PlayerSystemInfo.ProcessorCount");
AddMismatchPlayerMetadata(
ref PlayerSystemInfoResultFiles,
MismatchedPlayerSystemInfoValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSystemInfo.ProcessorCount),
testRun1.PlayerSystemInfo.ProcessorCount.ToString(),
testRun2.PlayerSystemInfo.ProcessorCount.ToString());
}
if (testRun1.PlayerSystemInfo.ProcessorType != testRun2.PlayerSystemInfo.ProcessorType)
{
WriteWarningMessage("Test results with mismatching PlayerSystemInfo.ProcessorType");
AddMismatchPlayerMetadata(
ref PlayerSystemInfoResultFiles,
MismatchedPlayerSystemInfoValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSystemInfo.ProcessorType),
testRun1.PlayerSystemInfo.ProcessorType,
testRun2.PlayerSystemInfo.ProcessorType);
}
if (testRun1.PlayerSystemInfo.XrDevice != testRun2.PlayerSystemInfo.XrDevice)
{
WriteWarningMessage("Test results with mismatching PlayerSystemInfo.XrDevice");
AddMismatchPlayerMetadata(
ref PlayerSystemInfoResultFiles,
MismatchedPlayerSystemInfoValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSystemInfo.XrDevice),
testRun1.PlayerSystemInfo.XrDevice,
testRun2.PlayerSystemInfo.XrDevice);
}
if (testRun1.PlayerSystemInfo.XrModel != testRun2.PlayerSystemInfo.XrModel)
{
WriteWarningMessage("Test results with mismatching PlayerSystemInfo.XrModel");
AddMismatchPlayerMetadata(
ref PlayerSystemInfoResultFiles,
MismatchedPlayerSystemInfoValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSystemInfo.XrModel),
testRun1.PlayerSystemInfo.XrModel,
testRun2.PlayerSystemInfo.XrModel);
}
}
public void ValidatePlayerSettings(PerformanceTestRun testRun1, PerformanceTestRun testRun2)
public void ValidatePlayerSettings(PerformanceTestRun testRun1, PerformanceTestRun testRun2, string firstTestRunResultPath, string xmlFileNamePath)
{
if (testRun1.PlayerSettings.AndroidMinimumSdkVersion != testRun2.PlayerSettings.AndroidMinimumSdkVersion)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.AndroidMinimumSdkVersion");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.AndroidMinimumSdkVersion),
testRun1.PlayerSettings.AndroidMinimumSdkVersion,
testRun2.PlayerSettings.AndroidMinimumSdkVersion);
}
if (testRun1.PlayerSettings.AndroidTargetSdkVersion != testRun2.PlayerSettings.AndroidTargetSdkVersion)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.GraphicsDeviceName");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.AndroidTargetSdkVersion),
testRun1.PlayerSettings.AndroidTargetSdkVersion,
testRun2.PlayerSettings.AndroidTargetSdkVersion);
}
// TODO Refactor this to match all strings, not one by one
foreach (var enabledXrTarget in testRun1.PlayerSettings.EnabledXrTargets)
{
if (!testRun2.PlayerSettings.EnabledXrTargets.Contains(enabledXrTarget))
@ -52,79 +125,310 @@ namespace UnityPerformanceBenchmarkReporter
}
if (testRun1.PlayerSettings.GpuSkinning != testRun2.PlayerSettings.GpuSkinning)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.GpuSkinning");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.GpuSkinning),
testRun1.PlayerSettings.GpuSkinning.ToString(),
testRun2.PlayerSettings.GpuSkinning.ToString());
}
if (testRun1.PlayerSettings.GraphicsApi != testRun2.PlayerSettings.GraphicsApi)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.GraphicsApi");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.GraphicsApi),
testRun1.PlayerSettings.GraphicsApi,
testRun2.PlayerSettings.GraphicsApi);
}
if (testRun1.PlayerSettings.GraphicsJobs != testRun2.PlayerSettings.GraphicsJobs)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.GraphicsJobs");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.GraphicsJobs),
testRun1.PlayerSettings.GraphicsJobs.ToString(),
testRun2.PlayerSettings.GraphicsJobs.ToString());
}
if (testRun1.PlayerSettings.MtRendering != testRun2.PlayerSettings.MtRendering)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.MtRendering");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.MtRendering),
testRun1.PlayerSettings.MtRendering.ToString(),
testRun2.PlayerSettings.MtRendering.ToString());
}
if (testRun1.PlayerSettings.RenderThreadingMode != testRun2.PlayerSettings.RenderThreadingMode)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.RenderThreadingMode");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.RenderThreadingMode),
testRun1.PlayerSettings.RenderThreadingMode,
testRun2.PlayerSettings.RenderThreadingMode);
}
if (testRun1.PlayerSettings.ScriptingBackend != testRun2.PlayerSettings.ScriptingBackend)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.ScriptingBackend");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.ScriptingBackend),
testRun1.PlayerSettings.ScriptingBackend,
testRun2.PlayerSettings.ScriptingBackend);
}
if (testRun1.PlayerSettings.StereoRenderingPath != testRun2.PlayerSettings.StereoRenderingPath)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.StereoRenderingPath");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.StereoRenderingPath),
testRun1.PlayerSettings.StereoRenderingPath,
testRun2.PlayerSettings.StereoRenderingPath);
}
if (testRun1.PlayerSettings.VrSupported != testRun2.PlayerSettings.VrSupported)
{
WriteWarningMessage("Test results with mismatching PlayerSettings.VrSupported");
AddMismatchPlayerMetadata(
ref PlayerSettingsResultFiles,
MismatchedPlayerSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.PlayerSettings.VrSupported),
testRun1.PlayerSettings.VrSupported.ToString(),
testRun2.PlayerSettings.VrSupported.ToString());
}
}
public void ValidateQualitySettings(PerformanceTestRun testRun1, PerformanceTestRun testRun2)
public void ValidateQualitySettings(PerformanceTestRun testRun1, PerformanceTestRun testRun2, string firstTestRunResultPath, string xmlFileNamePath)
{
if (testRun1.QualitySettings.AnisotropicFiltering != testRun2.QualitySettings.AnisotropicFiltering)
{
WriteWarningMessage("Test results with mismatching QualitySettings.AnisotropicFiltering");
AddMismatchPlayerMetadata(
ref QualitySettingsResultFiles,
MismatchedQualitySettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.QualitySettings.AnisotropicFiltering),
testRun1.QualitySettings.AnisotropicFiltering,
testRun2.QualitySettings.AnisotropicFiltering);
}
if (testRun1.QualitySettings.AntiAliasing != testRun2.QualitySettings.AntiAliasing)
{
WriteWarningMessage("Test results with mismatching QualitySettings.AntiAliasing");
AddMismatchPlayerMetadata(
ref QualitySettingsResultFiles,
MismatchedQualitySettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.QualitySettings.AntiAliasing),
testRun1.QualitySettings.AntiAliasing.ToString(),
testRun2.QualitySettings.AntiAliasing.ToString());
}
if (testRun1.QualitySettings.BlendWeights != testRun2.QualitySettings.BlendWeights)
{
WriteWarningMessage("Test results with mismatching QualitySettings.BlendWeights");
AddMismatchPlayerMetadata(
ref QualitySettingsResultFiles,
MismatchedQualitySettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.QualitySettings.BlendWeights),
testRun1.QualitySettings.BlendWeights,
testRun2.QualitySettings.BlendWeights);
}
if (testRun1.QualitySettings.ColorSpace != testRun2.QualitySettings.ColorSpace)
{
WriteWarningMessage("Test results with mismatching QualitySettings.ColorSpace");
AddMismatchPlayerMetadata(
ref QualitySettingsResultFiles,
MismatchedQualitySettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.QualitySettings.ColorSpace),
testRun1.QualitySettings.ColorSpace,
testRun2.QualitySettings.ColorSpace);
}
if (testRun1.QualitySettings.Vsync != testRun2.QualitySettings.Vsync)
{
WriteWarningMessage("Test results with mismatching QualitySettings.Vsync");
AddMismatchPlayerMetadata(
ref QualitySettingsResultFiles,
MismatchedQualitySettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.QualitySettings.Vsync),
testRun1.QualitySettings.Vsync.ToString(),
testRun2.QualitySettings.Vsync.ToString());
}
}
public void ValidateScreenSettings(PerformanceTestRun testRun1, PerformanceTestRun testRun2)
public void ValidateScreenSettings(PerformanceTestRun testRun1, PerformanceTestRun testRun2, string firstTestRunResultPath, string xmlFileNamePath)
{
if (testRun1.ScreenSettings.Fullscreen != testRun2.ScreenSettings.Fullscreen)
{
WriteWarningMessage("Test results with mismatching ScreenSettings.Fullscreen");
AddMismatchPlayerMetadata(
ref ScreenSettingsResultFiles,
MismatchedScreenSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.ScreenSettings.Fullscreen),
testRun1.ScreenSettings.Fullscreen.ToString(),
testRun2.ScreenSettings.Fullscreen.ToString());
}
if (testRun1.ScreenSettings.ScreenHeight != testRun2.ScreenSettings.ScreenHeight)
{
WriteWarningMessage("Test results with mismatching ScreenSettings.ScreenHeight");
AddMismatchPlayerMetadata(
ref ScreenSettingsResultFiles,
MismatchedScreenSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.ScreenSettings.ScreenHeight),
testRun1.ScreenSettings.ScreenHeight.ToString(),
testRun2.ScreenSettings.ScreenHeight.ToString());
}
if (testRun1.ScreenSettings.ScreenRefreshRate != testRun2.ScreenSettings.ScreenRefreshRate)
{
WriteWarningMessage("Test results with mismatching ScreenSettings.ScreenRefreshRate");
AddMismatchPlayerMetadata(
ref ScreenSettingsResultFiles,
MismatchedScreenSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.ScreenSettings.ScreenRefreshRate),
testRun1.ScreenSettings.ScreenRefreshRate.ToString(),
testRun2.ScreenSettings.ScreenRefreshRate.ToString());
}
if (testRun1.ScreenSettings.ScreenWidth != testRun2.ScreenSettings.ScreenWidth)
{
WriteWarningMessage("Test results with mismatching ScreenSettings.ScreenWidth");
AddMismatchPlayerMetadata(
ref ScreenSettingsResultFiles,
MismatchedScreenSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.ScreenSettings.ScreenWidth),
testRun1.ScreenSettings.ScreenWidth.ToString(),
testRun2.ScreenSettings.ScreenWidth.ToString());
}
}
public void ValidateBuildSettings(PerformanceTestRun testRun1, PerformanceTestRun testRun2, string firstTestRunResultPath, string xmlFileNamePath)
{
if (testRun1.BuildSettings.Platform != testRun2.BuildSettings.Platform)
{
AddMismatchPlayerMetadata(
ref BuildSettingsResultFiles,
MismatchedBuildSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.BuildSettings.Platform),
testRun1.BuildSettings.Platform,
testRun2.BuildSettings.Platform);
}
if (testRun1.BuildSettings.BuildTarget != testRun2.BuildSettings.BuildTarget)
{
AddMismatchPlayerMetadata(
ref BuildSettingsResultFiles,
MismatchedBuildSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.BuildSettings.BuildTarget),
testRun1.BuildSettings.BuildTarget,
testRun2.BuildSettings.BuildTarget);
}
if (testRun1.BuildSettings.DevelopmentPlayer != testRun2.BuildSettings.DevelopmentPlayer)
{
AddMismatchPlayerMetadata(
ref BuildSettingsResultFiles,
MismatchedBuildSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.BuildSettings.DevelopmentPlayer),
testRun1.BuildSettings.DevelopmentPlayer.ToString(),
testRun2.BuildSettings.DevelopmentPlayer.ToString());
}
if (testRun1.BuildSettings.AndroidBuildSystem != testRun2.BuildSettings.AndroidBuildSystem)
{
AddMismatchPlayerMetadata(
ref BuildSettingsResultFiles,
MismatchedBuildSettingsValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.BuildSettings.AndroidBuildSystem),
testRun1.BuildSettings.AndroidBuildSystem,
testRun2.BuildSettings.AndroidBuildSystem);
}
}
public void ValidateEditorVersion(PerformanceTestRun testRun1, PerformanceTestRun testRun2, string firstTestRunResultPath, string xmlFileNamePath)
{
if (testRun1.EditorVersion.FullVersion != testRun2.EditorVersion.FullVersion)
{
AddMismatchPlayerMetadata(
ref EditorVersionResultFiles,
MismatchedEditorVersionValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.EditorVersion.FullVersion),
testRun1.EditorVersion.FullVersion,
testRun2.EditorVersion.FullVersion);
}
if (testRun1.EditorVersion.Branch != testRun2.EditorVersion.Branch)
{
AddMismatchPlayerMetadata(
ref EditorVersionResultFiles,
MismatchedEditorVersionValues,
firstTestRunResultPath,
xmlFileNamePath,
nameof(testRun1.EditorVersion.Branch),
testRun1.EditorVersion.Branch,
testRun2.EditorVersion.Branch);
}
}
private void AddMismatchPlayerMetadata(
ref string[] infoResultFiles,
Dictionary<string, Dictionary<string, string>> mismatchedPlayerValues,
string firstTestRunResultPath,
string xmlFileNamePath,
string playerInfoName,
string refPlayerInfoValue,
string mismatchedPlayerInfoValue)
{
EnsureResultFileTracked(ref infoResultFiles, firstTestRunResultPath);
EnsureResultFileTracked(ref infoResultFiles, xmlFileNamePath);
if (!mismatchedPlayerValues.ContainsKey(playerInfoName))
{
mismatchedPlayerValues.Add(
playerInfoName,
new Dictionary<string, string>
{
{firstTestRunResultPath, refPlayerInfoValue}
});
}
mismatchedPlayerValues[playerInfoName].Add(xmlFileNamePath, mismatchedPlayerInfoValue ?? string.Empty);
}
private void EnsureResultFileTracked(ref string[] infoResultFiles, string resultPath)
{
if (!infoResultFiles.Contains(resultPath))
{
Array.Resize(ref infoResultFiles, infoResultFiles.Length + 1);
infoResultFiles[infoResultFiles.Length - 1] = resultPath;
}
}
@ -134,5 +438,96 @@ namespace UnityPerformanceBenchmarkReporter
Console.WriteLine(msg);
Console.ResetColor();
}
private void WriteWarningMessage(string msg, string[] playerResultFiles, Dictionary<string, Dictionary<string, string>> mismatchedPlayerValues)
{
var sb = new StringBuilder();
sb.Append(msg + "\r\n");
sb.Append(GetLine());
var tableHeader = new string[playerResultFiles.Length + 1];
tableHeader[0] = "Name";
playerResultFiles.CopyTo(tableHeader, 1);
sb.Append(GetRow(tableHeader));
sb.Append(GetLine());
foreach (var mismatchPlayerValue in mismatchedPlayerValues)
{
string [] rowData = new string[tableHeader.Length];
rowData[0] = mismatchPlayerValue.Key;
for (int i = 0; i < playerResultFiles.Length; i++)
{
if (mismatchPlayerValue.Value.Any(v => v.Key.Equals(playerResultFiles[i])))
{
rowData[i + 1] = mismatchPlayerValue.Value.First(v => v.Key.Equals(playerResultFiles[i])).Value;
}
else
{
rowData[i + 1] = string.Empty;
}
}
sb.Append(GetRow(rowData));
}
sb.Append(GetLine());
WriteWarningMessage(sb.ToString());
}
static int _tableWidth = 100;
private string GetLine()
{
return string.Format("{0}\r\n", new string('-', _tableWidth));
}
private string GetRow(params string[] columns)
{
int width = (_tableWidth - columns.Length) / columns.Length;
string row = "|";
foreach (string column in columns)
{
row += AlignCentre(column, width) + "|";
}
return string.Format("{0}\r\n", row);
}
private string AlignCentre(string alignText, int width)
{
var text = alignText;
if (text.Length > width)
{
var startIndex = text.Length - width + 3;
var length = width - 3;
var substring = text.Substring(startIndex, length);
text = "..." + substring;
}
if (string.IsNullOrEmpty(text))
{
return new string(' ', width);
}
else
{
return text.PadRight(width - (width - text.Length) / 2).PadLeft(width);
}
}
public string ResizeString(string resizeText, int width)
{
var text = resizeText;
if (text.Length > width)
{
var startIndex = text.Length - width + 3;
var length = width - 3;
var substring = text.Substring(startIndex, length);
text = "..." + substring;
}
return text;
}
}
}

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

@ -16,11 +16,14 @@ namespace UnityPerformanceBenchmarkReporter
public uint SigFig { get; private set; }
public string ReportDirPath { get; set; }
public MetadataValidator MetadataValidator = new MetadataValidator();
private bool firstResult = true;
private string firstTestRunResultPath;
private PerformanceTestRun firstTestRun = new PerformanceTestRun();
private readonly PerformanceTestRunProcessor performanceTestRunProcessor = new PerformanceTestRunProcessor();
private readonly string xmlFileExtension = ".xml";
public bool BaselineResultFilesExist => BaselineXmlFilePaths.Any() || BaselineXmlDirectoryPaths.Any();
@ -31,7 +34,7 @@ namespace UnityPerformanceBenchmarkReporter
// Default significant figures to use for non-integer metrics if user doesn't specify another value.
// Most values are in milliseconds or a count of something, so using more often creates an artificial baseline
// failure based on insignificant digits
SigFig = 0;
SigFig = 2;
}
public void AddPerformanceTestRunResults(
@ -92,11 +95,11 @@ namespace UnityPerformanceBenchmarkReporter
performanceTestRunProcessor.UpdateTestResultsBasedOnBaselineResults(baselineTestResults, testResults, SigFig);
ValidateMetadata(performanceTestRun);
ValidateMetadata(performanceTestRun, xmlFileNamePath);
runResults.Add(performanceTestRunProcessor.CreateTestRunResult
(
firstTestRun,
testResults,
performanceTestRun,
results,
Path.GetFileNameWithoutExtension(xmlFileNamePath),
isBaseline)
);
@ -112,20 +115,22 @@ namespace UnityPerformanceBenchmarkReporter
return xmlFileNames;
}
private void ValidateMetadata(PerformanceTestRun performanceTestRun)
private void ValidateMetadata(PerformanceTestRun performanceTestRun, string xmlFileNamePath)
{
if (firstResult)
{
firstTestRunResultPath = xmlFileNamePath;
firstTestRun = performanceTestRun;
firstResult = false;
}
else
{
var metadataValidator = new MetadataValidator();
metadataValidator.ValidatePlayerSystemInfo(firstTestRun, performanceTestRun);
metadataValidator.ValidatePlayerSettings(firstTestRun, performanceTestRun);
metadataValidator.ValidateQualitySettings(firstTestRun, performanceTestRun);
metadataValidator.ValidateScreenSettings(firstTestRun, performanceTestRun);
MetadataValidator.ValidatePlayerSystemInfo(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath);
MetadataValidator.ValidatePlayerSettings(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath);
MetadataValidator.ValidateQualitySettings(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath);
MetadataValidator.ValidateScreenSettings(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath);
MetadataValidator.ValidateBuildSettings(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath);
MetadataValidator.ValidateEditorVersion(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath);
}
}

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

@ -50,7 +50,7 @@ namespace UnityPerformanceBenchmarkReporter
}
var reportWriter = new ReportWriter();
reportWriter.WriteReport(aggregateTestRunResults, performanceBenchmark.SigFig, performanceBenchmark.ReportDirPath, performanceBenchmark.BaselineResultFilesExist);
reportWriter.WriteReport(aggregateTestRunResults, performanceBenchmark.MetadataValidator, performanceBenchmark.SigFig, performanceBenchmark.ReportDirPath, performanceBenchmark.BaselineResultFilesExist);
}
}
}

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

@ -27,12 +27,14 @@ namespace UnityPerformanceBenchmarkReporter.Report
private readonly Regex illegalCharacterScrubberRegex = new Regex("[^0-9a-zA-Z]", RegexOptions.Compiled);
private uint thisSigFig;
private bool thisHasBenchmarkResults;
private MetadataValidator metadataValidator;
public void WriteReport(List<PerformanceTestRunResult> results, uint sigFig = 2,
public void WriteReport(List<PerformanceTestRunResult> results, MetadataValidator mdValidator, uint sigFig = 2,
string reportDirectoryPath = null, bool hasBenchmarkResults = false)
{
if (results != null && results.Count > 0)
{
metadataValidator = mdValidator;
thisSigFig = sigFig;
thisHasBenchmarkResults = hasBenchmarkResults;
EnsureOrderedResults(results);
@ -644,43 +646,45 @@ rw.WriteLine(" document.getElementById(\"toggleconfig\").innerHTML=\"Show Test C
if (firstResult.PlayerSystemInfo != null)
{
WriteClassNameWithFields<PlayerSystemInfo>(rw, firstResult.PlayerSystemInfo);
WriteClassNameWithFields<PlayerSystemInfo>(rw, firstResult.PlayerSystemInfo, metadataValidator.PlayerSystemInfoResultFiles, metadataValidator.MismatchedPlayerSystemInfoValues);
}
if (firstResult.PlayerSettings != null)
{
WriteClassNameWithFields<PlayerSettings>(rw, firstResult.PlayerSettings);
WriteClassNameWithFields<PlayerSettings>(rw, firstResult.PlayerSettings, metadataValidator.PlayerSettingsResultFiles, metadataValidator.MismatchedPlayerSettingsValues);
}
if (firstResult.QualitySettings != null)
{
WriteClassNameWithFields<QualitySettings>(rw, firstResult.QualitySettings);
WriteClassNameWithFields<QualitySettings>(rw, firstResult.QualitySettings, metadataValidator.QualitySettingsResultFiles, metadataValidator.MismatchedQualitySettingsValues);
}
if (firstResult.ScreenSettings != null)
{
WriteClassNameWithFields<ScreenSettings>(rw, firstResult.ScreenSettings);
WriteClassNameWithFields<ScreenSettings>(rw, firstResult.ScreenSettings, metadataValidator.ScreenSettingsResultFiles, metadataValidator.MismatchedScreenSettingsValues);
}
if (firstResult.BuildSettings != null)
{
WriteClassNameWithFields<BuildSettings>(rw, firstResult.BuildSettings);
WriteClassNameWithFields<BuildSettings>(rw, firstResult.BuildSettings, metadataValidator.BuildSettingsResultFiles, metadataValidator.MismatchedBuildSettingsValues);
}
if (firstResult.EditorVersion != null)
{
WriteClassNameWithFields<EditorVersion>(rw, firstResult.EditorVersion, new[] { "DateSeconds", "RevisionValue" });
WriteClassNameWithFields<EditorVersion>(rw, firstResult.EditorVersion, metadataValidator.EditorVersionResultFiles, metadataValidator.MismatchedEditorVersionValues, new[] { "DateSeconds", "RevisionValue" }, true);
}
rw.WriteLine("</div>");
rw.WriteLine("</div>");
}
private void WriteClassNameWithFields<T>(StreamWriter rw, object instance, string[] excludedFields = null)
private void WriteClassNameWithFields<T>(StreamWriter rw, object instance, string[] resultFiles,
Dictionary<string, Dictionary<string, string>> mismatchedValues, string[] excludedFields = null, bool wideLayout = false)
{
var thisObject = (T)instance;
rw.WriteLine("<div><hr></div><div class=\"typename\">{0}</div><div><hr></div>", thisObject.GetType().Name);
rw.WriteLine("<div class=\"systeminfo\">");
rw.WriteLine(wideLayout ? "<div class=\"systeminfowide\">" : "<div class=\"systeminfo\">");
var sb = new StringBuilder();
foreach (var field in thisObject.GetType().GetFields())
{
@ -692,24 +696,50 @@ rw.WriteLine(" document.getElementById(\"toggleconfig\").innerHTML=\"Show Test C
// if field is an IEnumberable, enumerate and append each value to the sb
if (typeof(IEnumerable).IsAssignableFrom(field.FieldType) && field.FieldType != typeof(string))
{
sb.Append(string.Format("<div><div class=\"fieldname\">{0}:</div><div class=\"fieldvalue\">", field.Name));
foreach (var enumerable in (IEnumerable) field.GetValue(thisObject))
{
sb.Append(enumerable + ",");
}
sb.Append(string.Format("<div><div class=\"fieldname\"><pre>{0}</pre></div><div class=\"fieldvalue\"><pre>", field.Name));
if (sb.ToString().EndsWith(','))
{
// trim trailing comma
sb.Length--;
}
//if (mismatchedValues.Count > 0 && mismatchedValues.ContainsKey(field.Name))
//{
foreach (var enumerable in (IEnumerable)field.GetValue(thisObject))
{
sb.Append(enumerable + ",");
}
if (sb.ToString().EndsWith(','))
{
// trim trailing comma
sb.Length--;
}
//}
sb.Append("</div></div>");
sb.Append("</pre></div></div>");
}
else
{
sb.Append(string.Format("<div><div class=\"fieldname\">{0}:</div><div class=\"fieldvalue\">{1}</div></div>", field.Name, field.GetValue(thisObject)));
sb.Append(string.Format("<div class=\"fieldgroup\"><div class=\"fieldname\"><pre>{0}</pre></div>", field.Name));
if (mismatchedValues.Count > 0 && mismatchedValues.ContainsKey(field.Name))
{
var mismatchedValue = mismatchedValues[field.Name];
for (int i = 0; i < resultFiles.Length; i++)
{
sb.Append(string.Format("<div class=\"fieldvaluewarning\" title=\"{0}\"><pre>", resultFiles[i]));
var value = mismatchedValue.Any(kv => kv.Key.Equals(resultFiles[i])) ?
mismatchedValue.First(kv => kv.Key.Equals(resultFiles[i])).Value :
mismatchedValue.First(kv => kv.Key.Equals(resultFiles[0])).Value;
sb.Append(string.Format("|&nbsp;{0}:&nbsp;&nbsp;&nbsp;&nbsp;{1}&nbsp;|", metadataValidator.ResizeString(resultFiles[i], 20), value));
sb.Append(i == resultFiles.Length - 1 ? "</pre></div >" : "</pre><br></div >");
}
}
else
{
sb.Append(string.Format("<div class=\"fieldvalue\"><pre>{0}</pre></div>", field.GetValue(thisObject)));
}
sb.Append("</div>");
}
}
rw.WriteLine(sb.ToString());

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

@ -54,11 +54,19 @@ h3 {
display: inline-block;
*display: inline; /* For IE7 */
zoom: 1; /* Trigger hasLayout */
width: 15%;
width: 20%;
text-align: left;
vertical-align: text-top;
font-family: 'Arial', 'Helvetica', 'Helvetica Neue', sans-serif;
}
.systeminfowide > div {
display: inline-block;
*display: inline; /* For IE7 */
zoom: 1; /* Trigger hasLayout */
width: 50%;
text-align: left;
vertical-align: text-top;
font-size: small;
padding: 5px 5px 5px 5px;
font-family: 'Arial', 'Helvetica', 'Helvetica Neue', sans-serif;
}
@ -127,6 +135,9 @@ h3 {
padding: 5px 5px 5px 10px;
}
.fieldgroup {
}
.fieldname {
font-weight: bold;
font-size: 1.15vh;
@ -135,8 +146,19 @@ h3 {
.fieldvalue {
font-size: 1vh;
padding: 5px 5px 5px 0px;
overflow-wrap: break-word;
}
.fieldvaluewarning {
font-size: 1vh;
color: darkorange;
}
pre {
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
.containerLabel {
@ -278,4 +300,4 @@ h3 {
width: 5px;
height: auto;
display: inline-block;
}
}

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

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using UnityPerformanceBenchmarkReporter;
using UnityPerformanceBenchmarkReporter.Entities;
using UnityPerformanceBenchmarkReporter.Report;
namespace UnityPerformanceBenchmarkReporterTests
{
public class ExtensionMethodsTests
{
[Test]
public void VerifyZeroValue()
{
// Arrange
double d = 0;
// Act
var truncatedD = d.TruncToSigFig(2);
// Assert
Assert.AreEqual(0, truncatedD, 0);
}
[Test]
public void VerifyNonZeroValue_GreaterThan1_0SigFigs()
{
// Arrange
double d = 1.58888299999999993;
// Act
var truncatedD = d.TruncToSigFig(0);
// Assert
Assert.AreEqual(1, truncatedD, 0);
}
[Test]
public void VerifyNonZeroValue_LessThan1_0SigFigs()
{
// Arrange
double d = 0.58888299999999993;
// Act
var truncatedD = d.TruncToSigFig(0);
// Assert
Assert.AreEqual(0, truncatedD, 0);
}
[Test]
public void VerifyNonZeroValue_GreaterThan1_1SigFigs()
{
// Arrange
double d = 1.58888299999999993;
// Act
var truncatedD = d.TruncToSigFig(1);
// Assert
Assert.AreEqual(1.5, truncatedD, 0);
}
[Test]
public void VerifyNonZeroValue_LessThan1_1SigFigs()
{
// Arrange
double d = 0.58888299999999993;
// Act
var truncatedD = d.TruncToSigFig(1);
// Assert
Assert.AreEqual(0.5, truncatedD, 0);
}
}
}