node degree overview
This commit is contained in:
parent
745b7e43b4
commit
11a015e0b6
|
@ -77,7 +77,7 @@ namespace Logging
|
|||
return new LogFile($"{GetFullName()}_{GetSubfileNumber()}", ext);
|
||||
}
|
||||
|
||||
private string ApplyReplacements(string str)
|
||||
protected string ApplyReplacements(string str)
|
||||
{
|
||||
if (IsDebug) return str;
|
||||
foreach (var replacement in replacements)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
public override void Log(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
Console.WriteLine(ApplyReplacements(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace TranscriptAnalysis
|
|||
if (!reader.Next())
|
||||
{
|
||||
miss++;
|
||||
if (miss > 1000)
|
||||
if (miss > 20)
|
||||
{
|
||||
log.Log("Done");
|
||||
return;
|
||||
|
|
|
@ -4,11 +4,10 @@ using TranscriptAnalysis;
|
|||
|
||||
public static class Program
|
||||
{
|
||||
private static ILog log;
|
||||
private static readonly ILog log = new ConsoleLog();
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
log = new ConsoleLog();
|
||||
args = new[] { "D:\\Projects\\cs-codex-dist-tests\\Tests\\CodexTests\\bin\\Debug\\net7.0\\CodexTestLogs\\2024-08\\06\\08-24-45Z_ThreeClientTest\\SwarmTest_SwarmTest.owts" };
|
||||
|
||||
Log("Transcript Analysis");
|
||||
|
@ -32,12 +31,13 @@ public static class Program
|
|||
CloseReader(reader);
|
||||
};
|
||||
|
||||
var duplicatesReceived = new DuplicateBlocksReceived(log, reader);
|
||||
var receivers = new ReceiverSet(log, reader);
|
||||
receivers.InitAll();
|
||||
|
||||
var processor = new Processor(log, reader);
|
||||
processor.RunAll();
|
||||
|
||||
duplicatesReceived.Finish();
|
||||
receivers.FinishAll();
|
||||
|
||||
CloseReader(reader);
|
||||
Log("Done.");
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
using Logging;
|
||||
using OverwatchTranscript;
|
||||
using TranscriptAnalysis.Receivers;
|
||||
|
||||
namespace TranscriptAnalysis
|
||||
{
|
||||
public interface IEventReceiver
|
||||
{
|
||||
void Init(ILog log);
|
||||
void Finish();
|
||||
}
|
||||
|
||||
public interface IEventReceiver<T> : IEventReceiver
|
||||
{
|
||||
void Receive(ActivateEvent<T> @event);
|
||||
}
|
||||
|
||||
public class ReceiverSet
|
||||
{
|
||||
private readonly ILog log;
|
||||
private readonly ITranscriptReader reader;
|
||||
private readonly List<IEventReceiver> receivers = new List<IEventReceiver>();
|
||||
|
||||
public ReceiverSet(ILog log, ITranscriptReader reader)
|
||||
{
|
||||
this.log = log;
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public void InitAll()
|
||||
{
|
||||
Add(new LogReplaceReceiver());
|
||||
Add(new DuplicateBlocksReceived());
|
||||
Add(new NodesDegree());
|
||||
}
|
||||
|
||||
public void FinishAll()
|
||||
{
|
||||
foreach (var r in receivers)
|
||||
{
|
||||
r.Finish();
|
||||
}
|
||||
receivers.Clear();
|
||||
}
|
||||
|
||||
|
||||
private void Add<T>(IEventReceiver<T> receiver)
|
||||
{
|
||||
var mux = GetMux<T>();
|
||||
mux.Add(receiver);
|
||||
|
||||
receivers.Add(receiver);
|
||||
receiver.Init(log);
|
||||
}
|
||||
|
||||
// We use a mux here because, for each time we call reader.AddEventHandler,
|
||||
// The reader will perform one separate round of JSON deserialization.
|
||||
// TODO: Move the mux into the reader.
|
||||
private readonly Dictionary<string, IEventMux> muxes = new Dictionary<string, IEventMux>();
|
||||
private IEventMux GetMux<T>()
|
||||
{
|
||||
var typeName = typeof(T).FullName;
|
||||
if (string.IsNullOrEmpty(typeName)) throw new Exception("A!");
|
||||
|
||||
if (!muxes.ContainsKey(typeName))
|
||||
{
|
||||
muxes.Add(typeName, new EventMux<T>(reader));
|
||||
}
|
||||
return muxes[typeName];
|
||||
}
|
||||
}
|
||||
|
||||
public interface IEventMux
|
||||
{
|
||||
void Add(IEventReceiver receiver);
|
||||
}
|
||||
|
||||
public class EventMux<T> : IEventMux
|
||||
{
|
||||
private readonly List<IEventReceiver<T>> receivers = new List<IEventReceiver<T>>();
|
||||
|
||||
public EventMux(ITranscriptReader reader)
|
||||
{
|
||||
reader.AddEventHandler<T>(Handle);
|
||||
}
|
||||
|
||||
public void Add(IEventReceiver receiver)
|
||||
{
|
||||
if (receiver is IEventReceiver<T> r)
|
||||
{
|
||||
receivers.Add(r);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ActivateEvent<T> @event)
|
||||
{
|
||||
foreach (var r in receivers) r.Receive(@event);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
using Logging;
|
||||
using OverwatchTranscript;
|
||||
|
||||
namespace TranscriptAnalysis.Receivers
|
||||
{
|
||||
public abstract class BaseReceiver<T> : IEventReceiver<T>
|
||||
{
|
||||
protected ILog log { get; private set; } = new NullLog();
|
||||
|
||||
public abstract string Name { get; }
|
||||
public abstract void Receive(ActivateEvent<T> @event);
|
||||
public abstract void Finish();
|
||||
|
||||
public void Init(ILog log)
|
||||
{
|
||||
this.log = new LogPrefixer(log, $"({Name}) ");
|
||||
}
|
||||
|
||||
protected void Log(string msg)
|
||||
{
|
||||
log.Log(msg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,21 @@
|
|||
using CodexPlugin.OverwatchSupport;
|
||||
using Logging;
|
||||
using OverwatchTranscript;
|
||||
|
||||
namespace TranscriptAnalysis
|
||||
namespace TranscriptAnalysis.Receivers
|
||||
{
|
||||
public class DuplicateBlocksReceived
|
||||
public class DuplicateBlocksReceived : BaseReceiver<OverwatchCodexEvent>
|
||||
{
|
||||
private readonly ILog log;
|
||||
public override string Name => "BlocksReceived";
|
||||
|
||||
public DuplicateBlocksReceived(ILog log, ITranscriptReader reader)
|
||||
public override void Receive(ActivateEvent<OverwatchCodexEvent> @event)
|
||||
{
|
||||
this.log = new LogPrefixer(log, "(DuplicateBlocks) ");
|
||||
|
||||
reader.AddEventHandler<OverwatchCodexEvent>(Handle);
|
||||
if (@event.Payload.BlockReceived != null)
|
||||
{
|
||||
Handle(@event.Payload, @event.Payload.BlockReceived);
|
||||
}
|
||||
}
|
||||
|
||||
public void Finish()
|
||||
public override void Finish()
|
||||
{
|
||||
Log("Number of BlockReceived events seen: " + seen);
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace TranscriptAnalysis
|
|||
foreach (var pair in peerPair.Value)
|
||||
{
|
||||
occurances[pair.Value]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float t = totalReceived;
|
||||
|
@ -40,14 +40,6 @@ namespace TranscriptAnalysis
|
|||
}
|
||||
}
|
||||
|
||||
private void Handle(ActivateEvent<OverwatchCodexEvent> obj)
|
||||
{
|
||||
if (obj.Payload.BlockReceived != null)
|
||||
{
|
||||
Handle(obj.Payload, obj.Payload.BlockReceived);
|
||||
}
|
||||
}
|
||||
|
||||
private int seen = 0;
|
||||
private readonly Dictionary<string, Dictionary<string, int>> peerIdBlockAddrCount = new Dictionary<string, Dictionary<string, int>>();
|
||||
|
||||
|
@ -71,10 +63,5 @@ namespace TranscriptAnalysis
|
|||
blockAddCount[blockAddress]++;
|
||||
}
|
||||
}
|
||||
|
||||
private void Log(string v)
|
||||
{
|
||||
log.Log(v);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
using CodexPlugin;
|
||||
using CodexPlugin.OverwatchSupport;
|
||||
using OverwatchTranscript;
|
||||
|
||||
namespace TranscriptAnalysis.Receivers
|
||||
{
|
||||
public class LogReplaceReceiver : BaseReceiver<OverwatchCodexEvent>
|
||||
{
|
||||
public override string Name => "LogReplacer";
|
||||
|
||||
private readonly List<string> seen = new List<string>();
|
||||
|
||||
public override void Receive(ActivateEvent<OverwatchCodexEvent> @event)
|
||||
{
|
||||
if (!seen.Contains(@event.Payload.PeerId))
|
||||
{
|
||||
seen.Add(@event.Payload.PeerId);
|
||||
|
||||
log.AddStringReplace(@event.Payload.PeerId, @event.Payload.Name);
|
||||
log.AddStringReplace(CodexUtils.ToShortId(@event.Payload.PeerId), @event.Payload.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Finish()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
using CodexPlugin;
|
||||
using CodexPlugin.OverwatchSupport;
|
||||
using OverwatchTranscript;
|
||||
|
||||
namespace TranscriptAnalysis.Receivers
|
||||
{
|
||||
public class NodesDegree : BaseReceiver<OverwatchCodexEvent>
|
||||
{
|
||||
private readonly Dictionary<string, Dictionary<string, int>> dials = new Dictionary<string, Dictionary<string, int>>();
|
||||
|
||||
public override string Name => "NodesDegree";
|
||||
|
||||
public override void Receive(ActivateEvent<OverwatchCodexEvent> @event)
|
||||
{
|
||||
if (@event.Payload.DialSuccessful != null)
|
||||
{
|
||||
AddDial(@event.Payload.PeerId, @event.Payload.DialSuccessful.TargetPeerId);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddDial(string peerId, string targetPeerId)
|
||||
{
|
||||
if (!dials.ContainsKey(peerId))
|
||||
{
|
||||
dials.Add(peerId, new Dictionary<string, int>());
|
||||
}
|
||||
|
||||
var d = dials[peerId];
|
||||
if (!d.ContainsKey(targetPeerId))
|
||||
{
|
||||
d.Add(targetPeerId, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
d[targetPeerId]++;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Finish()
|
||||
{
|
||||
var numNodes = dials.Keys.Count;
|
||||
var redials = dials.Values.Count(t => t.Values.Any(nd => nd > 1));
|
||||
|
||||
var min = dials.Values.Min(t => t.Count);
|
||||
var avg = dials.Values.Average(t => t.Count);
|
||||
var max = dials.Values.Max(t => t.Count);
|
||||
|
||||
Log($"Nodes: {numNodes} - Degrees: min:{min} avg:{avg} max:{max} - Redials: {redials}");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue