This reader process multiples .ckmon files (possibly in different steps: it internally aggregates the result) and can create ActivityMap objects on demand. It is a thread safe object (the ActivityMap is immutable).
Inheritance: IDisposable
Ejemplo n.º 1
0
 internal LiveIndexedMonitor( Guid monitorId, MultiLogReader reader )
 {
     MonitorId = monitorId;
     _reader = reader;
     _files = new List<RawLogFileMonitorOccurence>();
     _firstEntryTime = DateTimeStamp.MaxValue;
     _lastEntryTime = DateTimeStamp.MinValue;
 }
Ejemplo n.º 2
0
 internal LiveIndexedMonitor(Guid monitorId, MultiLogReader reader)
 {
     MonitorId       = monitorId;
     _reader         = reader;
     _files          = new List <RawLogFileMonitorOccurence>();
     _firstEntryTime = DateTimeStamp.MaxValue;
     _lastEntryTime  = DateTimeStamp.MinValue;
 }
 internal ActivityMap(MultiLogReader reader)
 {
     // ConcurrentDictionary.Values is a snapshot (a ReadOnlyCollection), this is why
     // it is safe to wrap it in a IReadOnlyCollection wrapper.
     _allFiles       = (ReadOnlyCollection <RawLogFile>)reader._files.Values;
     _validFiles     = _allFiles.Where(f => f.Error == null && f.TotalEntryCount > 0).ToArray();
     _monitors       = reader._monitors.ToDictionary(e => e.Key, e => new Monitor(e.Value));
     _monitorList    = _monitors.Values.OrderBy(m => m.FirstEntryTime).ToArray();
     _firstEntryDate = reader._globalFirstEntryTime;
     _lastEntryDate  = reader._globalLastEntryTime;
 }
Ejemplo n.º 4
0
            void UpdateMonitor(MultiLogReader reader, long streamOffset, Dictionary <string, RawLogFileMonitorOccurence> monitorOccurrence, List <RawLogFileMonitorOccurence> monitorOccurenceList, IMulticastLogEntry log)
            {
                bool newOccurrence = false;

                if (!monitorOccurrence.TryGetValue(log.MonitorId, out RawLogFileMonitorOccurence? occ))
                {
                    occ = new RawLogFileMonitorOccurence(this, log.MonitorId, streamOffset);
                    monitorOccurrence.Add(log.MonitorId, occ);
                    monitorOccurenceList.Add(occ);
                    newOccurrence = true;
                }
                if (occ.FirstEntryTime > log.LogTime)
                {
                    occ.FirstEntryTime = log.LogTime;
                }
                if (occ.LastEntryTime < log.LogTime)
                {
                    occ.LastEntryTime = log.LogTime;
                }
                occ.LastOffset = streamOffset;
                reader.RegisterOneLog(occ, newOccurrence, streamOffset, log);
            }
Ejemplo n.º 5
0
 internal void Initialize(MultiLogReader reader)
 {
     try
     {
         var monitorOccurrences    = new Dictionary <Guid, RawLogFileMonitorOccurence>();
         var monitorOccurrenceList = new List <RawLogFileMonitorOccurence>();
         using (var r = LogReader.Open(_fileName))
         {
             if (r.MoveNext())
             {
                 _fileVersion = r.StreamVersion;
                 do
                 {
                     var log = r.Current as IMulticastLogEntry;
                     if (log != null)
                     {
                         ++_totalEntryCount;
                         if (_firstEntryTime > log.LogTime)
                         {
                             _firstEntryTime = log.LogTime;
                         }
                         if (_lastEntryTime < log.LogTime)
                         {
                             _lastEntryTime = log.LogTime;
                         }
                         UpdateMonitor(reader, r.StreamOffset, monitorOccurrences, monitorOccurrenceList, log);
                     }
                 }while(r.MoveNext());
             }
             _badEndOfFile = r.BadEndOfFileMarker;
             _error        = r.ReadException;
         }
         _monitors = monitorOccurrenceList.ToArray();
     }
     catch (Exception ex)
     {
         _error = ex;
     }
 }
Ejemplo n.º 6
0
        public static void ReplayLogs(DirectoryInfo directory, bool recurse, Func <MultiLogReader.Monitor, ActivityMonitor> monitorProvider, IActivityMonitor m = null)
        {
            var reader = new MultiLogReader();

            using (m?.OpenTrace($"Reading files from '{directory.FullName}' {(recurse ? "(recursive)" : null)}."))
            {
                var files = reader.Add(directory.EnumerateFiles("*.ckmon", recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Select(f => f.FullName));
                if (files.Count == 0)
                {
                    if (m != null)
                    {
                        m.Warn("No *.ckmon files found!");
                    }
                }
                else
                {
                    var monitors = reader.GetActivityMap().Monitors;
                    if (m != null)
                    {
                        m.Trace(String.Join(Environment.NewLine, files));
                        m.CloseGroup($"Found {files.Count} file(s) containing {monitors.Count} monitor(s).");
                        m.OpenTrace("Extracting entries.");
                    }
                    foreach (var mon in monitors)
                    {
                        var replay = monitorProvider(mon);
                        if (replay == null)
                        {
                            m?.Info($"Skipping activity from '{mon.MonitorId}'.");
                        }
                        else
                        {
                            mon.Replay(replay, m);
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
 void UpdateMonitor( MultiLogReader reader, long streamOffset, Dictionary<Guid, RawLogFileMonitorOccurence> monitorOccurrence, List<RawLogFileMonitorOccurence> monitorOccurenceList, IMulticastLogEntry log )
 {
     bool newOccurrence = false;
     RawLogFileMonitorOccurence occ;
     if( !monitorOccurrence.TryGetValue( log.MonitorId, out occ ) )
     {
         occ = new RawLogFileMonitorOccurence( this, log.MonitorId, streamOffset );
         monitorOccurrence.Add( log.MonitorId, occ );
         monitorOccurenceList.Add( occ );
         newOccurrence = true;
     }
     if( occ.FirstEntryTime > log.LogTime ) occ.FirstEntryTime = log.LogTime;
     if( occ.LastEntryTime < log.LogTime ) occ.LastEntryTime = log.LogTime;
     occ.LastOffset = streamOffset;
     reader.RegisterOneLog( occ, newOccurrence, streamOffset, log );
 }
Ejemplo n.º 8
0
 internal void Initialize( MultiLogReader reader )
 {
     try
     {
         var monitorOccurrences = new Dictionary<Guid, RawLogFileMonitorOccurence>();
         var monitorOccurrenceList = new List<RawLogFileMonitorOccurence>();
         using( var r = LogReader.Open( _fileName ) )
         {
             if( r.MoveNext() )
             {
                 _fileVersion = r.StreamVersion;
                 do
                 {
                     var log = r.Current as IMulticastLogEntry;
                     if( log != null )
                     {
                         ++_totalEntryCount;
                         if( _firstEntryTime > log.LogTime ) _firstEntryTime = log.LogTime;
                         if( _lastEntryTime < log.LogTime ) _lastEntryTime = log.LogTime;
                         UpdateMonitor( reader, r.StreamOffset, monitorOccurrences, monitorOccurrenceList, log );
                     }
                 }
                 while( r.MoveNext() );
             }
             _badEndOfFile = r.BadEndOfFileMarker;
             _error = r.ReadException;
         }
         _monitors = monitorOccurrenceList.ToArray();
     }
     catch( Exception ex )
     {
         _error = ex;
     }
 }