cs-codex-dist-tests/Tools/AutoClient/Performance.cs

66 lines
1.6 KiB
C#
Raw Normal View History

using Logging;
namespace AutoClient
2024-09-12 12:38:15 +00:00
{
public class Performance
{
private readonly ILog log;
public Performance(ILog log)
{
this.log = log;
}
public void DownloadFailed(Exception ex)
{
Log($"Download failed: {ex}");
}
public void DownloadSuccessful(long size, TimeSpan time)
2024-09-12 12:38:15 +00:00
{
2024-09-12 13:14:15 +00:00
long milliseconds = Convert.ToInt64(time.TotalMilliseconds);
if (milliseconds < 1) milliseconds = 1;
long bytesPerSecond = 1000 * (size / milliseconds);
Log($"Download successful: {bytesPerSecond} bytes per second");
2024-09-12 12:38:15 +00:00
}
public void StorageContractCancelled()
2024-09-12 12:38:15 +00:00
{
Log("Contract cancelled");
2024-09-12 12:38:15 +00:00
}
public void StorageContractErrored(string error)
2024-09-12 12:38:15 +00:00
{
Log($"Contract errored: {error}");
2024-09-12 12:38:15 +00:00
}
public void StorageContractFinished()
2024-09-12 12:38:15 +00:00
{
Log("Contract finished");
2024-09-12 12:38:15 +00:00
}
public void StorageContractStarted()
2024-09-12 12:38:15 +00:00
{
Log("Contract started");
2024-09-12 12:38:15 +00:00
}
public void UploadFailed(Exception ex)
2024-09-12 12:38:15 +00:00
{
Log($"Upload failed: {ex}");
2024-09-12 12:38:15 +00:00
}
public void UploadSuccessful(long size, TimeSpan time)
2024-09-12 12:38:15 +00:00
{
2024-09-12 13:14:15 +00:00
long milliseconds = Convert.ToInt64(time.TotalMilliseconds);
if (milliseconds < 1) milliseconds = 1;
long bytesPerSecond = 1000 * (size / milliseconds);
Log($"Upload successful: {bytesPerSecond} bytes per second");
2024-09-12 12:38:15 +00:00
}
private void Log(string msg)
2024-09-12 12:38:15 +00:00
{
log.Log(msg);
2024-09-12 12:38:15 +00:00
}
}
}