From 7e040892cc4e58492b793fe496bd2065077e02fd Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Thu, 13 Mar 2025 15:55:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D1=8F=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=B0=D0=B4=D0=B5=D1=80?= =?UTF-8?q?=D0=B6=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example.Backend/Program.cs | 2 ++ .../Example.Events.Backend.csproj | 4 ++++ Example.Events.Client/Example.Events.Client.csproj | 4 ++++ Example.Events.Client/Program.cs | 12 ++++++++++-- mROA/Implementation/Frontend/RequestExtractor.cs | 14 ++++++++++++-- .../NextGenerationInteractionModule.cs | 3 ++- mROA/Implementation/RepresentationModule.cs | 2 +- 7 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Example.Backend/Program.cs b/Example.Backend/Program.cs index 2885243..1e12d48 100644 --- a/Example.Backend/Program.cs +++ b/Example.Backend/Program.cs @@ -17,6 +17,8 @@ class Program // builder.UseJsonSerialisation(); builder.Modules.Add(new CborSerializationToolkit()); builder.Modules.Add(new BackendIdentityGenerator()); + // builder.UseNetworkGateway(new IPEndPoint(IPAddress.Loopback, 4567), typeof(NextGenerationInteractionModule), + // builder.GetModule()!); builder.UseNetworkGateway(new IPEndPoint(IPAddress.Loopback, 4567), typeof(NextGenerationInteractionModule), builder.GetModule()!); diff --git a/Example.Events.Backend/Example.Events.Backend.csproj b/Example.Events.Backend/Example.Events.Backend.csproj index 2c675f7..4e79fe1 100644 --- a/Example.Events.Backend/Example.Events.Backend.csproj +++ b/Example.Events.Backend/Example.Events.Backend.csproj @@ -7,6 +7,10 @@ enable + + + + diff --git a/Example.Events.Client/Example.Events.Client.csproj b/Example.Events.Client/Example.Events.Client.csproj index 2c675f7..4e79fe1 100644 --- a/Example.Events.Client/Example.Events.Client.csproj +++ b/Example.Events.Client/Example.Events.Client.csproj @@ -7,6 +7,10 @@ enable + + + + diff --git a/Example.Events.Client/Program.cs b/Example.Events.Client/Program.cs index 2a3e14c..155e969 100644 --- a/Example.Events.Client/Program.cs +++ b/Example.Events.Client/Program.cs @@ -1,4 +1,5 @@ -using System.Net; +using System.Diagnostics; +using System.Net; using Example.Events.Shared; using mROA.Cbor; using mROA.Codegen; @@ -56,9 +57,16 @@ class Program } else symb = input.KeyChar.ToString(); - +#if TRACE + Console.Write(symb); + var sw = Stopwatch.StartNew(); + chat.PostSymbol(symb); + sw.Stop(); + Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); +#else Console.Write(symb); chat.PostSymbol(symb); +#endif } } } \ No newline at end of file diff --git a/mROA/Implementation/Frontend/RequestExtractor.cs b/mROA/Implementation/Frontend/RequestExtractor.cs index 7db7a73..cb87c79 100644 --- a/mROA/Implementation/Frontend/RequestExtractor.cs +++ b/mROA/Implementation/Frontend/RequestExtractor.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using mROA.Abstract; @@ -25,7 +26,7 @@ namespace mROA.Implementation.Frontend case IExecuteModule executeModule: _executeModule = executeModule; break; - case MultiClientContextRepository : + case MultiClientContextRepository: case ContextRepository: _realContextRepository = dependency as IContextRepository; break; @@ -67,10 +68,18 @@ namespace mROA.Implementation.Frontend try { +#if TRACE + var sw = new Stopwatch(); +#endif while (true) { #if TRACE Console.WriteLine("Waiting for request..."); + if (sw.IsRunning) + { + sw.Stop(); + Console.WriteLine($"Request handling took {sw.ElapsedMilliseconds} milliseconds."); + } #endif var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; @@ -86,6 +95,7 @@ namespace mROA.Implementation.Frontend Task.WaitAny(defaultRequest, cancelRequest, eventRequest); #if TRACE Console.WriteLine("Request received"); + sw.Restart(); #endif if (cancelRequest.IsCompleted) { @@ -128,4 +138,4 @@ namespace mROA.Implementation.Frontend }); } } -} \ No newline at end of file +} diff --git a/mROA/Implementation/NextGenerationInteractionModule.cs b/mROA/Implementation/NextGenerationInteractionModule.cs index 7ae9170..733c921 100644 --- a/mROA/Implementation/NextGenerationInteractionModule.cs +++ b/mROA/Implementation/NextGenerationInteractionModule.cs @@ -51,6 +51,7 @@ namespace mROA.Implementation var rawMessage = _serialization.Serialize(message); var header = BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort)); + await BaseStream.WriteAsync(header); await BaseStream.WriteAsync(rawMessage); } @@ -89,7 +90,7 @@ namespace mROA.Implementation var message = _serialization.Deserialize(localSpan.Span); #if TRACE - Console.WriteLine($"Received Message {message.Id} - {message.SchemaId}"); + Console.WriteLine($"{DateTime.Now.TimeOfDay} Received Message {message.Id} - {message.SchemaId}"); TransmissionConfig.TotalTransmittedBytes += len; Console.WriteLine($"Total recieced bytes are {TransmissionConfig.TotalTransmittedBytes}"); #endif diff --git a/mROA/Implementation/RepresentationModule.cs b/mROA/Implementation/RepresentationModule.cs index 58f2ce5..ffd1b87 100644 --- a/mROA/Implementation/RepresentationModule.cs +++ b/mROA/Implementation/RepresentationModule.cs @@ -91,7 +91,7 @@ namespace mROA.Implementation if (_serialization == null) throw new NullReferenceException("Serialization toolkit is not initialized"); #if TRACE - Console.WriteLine($"Posting message: {id} - {messageType} to {Id}"); + Console.WriteLine($"{DateTime.Now.TimeOfDay} Posting message: {id} - {messageType} to {Id}"); #endif var serialized = _serialization.Serialize(payload, payloadType);