提交 b3d6ef9d 编写于 作者: T Ty Overby 提交者: GitHub

add wallclock time (#15121)

* add wallclock time

* you only need to track durations

* use sum instead

* use stopwatch

* style fixes
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Roslyn.Test.Performance.Utilities;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.IO;
using static Roslyn.Test.Performance.Utilities.TestUtilities;
......@@ -18,13 +21,13 @@ public static ITraceManager GetBestTraceManager()
else
{
Log($"WARNING: Could not find CPC at {cpcFullPath} (no traces will be collected)");
return new NoOpTraceManager();
return new WallClockTraceManager();
}
}
public static ITraceManager NoOpTraceManager()
{
return new NoOpTraceManager();
return new WallClockTraceManager();
}
}
......@@ -119,9 +122,14 @@ public void ResetScenarioGenerator()
}
}
public class NoOpTraceManager : ITraceManager
public class WallClockTraceManager : ITraceManager
{
public NoOpTraceManager()
private readonly List<long> _durations = new List<long>();
private string _testName = "";
private Stopwatch _stopwatch;
public WallClockTraceManager()
{
}
......@@ -131,8 +139,17 @@ public void Initialize()
{
}
// We have one WallClockTraceManager per test, so we don't
// need to worry about other tests showing up
public void Cleanup()
{
var totalDuration = _durations.Sum(v => v);
var average = totalDuration / _durations.Count;
var allString = string.Join(",", _durations);
Log($"Wallclock times for {_testName}");
Log($"ALL: [{allString}]");
Log($"AVERAGE: {average}");
}
public void EndEvent()
......@@ -141,6 +158,8 @@ public void EndEvent()
public void EndScenario()
{
_stopwatch.Stop();
_durations.Add(_stopwatch.ElapsedMilliseconds);
}
public void EndScenarios()
......@@ -169,6 +188,8 @@ public void StartScenarios()
public void StartScenario(string scenarioName, string processName)
{
_testName = scenarioName;
_stopwatch = Stopwatch.StartNew();
}
public void Stop()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册