Exemplo n.º 1
0
        private Dictionary<Type, CsvRelatedStats> CalculateTypeStatistics(TypeCache typeCache, string inputFile)
        {
            Console.WriteLine("Getting statistics from file {0}.", inputFile);

            var statsPerType = new Dictionary<Type, CsvRelatedStats>();

            Stopwatch sw = Stopwatch.StartNew();

            var rawCount = from events in BinaryEtwObservable.FromSequentialFiles(inputFile)
                           group events by events.TypeId
                               into eventTypes
                               from all in
                                   eventTypes.Aggregate(
                                       new { EventCount = (long)0, Bytes = (long)0, minTime = long.MaxValue, maxTime = 0L },
                                       (ac, events) =>
                                       new
                                       {
                                           EventCount = ac.EventCount + 1,
                                           Bytes = ac.Bytes + events.Payload.Length,
                                           minTime = Math.Min(ac.minTime, events.ReceivedTime.ToFileTime()),
                                           maxTime = Math.Max(ac.maxTime, events.ReceivedTime.ToFileTime()),
                                       })
                               select new { ManifestId = eventTypes.Key, all.EventCount, all.Bytes, all.minTime, all.maxTime, };

            var counts = rawCount.ToEnumerable().ToArray();

            sw.Stop();
            Console.WriteLine("Query took {0} milliseconds.", sw.ElapsedMilliseconds);

            foreach (var c in counts)
            {
                var typeCacheItem = typeCache.FindMatchOrDefault(c.ManifestId);

                if (typeCacheItem != null && typeCacheItem.Type != null)
                {
                    var type = typeCacheItem.Type;
                    if (type != null)
                    {
                        var minDateTime = DateTime.FromFileTimeUtc(c.minTime);
                        var maxDateTime = DateTime.FromFileTimeUtc(c.maxTime);
                        var duration = (maxDateTime - minDateTime).TotalSeconds;
                        if (Math.Abs(duration) < 0.01) duration = 1;

                        var stats = new EventStatistics
                        {
                            AverageByteSize = c.Bytes / c.EventCount,
                            ByteSize = c.Bytes,
                            EventCount = c.EventCount,
                            EventsPerSecond = Math.Round(c.EventCount / duration, 3, MidpointRounding.AwayFromZero),
                        };

                        statsPerType[type] = new CsvRelatedStats
                        {
                            ManifestId = c.ManifestId,
                            Statistics = stats,
                        };
                    }
                }
            }

            return statsPerType;
        }
Exemplo n.º 2
0
        private Dictionary <Type, CsvRelatedStats> CalculateTypeStatistics(TypeCache typeCache, string inputFile)
        {
            Console.WriteLine("Getting statistics from file {0}.", inputFile);

            var statsPerType = new Dictionary <Type, CsvRelatedStats>();

            Stopwatch sw = Stopwatch.StartNew();

            var rawCount = from events in BinaryEtwObservable.FromSequentialFiles(inputFile)
                           group events by events.PayloadId
                           into eventTypes
                           from all in
                           eventTypes.Aggregate(
                new { EventCount = (long)0, Bytes = (long)0, minTime = long.MaxValue, maxTime = 0L },
                (ac, events) =>
                new
            {
                EventCount = ac.EventCount + 1,
                Bytes      = ac.Bytes + events.EventPayloadLength,
                minTime    = Math.Min(ac.minTime, events.ReceiveFileTimeUtc),
                maxTime    = Math.Max(ac.maxTime, events.ReceiveFileTimeUtc)
            })
                           select new { ManifestId = eventTypes.Key, all.EventCount, all.Bytes, all.minTime, all.maxTime };

            var counts = rawCount.ToEnumerable().ToArray();

            sw.Stop();
            Console.WriteLine("Query took {0} milliseconds.", sw.ElapsedMilliseconds);

            foreach (var c in counts)
            {
                var manifest = typeCache.Manifests
                               .FirstOrDefault(m => string.Equals(m.ManifestId, c.ManifestId, StringComparison.OrdinalIgnoreCase));

                if (manifest != null)
                {
                    var line = manifest.Manifest
                               .Split('\n').LastOrDefault(l => l.Trim().StartsWith(@"struct ", StringComparison.OrdinalIgnoreCase));

                    if (line != null)
                    {
                        var className = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();

                        var type = typeCache.Types.FirstOrDefault(t => t.Name == className);

                        if (type != null)
                        {
                            var minDateTime = DateTime.FromFileTimeUtc(c.minTime);
                            var maxDateTime = DateTime.FromFileTimeUtc(c.maxTime);
                            var duration    = (maxDateTime - minDateTime).TotalSeconds;
                            if (Math.Abs(duration) < 0.01)
                            {
                                duration = 1;
                            }

                            var stats = new EventStatistics
                            {
                                AverageByteSize = c.Bytes / c.EventCount,
                                ByteSize        = c.Bytes,
                                EventCount      = c.EventCount,
                                EventsPerSecond = c.EventCount / duration
                            };

                            statsPerType[type] = new CsvRelatedStats
                            {
                                ManifestId = c.ManifestId,
                                Statistics = stats,
                            };
                        }
                    }
                }
            }

            return(statsPerType);
        }
