From 02ca9db001d508de4723bef5af382103fcf6fb11 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 14 Oct 2024 09:11:29 +0200 Subject: [PATCH] wip: blockreceives to csv --- Tools/TranscriptAnalysis/Program.cs | 83 +++++++++++++++---- .../Receivers/DuplicateBlocksReceived.cs | 7 ++ 2 files changed, 73 insertions(+), 17 deletions(-) diff --git a/Tools/TranscriptAnalysis/Program.cs b/Tools/TranscriptAnalysis/Program.cs index 289d70b..58cb2a4 100644 --- a/Tools/TranscriptAnalysis/Program.cs +++ b/Tools/TranscriptAnalysis/Program.cs @@ -2,6 +2,7 @@ using Logging; using OverwatchTranscript; using TranscriptAnalysis; +using TranscriptAnalysis.Receivers; public static class Program { @@ -10,26 +11,75 @@ public static class Program public static void Main(string[] args) { Log("Transcript Analysis"); - if (!args.Any()) - { - Log("Please pass a .owts file"); - Console.ReadLine(); - return; - } - if (!File.Exists(args[0])) + var path1 = "d:\\Projects\\cs-codex-dist-tests\\Tests\\CodexTests\\bin\\Debug\\net8.0\\CodexTestLogs\\2024-10\\11\\08-31-52Z_SwarmTests\\"; + var path2 = "d:\\Projects\\cs-codex-dist-tests\\Tests\\CodexTests\\bin\\Debug\\net8.0\\CodexTestLogs\\2024-10\\11\\09-28-29Z_SwarmTests\\"; + var files1 = new[] { - Log("File doesn't exist: " + args[0]); - Console.ReadLine(); - return; - } - - var reader = OpenReader(args[0]); - AppDomain.CurrentDomain.ProcessExit += (e, s) => + (1, 3, "DetectBlockRetransmits[1,3]_swarm_retransmit.owts"), + (1, 5, "DetectBlockRetransmits[1,5]_swarm_retransmit.owts"), + (1, 10, "DetectBlockRetransmits[1,10]_swarm_retransmit.owts"), + (1, 20, "DetectBlockRetransmits[1,20]_swarm_retransmit.owts"), + (5, 3, "DetectBlockRetransmits[5,3]_swarm_retransmit.owts"), + (5, 5, "DetectBlockRetransmits[5,5]_swarm_retransmit.owts"), + (5, 10, "DetectBlockRetransmits[5,10]_swarm_retransmit.owts"), + (5, 20, "DetectBlockRetransmits[5,20]_swarm_retransmit.owts"), + (10, 5, "DetectBlockRetransmits[10,5]_swarm_retransmit.owts"), + (10, 10, "DetectBlockRetransmits[10,10]_swarm_retransmit.owts") + }; + var files2 = new[] { - CloseReader(reader); + (10, 20, "DetectBlockRetransmits[10,20]_swarm_retransmit.owts"), + (20, 3, "DetectBlockRetransmits[20,3]_swarm_retransmit.owts"), + (20, 5, "DetectBlockRetransmits[20,5]_swarm_retransmit.owts"), + (20, 10, "DetectBlockRetransmits[20,10]_swarm_retransmit.owts"), + (20, 20, "DetectBlockRetransmits[20,20]_swarm_retransmit.owts") }; + var countLines = new List(); + + foreach (var file in files1) + { + var path = Path.Combine(path1, file.Item3); + DuplicateBlocksReceived.Counts.Clear(); + Run(path); + + countLines.Add(new[] { file.Item1, file.Item2 }.Concat(DuplicateBlocksReceived.Counts).ToArray()); + } + foreach (var file in files2) + { + var path = Path.Combine(path2, file.Item3); + DuplicateBlocksReceived.Counts.Clear(); + Run(path); + + countLines.Add(new[] { file.Item1, file.Item2 }.Concat(DuplicateBlocksReceived.Counts).ToArray()); + } + + var numColumns = countLines.Max(l => l.Length); + var header = new List() { "filesize", "numNodes" }; + for (var i = 0; i < numColumns - 2; i++) header.Add("recv" + (i + 1) + "x"); + + var lines = new List() { string.Join(",", header.ToArray()) }; + foreach (var count in countLines) + { + var tokens = new List(); + for (var i = 0; i < numColumns; i++) + { + if (i < count.Length) tokens.Add(count[i]); + else tokens.Add(0); + } + lines.Add(string.Join(",", tokens.Select(t => t.ToString()).ToArray())); + } + + File.WriteAllLines("C:\\Users\\Ben\\Desktop\\blockretransmit.csv", lines.ToArray()); + + Log("Done."); + Console.ReadLine(); + } + + private static void Run(string file) + { + var reader = OpenReader(file); var header = reader.GetHeader("cdx_h"); var receivers = new ReceiverSet(log, reader, header); receivers.InitAll(); @@ -40,8 +90,7 @@ public static class Program receivers.FinishAll(); CloseReader(reader); - Log("Done."); - Console.ReadLine(); + } private static ITranscriptReader OpenReader(string filepath) diff --git a/Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs b/Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs index 6eeb38e..ed1ef9c 100644 --- a/Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs +++ b/Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs @@ -5,6 +5,8 @@ namespace TranscriptAnalysis.Receivers { public class DuplicateBlocksReceived : BaseReceiver { + public static List Counts = new List(); + public override string Name => "BlocksReceived"; public override void Receive(ActivateEvent @event) @@ -31,13 +33,17 @@ namespace TranscriptAnalysis.Receivers } } + if (Counts.Any()) throw new Exception("Should be empty"); + float t = totalReceived; occurances.PrintContinous((i, count) => { float n = count; float p = 100.0f * (n / t); Log($"Block received {i} times = {count}x ({p}%)"); + Counts.Add(count); }); + } private int seen = 0; @@ -46,6 +52,7 @@ namespace TranscriptAnalysis.Receivers private void Handle(OverwatchCodexEvent payload, BlockReceivedEvent blockReceived) { var receiverPeerId = GetPeerId(payload.NodeIdentity); + if (receiverPeerId == null) return; var blockAddress = blockReceived.BlockAddress; seen++;