##// END OF EJS Templates
Adde workaround to the behaviour of the logical operations stack in conjuction...
cin -
r255:b00441e04738 v3
parent child
Show More
@@ -0,0 +1,37
1 
2 Microsoft Visual Studio Solution File, Format Version 12.00
3 # Visual Studio 15
4 VisualStudioVersion = 15.0.27428.2005
5 MinimumVisualStudioVersion = 10.0.40219.1
6 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Implab", "Implab\Implab.csproj", "{FF2052B6-9C8F-4022-A347-F07ABF635885}"
7 EndProject
8 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Implab.Test", "Implab.Test\Implab.Test.csproj", "{6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}"
9 EndProject
10 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Playground", "Implab.Playground\Implab.Playground.csproj", "{100DFEB0-75BE-436F-ADDF-1F46EF433F46}"
11 EndProject
12 Global
13 GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 Debug|Any CPU = Debug|Any CPU
15 Release|Any CPU = Release|Any CPU
16 EndGlobalSection
17 GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 {FF2052B6-9C8F-4022-A347-F07ABF635885}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 {FF2052B6-9C8F-4022-A347-F07ABF635885}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 {FF2052B6-9C8F-4022-A347-F07ABF635885}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 {FF2052B6-9C8F-4022-A347-F07ABF635885}.Release|Any CPU.Build.0 = Release|Any CPU
22 {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Release|Any CPU.Build.0 = Release|Any CPU
26 {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Release|Any CPU.Build.0 = Release|Any CPU
30 EndGlobalSection
31 GlobalSection(SolutionProperties) = preSolution
32 HideSolutionNode = FALSE
33 EndGlobalSection
34 GlobalSection(ExtensibilityGlobals) = postSolution
35 SolutionGuid = {36D837FC-4CDD-4AEA-87BF-F130FEB22E02}
36 EndGlobalSection
37 EndGlobal
@@ -1,6 +1,6
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <configuration>
3 3 <startup>
4 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
4 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
5 5 </startup>
6 6 </configuration>
@@ -1,69 +1,69
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4 4 <PropertyGroup>
5 5 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6 6 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7 7 <ProjectGuid>{100DFEB0-75BE-436F-ADDF-1F46EF433F46}</ProjectGuid>
8 8 <OutputType>Exe</OutputType>
9 9 <AppDesignerFolder>Properties</AppDesignerFolder>
10 10 <RootNamespace>Implab.Playground</RootNamespace>
11 11 <AssemblyName>Implab.Playground</AssemblyName>
12 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12 <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
13 13 <FileAlignment>512</FileAlignment>
14 14 <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15 15 <TargetFrameworkProfile />
16 16 </PropertyGroup>
17 17 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18 18 <PlatformTarget>AnyCPU</PlatformTarget>
19 19 <DebugSymbols>true</DebugSymbols>
20 20 <DebugType>full</DebugType>
21 21 <Optimize>false</Optimize>
22 22 <OutputPath>bin\Debug\</OutputPath>
23 23 <DefineConstants>DEBUG;TRACE</DefineConstants>
24 24 <ErrorReport>prompt</ErrorReport>
25 25 <WarningLevel>4</WarningLevel>
26 26 </PropertyGroup>
27 27 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28 28 <PlatformTarget>AnyCPU</PlatformTarget>
29 29 <DebugType>pdbonly</DebugType>
30 30 <Optimize>true</Optimize>
31 31 <OutputPath>bin\Release\</OutputPath>
32 32 <DefineConstants>TRACE</DefineConstants>
33 33 <ErrorReport>prompt</ErrorReport>
34 34 <WarningLevel>4</WarningLevel>
35 35 <Prefer32Bit>true</Prefer32Bit>
36 36 <DebugSymbols>true</DebugSymbols>
37 37 </PropertyGroup>
38 38 <ItemGroup>
39 39 <Reference Include="System" />
40 40 <Reference Include="System.Core" />
41 41 <Reference Include="System.Xml.Linq" />
42 42 <Reference Include="System.Data.DataSetExtensions" />
43 43 <Reference Include="Microsoft.CSharp" />
44 44 <Reference Include="System.Data" />
45 45 <Reference Include="System.Net.Http" />
46 46 <Reference Include="System.Xml" />
47 47 </ItemGroup>
48 48 <ItemGroup>
49 49 <Compile Include="Program.cs" />
50 50 <Compile Include="Properties\AssemblyInfo.cs" />
51 51 </ItemGroup>
52 52 <ItemGroup>
53 53 <None Include="App.config" />
54 54 </ItemGroup>
55 55 <ItemGroup>
56 56 <ProjectReference Include="..\Implab\Implab.csproj">
57 57 <Project>{f550f1f8-8746-4ad0-9614-855f4c4b7f05}</Project>
58 58 <Name>Implab</Name>
59 59 </ProjectReference>
60 60 </ItemGroup>
61 61 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62 62 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
63 63 Other similar extension points exist, see Microsoft.Common.targets.
64 64 <Target Name="BeforeBuild">
65 65 </Target>
66 66 <Target Name="AfterBuild">
67 67 </Target>
68 68 -->
69 69 </Project> No newline at end of file
@@ -1,92 +1,55
1 using Implab.Formats.Json;
1 using Implab.Diagnostics;
2 using Implab.Formats.Json;
2 3 using Implab.Parallels;
3 4 using Implab.Xml;
4 5 using System;
5 6 using System.Collections.Concurrent;
6 7 using System.Collections.Generic;
7 8 using System.IO;
8 9 using System.Linq;
9 10 using System.Text;
10 11 using System.Threading;
11 12 using System.Threading.Tasks;
12 13 using System.Xml;
13 14 using System.Xml.Serialization;
14 15
15 16 namespace Implab.Playground {
17 using System.Diagnostics;
18 using System.Runtime.Remoting.Messaging;
19 using static Trace<Program>;
20
16 21 public class Program {
17 22
18 static void EnqueueRange<T>(ConcurrentQueue<T> q, T[] data, int offset, int len) {
19 for (var i = offset; i < offset + len; i++)
20 q.Enqueue(data[i]);
21 }
23 static void Main(string[] args) {
24 var listener = new SimpleTraceListener(Console.Out);
25
26 var source = Trace<Program>.TraceSource;
27 source.Switch.Level = SourceLevels.All;
22 28
23 static bool TryDequeueRange<T>(ConcurrentQueue<T> q,T[] buffer,int offset, int len, out int actual) {
24 actual = 0;
25 T res;
26 while(q.TryDequeue(out res)) {
27 buffer[offset + actual] = res;
28 actual++;
29 if (actual == len)
30 break;
31 }
32 return actual != 0;
33 }
29 source.Listeners.Add(listener);
30
31 var t = Environment.TickCount;
34 32
35 static void EnqueueRange<T>(SimpleAsyncQueue<T> q, T[] data, int offset, int len) {
36 for (var i = offset; i < offset + len; i++)
37 q.Enqueue(data[i]);
33 Main().Wait();
34
35 Console.WriteLine($"Done: {Environment.TickCount - t} ms");
36 Console.ReadKey();
38 37 }
39 38
40 static bool TryDequeueRange<T>(SimpleAsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) {
41 actual = 0;
42 T res;
43 while (q.TryDequeue(out res)) {
44 buffer[offset + actual] = res;
45 actual++;
46 if (actual == len)
47 break;
48 }
49 return actual != 0;
50 }
51
52 static void EnqueueRange<T>(AsyncQueue<T> q, T[] data, int offset, int len) {
53 for (var i = offset; i < offset + len; i++)
54 q.Enqueue(data[i]);
55 }
56
57 static bool TryDequeueRange<T>(AsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) {
58 actual = 0;
59 T res;
60 while (q.TryDequeue(out res)) {
61 buffer[offset + actual] = res;
62 actual++;
63 if (actual == len)
64 break;
65 }
66 return actual != 0;
67 }
68
69
70 /*static void EnqueueRange<T>(AsyncQueue<T> q, T[] data, int offset, int len) {
71 q.EnqueueRange(data, offset, len);
72 }
73
74 static bool TryDequeueRange<T>(AsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) {
75 return q.TryDequeueRange(buffer, offset, len, out actual);
76 }*/
77
78
79 static void Main(string[] args) {
80
81 var t = Environment.TickCount;
82 using (var reader = JsonReader.Create("e:\\citylots.json")) {
83 while (reader.Read()) {
39 static async Task Main() {
40 using (LogicalOperation(nameof(Main))) {
41 Log("Start");
42 await SomeAsync();
43 Log("End");
84 44 }
85 45 }
86 46
87 Console.WriteLine($"JsonReader: {Environment.TickCount - t} ms");
88
89 Console.WriteLine("done");
47 static async Task SomeAsync() {
48 using (LogicalOperation(nameof(SomeAsync))) {
49 Log("Do prepare");
50 await Task.Yield();
51 Log("Yield");
90 52 }
91 53 }
92 54 }
55 }
@@ -1,16 +1,17
1 1 <Project Sdk="Microsoft.NET.Sdk">
2 2
3 3 <PropertyGroup>
4 <TargetFramework>netcoreapp2.0</TargetFramework>
4 <TargetFramework>net46</TargetFramework>
5 <FrameworkPathOverride Condition="'$(TargetFramework)'=='net45' and '$(OSTYPE)'=='linux'">/usr/lib/mono/4.5/</FrameworkPathOverride>
5 6
6 7 <IsPackable>false</IsPackable>
7 8 </PropertyGroup>
8 9 <ItemGroup>
9 10 <ProjectReference Include="../Implab/Implab.csproj"/>
10 11 <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
11 12 <PackageReference Include="xunit" Version="2.3.1" />
12 13 <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
13 14 <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
14 15 </ItemGroup>
15 16
16 17 </Project>
@@ -1,127 +1,132
1 1 using System;
2 2 using System.Collections.Generic;
3 3 using System.Diagnostics;
4 4 using System.Linq;
5 5 using System.Text;
6 using System.Threading;
6 7 using System.Threading.Tasks;
7 8
8 9 namespace Implab.Diagnostics {
9 10 public static class Trace<T> {
10 11
11 readonly static TraceSource _traceSource = new TraceSource(typeof(T).Name);
12 public static TraceSource TraceSource { get; } = new TraceSource(typeof(T).Name);
12 13
13 public static TraceSource TraceSource {
14 get { return _traceSource; }
15 }
14 #if NETFX_TRACE_BUG
15 readonly static AsyncLocal<object> m_currentOperation = new AsyncLocal<object>();
16 #endif
16 17
17 18 /// <summary>
18 19 /// Starts the logical operation nested to the current operation nested to the current one.
19 20 /// </summary>
20 [Conditional("TRACE")]
21 21 public static void StartLogicalOperation() {
22 22 Trace.CorrelationManager.StartLogicalOperation();
23 23
24 24 }
25 25
26 26 /// <summary>
27 27 /// Starts the logical operation with the specified name, this name is usefull in logs.
28 28 /// </summary>
29 29 /// <param name="name">Name.</param>
30 [Conditional("TRACE")]
31 public static void StartLogicalOperation(string name) {
30 #if NETFX_TRACE_BUG
31 public static void StartLogicalOperation(object name) {
32 m_currentOperation.Value = name;
32 33 Trace.CorrelationManager.StartLogicalOperation(name);
33 34 }
35 #else
36 public static void StartLogicalOperation(object name) {
37 Trace.CorrelationManager.StartLogicalOperation(name);
38 }
39 #endif
34 40
35 41 /// <summary>
36 42 /// Ends the logical operation and restores the previous one.
37 43 /// </summary>
38 [Conditional("TRACE")]
39 44 public static void StopLogicalOperation() {
40 45 Trace.CorrelationManager.StopLogicalOperation();
41 46 }
42 47
43 48 /// <summary>
44 49 /// Writes an informational message.
45 50 /// </summary>
46 51 /// <param name="format">Format.</param>
47 52 /// <param name="arguments">Arguments.</param>
48 53 [Conditional("TRACE")]
49 54 public static void Log(string format, params object[] arguments) {
50 55 TraceSource.TraceEvent(TraceEventType.Information, 0, format, arguments);
51 56 }
52 57
53 58 /// <summary>
54 59 /// Writes a warning message.
55 60 /// </summary>
56 61 /// <param name="format">Format.</param>
57 62 /// <param name="arguments">Arguments.</param>
58 63 [Conditional("TRACE")]
59 64 public static void Warn(string format, params object[] arguments) {
60 65 TraceSource.TraceEvent(TraceEventType.Warning, 0, format, arguments);
61 66 }
62 67
63 68 [Conditional("TRACE")]
64 69 public static void Error(string format, params object[] arguments) {
65 70 TraceSource.TraceEvent(TraceEventType.Error, 0, format, arguments);
66 71 }
67 72
68 73 [Conditional("TRACE")]
69 74 public static void Error(Exception err) {
70 75 TraceSource.TraceData(TraceEventType.Error, 0, err);
71 76 }
72 77
73 78 /// <summary>
74 79 /// This method save the current activity, and transfers to the specified activity,
75 80 /// emits <see cref="TraceEventType.Start"/> and returns a scope of the new
76 81 /// activity.
77 82 /// </summary>
78 83 /// <param name="activityName">The name of the new activity/</param>
79 84 /// <param name="activityId">The identifier of the activity to which
80 85 /// the control will be transferred</param>
81 86 /// <returns>A scope of the new activity, dispose it to transfer
82 87 /// the control back to the original activity.</returns>
83 88 public static ActivityScope TransferActivity(string activityName, Guid activityId) {
84 89 var prev = Trace.CorrelationManager.ActivityId;
85 90
86 91 TraceSource.TraceTransfer(0, "Transfer", activityId);
87 92 Trace.CorrelationManager.ActivityId = activityId;
88 93 TraceSource.TraceEvent(TraceEventType.Start, 0, activityName);
89 94
90 95 return new ActivityScope(TraceSource, prev, 0, activityName);
91 96 }
92 97
93 98 /// <summary>
94 99 /// Emits <see cref="TraceEventType.Start"/> and returns a scope of the
95 100 /// activity.
96 101 /// </summary>
97 102 /// <param name="activityName">The name of the activity to start</param>
98 103 /// <returns>A scope of the new activity, dispose it to emit
99 104 /// <see cref="TraceEventType.Stop"/> for the current activity.</returns>
100 105 public static ActivityScope StartActivity(string activityName) {
101 106 if (Trace.CorrelationManager.ActivityId == Guid.Empty)
102 107 Trace.CorrelationManager.ActivityId = Guid.NewGuid();
103 108
104 109 var prev = Trace.CorrelationManager.ActivityId;
105 110
106 111 TraceSource.TraceEvent(TraceEventType.Start, 0, activityName);
107 112 return new ActivityScope(TraceSource, prev, 0, activityName);
108 113 }
109 114
110 115 /// <summary>
111 116 /// Creates new <see cref="LogicalOperation(string)"/> and calls
112 117 /// to <see cref="CorrelationManager.StartLogicalOperation(object)"/>
113 118 /// passing the created operation as identity. Calls
114 119 /// <see cref="TraceSource.TraceData(TraceEventType, int, object)"/>
115 120 /// to notify listeners on operation start.
116 121 /// </summary>
117 122 /// <param name="name">The name of the logical operation.</param>
118 123 /// <returns>Logical operation scope, disposing it will stop
119 124 /// logical operation and notify trace listeners.</returns>
120 125 public static LogicalOperationScope LogicalOperation(string name) {
121 126 var operation = new LogicalOperation(name);
122 127 TraceSource.TraceData(TraceEventType.Information, TraceEventCodes.StartLogicalOperation, operation);
123 Trace.CorrelationManager.StartLogicalOperation(operation);
128 StartLogicalOperation(operation);
124 129 return new LogicalOperationScope(TraceSource, operation);
125 130 }
126 131 }
127 132 }
@@ -1,18 +1,19
1 1 <Project Sdk="Microsoft.NET.Sdk">
2 2
3 3 <PropertyGroup>
4 4 <Authors>Sergey Smirnov</Authors>
5 5 <Title>Implab library</Title>
6 6 <Description>Provides some helper clesses like XML serialization helpers, JSON XML reader,
7 7 JSON pull-parser, ECMA-style promises, lightweight synchonization routines Signal
8 8 and SharedLock, Trace helpers on top of System.Diagnostics, ObjectPool etc.
9 9 </Description>
10 10 <Copyright>2012-2018 Sergey Smirnov</Copyright>
11 11 <LicenseUrl>https://opensource.org/licenses/BSD-2-Clause</LicenseUrl>
12 12 <ProjectUrl>https://implab.org</ProjectUrl>
13 13 <RepositoryUrl>https://hg.implab.org/pub/ImplabNet/</RepositoryUrl>
14 <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
15 <FrameworkPathOverride Condition="'$(TargetFramework)'=='net45' and '$(OSTYPE)'=='linux'">/usr/lib/mono/4.5/</FrameworkPathOverride>
14 <TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
15 <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46' and '$(OSTYPE)'=='linux'">/usr/lib/mono/4.5/</FrameworkPathOverride>
16 <DefineConstants Condition="'$(TargetFramework)'=='net46'">NETFX_TRACE_BUG;$(DefineConstants)</DefineConstants>
16 17 </PropertyGroup>
17 18
18 19 </Project>
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

ok, latest stable version should be in default

You need to be logged in to leave comments. Login now