-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathProgram.cs
93 lines (78 loc) · 2.99 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Linq;
using System.Net;
using System.Reactive;
using System.Reactive.Linq;
using Tx.Windows;
using Tx.Windows.Microsoft_Windows_Kernel_Network;
namespace SynCtr
{
class Program
{
static IDisposable _subscription;
static Playback _playback;
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine(
@"Usage: SynCtr [option]
Options are:
Playback - use Playback to copy ETW events into heap-allocated C# objects, and then Rx query
Raw - Rx query on EtwNativeEvent-s, which is lower level in Tx (no copying to typed objects)
Imperative - use imperative code, over EtwNativeEvent-s
Unsafe - use wrapper that accesses data in the ETW buffer by pointer, like TraceEvent
note ETW can overwrite these buffers at unpredictable moment");
return;
}
Baseline.StartSession();
switch (args[0])
{
case "Playback":
ListenWithQuery();
break;
case "Raw":
RxRaw.ListenWintQueryOnEtwNativeEvent();
break;
case "Imperative":
Baseline.ListenWithImperativeCode();
break;
case "Unsafe":
RxRaw.ListenWintUnsafeClass();
break;
default:
throw new Exception("Unknown option " + args[0]);
}
}
static void ListenWithQuery()
{
Console.WriteLine("----- Listening with Tx-Playback and Rx query -----");
_playback = new Playback();
_playback.AddRealTimeSession(Baseline.SessionName);
var received = _playback.GetObservable<KNetEvt_RecvIPV4>();
var x = from window in received.Window(TimeSpan.FromSeconds(1), _playback.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();
});
_playback.Start();
Console.ReadLine();
_subscription.Dispose();
}
}
}