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 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.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); }