public void AddOperatorTestValidations() { EventStatistics y = new EventStatistics { AverageByteSize = 2, ByteSize = 3, EventCount = 4, EventsPerSecond = 5, }; var result = null + y; }
public Dictionary<Type, EventStatistics> GetTypeStatistics(TypeCache typeCache, string inputFile) { var statsPerType = new Dictionary<Type, EventStatistics>(); if (string.IsNullOrWhiteSpace(inputFile)) { throw new ArgumentException("inputFile"); } Console.WriteLine("Getting Statistics..."); 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(); 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)); var className = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(); var type = typeCache.Types.FirstOrDefault(t => t.Name == className); var minDateTime = DateTime.FromFileTimeUtc(c.minTime); var maxDateTime = DateTime.FromFileTimeUtc(c.maxTime); var duration = (maxDateTime - minDateTime).TotalSeconds; if (Math.Abs(this.duration) < 0.01) this.duration = 1; var stats = new EventStatistics { AverageByteSize = c.Bytes / c.EventCount, ByteSize = c.Bytes, EventCount = c.EventCount, EventsPerSecond = c.EventCount / duration }; statsPerType.Add(type, stats); } } return statsPerType; }
public Dictionary <Type, EventStatistics> GetTypeStatistics(TypeCache typeCache, string inputFile) { var statsPerType = new Dictionary <Type, EventStatistics>(); if (string.IsNullOrWhiteSpace(inputFile)) { throw new ArgumentException("inputFile"); } Console.WriteLine("Getting Statistics..."); 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(); 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)); var className = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(); var type = typeCache.Types.FirstOrDefault(t => t.Name == className); var minDateTime = DateTime.FromFileTimeUtc(c.minTime); var maxDateTime = DateTime.FromFileTimeUtc(c.maxTime); var duration = (maxDateTime - minDateTime).TotalSeconds; if (Math.Abs(this.duration) < 0.01) { this.duration = 1; } var stats = new EventStatistics { AverageByteSize = c.Bytes / c.EventCount, ByteSize = c.Bytes, EventCount = c.EventCount, EventsPerSecond = c.EventCount / duration }; statsPerType.Add(type, stats); } } return(statsPerType); }
private bool IsCsvLineParsable(string line, TypeCache typeCache, Dictionary<Type, EventStatistics> eventStatsCollection) { bool isParsable = false; var tokens = line.Split(CsvSeparator); string eventManifestIdFromCsv = string.Empty; string typeNameFromCsv = string.Empty; if (tokens != null && tokens.Length == 6 && tokens.All(a => !string.IsNullOrWhiteSpace(a))) { eventManifestIdFromCsv = tokens[0]; typeNameFromCsv = tokens[1]; var typeCacheItem = typeCache.FindMatchOrDefault(eventManifestIdFromCsv); if (typeCacheItem != null && typeCacheItem.Type != null && string.Equals(typeCacheItem.Type.Name, typeNameFromCsv, StringComparison.OrdinalIgnoreCase)) { Debug.WriteLine(typeCacheItem.Type.Name); EventStatistics statsFromCsv = new EventStatistics { AverageByteSize = long.Parse(tokens[5]), ByteSize = long.Parse(tokens[4]), EventCount = long.Parse(tokens[2]), EventsPerSecond = double.Parse(tokens[3]), }; EventStatistics existingStats; if (eventStatsCollection.TryGetValue(typeCacheItem.Type, out existingStats)) { existingStats = existingStats + statsFromCsv; Console.WriteLine("Stats for type {0} updated.", typeNameFromCsv); } else { eventStatsCollection[typeCacheItem.Type] = statsFromCsv; Console.WriteLine("Stats for type {0} added.", typeNameFromCsv); } isParsable = true; } } return isParsable; }
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; }
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; }