This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
PerformanceTestRunParser.cs
56 lines (49 loc) · 2.02 KB
/
PerformanceTestRunParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.IO;
using Improbable.Gdk.Core;
using Newtonsoft.Json;
using Unity.PerformanceTesting.Editor;
using UnityEngine;
namespace Improbable.Gdk.TestUtils.Editor
{
public static class PerformanceTestRunParser
{
private static string xmlResultsDirKey = "xmlResultsDirectory";
private static string jsonOutputDirKey = "jsonOutputDirectory";
public static void Parse()
{
var args = CommandLineArgs.FromCommandLine();
var xmlResultsDirectory = string.Empty;
var jsonOutputDirectory = string.Empty;
if (!args.TryGetCommandLineValue(xmlResultsDirKey, ref xmlResultsDirectory) ||
!args.TryGetCommandLineValue(jsonOutputDirKey, ref jsonOutputDirectory))
{
Debug.LogError($"You must provide valid {xmlResultsDirKey} and {jsonOutputDirKey} arguments.");
return;
}
var jsonOutputPath = Path.GetFullPath(jsonOutputDirectory);
Directory.CreateDirectory(jsonOutputPath);
var testResults = Directory.EnumerateFiles(Path.GetFullPath(xmlResultsDirectory), "*.xml");
foreach (var testResult in testResults)
{
try
{
var jsonFileName = Path.ChangeExtension(Path.GetFileName(testResult), "json");
var jsonFilePath = Path.Combine(jsonOutputPath, jsonFileName);
var xmlParser = new TestResultXmlParser();
var run = xmlParser.GetPerformanceTestRunFromXml(testResult);
if (run == null)
{
Debug.LogError($"No result at given path: {testResult}");
return;
}
File.WriteAllText(jsonFilePath, JsonConvert.SerializeObject(run, Formatting.Indented));
}
catch (Exception e)
{
Debug.LogException(e);
}
}
}
}
}