# HG changeset patch # User cin # Date 2016-04-25 12:18:56 # Node ID d45bdf510514d2a28d0d8ec63aee6c9c86f27bc2 # Parent cc19dc78edb7ab00b8e227dd379ea42670a9e190 working on diagnostics diff --git a/Implab.Test/RunnableComponentTests.cs b/Implab.Test/RunnableComponentTests.cs --- a/Implab.Test/RunnableComponentTests.cs +++ b/Implab.Test/RunnableComponentTests.cs @@ -132,7 +132,7 @@ namespace Implab.Test { ShouldThrow(() => p.Join(1000)); Assert.AreEqual(ExecutionState.Failed, comp.State); - Assert.IsInstanceOfType(comp.LastError, typeof(OperationCanceledException)); + Assert.IsTrue(comp.LastError is OperationCanceledException); comp.Dispose(); } @@ -185,7 +185,7 @@ namespace Implab.Test { p.Cancel(); ShouldThrow(() => p.Join(1000)); Assert.AreEqual(ExecutionState.Failed, comp.State); - Assert.IsInstanceOfType(comp.LastError, typeof(OperationCanceledException)); + Assert.IsTrue(comp.LastError is OperationCanceledException); comp.Dispose(); } diff --git a/Implab/Diagnostics/EventText.cs b/Implab/Diagnostics/EventText.cs deleted file mode 100644 --- a/Implab/Diagnostics/EventText.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Implab.Diagnostics { - public struct EventText { - public int indent; - - public string content; - } -} diff --git a/Implab/Diagnostics/ListenerBase.cs b/Implab/Diagnostics/ListenerBase.cs --- a/Implab/Diagnostics/ListenerBase.cs +++ b/Implab/Diagnostics/ListenerBase.cs @@ -59,8 +59,8 @@ namespace Implab.Diagnostics { public void UnsubscribeAll() { lock (m_subscriptions) { - foreach (var subscription in m_subscriptions.Values) - subscription(); + foreach (var remove in m_subscriptions.Values) + remove(); m_subscriptions.Clear(); } } diff --git a/Implab/Diagnostics/LogChannel.cs b/Implab/Diagnostics/LogChannel.cs --- a/Implab/Diagnostics/LogChannel.cs +++ b/Implab/Diagnostics/LogChannel.cs @@ -69,7 +69,7 @@ namespace Implab.Diagnostics { this, new LogEventArgs( data, - Name, + this, traceContext.ThreadId, traceContext.CurrentOperation, traceContext.CurrentOperation.Duration @@ -77,5 +77,9 @@ namespace Implab.Diagnostics { ); } } + + public override string ToString() { + return Name; + } } } diff --git a/Implab/Diagnostics/LogEventArgs.cs b/Implab/Diagnostics/LogEventArgs.cs --- a/Implab/Diagnostics/LogEventArgs.cs +++ b/Implab/Diagnostics/LogEventArgs.cs @@ -2,7 +2,7 @@ namespace Implab.Diagnostics { public class LogEventArgs : EventArgs { - public string ChannelName { + public object Channel { get; private set; } @@ -18,8 +18,8 @@ namespace Implab.Diagnostics { get; private set; } - public LogEventArgs(string channelName, int threadId, LogicalOperation operation, int timeOffset) { - ChannelName = channelName; + public LogEventArgs(object channel, int threadId, LogicalOperation operation, int timeOffset) { + Channel = channel; ThreadId = threadId; Operation = operation; OperationTimeOffset = timeOffset; diff --git a/Implab/Diagnostics/LogEventArgsT.cs b/Implab/Diagnostics/LogEventArgsT.cs --- a/Implab/Diagnostics/LogEventArgsT.cs +++ b/Implab/Diagnostics/LogEventArgsT.cs @@ -5,7 +5,7 @@ private set; } - public LogEventArgs(TEvent value,string channelName, int threadId, LogicalOperation operation, int timeOffset) : base(channelName, threadId, operation, timeOffset) { + public LogEventArgs(TEvent value,object channel, int threadId, LogicalOperation operation, int timeOffset) : base(channel, threadId, operation, timeOffset) { Value = value; } } diff --git a/Implab/Diagnostics/TextFileListener.cs b/Implab/Diagnostics/TextFileListener.cs --- a/Implab/Diagnostics/TextFileListener.cs +++ b/Implab/Diagnostics/TextFileListener.cs @@ -18,7 +18,7 @@ namespace Implab.Diagnostics { var msg = new StringBuilder(); for (int i = 0; i < args.Operation.Level; i++) msg.Append(" "); - msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, args.ChannelName, entry); + msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, args.Channel, entry); lock (m_textWriter) { if (!IsDisposed) { diff --git a/Implab/Implab.csproj b/Implab/Implab.csproj --- a/Implab/Implab.csproj +++ b/Implab/Implab.csproj @@ -77,7 +77,6 @@ - diff --git a/MonoPlay/Program.cs b/MonoPlay/Program.cs --- a/MonoPlay/Program.cs +++ b/MonoPlay/Program.cs @@ -4,39 +4,42 @@ using System.Threading.Tasks; using Implab.Formats.JSON; using System.IO; using System.Text.Json; +using System.Diagnostics; +using Implab.Parallels; +using System.Threading; namespace MonoPlay { class MainClass { public static void Main(string[] args) { - if (args == null) - throw new ArgumentNullException("args"); - int t1, t2; + var pool = new WorkerPool(10); - for (int i = 0; i < 2; i++) { - t1 = Environment.TickCount; - int elements =0; - using (var reader = new JSONParser(File.OpenText("/home/sergey/temp/citylots.json"))) { - while (reader.Read()) - elements++; - } + var listerner = new ConsoleTraceListener(); + listerner.TraceOutputOptions = TraceOptions.LogicalOperationStack; + Trace.Listeners.Add(listerner); + + Trace.CorrelationManager.StartLogicalOperation("Main"); - t2 = Environment.TickCount; - Console.WriteLine("attempt {0} done: {1} ms, {2:.00} Mb, {3} GC, Elements: {4}",i+1, t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0), elements ); - } + var d = pool.Invoke(() => { + Trace.CorrelationManager.StartLogicalOperation("Worker"); + Thread.Sleep(100); + Trace.TraceInformation("worker done"); + Trace.CorrelationManager.StopLogicalOperation(); + }); - Console.WriteLine("Syste.Text.Json"); - var paraser = new JsonParser(); - for (int i = 0; i < 2; i++) { - t1 = Environment.TickCount; - using (var reader = File.OpenText("/home/sergey/temp/citylots.json")) { - paraser.Parse(reader); - } + ThreadPool.QueueUserWorkItem((o) => { + Trace.CorrelationManager.StartLogicalOperation("Thread"); + Thread.Sleep(100); + Trace.TraceInformation("thread done"); + Trace.CorrelationManager.StopLogicalOperation(); + }); - t2 = Environment.TickCount; - Console.WriteLine("attempt {0} done: {1} ms, {2:.00} Mb, {3} GC, ",i+1, t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0)); - } + Trace.TraceInformation("main done"); + Trace.CorrelationManager.StopLogicalOperation(); + + d.Join(); + }