public void TimeSource101() { TestScheduler scheduler = new TestScheduler(); var xs = scheduler.CreateHotObservable(s_testData); var timeSource = new TimeSource<long>(xs, x => new DateTimeOffset(x, TimeSpan.Zero)); timeSource.StartTime = new DateTimeOffset(101, TimeSpan.Zero); var counts = from window in timeSource.Window(TimeSpan.FromTicks(5), timeSource.Scheduler) from Count in window.Count() select Count; var list = new List<Timestamped<int>>(); counts .Timestamp(timeSource.Scheduler) .Subscribe(ts => list.Add(ts)); timeSource.Connect(); scheduler.AdvanceTo(120); Assert.AreEqual(3, list.Count); list.AssertEqual( Result(106, 2), Result(111, 3), Result(115, 1)); }
public void EtwFileSourceTest() { var observable = EtwObservable.FromFiles(FileName); var source = new TimeSource <EtwNativeEvent>(observable, e => e.TimeStamp); var parsed = from p in source where p.Id == 2 select p.TimeStamp; var buf = parsed.Take(13).Buffer(TimeSpan.FromSeconds(1), source.Scheduler); var list = new List <IList <DateTimeOffset> >(); ManualResetEvent completed = new ManualResetEvent(false); buf.Subscribe( t => list.Add(t), () => completed.Set()); source.Connect(); completed.WaitOne(); Assert.AreEqual(2, list.Count()); Assert.AreEqual(7, list.First().Count); Assert.AreEqual(6, list.Skip(1).First().Count); }
public void TimeAutoStart() { TestScheduler scheduler = new TestScheduler(); var xs = scheduler.CreateHotObservable(s_testData); var timeSource = new TimeSource <long>(xs, x => new DateTimeOffset(x, TimeSpan.Zero)); // Note: no start time specified, result should be the same as 101 var counts = from window in timeSource.Window(TimeSpan.FromTicks(5), timeSource.Scheduler) from Count in window.Count() select Count; var list = new List <Timestamped <int> >(); counts .Timestamp(timeSource.Scheduler) .Subscribe(ts => list.Add(ts)); timeSource.Connect(); scheduler.AdvanceTo(120); Assert.AreEqual(3, list.Count); list.AssertEqual( Result(106, 2), Result(111, 3), Result(115, 1)); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: SessionStatistics <real-time session name> <seconds>"); return; } string sessionName = args[0]; int seconds = int.Parse(args[1]); Console.WriteLine("Measuring provider verbosity for session '{0}' for {1} seconds", sessionName, seconds); IObservable <EtwNativeEvent> session = EtwObservable.FromSession(sessionName); var timeSource = new TimeSource <EtwNativeEvent>(session, e => e.TimeStamp); var countPerWindow = from e in timeSource.Take(TimeSpan.FromSeconds(seconds), timeSource.Scheduler) group e by new { e.ProviderId } into g from total in g.Count() select new { Provider = g.Key, Count = total }; ManualResetEvent evt = new ManualResetEvent(false); IDisposable output = countPerWindow.Subscribe( stat => Console.WriteLine("{0} {1}", stat.Provider, stat.Count), // OnNext e => Console.WriteLine(e.Message), // OnError () => { evt.Set(); }); // OnCompleted IDisposable input = timeSource.Connect(); evt.WaitOne(); output.Dispose(); input.Dispose(); }
public void TimeSource100() { TestScheduler scheduler = new TestScheduler(); var xs = scheduler.CreateHotObservable(s_testData); var timeSource = new TimeSource <long>(xs, x => new DateTimeOffset(x, TimeSpan.Zero)); timeSource.StartTime = new DateTimeOffset(100, TimeSpan.Zero); var counts = from window in timeSource.Window(TimeSpan.FromTicks(5), timeSource.Scheduler) from Count in window.Count() select Count; var list = new List <Timestamped <int> >(); counts .Timestamp(timeSource.Scheduler) .Subscribe(ts => list.Add(ts)); timeSource.Connect(); scheduler.AdvanceTo(120); Assert.AreEqual(4, list.Count); list.AssertEqual( Result(105, 2), Result(110, 3), Result(115, 0), Result(115, 1)); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: SessionStatistics <real-time session name> <seconds>"); return; } string sessionName = args[0]; int seconds = int.Parse(args[1]); Console.WriteLine("Measuring provider verbosity for session '{0}' for {1} seconds", sessionName, seconds); IObservable<EtwNativeEvent> session = EtwObservable.FromSession(sessionName); var timeSource = new TimeSource<EtwNativeEvent>(session, e => e.TimeStamp); var countPerWindow = from e in timeSource.Take(TimeSpan.FromSeconds(seconds), timeSource.Scheduler) group e by new {e.ProviderId} into g from total in g.Count() select new {Provider = g.Key, Count = total}; ManualResetEvent evt = new ManualResetEvent(false); IDisposable output = countPerWindow.Subscribe( stat => Console.WriteLine("{0} {1}", stat.Provider, stat.Count), // OnNext e => Console.WriteLine(e.Message), // OnError () =>{ evt.Set();}); // OnCompleted IDisposable input = timeSource.Connect(); evt.WaitOne(); output.Dispose(); input.Dispose(); }
public void EtwFileSourceTest() { var observable = EtwObservable.FromFiles(FileName); var source = new TimeSource<EtwNativeEvent>(observable, e => e.TimeStamp); var parsed = from p in source where p.Id == 2 select p.TimeStamp; var buf = parsed.Take(13).Buffer(TimeSpan.FromSeconds(1), source.Scheduler); var list = new List<IList<DateTimeOffset>>(); ManualResetEvent completed = new ManualResetEvent(false); buf.Subscribe( t => list.Add(t), ()=>completed.Set()); source.Connect(); completed.WaitOne(); Assert.AreEqual(2, list.Count()); Assert.AreEqual(7, list.First().Count); Assert.AreEqual(6, list.Skip(1).First().Count); }
public static void ListenWintUnsafeClass() { Console.WriteLine("----- Listening with Unsafe wrapper class and Rx query -----"); // this is the approach used by TraceEvent // http://blogs.msdn.com/b/dotnet/archive/2013/08/15/announcing-traceevent-monitoring-and-diagnostics-for-the-cloud.aspx // - It works in this case and provides better performance // - In general means the user must think which data to copy as the first step in the query // For example in query that joins begin and end event, we can't stop ETW from overwriting the buffer before matching end arrives var instance = new RecvV4(); _raw = EtwObservable.FromSession(Baseline.SessionName); var timeSource = new TimeSource <EtwNativeEvent>(_raw, e => e.TimeStamp); var received = timeSource.Select(e => { unsafe { instance.userData = (byte *)e.UserData.ToPointer(); } return(instance); }); var x = from window in received.Window(TimeSpan.FromSeconds(1), timeSource.Scheduler) from stats in (from packet in window group packet by packet.daddr into g from total in g.Sum(p => p.size) select new { address = new IPAddress(g.Key).ToString(), received = total }) .ToList() select stats.OrderBy(s => s.address); _subscription = x.Subscribe(v => { //Console.WriteLine("--- {0} ---", DateTime.Now); //foreach (var s in v) // Console.WriteLine("{0, -15} {1,-10:n0} ", s.address, s.received); //Console.WriteLine(); }); timeSource.Connect(); Console.ReadLine(); _subscription.Dispose(); timeSource.Dispose(); }
public static void ListenWintQueryOnEtwNativeEvent() { Console.WriteLine("----- Listening with Tx-EtwObservable and Rx query -----"); _raw = EtwObservable.FromSession(Baseline.SessionName); UInt32 pid = 0; UInt32 size = 0; UInt32 daddr = 0; var timeSource = new TimeSource <EtwNativeEvent>(_raw, e => e.TimeStamp); var toStackVars = timeSource.Do(e => // this copies the variables on the stack { pid = e.ReadUInt32(); // skip PID size = e.ReadUInt32(); daddr = e.ReadUInt32(); }); var x = from window in toStackVars.Window(TimeSpan.FromSeconds(1)) from stats in (from packet in window group packet by daddr into g from total in g.Sum(p => size) select new { address = new IPAddress(g.Key).ToString(), received = total }) .ToList() select stats.OrderBy(s => s.address); _subscription = x.Subscribe(v => { Console.WriteLine("--- {0} ---", DateTime.Now); foreach (var s in v) { Console.WriteLine("{0, -15} {1,-10:n0} ", s.address, s.received); } Console.WriteLine(); }); timeSource.Connect(); Console.ReadLine(); Console.WriteLine(pid); // prevent the compiler to optimize this away _subscription.Dispose(); timeSource.Dispose(); }
public static void ListenWintQueryOnEtwNativeEvent() { Console.WriteLine("----- Listening with Tx-EtwObservable and Rx query -----"); _raw = EtwObservable.FromSession(Baseline.SessionName); UInt32 pid = 0; UInt32 size = 0; UInt32 daddr = 0; var timeSource = new TimeSource<EtwNativeEvent>(_raw, e => e.TimeStamp); var toStackVars = timeSource.Do(e => // this copies the variables on the stack { pid = e.ReadUInt32(); // skip PID size = e.ReadUInt32(); daddr = e.ReadUInt32(); }); var x = from window in toStackVars.Window(TimeSpan.FromSeconds(1)) from stats in (from packet in window group packet by daddr into g from total in g.Sum(p => size) select new { address = new IPAddress(g.Key).ToString(), received = total }) .ToList() select stats.OrderBy(s => s.address); _subscription = x.Subscribe(v => { Console.WriteLine("--- {0} ---", DateTime.Now); foreach (var s in v) Console.WriteLine("{0, -15} {1,-10:n0} ", s.address, s.received); Console.WriteLine(); }); timeSource.Connect(); Console.ReadLine(); Console.WriteLine(pid); // prevent the compiler to optimize this away _subscription.Dispose(); timeSource.Dispose(); }
static void Main() { IObservable<EtwNativeEvent> etl = EtwObservable.FromFiles(@"..\..\..\HTTP_Server.etl"); var timeSource = new TimeSource<EtwNativeEvent>(etl, e => e.TimeStamp); var countPerWindow = from window in timeSource.Window(TimeSpan.FromSeconds(5), timeSource.Scheduler) from Count in window.Count() select Count; var withTime = countPerWindow.Timestamp(timeSource.Scheduler); withTime.Subscribe(ts => Console.WriteLine("{0} {1}", ts.Timestamp, ts.Value)); timeSource.Connect(); Console.ReadLine(); }
public static void ListenWintUnsafeClass() { Console.WriteLine("----- Listening with Unsafe wrapper class and Rx query -----"); var instance = new RecvV4(); _raw = EtwObservable.FromSession(Baseline.SessionName); var timeSource = new TimeSource <EtwNativeEvent>(_raw, e => e.TimeStamp); var received = timeSource.Select(e => { unsafe { instance.userData = (byte *)e.UserData.ToPointer(); } return(instance); }); var x = from window in received.Window(TimeSpan.FromSeconds(1), timeSource.Scheduler) from stats in (from packet in window group packet by packet.daddr into g from total in g.Sum(p => p.size) select new { address = new IPAddress(g.Key).ToString(), received = total }) .ToList() select stats.OrderBy(s => s.address); _subscription = x.Subscribe(v => { //Console.WriteLine("--- {0} ---", DateTime.Now); //foreach (var s in v) // Console.WriteLine("{0, -15} {1,-10:n0} ", s.address, s.received); //Console.WriteLine(); }); timeSource.Connect(); Console.ReadLine(); _subscription.Dispose(); timeSource.Dispose(); }
static void Main() { IObservable <EtwNativeEvent> etl = EtwObservable.FromFiles(@"HTTP_Server.etl"); var timeSource = new TimeSource <EtwNativeEvent>(etl, e => e.TimeStamp); var countPerWindow = from window in timeSource.Window(TimeSpan.FromSeconds(5), timeSource.Scheduler) from Count in window.Count() select Count; var withTime = countPerWindow.Timestamp(timeSource.Scheduler); using (withTime.Subscribe(ts => Console.WriteLine("{0} {1}", ts.Timestamp, ts.Value))) { timeSource.Connect(); Console.ReadLine(); } }
static void Option1_TimeSource() { IObservable<PublishedEvent> obs = XeObservable.FromFiles(@"..\..\gatewaysample*.xel"); TimeSource<PublishedEvent> timeSource = new TimeSource<PublishedEvent>(obs, e => e.Timestamp); timeSource .Take(TimeSpan.FromMinutes(1), timeSource.Scheduler) .Where(e=>(double)e.Fields["LoginDurationMs"].Value > 100) .Subscribe(e => { Console.WriteLine("--- {0} {1}.{2} ---", e.Name, e.Timestamp, e.Timestamp.Millisecond); foreach (PublishedEventField f in e.Fields) { Console.WriteLine("{0} = {1}", f.Name, f.Value); } }); timeSource.Connect(); Console.ReadLine(); }
static void Option1_TimeSource() { IObservable <PublishedEvent> obs = XeObservable.FromFiles(@"gatewaysample.xel"); TimeSource <PublishedEvent> timeSource = new TimeSource <PublishedEvent>(obs, e => e.Timestamp); timeSource .Take(TimeSpan.FromMinutes(1), timeSource.Scheduler) .Where(e => (double)e.Fields["LoginDurationMs"].Value > 100) .Subscribe(e => { Console.WriteLine("--- {0} {1}.{2} ---", e.Name, e.Timestamp, e.Timestamp.Millisecond); foreach (PublishedEventField f in e.Fields) { Console.WriteLine("{0} = {1}", f.Name, f.Value); } }); using (timeSource.Connect()) { Console.ReadLine(); } }
public static void ListenWintUnsafeClass() { Console.WriteLine("----- Listening with Unsafe wrapper class and Rx query -----"); var instance = new RecvV4(); _raw = EtwObservable.FromSession(Baseline.SessionName); var timeSource = new TimeSource<EtwNativeEvent>(_raw, e => e.TimeStamp); var received = timeSource.Select(e => { unsafe { instance.userData = (byte*) e.UserData.ToPointer(); } return instance; }); var x = from window in received.Window(TimeSpan.FromSeconds(1), timeSource.Scheduler) from stats in (from packet in window group packet by packet.daddr into g from total in g.Sum(p => p.size) select new { address = new IPAddress(g.Key).ToString(), received = total }) .ToList() select stats.OrderBy(s => s.address); _subscription = x.Subscribe(v => { //Console.WriteLine("--- {0} ---", DateTime.Now); //foreach (var s in v) // Console.WriteLine("{0, -15} {1,-10:n0} ", s.address, s.received); //Console.WriteLine(); }); timeSource.Connect(); Console.ReadLine(); _subscription.Dispose(); timeSource.Dispose(); }
public static void ListenWintUnsafeClass() { Console.WriteLine("----- Listening with Unsafe wrapper class and Rx query -----"); // this is the approach used by TraceEvent // http://blogs.msdn.com/b/dotnet/archive/2013/08/15/announcing-traceevent-monitoring-and-diagnostics-for-the-cloud.aspx // - It works in this case and provides better performance // - In general means the user must think which data to copy as the first step in the query // For example in query that joins begin and end event, we can't stop ETW from overwriting the buffer before matching end arrives var instance = new RecvV4(); _raw = EtwObservable.FromSession(Baseline.SessionName); var timeSource = new TimeSource<EtwNativeEvent>(_raw, e => e.TimeStamp); var received = timeSource.Select(e => { unsafe { instance.userData = (byte*) e.UserData.ToPointer(); } return instance; }); var x = from window in received.Window(TimeSpan.FromSeconds(1), timeSource.Scheduler) from stats in (from packet in window group packet by packet.daddr into g from total in g.Sum(p => p.size) select new { address = new IPAddress(g.Key).ToString(), received = total }) .ToList() select stats.OrderBy(s => s.address); _subscription = x.Subscribe(v => { //Console.WriteLine("--- {0} ---", DateTime.Now); //foreach (var s in v) // Console.WriteLine("{0, -15} {1,-10:n0} ", s.address, s.received); //Console.WriteLine(); }); timeSource.Connect(); Console.ReadLine(); _subscription.Dispose(); timeSource.Dispose(); }