##// END OF EJS Templates
working on diagnostics
cin -
r194:d45bdf510514 v2
parent child
Show More
@@ -1,195 +1,195
1 1 using System;
2 2 using System.Reflection;
3 3 using System.Threading;
4 4 using Implab.Parallels;
5 5 using Implab.Components;
6 6
7 7 #if MONO
8 8
9 9 using NUnit.Framework;
10 10 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
11 11 using TestMethodAttribute = NUnit.Framework.TestAttribute;
12 12 using AssertFailedException = NUnit.Framework.AssertionException;
13 13 #else
14 14
15 15 using Microsoft.VisualStudio.TestTools.UnitTesting;
16 16
17 17 #endif
18 18
19 19 namespace Implab.Test {
20 20 [TestClass]
21 21 public class RunnableComponentTests {
22 22
23 23 static void ShouldThrow(Action action) {
24 24 try {
25 25 action();
26 26 Assert.Fail();
27 27 } catch (AssertFailedException) {
28 28 throw;
29 29 } catch {
30 30 }
31 31 }
32 32
33 33 class Runnable : RunnableComponent {
34 34 public Runnable(bool initialized) : base(initialized) {
35 35 }
36 36
37 37 public Action MockInit {
38 38 get;
39 39 set;
40 40 }
41 41
42 42 public Func<IPromise> MockStart {
43 43 get;
44 44 set;
45 45 }
46 46
47 47 public Func<IPromise> MockStop {
48 48 get;
49 49 set;
50 50 }
51 51
52 52 protected override IPromise OnStart() {
53 53 return MockStart != null ? MockStart() : base.OnStart();
54 54 }
55 55
56 56 protected override IPromise OnStop() {
57 57 return MockStop != null ? MockStop() : base.OnStart();
58 58 }
59 59
60 60 protected override void OnInitialize() {
61 61 if (MockInit != null)
62 62 MockInit();
63 63 }
64 64 }
65 65
66 66 [TestMethod]
67 67 public void NormalFlowTest() {
68 68 var comp = new Runnable(false);
69 69
70 70 Assert.AreEqual(ExecutionState.Created, comp.State);
71 71
72 72 comp.Init();
73 73
74 74 Assert.AreEqual(ExecutionState.Ready, comp.State);
75 75
76 76 comp.Start().Join(1000);
77 77
78 78 Assert.AreEqual(ExecutionState.Running, comp.State);
79 79
80 80 comp.Stop().Join(1000);
81 81
82 82 Assert.AreEqual(ExecutionState.Disposed, comp.State);
83 83
84 84 }
85 85
86 86 [TestMethod]
87 87 public void InitFailTest() {
88 88 var comp = new Runnable(false) {
89 89 MockInit = () => {
90 90 throw new Exception("BAD");
91 91 }
92 92 };
93 93
94 94 ShouldThrow(() => comp.Start());
95 95 ShouldThrow(() => comp.Stop());
96 96 Assert.AreEqual(ExecutionState.Created, comp.State);
97 97
98 98 ShouldThrow(comp.Init);
99 99
100 100 Assert.AreEqual(ExecutionState.Failed, comp.State);
101 101
102 102 ShouldThrow(() => comp.Start());
103 103 ShouldThrow(() => comp.Stop());
104 104 Assert.AreEqual(ExecutionState.Failed, comp.State);
105 105
106 106 comp.Dispose();
107 107 Assert.AreEqual(ExecutionState.Disposed, comp.State);
108 108 }
109 109
110 110 [TestMethod]
111 111 public void DisposedTest() {
112 112
113 113 var comp = new Runnable(false);
114 114 comp.Dispose();
115 115
116 116 ShouldThrow(() => comp.Start());
117 117 ShouldThrow(() => comp.Stop());
118 118 ShouldThrow(comp.Init);
119 119
120 120 Assert.AreEqual(ExecutionState.Disposed, comp.State);
121 121 }
122 122
123 123 [TestMethod]
124 124 public void StartCancelTest() {
125 125 var comp = new Runnable(true) {
126 126 MockStart = () => PromiseHelper.Sleep(100000, 0)
127 127 };
128 128
129 129 var p = comp.Start();
130 130 Assert.AreEqual(ExecutionState.Starting, comp.State);
131 131 p.Cancel();
132 132 ShouldThrow(() => p.Join(1000));
133 133 Assert.AreEqual(ExecutionState.Failed, comp.State);
134 134
135 Assert.IsInstanceOfType(comp.LastError, typeof(OperationCanceledException));
135 Assert.IsTrue(comp.LastError is OperationCanceledException);
136 136
137 137 comp.Dispose();
138 138 }
139 139
140 140 [TestMethod]
141 141 public void StartStopTest() {
142 142 var stop = new Signal();
143 143 var comp = new Runnable(true) {
144 144 MockStart = () => PromiseHelper.Sleep(100000, 0),
145 145 MockStop = () => AsyncPool.RunThread(stop.Wait)
146 146 };
147 147
148 148 var p1 = comp.Start();
149 149 var p2 = comp.Stop();
150 150 // should enter stopping state
151 151
152 152 ShouldThrow(p1.Join);
153 153 Assert.IsTrue(p1.IsCancelled);
154 154 Assert.AreEqual(ExecutionState.Stopping, comp.State);
155 155
156 156 stop.Set();
157 157 p2.Join(1000);
158 158 Assert.AreEqual(ExecutionState.Disposed, comp.State);
159 159 }
160 160
161 161 [TestMethod]
162 162 public void StartStopFailTest() {
163 163 var comp = new Runnable(true) {
164 164 MockStart = () => PromiseHelper.Sleep(100000, 0).Then(null,null,x => { throw new Exception("I'm dead"); })
165 165 };
166 166
167 167 comp.Start();
168 168 var p = comp.Stop();
169 169 // if Start fails to cancel, should fail to stop
170 170 ShouldThrow(() => p.Join(1000));
171 171 Assert.AreEqual(ExecutionState.Failed, comp.State);
172 172 Assert.IsNotNull(comp.LastError);
173 173 Assert.AreEqual("I'm dead", comp.LastError.Message);
174 174 }
175 175
176 176 [TestMethod]
177 177 public void StopCancelTest() {
178 178 var comp = new Runnable(true) {
179 179 MockStop = () => PromiseHelper.Sleep(100000, 0)
180 180 };
181 181
182 182 comp.Start();
183 183 var p = comp.Stop();
184 184 Assert.AreEqual(ExecutionState.Stopping, comp.State);
185 185 p.Cancel();
186 186 ShouldThrow(() => p.Join(1000));
187 187 Assert.AreEqual(ExecutionState.Failed, comp.State);
188 Assert.IsInstanceOfType(comp.LastError, typeof(OperationCanceledException));
188 Assert.IsTrue(comp.LastError is OperationCanceledException);
189 189
190 190 comp.Dispose();
191 191 }
192 192
193 193 }
194 194 }
195 195
@@ -1,86 +1,86
1 1 using System;
2 2 using System.Collections.Generic;
3 3 using Implab.Components;
4 4
5 5 namespace Implab.Diagnostics {
6 6 public abstract class ListenerBase : ServiceLocator, ILogWriter<object>, ILogWriter<TraceEvent> {
7 7
8 8 readonly Dictionary<object, Action> m_subscriptions = new Dictionary<object, Action>();
9 9
10 10 protected ListenerBase() {
11 11 Register(this);
12 12 }
13 13
14 14 public void Subscribe(Type eventType) {
15 15 if (eventType == null)
16 16 throw new ArgumentNullException("eventType");
17 17 GetType().GetMethod("Subscribe", new Type[0]).MakeGenericMethod(eventType).Invoke(this, null);
18 18 }
19 19
20 20 public void Subscribe<TEvent>() {
21 21 Subscribe<TEvent>(LogChannel<TEvent>.Default);
22 22 }
23 23
24 24 public void Subscribe<TEvent>(LogChannel<TEvent> channel) {
25 25 if (channel == null)
26 26 throw new ArgumentNullException("channel");
27 27
28 28 lock (m_subscriptions) {
29 29 AssertNotDisposed();
30 30 if (m_subscriptions.ContainsKey(channel))
31 31 return;
32 32
33 33 var writer = GetService<ILogWriter<TEvent>>();
34 34
35 35 EventHandler<LogEventArgs<TEvent>> handler = (sender, args) => writer.Write(args,args.Value);
36 36
37 37 channel.Events += handler;
38 38
39 39 Action unsubscribe = () => {
40 40 channel.Events -= handler;
41 41 };
42 42
43 43 m_subscriptions.Add(channel, unsubscribe);
44 44 }
45 45 }
46 46
47 47 public void Unsubscribe<TEvent>(LogChannel<TEvent> channel) {
48 48 if (channel == null)
49 49 throw new ArgumentNullException("channel");
50 50
51 51 lock (m_subscriptions) {
52 52 Action subscription;
53 53 if (m_subscriptions.TryGetValue(channel, out subscription)) {
54 54 subscription();
55 55 m_subscriptions.Remove(channel);
56 56 }
57 57 }
58 58 }
59 59
60 60 public void UnsubscribeAll() {
61 61 lock (m_subscriptions) {
62 foreach (var subscription in m_subscriptions.Values)
63 subscription();
62 foreach (var remove in m_subscriptions.Values)
63 remove();
64 64 m_subscriptions.Clear();
65 65 }
66 66 }
67 67
68 68 #region ILogWriter implementation
69 69 public abstract void Write(LogEventArgs args, object entry);
70 70 #endregion
71 71
72 72 #region ILogWriter implementation
73 73 public virtual void Write(LogEventArgs args, TraceEvent entry) {
74 74 Write(args, (object)entry);
75 75 }
76 76 #endregion
77 77
78 78
79 79 protected override void Dispose(bool disposing) {
80 80 base.Dispose(disposing);
81 81 if (disposing) {
82 82 UnsubscribeAll();
83 83 }
84 84 }
85 85 }
86 86 }
@@ -1,81 +1,85
1 1 using System;
2 2 using System.Collections.Generic;
3 3 using System.Linq;
4 4 using System.Text;
5 5
6 6 namespace Implab.Diagnostics {
7 7 /// <summary>
8 8 /// Канал, через который публикуются события журнала.
9 9 /// </summary>
10 10 /// <typeparam name="TEvent">Тип событий в канале</typeparam>
11 11 /// <remarks>
12 12 /// Событиями журнала могут быть любые типы, например строки, в которых будет передаваться
13 13 /// информация, или структуры с набором полей, описывающих важность, текст и другую информацию.
14 14 /// </remarks>
15 15 public class LogChannel<TEvent> {
16 16 static LogChannel<TEvent> _default = new LogChannel<TEvent>();
17 17
18 18 /// <summary>
19 19 /// Канал по-умолчанию для событий типа <typeparam name="TEvent"/>.
20 20 /// </summary>
21 21 public static LogChannel<TEvent> Default {
22 22 get {
23 23 return _default;
24 24 }
25 25 }
26 26
27 27 /// <summary>
28 28 /// Событие появление новой записи в журнале, на это событие подписываются слушатели.
29 29 /// </summary>
30 30 public event EventHandler<LogEventArgs<TEvent>> Events;
31 31
32 32 /// <summary>
33 33 /// Имя канала, полезно для отображения в журнале
34 34 /// </summary>
35 35 public string Name {
36 36 get;
37 37 private set;
38 38 }
39 39
40 40 /// <summary>
41 41 /// Создает журнал, имя типа событий назначается в качетве имени канала.
42 42 /// </summary>
43 43 public LogChannel()
44 44 : this(null) {
45 45 }
46 46
47 47 /// <summary>
48 48 /// Содает канал с указанным именем.
49 49 /// </summary>
50 50 /// <param name="name">Имя канала.</param>
51 51 public LogChannel(string name) {
52 52 if (String.IsNullOrEmpty(name))
53 53 name = typeof(TEvent).Name;
54 54 Name = name;
55 55 }
56 56
57 57 /// <summary>
58 58 /// Отправляет запись журнала через канал подписчикам.
59 59 /// </summary>
60 60 /// <param name="data">Запись журнала.</param>
61 61 /// <remarks>
62 62 /// Контекст трассировки от которого рассылается сообщение определяется автоматически из текущего потока.
63 63 /// </remarks>
64 64 public void LogEvent(TEvent data) {
65 65 var t = Events;
66 66 if (t != null) {
67 67 var traceContext = TraceContext.Instance;
68 68 t(
69 69 this,
70 70 new LogEventArgs<TEvent>(
71 71 data,
72 Name,
72 this,
73 73 traceContext.ThreadId,
74 74 traceContext.CurrentOperation,
75 75 traceContext.CurrentOperation.Duration
76 76 )
77 77 );
78 78 }
79 79 }
80
81 public override string ToString() {
82 return Name;
83 }
80 84 }
81 85 }
@@ -1,29 +1,29
1 1 using System;
2 2
3 3 namespace Implab.Diagnostics {
4 4 public class LogEventArgs : EventArgs {
5 public string ChannelName {
5 public object Channel {
6 6 get;
7 7 private set;
8 8 }
9 9 public int ThreadId {
10 10 get;
11 11 private set;
12 12 }
13 13 public LogicalOperation Operation {
14 14 get;
15 15 private set;
16 16 }
17 17 public int OperationTimeOffset {
18 18 get;
19 19 private set;
20 20 }
21 public LogEventArgs(string channelName, int threadId, LogicalOperation operation, int timeOffset) {
22 ChannelName = channelName;
21 public LogEventArgs(object channel, int threadId, LogicalOperation operation, int timeOffset) {
22 Channel = channel;
23 23 ThreadId = threadId;
24 24 Operation = operation;
25 25 OperationTimeOffset = timeOffset;
26 26 }
27 27 }
28 28 }
29 29
@@ -1,13 +1,13
1 1 namespace Implab.Diagnostics {
2 2 public class LogEventArgs<TEvent> : LogEventArgs {
3 3 public TEvent Value {
4 4 get;
5 5 private set;
6 6 }
7 7
8 public LogEventArgs(TEvent value,string channelName, int threadId, LogicalOperation operation, int timeOffset) : base(channelName, threadId, operation, timeOffset) {
8 public LogEventArgs(TEvent value,object channel, int threadId, LogicalOperation operation, int timeOffset) : base(channel, threadId, operation, timeOffset) {
9 9 Value = value;
10 10 }
11 11 }
12 12 }
13 13
@@ -1,46 +1,46
1 1 using System;
2 2 using System.IO;
3 3 using System.Text;
4 4
5 5 namespace Implab.Diagnostics {
6 6 public class TextFileListener: ListenerBase {
7 7 readonly TextWriter m_textWriter;
8 8
9 9 public TextFileListener(string fileName) {
10 10 m_textWriter = File.CreateText(fileName);
11 11
12 12 m_textWriter.WriteLine("LOG {0}", DateTime.Now);
13 13 }
14 14
15 15 #region implemented abstract members of ListenerBase
16 16
17 17 public override void Write(LogEventArgs args, object entry) {
18 18 var msg = new StringBuilder();
19 19 for (int i = 0; i < args.Operation.Level; i++)
20 20 msg.Append(" ");
21 msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, args.ChannelName, entry);
21 msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, args.Channel, entry);
22 22
23 23 lock (m_textWriter) {
24 24 if (!IsDisposed) {
25 25 // тут гарантировано еще не освобожден m_textWriter
26 26 m_textWriter.WriteLine(msg);
27 27 m_textWriter.Flush();
28 28 }
29 29 }
30 30 }
31 31
32 32 #endregion
33 33
34 34 protected override void Dispose(bool disposing) {
35 35 base.Dispose(disposing);
36 36 if (disposing) {
37 37 // IsDisposed = true
38 38 lock (m_textWriter) {
39 39 Safe.Dispose(m_textWriter);
40 40 }
41 41 }
42 42 }
43 43
44 44
45 45 }
46 46 }
@@ -1,276 +1,275
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3 <PropertyGroup>
4 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6 6 <ProjectGuid>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</ProjectGuid>
7 7 <OutputType>Library</OutputType>
8 8 <RootNamespace>Implab</RootNamespace>
9 9 <AssemblyName>Implab</AssemblyName>
10 10 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11 11 <ReleaseVersion>0.2</ReleaseVersion>
12 12 <ProductVersion>8.0.30703</ProductVersion>
13 13 <SchemaVersion>2.0</SchemaVersion>
14 14 </PropertyGroup>
15 15 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16 16 <DebugSymbols>true</DebugSymbols>
17 17 <DebugType>full</DebugType>
18 18 <Optimize>false</Optimize>
19 19 <OutputPath>bin\Debug</OutputPath>
20 20 <DefineConstants>TRACE;DEBUG;</DefineConstants>
21 21 <ErrorReport>prompt</ErrorReport>
22 22 <WarningLevel>4</WarningLevel>
23 23 <ConsolePause>false</ConsolePause>
24 24 <RunCodeAnalysis>true</RunCodeAnalysis>
25 25 </PropertyGroup>
26 26 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27 27 <DebugType>full</DebugType>
28 28 <Optimize>true</Optimize>
29 29 <OutputPath>bin\Release</OutputPath>
30 30 <ErrorReport>prompt</ErrorReport>
31 31 <WarningLevel>4</WarningLevel>
32 32 <ConsolePause>false</ConsolePause>
33 33 </PropertyGroup>
34 34 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' ">
35 35 <DebugSymbols>true</DebugSymbols>
36 36 <DebugType>full</DebugType>
37 37 <Optimize>false</Optimize>
38 38 <OutputPath>bin\Debug</OutputPath>
39 39 <DefineConstants>TRACE;DEBUG;NET_4_5</DefineConstants>
40 40 <ErrorReport>prompt</ErrorReport>
41 41 <WarningLevel>4</WarningLevel>
42 42 <RunCodeAnalysis>true</RunCodeAnalysis>
43 43 <ConsolePause>false</ConsolePause>
44 44 </PropertyGroup>
45 45 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' ">
46 46 <Optimize>true</Optimize>
47 47 <OutputPath>bin\Release</OutputPath>
48 48 <ErrorReport>prompt</ErrorReport>
49 49 <WarningLevel>4</WarningLevel>
50 50 <ConsolePause>false</ConsolePause>
51 51 <DefineConstants>NET_4_5</DefineConstants>
52 52 </PropertyGroup>
53 53 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|AnyCPU' ">
54 54 <DebugSymbols>true</DebugSymbols>
55 55 <DebugType>full</DebugType>
56 56 <Optimize>false</Optimize>
57 57 <OutputPath>bin\Debug</OutputPath>
58 58 <DefineConstants>TRACE;DEBUG;NET_4_5;MONO</DefineConstants>
59 59 <ErrorReport>prompt</ErrorReport>
60 60 <WarningLevel>4</WarningLevel>
61 61 <RunCodeAnalysis>true</RunCodeAnalysis>
62 62 <ConsolePause>false</ConsolePause>
63 63 </PropertyGroup>
64 64 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|AnyCPU' ">
65 65 <Optimize>true</Optimize>
66 66 <OutputPath>bin\Release</OutputPath>
67 67 <DefineConstants>NET_4_5;MONO;</DefineConstants>
68 68 <ErrorReport>prompt</ErrorReport>
69 69 <WarningLevel>4</WarningLevel>
70 70 <ConsolePause>false</ConsolePause>
71 71 </PropertyGroup>
72 72 <ItemGroup>
73 73 <Reference Include="System" />
74 74 <Reference Include="System.Xml" />
75 75 <Reference Include="mscorlib" />
76 76 </ItemGroup>
77 77 <ItemGroup>
78 78 <Compile Include="CustomEqualityComparer.cs" />
79 79 <Compile Include="Diagnostics\ConsoleTraceListener.cs" />
80 <Compile Include="Diagnostics\EventText.cs" />
81 80 <Compile Include="Diagnostics\LogChannel.cs" />
82 81 <Compile Include="Diagnostics\LogicalOperation.cs" />
83 82 <Compile Include="Diagnostics\TextFileListener.cs" />
84 83 <Compile Include="Diagnostics\TraceLog.cs" />
85 84 <Compile Include="Diagnostics\TraceEvent.cs" />
86 85 <Compile Include="Diagnostics\TraceEventType.cs" />
87 86 <Compile Include="ICancellable.cs" />
88 87 <Compile Include="IProgressHandler.cs" />
89 88 <Compile Include="IProgressNotifier.cs" />
90 89 <Compile Include="IPromiseT.cs" />
91 90 <Compile Include="IPromise.cs" />
92 91 <Compile Include="IServiceLocator.cs" />
93 92 <Compile Include="ITaskController.cs" />
94 93 <Compile Include="Parallels\DispatchPool.cs" />
95 94 <Compile Include="Parallels\ArrayTraits.cs" />
96 95 <Compile Include="Parallels\MTQueue.cs" />
97 96 <Compile Include="Parallels\WorkerPool.cs" />
98 97 <Compile Include="ProgressInitEventArgs.cs" />
99 98 <Compile Include="Properties\AssemblyInfo.cs" />
100 99 <Compile Include="Parallels\AsyncPool.cs" />
101 100 <Compile Include="Safe.cs" />
102 101 <Compile Include="ValueEventArgs.cs" />
103 102 <Compile Include="PromiseExtensions.cs" />
104 103 <Compile Include="SyncContextPromise.cs" />
105 104 <Compile Include="Diagnostics\OperationContext.cs" />
106 105 <Compile Include="Diagnostics\TraceContext.cs" />
107 106 <Compile Include="Diagnostics\LogEventArgs.cs" />
108 107 <Compile Include="Diagnostics\LogEventArgsT.cs" />
109 108 <Compile Include="Diagnostics\Extensions.cs" />
110 109 <Compile Include="PromiseEventType.cs" />
111 110 <Compile Include="Parallels\AsyncQueue.cs" />
112 111 <Compile Include="PromiseT.cs" />
113 112 <Compile Include="IDeferred.cs" />
114 113 <Compile Include="IDeferredT.cs" />
115 114 <Compile Include="Promise.cs" />
116 115 <Compile Include="PromiseTransientException.cs" />
117 116 <Compile Include="Parallels\Signal.cs" />
118 117 <Compile Include="Parallels\SharedLock.cs" />
119 118 <Compile Include="Diagnostics\ILogWriter.cs" />
120 119 <Compile Include="Diagnostics\ListenerBase.cs" />
121 120 <Compile Include="Parallels\BlockingQueue.cs" />
122 121 <Compile Include="AbstractEvent.cs" />
123 122 <Compile Include="AbstractPromise.cs" />
124 123 <Compile Include="AbstractPromiseT.cs" />
125 124 <Compile Include="FuncTask.cs" />
126 125 <Compile Include="FuncTaskBase.cs" />
127 126 <Compile Include="FuncTaskT.cs" />
128 127 <Compile Include="ActionChainTaskBase.cs" />
129 128 <Compile Include="ActionChainTask.cs" />
130 129 <Compile Include="ActionChainTaskT.cs" />
131 130 <Compile Include="FuncChainTaskBase.cs" />
132 131 <Compile Include="FuncChainTask.cs" />
133 132 <Compile Include="FuncChainTaskT.cs" />
134 133 <Compile Include="ActionTaskBase.cs" />
135 134 <Compile Include="ActionTask.cs" />
136 135 <Compile Include="ActionTaskT.cs" />
137 136 <Compile Include="ICancellationToken.cs" />
138 137 <Compile Include="SuccessPromise.cs" />
139 138 <Compile Include="SuccessPromiseT.cs" />
140 139 <Compile Include="PromiseAwaiterT.cs" />
141 140 <Compile Include="PromiseAwaiter.cs" />
142 141 <Compile Include="Components\ComponentContainer.cs" />
143 142 <Compile Include="Components\Disposable.cs" />
144 143 <Compile Include="Components\DisposablePool.cs" />
145 144 <Compile Include="Components\ObjectPool.cs" />
146 145 <Compile Include="Components\ServiceLocator.cs" />
147 146 <Compile Include="Components\IInitializable.cs" />
148 147 <Compile Include="TaskController.cs" />
149 148 <Compile Include="Components\App.cs" />
150 149 <Compile Include="Components\IRunnable.cs" />
151 150 <Compile Include="Components\ExecutionState.cs" />
152 151 <Compile Include="Components\RunnableComponent.cs" />
153 152 <Compile Include="Components\IFactory.cs" />
154 153 <Compile Include="Automaton\IAlphabet.cs" />
155 154 <Compile Include="Automaton\ParserException.cs" />
156 155 <Compile Include="Automaton\IndexedAlphabetBase.cs" />
157 156 <Compile Include="Automaton\IAlphabetBuilder.cs" />
158 157 <Compile Include="Automaton\RegularExpressions\AltToken.cs" />
159 158 <Compile Include="Automaton\RegularExpressions\BinaryToken.cs" />
160 159 <Compile Include="Automaton\RegularExpressions\CatToken.cs" />
161 160 <Compile Include="Automaton\RegularExpressions\StarToken.cs" />
162 161 <Compile Include="Automaton\RegularExpressions\SymbolToken.cs" />
163 162 <Compile Include="Automaton\RegularExpressions\EmptyToken.cs" />
164 163 <Compile Include="Automaton\RegularExpressions\Token.cs" />
165 164 <Compile Include="Automaton\RegularExpressions\IVisitor.cs" />
166 165 <Compile Include="Automaton\AutomatonTransition.cs" />
167 166 <Compile Include="Formats\JSON\JSONElementContext.cs" />
168 167 <Compile Include="Formats\JSON\JSONElementType.cs" />
169 168 <Compile Include="Formats\JSON\JSONGrammar.cs" />
170 169 <Compile Include="Formats\JSON\JSONParser.cs" />
171 170 <Compile Include="Formats\JSON\JSONScanner.cs" />
172 171 <Compile Include="Formats\JSON\JsonTokenType.cs" />
173 172 <Compile Include="Formats\JSON\JSONWriter.cs" />
174 173 <Compile Include="Formats\JSON\JSONXmlReader.cs" />
175 174 <Compile Include="Formats\JSON\JSONXmlReaderOptions.cs" />
176 175 <Compile Include="Formats\JSON\StringTranslator.cs" />
177 176 <Compile Include="Automaton\MapAlphabet.cs" />
178 177 <Compile Include="Formats\CharAlphabet.cs" />
179 178 <Compile Include="Formats\ByteAlphabet.cs" />
180 179 <Compile Include="Automaton\IDFATable.cs" />
181 180 <Compile Include="Automaton\IDFATableBuilder.cs" />
182 181 <Compile Include="Automaton\DFATable.cs" />
183 182 <Compile Include="Automaton\RegularExpressions\RegularExpressionVisitor.cs" />
184 183 <Compile Include="Automaton\RegularExpressions\ITaggedDFABuilder.cs" />
185 184 <Compile Include="Formats\TextScanner.cs" />
186 185 <Compile Include="Formats\StringScanner.cs" />
187 186 <Compile Include="Formats\ReaderScanner.cs" />
188 187 <Compile Include="Formats\ScannerContext.cs" />
189 188 <Compile Include="Formats\Grammar.cs" />
190 189 <Compile Include="Automaton\RegularExpressions\EndTokenT.cs" />
191 190 <Compile Include="Automaton\RegularExpressions\EndToken.cs" />
192 191 <Compile Include="Automaton\RegularExpressions\RegularExpressionVisitorT.cs" />
193 192 <Compile Include="Automaton\AutomatonConst.cs" />
194 193 <Compile Include="Automaton\RegularExpressions\RegularDFA.cs" />
195 194 <Compile Include="Components\LazyAndWeak.cs" />
196 195 <Compile Include="AbstractTask.cs" />
197 196 <Compile Include="AbstractTaskT.cs" />
198 197 </ItemGroup>
199 198 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
200 199 <ItemGroup />
201 200 <ProjectExtensions>
202 201 <MonoDevelop>
203 202 <Properties>
204 203 <Policies>
205 204 <CSharpFormattingPolicy IndentSwitchBody="True" NamespaceBraceStyle="EndOfLine" ClassBraceStyle="EndOfLine" InterfaceBraceStyle="EndOfLine" StructBraceStyle="EndOfLine" EnumBraceStyle="EndOfLine" MethodBraceStyle="EndOfLine" ConstructorBraceStyle="EndOfLine" DestructorBraceStyle="EndOfLine" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" NewLineBeforeConstructorInitializerColon="NewLine" NewLineAfterConstructorInitializerColon="SameLine" BeforeIndexerDeclarationBracket="False" BeforeDelegateDeclarationParentheses="False" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
206 205 <TextStylePolicy FileWidth="120" EolMarker="Unix" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
207 206 <DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="MSBuild" />
208 207 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="application/xml" />
209 208 <XmlFormattingPolicy inheritsSet="Mono" inheritsScope="application/xml" scope="application/xml" />
210 209 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/plain" />
211 210 <NameConventionPolicy>
212 211 <Rules>
213 212 <NamingRule Name="Namespaces" AffectedEntity="Namespace" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
214 213 <NamingRule Name="Types" AffectedEntity="Class, Struct, Enum, Delegate" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
215 214 <NamingRule Name="Interfaces" AffectedEntity="Interface" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
216 215 <RequiredPrefixes>
217 216 <String>I</String>
218 217 </RequiredPrefixes>
219 218 </NamingRule>
220 219 <NamingRule Name="Attributes" AffectedEntity="CustomAttributes" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
221 220 <RequiredSuffixes>
222 221 <String>Attribute</String>
223 222 </RequiredSuffixes>
224 223 </NamingRule>
225 224 <NamingRule Name="Event Arguments" AffectedEntity="CustomEventArgs" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
226 225 <RequiredSuffixes>
227 226 <String>EventArgs</String>
228 227 </RequiredSuffixes>
229 228 </NamingRule>
230 229 <NamingRule Name="Exceptions" AffectedEntity="CustomExceptions" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
231 230 <RequiredSuffixes>
232 231 <String>Exception</String>
233 232 </RequiredSuffixes>
234 233 </NamingRule>
235 234 <NamingRule Name="Methods" AffectedEntity="Methods" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
236 235 <NamingRule Name="Static Readonly Fields" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Protected, Public" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True" />
237 236 <NamingRule Name="Fields (Non Private)" AffectedEntity="Field" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
238 237 <NamingRule Name="ReadOnly Fields (Non Private)" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False" />
239 238 <NamingRule Name="Fields (Private)" AffectedEntity="Field, ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
240 239 <RequiredPrefixes>
241 240 <String>m_</String>
242 241 </RequiredPrefixes>
243 242 </NamingRule>
244 243 <NamingRule Name="Static Fields (Private)" AffectedEntity="Field" VisibilityMask="Private" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True">
245 244 <RequiredPrefixes>
246 245 <String>_</String>
247 246 </RequiredPrefixes>
248 247 </NamingRule>
249 248 <NamingRule Name="ReadOnly Fields (Private)" AffectedEntity="ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
250 249 <RequiredPrefixes>
251 250 <String>m_</String>
252 251 </RequiredPrefixes>
253 252 </NamingRule>
254 253 <NamingRule Name="Constant Fields" AffectedEntity="ConstantField" VisibilityMask="VisibilityMask" NamingStyle="AllUpper" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
255 254 <NamingRule Name="Properties" AffectedEntity="Property" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
256 255 <NamingRule Name="Events" AffectedEntity="Event" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
257 256 <NamingRule Name="Enum Members" AffectedEntity="EnumMember" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
258 257 <NamingRule Name="Parameters" AffectedEntity="Parameter, LocalVariable" VisibilityMask="VisibilityMask" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
259 258 <NamingRule Name="Type Parameters" AffectedEntity="TypeParameter" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
260 259 <RequiredPrefixes>
261 260 <String>T</String>
262 261 </RequiredPrefixes>
263 262 </NamingRule>
264 263 </Rules>
265 264 </NameConventionPolicy>
266 265 </Policies>
267 266 </Properties>
268 267 </MonoDevelop>
269 268 </ProjectExtensions>
270 269 <ItemGroup>
271 270 <Folder Include="Components\" />
272 271 <Folder Include="Automaton\RegularExpressions\" />
273 272 <Folder Include="Formats\" />
274 273 <Folder Include="Formats\JSON\" />
275 274 </ItemGroup>
276 275 </Project> No newline at end of file
@@ -1,45 +1,48
1 1 using System;
2 2 using Implab;
3 3 using System.Threading.Tasks;
4 4 using Implab.Formats.JSON;
5 5 using System.IO;
6 6 using System.Text.Json;
7 using System.Diagnostics;
8 using Implab.Parallels;
9 using System.Threading;
7 10
8 11 namespace MonoPlay {
9 12 class MainClass {
10 13
11 14
12 15 public static void Main(string[] args) {
13 if (args == null)
14 throw new ArgumentNullException("args");
15 int t1, t2;
16 var pool = new WorkerPool(10);
16 17
17 for (int i = 0; i < 2; i++) {
18 t1 = Environment.TickCount;
19 int elements =0;
20 using (var reader = new JSONParser(File.OpenText("/home/sergey/temp/citylots.json"))) {
21 while (reader.Read())
22 elements++;
23 }
18 var listerner = new ConsoleTraceListener();
19 listerner.TraceOutputOptions = TraceOptions.LogicalOperationStack;
20 Trace.Listeners.Add(listerner);
21
22 Trace.CorrelationManager.StartLogicalOperation("Main");
24 23
25 t2 = Environment.TickCount;
26 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 );
27 }
24 var d = pool.Invoke(() => {
25 Trace.CorrelationManager.StartLogicalOperation("Worker");
26 Thread.Sleep(100);
27 Trace.TraceInformation("worker done");
28 Trace.CorrelationManager.StopLogicalOperation();
29 });
28 30
29 Console.WriteLine("Syste.Text.Json");
30 var paraser = new JsonParser();
31 for (int i = 0; i < 2; i++) {
32 t1 = Environment.TickCount;
33 using (var reader = File.OpenText("/home/sergey/temp/citylots.json")) {
34 paraser.Parse(reader);
35 }
31 ThreadPool.QueueUserWorkItem((o) => {
32 Trace.CorrelationManager.StartLogicalOperation("Thread");
33 Thread.Sleep(100);
34 Trace.TraceInformation("thread done");
35 Trace.CorrelationManager.StopLogicalOperation();
36 });
36 37
37 t2 = Environment.TickCount;
38 Console.WriteLine("attempt {0} done: {1} ms, {2:.00} Mb, {3} GC, ",i+1, t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0));
39 }
38 Trace.TraceInformation("main done");
39 Trace.CorrelationManager.StopLogicalOperation();
40
41 d.Join();
42
40 43
41 44
42 45 }
43 46
44 47 }
45 48 }
1 NO CONTENT: file was removed
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