diff --git a/Framework/Logging/Stopwatch.cs b/Framework/Logging/Stopwatch.cs index 830b49a..fddd8b5 100644 --- a/Framework/Logging/Stopwatch.cs +++ b/Framework/Logging/Stopwatch.cs @@ -51,7 +51,7 @@ namespace Logging return new Stopwatch(log, name, debug); } - public void End(string msg = "", int skipFrames = 0) + public TimeSpan End(string msg = "", int skipFrames = 0) { var duration = DateTime.UtcNow - start; var entry = $"{name} {msg} ({Time.FormatDuration(duration)})"; @@ -64,6 +64,8 @@ namespace Logging { log.Log(entry); } + + return duration; } } } diff --git a/Tests/CodexContinuousTests/Tests/TwoClientTest.cs b/Tests/CodexContinuousTests/Tests/TwoClientTest.cs index 12a4d3f..bf08bae 100644 --- a/Tests/CodexContinuousTests/Tests/TwoClientTest.cs +++ b/Tests/CodexContinuousTests/Tests/TwoClientTest.cs @@ -1,5 +1,6 @@ using CodexPlugin; using FileUtils; +using Logging; using NUnit.Framework; using Utils; @@ -15,16 +16,16 @@ namespace ContinuousTests.Tests private ContentId? cid; private TrackedFile file = null!; + private readonly ByteSize size = 80.MB(); [TestMoment(t: Zero)] public void UploadTestFile() { - var size = 80.MB(); file = FileManager.GenerateFile(size); - AssertBytesStoredMetric(size, Nodes[0], () => + AssertBytesStoredMetric(Nodes[0], () => { - cid = Nodes[0].UploadFile(file); + LogBytesPerMillisecond(() => cid = Nodes[0].UploadFile(file)); Assert.That(cid, Is.Not.Null); }); } @@ -32,15 +33,17 @@ namespace ContinuousTests.Tests [TestMoment(t: 10)] public void DownloadTestFile() { - var dl = Nodes[1].DownloadContent(cid!); + TrackedFile? dl = null; + + LogBytesPerMillisecond(() => dl = Nodes[1].DownloadContent(cid!)); file.AssertIsEqual(dl); } - private void AssertBytesStoredMetric(ByteSize uploadedSize, ICodexNode node, Action action) + private void AssertBytesStoredMetric(ICodexNode node, Action action) { - var lowExpected = uploadedSize.SizeInBytes; - var highExpected = uploadedSize.SizeInBytes * 1.2; + var lowExpected = size.SizeInBytes; + var highExpected = size.SizeInBytes * 1.2; var metrics = CreateMetricsAccess(node); var before = metrics.GetMetric(BytesStoredMetric); @@ -57,5 +60,17 @@ namespace ContinuousTests.Tests return highExpected > newBytes && newBytes > lowExpected; }); } + + private void LogBytesPerMillisecond(Action action) + { + var sw = Stopwatch.Begin(Log); + action(); + var duration = sw.End(); + double totalMs = duration.TotalMilliseconds; + double totalBytes = size.SizeInBytes; + + var bytesPerMs = totalBytes / totalMs; + Log.Log($"Bytes per millisecond: {bytesPerMs}"); + } } } diff --git a/Tests/CodexTests/BasicTests/ContinuousSubstitute.cs b/Tests/CodexTests/BasicTests/ContinuousSubstitute.cs index 1258f55..a5d3aea 100644 --- a/Tests/CodexTests/BasicTests/ContinuousSubstitute.cs +++ b/Tests/CodexTests/BasicTests/ContinuousSubstitute.cs @@ -2,6 +2,7 @@ using CodexPlugin; using GethPlugin; using KubernetesWorkflow; +using Logging; using MetricsPlugin; using NUnit.Framework; using Utils; @@ -53,6 +54,18 @@ namespace Tests.BasicTests } } + private void LogBytesPerMillisecond(Action action) + { + var sw = Stopwatch.Begin(GetTestLog()); + action(); + var duration = sw.End(); + double totalMs = duration.TotalMilliseconds; + double totalBytes = fileSize.SizeInBytes; + + var bytesPerMs = totalBytes / totalMs; + Log($"Bytes per millisecond: {bytesPerMs}"); + } + [Test] public void PeerTest() { @@ -122,7 +135,8 @@ namespace Tests.BasicTests var metrics = Ci.WrapMetricsCollector(rc, primary); var beforeBytesStored = metrics.GetMetric(BytesStoredMetric); - var contentId = primary.UploadFile(testFile); + ContentId contentId = null!; + LogBytesPerMillisecond(() => contentId = primary.UploadFile(testFile)); var low = fileSize.SizeInBytes; var high = low * 1.2; @@ -136,7 +150,8 @@ namespace Tests.BasicTests return high > newBytes && newBytes > low; }, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(2)); - var downloadedFile = secondary.DownloadContent(contentId); + FileUtils.TrackedFile? downloadedFile = null; + LogBytesPerMillisecond(() => downloadedFile = secondary.DownloadContent(contentId)); testFile.AssertIsEqual(downloadedFile); });