diff --git a/Implab.Playground/App.config b/Implab.Playground/App.config --- a/Implab.Playground/App.config +++ b/Implab.Playground/App.config @@ -1,6 +1,6 @@ - + diff --git a/Implab.Playground/Implab.Playground.csproj b/Implab.Playground/Implab.Playground.csproj --- a/Implab.Playground/Implab.Playground.csproj +++ b/Implab.Playground/Implab.Playground.csproj @@ -9,7 +9,7 @@ Properties Implab.Playground Implab.Playground - v4.5 + v4.6 512 true diff --git a/Implab.Playground/Program.cs b/Implab.Playground/Program.cs --- a/Implab.Playground/Program.cs +++ b/Implab.Playground/Program.cs @@ -1,4 +1,5 @@ -using Implab.Formats.Json; +using Implab.Diagnostics; +using Implab.Formats.Json; using Implab.Parallels; using Implab.Xml; using System; @@ -13,80 +14,42 @@ using System.Xml; using System.Xml.Serialization; namespace Implab.Playground { + using System.Diagnostics; + using System.Runtime.Remoting.Messaging; + using static Trace; + public class Program { - static void EnqueueRange(ConcurrentQueue q, T[] data, int offset, int len) { - for (var i = offset; i < offset + len; i++) - q.Enqueue(data[i]); - } + static void Main(string[] args) { + var listener = new SimpleTraceListener(Console.Out); + + var source = Trace.TraceSource; + source.Switch.Level = SourceLevels.All; - static bool TryDequeueRange(ConcurrentQueue q,T[] buffer,int offset, int len, out int actual) { - actual = 0; - T res; - while(q.TryDequeue(out res)) { - buffer[offset + actual] = res; - actual++; - if (actual == len) - break; - } - return actual != 0; - } + source.Listeners.Add(listener); + + var t = Environment.TickCount; - static void EnqueueRange(SimpleAsyncQueue q, T[] data, int offset, int len) { - for (var i = offset; i < offset + len; i++) - q.Enqueue(data[i]); - } + Main().Wait(); - static bool TryDequeueRange(SimpleAsyncQueue q, T[] buffer, int offset, int len, out int actual) { - actual = 0; - T res; - while (q.TryDequeue(out res)) { - buffer[offset + actual] = res; - actual++; - if (actual == len) - break; - } - return actual != 0; + Console.WriteLine($"Done: {Environment.TickCount - t} ms"); + Console.ReadKey(); } - static void EnqueueRange(AsyncQueue q, T[] data, int offset, int len) { - for (var i = offset; i < offset + len; i++) - q.Enqueue(data[i]); + static async Task Main() { + using (LogicalOperation(nameof(Main))) { + Log("Start"); + await SomeAsync(); + Log("End"); + } } - static bool TryDequeueRange(AsyncQueue q, T[] buffer, int offset, int len, out int actual) { - actual = 0; - T res; - while (q.TryDequeue(out res)) { - buffer[offset + actual] = res; - actual++; - if (actual == len) - break; + static async Task SomeAsync() { + using (LogicalOperation(nameof(SomeAsync))) { + Log("Do prepare"); + await Task.Yield(); + Log("Yield"); } - return actual != 0; - } - - - /*static void EnqueueRange(AsyncQueue q, T[] data, int offset, int len) { - q.EnqueueRange(data, offset, len); - } - - static bool TryDequeueRange(AsyncQueue q, T[] buffer, int offset, int len, out int actual) { - return q.TryDequeueRange(buffer, offset, len, out actual); - }*/ - - - static void Main(string[] args) { - - var t = Environment.TickCount; - using (var reader = JsonReader.Create("e:\\citylots.json")) { - while (reader.Read()) { - } - } - - Console.WriteLine($"JsonReader: {Environment.TickCount - t} ms"); - - Console.WriteLine("done"); } } } diff --git a/Implab.Test/Implab.Test.csproj b/Implab.Test/Implab.Test.csproj --- a/Implab.Test/Implab.Test.csproj +++ b/Implab.Test/Implab.Test.csproj @@ -1,12 +1,13 @@ - netcoreapp2.0 + net46 + /usr/lib/mono/4.5/ false - + diff --git a/Implab.sln b/Implab.sln new file mode 100644 --- /dev/null +++ b/Implab.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27428.2005 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Implab", "Implab\Implab.csproj", "{FF2052B6-9C8F-4022-A347-F07ABF635885}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Implab.Test", "Implab.Test\Implab.Test.csproj", "{6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Playground", "Implab.Playground\Implab.Playground.csproj", "{100DFEB0-75BE-436F-ADDF-1F46EF433F46}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FF2052B6-9C8F-4022-A347-F07ABF635885}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF2052B6-9C8F-4022-A347-F07ABF635885}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF2052B6-9C8F-4022-A347-F07ABF635885}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF2052B6-9C8F-4022-A347-F07ABF635885}.Release|Any CPU.Build.0 = Release|Any CPU + {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Release|Any CPU.Build.0 = Release|Any CPU + {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {36D837FC-4CDD-4AEA-87BF-F130FEB22E02} + EndGlobalSection +EndGlobal diff --git a/Implab/Diagnostics/Trace.cs b/Implab/Diagnostics/Trace.cs --- a/Implab/Diagnostics/Trace.cs +++ b/Implab/Diagnostics/Trace.cs @@ -3,21 +3,21 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Implab.Diagnostics { public static class Trace { - readonly static TraceSource _traceSource = new TraceSource(typeof(T).Name); - - public static TraceSource TraceSource { - get { return _traceSource; } - } - + public static TraceSource TraceSource { get; } = new TraceSource(typeof(T).Name); + +#if NETFX_TRACE_BUG + readonly static AsyncLocal m_currentOperation = new AsyncLocal(); +#endif + /// /// Starts the logical operation nested to the current operation nested to the current one. /// - [Conditional("TRACE")] public static void StartLogicalOperation() { Trace.CorrelationManager.StartLogicalOperation(); @@ -27,15 +27,20 @@ namespace Implab.Diagnostics { /// Starts the logical operation with the specified name, this name is usefull in logs. /// /// Name. - [Conditional("TRACE")] - public static void StartLogicalOperation(string name) { +#if NETFX_TRACE_BUG + public static void StartLogicalOperation(object name) { + m_currentOperation.Value = name; Trace.CorrelationManager.StartLogicalOperation(name); } +#else + public static void StartLogicalOperation(object name) { + Trace.CorrelationManager.StartLogicalOperation(name); + } +#endif /// /// Ends the logical operation and restores the previous one. /// - [Conditional("TRACE")] public static void StopLogicalOperation() { Trace.CorrelationManager.StopLogicalOperation(); } @@ -120,7 +125,7 @@ namespace Implab.Diagnostics { public static LogicalOperationScope LogicalOperation(string name) { var operation = new LogicalOperation(name); TraceSource.TraceData(TraceEventType.Information, TraceEventCodes.StartLogicalOperation, operation); - Trace.CorrelationManager.StartLogicalOperation(operation); + StartLogicalOperation(operation); return new LogicalOperationScope(TraceSource, operation); } } diff --git a/Implab/Implab.csproj b/Implab/Implab.csproj --- a/Implab/Implab.csproj +++ b/Implab/Implab.csproj @@ -11,8 +11,9 @@ https://opensource.org/licenses/BSD-2-Clause https://implab.org https://hg.implab.org/pub/ImplabNet/ - netstandard2.0;net45 - /usr/lib/mono/4.5/ + netstandard2.0;net46 + /usr/lib/mono/4.5/ + NETFX_TRACE_BUG;$(DefineConstants)