Skip to content

Commit 88c675a

Browse files
committed
implements performance logger for autoclient
1 parent 75fcc68 commit 88c675a

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace CodexPlugin
77
{
88
public class CodexContainerRecipe : ContainerRecipeFactory
99
{
10-
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-1e2ad95-dist-tests";
11-
10+
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-656ce37-dist-tests";
1211
public const string ApiPortTag = "codex_api_port";
1312
public const string ListenPortTag = "codex_listen_port";
1413
public const string MetricsPortTag = "codex_metrics_port";

Tools/AutoClient/App.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ public App(Configuration config)
1515

1616
Generator = CreateGenerator();
1717
CidRepo = new CidRepo(config);
18+
Performance = new Performance(new LogSplitter(
19+
new FileLog(Path.Combine(config.LogPath, "performance")),
20+
new ConsoleLog()
21+
));
1822
}
1923

2024
public Configuration Config { get; }
2125
public ILog Log { get; }
2226
public IFileGenerator Generator { get; }
2327
public CancellationTokenSource Cts { get; } = new CancellationTokenSource();
2428
public CidRepo CidRepo { get; }
25-
public Performance Performance { get; } = new Performance();
29+
public Performance Performance { get; }
2630

2731
private IFileGenerator CreateGenerator()
2832
{

Tools/AutoClient/Performance.cs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,63 @@
1-
namespace AutoClient
1+
using Logging;
2+
3+
namespace AutoClient
24
{
35
public class Performance
46
{
5-
internal void DownloadFailed(Exception ex)
7+
private readonly ILog log;
8+
9+
public Performance(ILog log)
10+
{
11+
this.log = log;
12+
}
13+
14+
public void DownloadFailed(Exception ex)
15+
{
16+
Log($"Download failed: {ex}");
17+
}
18+
19+
public void DownloadSuccessful(long size, TimeSpan time)
620
{
7-
throw new NotImplementedException();
21+
long seconds = Convert.ToInt64(time.TotalSeconds);
22+
long bytesPerSecond = size / seconds;
23+
Log($"Download successful: {bytesPerSecond} bytes per second");
824
}
925

10-
internal void DownloadSuccessful(long? size, TimeSpan time)
26+
public void StorageContractCancelled()
1127
{
12-
throw new NotImplementedException();
28+
Log("Contract cancelled");
1329
}
1430

15-
internal void StorageContractCancelled()
31+
public void StorageContractErrored(string error)
1632
{
17-
throw new NotImplementedException();
33+
Log($"Contract errored: {error}");
1834
}
1935

20-
internal void StorageContractErrored(string error)
36+
public void StorageContractFinished()
2137
{
22-
throw new NotImplementedException();
38+
Log("Contract finished");
2339
}
2440

25-
internal void StorageContractFinished()
41+
public void StorageContractStarted()
2642
{
27-
throw new NotImplementedException();
43+
Log("Contract started");
2844
}
2945

30-
internal void StorageContractStarted()
46+
public void UploadFailed(Exception ex)
3147
{
32-
throw new NotImplementedException();
48+
Log($"Upload failed: {ex}");
3349
}
3450

35-
internal void UploadFailed(Exception exc)
51+
public void UploadSuccessful(long size, TimeSpan time)
3652
{
37-
throw new NotImplementedException();
53+
long seconds = Convert.ToInt64(time.TotalSeconds);
54+
long bytesPerSecond = size / seconds;
55+
Log($"Upload successful: {bytesPerSecond} bytes per second");
3856
}
3957

40-
internal void UploadSuccessful(long length, TimeSpan time)
58+
private void Log(string msg)
4159
{
42-
throw new NotImplementedException();
60+
log.Log(msg);
4361
}
4462
}
4563
}

Tools/AutoClient/Purchaser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private async Task DownloadForeignCid()
6060
var cid = app.CidRepo.GetForeignCid(nodeId);
6161
if (cid == null) return;
6262
var size = app.CidRepo.GetSizeForCid(cid);
63-
if (cid == null) return;
63+
if (size == null) return;
6464

6565
try
6666
{
@@ -73,7 +73,7 @@ private async Task DownloadForeignCid()
7373
}
7474
var time = sw.Elapsed;
7575
File.Delete(filename);
76-
app.Performance.DownloadSuccessful(size, time);
76+
app.Performance.DownloadSuccessful(size.Value, time);
7777
}
7878
catch (Exception ex)
7979
{

0 commit comments

Comments
 (0)