diff MonoPlay/Program.cs @ 194:d45bdf510514 v2

working on diagnostics
author cin
date Mon, 25 Apr 2016 15:18:56 +0300
parents 4f82e0f161c3
children d7cd7a83189a
line wrap: on
line diff
--- a/MonoPlay/Program.cs	Fri Apr 22 13:09:57 2016 +0300
+++ b/MonoPlay/Program.cs	Mon Apr 25 15:18:56 2016 +0300
@@ -4,39 +4,42 @@
 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();
+
 
 
         }