Added method to parse data version from commandline

Implemented parsing of V2 data format
Updated IParser interface to pass down Data Version
This commit is contained in:
andre.maestas 2022-03-11 17:22:28 -08:00
Родитель 1f3d75c58d
Коммит 9e45f6c99c
4 изменённых файлов: 140 добавлений и 9 удалений

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

@ -4,6 +4,6 @@ namespace UnityPerformanceBenchmarkReporter
{
public interface IParser
{
public PerformanceTestRun Parse(string path);
public PerformanceTestRun Parse(string path,int version);
}
}

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

@ -14,6 +14,8 @@ namespace UnityPerformanceBenchmarkReporter
public readonly TestRunMetadataProcessor TestRunMetadataProcessor;
private ESupportedFileTypes fileExtension = ESupportedFileTypes.xml;
public ESupportedFileTypes FileType { get { return fileExtension; } }
public int DataVersion { get; private set; } = 2;
public PerformanceBenchmark(Dictionary<Type, string[]> configFieldNames = null)
{
// Default significant figures to use for non-integer metrics if user doesn't specify another value.
@ -84,7 +86,7 @@ namespace UnityPerformanceBenchmarkReporter
foreach (var fileNamePath in fileNamePaths)
{
var performanceTestRun = testResultParser.Parse(fileNamePath);
var performanceTestRun = testResultParser.Parse(fileNamePath,DataVersion);
if (performanceTestRun != null && performanceTestRun.Results.Any())
{
perfTestRuns.Add(
@ -98,7 +100,7 @@ namespace UnityPerformanceBenchmarkReporter
for (var i = 0; i < resultFilesOrderedByResultName.Length; i++)
{
var performanceTestRun =
testResultParser.Parse(resultFilesOrderedByResultName[i].Key);
testResultParser.Parse(resultFilesOrderedByResultName[i].Key,DataVersion);
if (performanceTestRun != null && performanceTestRun.Results.Any())
{
@ -129,7 +131,16 @@ namespace UnityPerformanceBenchmarkReporter
}
}
internal void SetFileType(string filetype)
public void SetDataVersion(string version)
{
if(int.TryParse(version,out int result)){
DataVersion = result;
}else{
throw new ArgumentException($"{version} is not a valid data format version");
}
}
public void SetFileType(string filetype)
{
if (String.IsNullOrEmpty(filetype))
return;
@ -140,7 +151,7 @@ namespace UnityPerformanceBenchmarkReporter
}
else
{
System.Console.WriteLine($"Failed to Parse FileType Parameter {filetype}");
throw new ArgumentException($"{filetype} is not a valid file format");
}
}

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

@ -12,7 +12,7 @@ namespace UnityPerformanceBenchmarkReporter
{
public class TestResultJsonParser : IParser
{
public PerformanceTestRun Parse(string path)
public PerformanceTestRun Parse(string path, int version)
{
string report = "";
try
@ -34,13 +34,22 @@ namespace UnityPerformanceBenchmarkReporter
throw;
}
return ParseJson(report);
switch (version)
{
case 1:
return ParseJsonV1(report);
case 2:
return ParseJsonV2(report);
default:
return null;
}
}
private static PerformanceTestRun ParseJson(string json)
private static PerformanceTestRun ParseJsonV1(string json)
{
PerformanceTestRun result;
try
{
result = JsonConvert.DeserializeObject<PerformanceTestRun>(json);
@ -55,6 +64,117 @@ namespace UnityPerformanceBenchmarkReporter
return result;
}
private static PerformanceTestRun ParseJsonV2(string json)
{
Run run = null;
try
{
run = JsonConvert.DeserializeObject<Run>(json);
}
catch (System.Exception)
{
throw;
}
if (run != null)
{
var testRun = new PerformanceTestRun()
{
BuildSettings = new BuildSettings()
{
Platform = run.Player.Platform,
BuildTarget = run.Player.BuildTarget,
DevelopmentPlayer = true,
AndroidBuildSystem = run.Player.AndroidBuildSystem
},
EditorVersion = new EditorVersion()
{
Branch = run.Editor.Branch,
DateSeconds = run.Editor.Date,
FullVersion = $"{run.Editor.Version} ({run.Editor.Changeset})",
RevisionValue = 0
},
PlayerSettings = new PlayerSettings()
{
GpuSkinning = run.Player.GpuSkinning,
GraphicsApi = run.Player.GraphicsApi,
RenderThreadingMode = run.Player.RenderThreadingMode,
ScriptingBackend = run.Player.ScriptingBackend,
AndroidTargetSdkVersion = run.Player.AndroidTargetSdkVersion,
EnabledXrTargets = new List<string>(),
ScriptingRuntimeVersion = "",
StereoRenderingPath = run.Player.StereoRenderingPath
},
QualitySettings = new QualitySettings()
{
Vsync = run.Player.Vsync,
AntiAliasing = run.Player.AntiAliasing,
AnisotropicFiltering = run.Player.AnisotropicFiltering,
BlendWeights = run.Player.BlendWeights,
ColorSpace = run.Player.ColorSpace
},
ScreenSettings = new ScreenSettings()
{
Fullscreen = run.Player.Fullscreen,
ScreenHeight = run.Player.ScreenHeight,
ScreenWidth = run.Player.ScreenWidth,
ScreenRefreshRate = run.Player.ScreenRefreshRate
},
PlayerSystemInfo = new Entities.PlayerSystemInfo()
{
DeviceModel = run.Hardware.DeviceModel,
DeviceName = run.Hardware.DeviceName,
OperatingSystem = run.Hardware.OperatingSystem,
ProcessorCount = run.Hardware.ProcessorCount,
ProcessorType = run.Hardware.ProcessorType,
GraphicsDeviceName = run.Hardware.GraphicsDeviceName,
SystemMemorySize = run.Hardware.SystemMemorySizeMB,
XrDevice = run.Hardware.XrDevice,
XrModel = run.Hardware.XrModel
},
StartTime = run.Date,
TestSuite = run.TestSuite,
Results = new List<PerformanceTestResult>()
};
testRun.EndTime = DateTime.Now.ToUniversalTime()
.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
.TotalMilliseconds;
foreach (var res in run.Results)
{
var pt = new PerformanceTestResult()
{
TestCategories = res.Categories,
TestName = res.Name,
TestVersion = res.Version,
SampleGroups = res.SampleGroups.Select(sg => new Entities.SampleGroup
{
Samples = sg.Samples,
Average = sg.Average,
Max = sg.Max,
Median = sg.Median,
Min = sg.Min,
Sum = sg.Sum,
StandardDeviation = sg.StandardDeviation,
SampleCount = sg.Samples.Count,
Definition = new SampleGroupDefinition()
{
Name = sg.Name,
SampleUnit = (Entities.SampleUnit)sg.Unit,
IncreaseIsBetter = sg.IncreaseIsBetter
}
}).ToList()
};
testRun.Results.Add(pt);
}
return testRun;
}
return null;
}
}
}

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

@ -12,7 +12,7 @@ namespace UnityPerformanceBenchmarkReporter
{
public class TestResultXmlParser : IParser
{
public PerformanceTestRun Parse(string path)
public PerformanceTestRun Parse(string path,int version)
{
var xmlDocument = XDocument.Load(path);
return Parse(xmlDocument);