From 98ab5d0164040427f7c554febae125686284e2a7 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:03:55 +0000 Subject: modification structure svn --- IvyToDel/IvyPerf/IvyPerf.cs | 74 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 IvyToDel/IvyPerf/IvyPerf.cs (limited to 'IvyToDel/IvyPerf/IvyPerf.cs') diff --git a/IvyToDel/IvyPerf/IvyPerf.cs b/IvyToDel/IvyPerf/IvyPerf.cs new file mode 100644 index 0000000..9d37883 --- /dev/null +++ b/IvyToDel/IvyPerf/IvyPerf.cs @@ -0,0 +1,74 @@ +using System; +using IvyBus; +using System.Threading; +using System.Globalization; +using System.Collections.Specialized; + +namespace IvyPerf +{ + /// + /// Description résumée de IvyPerf. + /// mesure des perfo de round trip entre deux applis + /// + class IvyPerf + { + static Ivy bus; + static double origin = 0; + + static double currentTime() // en ms + { + double time; + time = (double)(DateTime.Now.Ticks) / (double)(TimeSpan.TicksPerMillisecond); + //time = Environment.TickCount; + return time; + } + [IvyBinding("^ping ts=(.*)")] + static void Reply(object sender, IvyMessageEventArgs args) + { + bus.SendMsg("pong ts={0} tr={1}", args[0], currentTime() - origin ); + } + [IvyBinding("^pong ts=(.*) tr=(.*)")] + static void Pong(object sender, IvyMessageEventArgs args) + { + double current = currentTime() - origin; + double ts = double.Parse(args[0], bus.Culture ); + double tr = double.Parse(args[1], bus.Culture ); + double roundtrip1 = tr - ts; + double roundtrip2 = current - tr; + double roundtrip3 = current - ts; + Console.WriteLine("round trip {0} {1} {2}", roundtrip1, roundtrip2, roundtrip3); + } + /// + /// Point d'entrée principal de l'application. + /// + [STAThread] + static void Main(string[] args) + { + int timeout = 1000; + if (args.Length > 0) + timeout = int.Parse(args[0]); + bus = new Ivy("IvyPerf", "IvyPref ready"); + bus.SentMessageFilter.Add("ping"); + bus.SentMessageFilter.Add("pong"); + bus.SentMessageFilter.Add("IvyPref"); + bus.BindingFilter += new EventHandler(bus_BindingFilter); + //TODO how to autobind + //bus.BindAttibute(typeof(IvyPerf)); + //TODO auto generation of testtarget ?? how to + //bus.BindMsg("test", new EventHandler(testtarget)); + bus.Start(null); + origin = currentTime(); + while( true ) + { + Thread.Sleep( timeout ); + int count = bus.SendMsg("ping ts={0}", currentTime() - origin ); + if ( count == 0 ) Console.Write( "." ); + } + } + + static void bus_BindingFilter(object sender, IvyEventArgs e) + { + Console.WriteLine( "The app {0} regexp {1} was Filtred.", e.Client.ApplicationName,e.Argument); + } + } +} -- cgit v1.1