Exemplo n.º 3
0
        private Dictionary <Type, CsvRelatedStats> CalculateTypeStatistics(TypeCache typeCache, string inputFile)
        {
            Console.WriteLine("Getting statistics from file {0}.", inputFile);

            var statsPerType = new Dictionary <Type, CsvRelatedStats>();

            Stopwatch sw = Stopwatch.StartNew();

            var rawCount = from events in BinaryEtwObservable.FromSequentialFiles(inputFile)
                           group events by events.TypeId
                           into eventTypes
                           from all in
                           eventTypes.Aggregate(
                new { EventCount = (long)0, Bytes = (long)0, minTime = long.MaxValue, maxTime = 0L },
                (ac, events) =>
                new
            {
                EventCount = ac.EventCount + 1,
                Bytes      = ac.Bytes + events.Payload.Length,
                minTime    = Math.Min(ac.minTime, events.ReceivedTime.ToFileTime()),
                maxTime    = Math.Max(ac.maxTime, events.ReceivedTime.ToFileTime()),
            })
                           select new { ManifestId = eventTypes.Key, all.EventCount, all.Bytes, all.minTime, all.maxTime, };

            var counts = rawCount.ToEnumerable().ToArray();

            sw.Stop();
            Console.WriteLine("Query took {0} milliseconds.", sw.ElapsedMilliseconds);

            foreach (var c in counts)
            {
                var typeCacheItem = typeCache.FindMatchOrDefault(c.ManifestId);

                if (typeCacheItem != null && typeCacheItem.Type != null)
                {
                    var type = typeCacheItem.Type;
                    if (type != null)
                    {
                        var minDateTime = DateTime.FromFileTimeUtc(c.minTime);
                        var maxDateTime = DateTime.FromFileTimeUtc(c.maxTime);
                        var duration    = (maxDateTime - minDateTime).TotalSeconds;
                        if (Math.Abs(duration) < 0.01)
                        {
                            duration = 1;
                        }

                        var stats = new EventStatistics
                        {
                            AverageByteSize = c.Bytes / c.EventCount,
                            ByteSize        = c.Bytes,
                            EventCount      = c.EventCount,
                            EventsPerSecond = Math.Round(c.EventCount / duration, 3, MidpointRounding.AwayFromZero),
                        };

                        statsPerType[type] = new CsvRelatedStats
                        {
                            ManifestId = c.ManifestId,
                            Statistics = stats,
                        };
                    }
                }
            }

            return(statsPerType);
        }
Exemplo n.º 4
0
        private Dictionary<Type, CsvRelatedStats> CalculateTypeStatistics(TypeCache typeCache, string inputFile)
        {
            Console.WriteLine("Getting statistics from file {0}.", inputFile);

            var statsPerType = new Dictionary<Type, CsvRelatedStats>();

            Stopwatch sw = Stopwatch.StartNew();

            var rawCount = from events in BinaryEtwObservable.FromSequentialFiles(inputFile)
                           group events by events.PayloadId
                               into eventTypes
                               from all in
                                   eventTypes.Aggregate(
                                       new { EventCount = (long)0, Bytes = (long)0, minTime = long.MaxValue, maxTime = 0L },
                                       (ac, events) =>
                                       new
                                       {
                                           EventCount = ac.EventCount + 1,
                                           Bytes = ac.Bytes + events.EventPayloadLength,
                                           minTime = Math.Min(ac.minTime, events.ReceiveFileTimeUtc),
                                           maxTime = Math.Max(ac.maxTime, events.ReceiveFileTimeUtc)
                                       })
                               select new { ManifestId = eventTypes.Key, all.EventCount, all.Bytes, all.minTime, all.maxTime };

            var counts = rawCount.ToEnumerable().ToArray();

            sw.Stop();
            Console.WriteLine("Query took {0} milliseconds.", sw.ElapsedMilliseconds);

            foreach (var c in counts)
            {
                var manifest = typeCache.Manifests
                    .FirstOrDefault(m => string.Equals(m.ManifestId, c.ManifestId, StringComparison.OrdinalIgnoreCase));

                if (manifest != null)
                {
                    var line = manifest.Manifest
                        .Split('\n').LastOrDefault(l => l.Trim().StartsWith(@"struct ", StringComparison.OrdinalIgnoreCase));

                    if (line != null)
                    {
                        var className = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();

                        var type = typeCache.Types.FirstOrDefault(t => t.Name == className);

                        if (type != null)
                        {
                            var minDateTime = DateTime.FromFileTimeUtc(c.minTime);
                            var maxDateTime = DateTime.FromFileTimeUtc(c.maxTime);
                            var duration = (maxDateTime - minDateTime).TotalSeconds;
                            if (Math.Abs(duration) < 0.01) duration = 1;

                            var stats = new EventStatistics
                            {
                                AverageByteSize = c.Bytes / c.EventCount,
                                ByteSize = c.Bytes,
                                EventCount = c.EventCount,
                                EventsPerSecond = c.EventCount / duration
                            };

                            statsPerType[type] = new CsvRelatedStats
                                {
                                    ManifestId = c.ManifestId,
                                    Statistics = stats,
                                };
                        }
                    }
                }
            }

            return statsPerType;
        }