comparison MonoPlay/Program.cs @ 194:d45bdf510514 v2

working on diagnostics
author cin
date Mon, 25 Apr 2016 15:18:56 +0300
parents 4f82e0f161c3
children d7cd7a83189a
comparison
equal deleted inserted replaced
191:cc19dc78edb7 194:d45bdf510514
2 using Implab; 2 using Implab;
3 using System.Threading.Tasks; 3 using System.Threading.Tasks;
4 using Implab.Formats.JSON; 4 using Implab.Formats.JSON;
5 using System.IO; 5 using System.IO;
6 using System.Text.Json; 6 using System.Text.Json;
7 using System.Diagnostics;
8 using Implab.Parallels;
9 using System.Threading;
7 10
8 namespace MonoPlay { 11 namespace MonoPlay {
9 class MainClass { 12 class MainClass {
10 13
11 14
12 public static void Main(string[] args) { 15 public static void Main(string[] args) {
13 if (args == null) 16 var pool = new WorkerPool(10);
14 throw new ArgumentNullException("args");
15 int t1, t2;
16 17
17 for (int i = 0; i < 2; i++) { 18 var listerner = new ConsoleTraceListener();
18 t1 = Environment.TickCount; 19 listerner.TraceOutputOptions = TraceOptions.LogicalOperationStack;
19 int elements =0; 20 Trace.Listeners.Add(listerner);
20 using (var reader = new JSONParser(File.OpenText("/home/sergey/temp/citylots.json"))) {
21 while (reader.Read())
22 elements++;
23 }
24 21
25 t2 = Environment.TickCount; 22 Trace.CorrelationManager.StartLogicalOperation("Main");
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 }
28 23
29 Console.WriteLine("Syste.Text.Json"); 24 var d = pool.Invoke(() => {
30 var paraser = new JsonParser(); 25 Trace.CorrelationManager.StartLogicalOperation("Worker");
31 for (int i = 0; i < 2; i++) { 26 Thread.Sleep(100);
32 t1 = Environment.TickCount; 27 Trace.TraceInformation("worker done");
33 using (var reader = File.OpenText("/home/sergey/temp/citylots.json")) { 28 Trace.CorrelationManager.StopLogicalOperation();
34 paraser.Parse(reader); 29 });
35 }
36 30
37 t2 = Environment.TickCount; 31 ThreadPool.QueueUserWorkItem((o) => {
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)); 32 Trace.CorrelationManager.StartLogicalOperation("Thread");
39 } 33 Thread.Sleep(100);
34 Trace.TraceInformation("thread done");
35 Trace.CorrelationManager.StopLogicalOperation();
36 });
37
38 Trace.TraceInformation("main done");
39 Trace.CorrelationManager.StopLogicalOperation();
40
41 d.Join();
42
40 43
41 44
42 } 45 }
43 46
44 } 47 }