Skip to content

Commit 02ca9db

Browse files
committed
wip: blockreceives to csv
1 parent 672092b commit 02ca9db

File tree

2 files changed

+71
-15
lines changed

2 files changed

+71
-15
lines changed

Tools/TranscriptAnalysis/Program.cs

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Logging;
33
using OverwatchTranscript;
44
using TranscriptAnalysis;
5+
using TranscriptAnalysis.Receivers;
56

67
public static class Program
78
{
@@ -10,26 +11,75 @@ public static class Program
1011
public static void Main(string[] args)
1112
{
1213
Log("Transcript Analysis");
13-
if (!args.Any())
14+
15+
var path1 = "d:\\Projects\\cs-codex-dist-tests\\Tests\\CodexTests\\bin\\Debug\\net8.0\\CodexTestLogs\\2024-10\\11\\08-31-52Z_SwarmTests\\";
16+
var path2 = "d:\\Projects\\cs-codex-dist-tests\\Tests\\CodexTests\\bin\\Debug\\net8.0\\CodexTestLogs\\2024-10\\11\\09-28-29Z_SwarmTests\\";
17+
var files1 = new[]
1418
{
15-
Log("Please pass a .owts file");
16-
Console.ReadLine();
17-
return;
18-
}
19+
(1, 3, "DetectBlockRetransmits[1,3]_swarm_retransmit.owts"),
20+
(1, 5, "DetectBlockRetransmits[1,5]_swarm_retransmit.owts"),
21+
(1, 10, "DetectBlockRetransmits[1,10]_swarm_retransmit.owts"),
22+
(1, 20, "DetectBlockRetransmits[1,20]_swarm_retransmit.owts"),
23+
(5, 3, "DetectBlockRetransmits[5,3]_swarm_retransmit.owts"),
24+
(5, 5, "DetectBlockRetransmits[5,5]_swarm_retransmit.owts"),
25+
(5, 10, "DetectBlockRetransmits[5,10]_swarm_retransmit.owts"),
26+
(5, 20, "DetectBlockRetransmits[5,20]_swarm_retransmit.owts"),
27+
(10, 5, "DetectBlockRetransmits[10,5]_swarm_retransmit.owts"),
28+
(10, 10, "DetectBlockRetransmits[10,10]_swarm_retransmit.owts")
29+
};
30+
var files2 = new[]
31+
{
32+
(10, 20, "DetectBlockRetransmits[10,20]_swarm_retransmit.owts"),
33+
(20, 3, "DetectBlockRetransmits[20,3]_swarm_retransmit.owts"),
34+
(20, 5, "DetectBlockRetransmits[20,5]_swarm_retransmit.owts"),
35+
(20, 10, "DetectBlockRetransmits[20,10]_swarm_retransmit.owts"),
36+
(20, 20, "DetectBlockRetransmits[20,20]_swarm_retransmit.owts")
37+
};
1938

20-
if (!File.Exists(args[0]))
39+
var countLines = new List<int[]>();
40+
41+
foreach (var file in files1)
2142
{
22-
Log("File doesn't exist: " + args[0]);
23-
Console.ReadLine();
24-
return;
43+
var path = Path.Combine(path1, file.Item3);
44+
DuplicateBlocksReceived.Counts.Clear();
45+
Run(path);
46+
47+
countLines.Add(new[] { file.Item1, file.Item2 }.Concat(DuplicateBlocksReceived.Counts).ToArray());
48+
}
49+
foreach (var file in files2)
50+
{
51+
var path = Path.Combine(path2, file.Item3);
52+
DuplicateBlocksReceived.Counts.Clear();
53+
Run(path);
54+
55+
countLines.Add(new[] { file.Item1, file.Item2 }.Concat(DuplicateBlocksReceived.Counts).ToArray());
2556
}
2657

27-
var reader = OpenReader(args[0]);
28-
AppDomain.CurrentDomain.ProcessExit += (e, s) =>
58+
var numColumns = countLines.Max(l => l.Length);
59+
var header = new List<string>() { "filesize", "numNodes" };
60+
for (var i = 0; i < numColumns - 2; i++) header.Add("recv" + (i + 1) + "x");
61+
62+
var lines = new List<string>() { string.Join(",", header.ToArray()) };
63+
foreach (var count in countLines)
2964
{
30-
CloseReader(reader);
31-
};
65+
var tokens = new List<int>();
66+
for (var i = 0; i < numColumns; i++)
67+
{
68+
if (i < count.Length) tokens.Add(count[i]);
69+
else tokens.Add(0);
70+
}
71+
lines.Add(string.Join(",", tokens.Select(t => t.ToString()).ToArray()));
72+
}
73+
74+
File.WriteAllLines("C:\\Users\\Ben\\Desktop\\blockretransmit.csv", lines.ToArray());
75+
76+
Log("Done.");
77+
Console.ReadLine();
78+
}
3279

80+
private static void Run(string file)
81+
{
82+
var reader = OpenReader(file);
3383
var header = reader.GetHeader<OverwatchCodexHeader>("cdx_h");
3484
var receivers = new ReceiverSet(log, reader, header);
3585
receivers.InitAll();
@@ -40,8 +90,7 @@ public static void Main(string[] args)
4090
receivers.FinishAll();
4191

4292
CloseReader(reader);
43-
Log("Done.");
44-
Console.ReadLine();
93+
4594
}
4695

4796
private static ITranscriptReader OpenReader(string filepath)

Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace TranscriptAnalysis.Receivers
55
{
66
public class DuplicateBlocksReceived : BaseReceiver<OverwatchCodexEvent>
77
{
8+
public static List<int> Counts = new List<int>();
9+
810
public override string Name => "BlocksReceived";
911

1012
public override void Receive(ActivateEvent<OverwatchCodexEvent> @event)
@@ -31,13 +33,17 @@ public override void Finish()
3133
}
3234
}
3335

36+
if (Counts.Any()) throw new Exception("Should be empty");
37+
3438
float t = totalReceived;
3539
occurances.PrintContinous((i, count) =>
3640
{
3741
float n = count;
3842
float p = 100.0f * (n / t);
3943
Log($"Block received {i} times = {count}x ({p}%)");
44+
Counts.Add(count);
4045
});
46+
4147
}
4248

4349
private int seen = 0;
@@ -46,6 +52,7 @@ public override void Finish()
4652
private void Handle(OverwatchCodexEvent payload, BlockReceivedEvent blockReceived)
4753
{
4854
var receiverPeerId = GetPeerId(payload.NodeIdentity);
55+
if (receiverPeerId == null) return;
4956
var blockAddress = blockReceived.BlockAddress;
5057
seen++;
5158

0 commit comments

Comments
 (0)