示例#1
0
 public LogFileStats GetStats(ILogFile logFile, Filter filter)
 => impl_.GetOrAdd(new Key(logFile, filter), k => LogFileStats.GatherStats(logFile, k.UnstatableFilter));
示例#2
0
        public static LogFileStats GatherStats(ILogFile logFile, Filter filter)
        {
            var events         = logFile.GetEvents();
            var filteredEvents = filter != null
                ? events.Where(filter)
                : events;

            var stats = filteredEvents.Aggregate
                        (
                new
            {
                EventCount        = 0,
                GroupStats        = new Dictionary <EventGroupKey, int> (),
                EarliestTimestamp = Timestamp.MaxValue,
                LatestTimestamp   = Timestamp.MinValue
            },
                (a, e) =>
            {
                var ts = e.Timestamp;

                var gs       = a.GroupStats;
                var groupKey = new EventGroupKey(e);
                if (gs.TryGetValue(groupKey, out var groupCount))
                {
                    gs[groupKey] = groupCount + 1;
                }
                else
                {
                    gs.Add(groupKey, 1);
                }

                return(new
                {
                    EventCount = a.EventCount + 1,
                    GroupStats = gs,
                    EarliestTimestamp = ts <a.EarliestTimestamp?ts : a.EarliestTimestamp,
                                            LatestTimestamp = ts> a.LatestTimestamp ? ts : a.LatestTimestamp
                });
            }
                        );

            var   eventCount = stats.EventCount;
            var   groupStats = stats.GroupStats;
            Int64 earliestTimestamp;
            Int64 latestTimestamp;

            if (eventCount > 0)
            {
                earliestTimestamp = stats.EarliestTimestamp;
                latestTimestamp   = stats.LatestTimestamp;
            }
            else
            {
                earliestTimestamp = Timestamp.MinValue;
                latestTimestamp   = Timestamp.MaxValue;
            }

            var result = new LogFileStats
                             (logFile.FileName, logFile.Size, eventCount, groupStats, earliestTimestamp, latestTimestamp);

            return(result);
        }