public void reading_ckmon_files_in_previous_versions(int version) { var folder = Path.Combine(TestHelper.SolutionFolder, "Tests", "CK.Monitoring.Tests", "Persistence", "PrevVersionsData", "v" + version); var files = Directory.GetFiles(folder, "*.ckmon", SearchOption.TopDirectoryOnly); using MultiLogReader reader = new MultiLogReader(); bool newIndex; for (int i = 0; i < files.Length; ++i) { var f = reader.Add(files[i], out newIndex); newIndex.Should().BeTrue(); f.Error.Should().BeNull(); f.FileVersion.Should().Be(version); } var allEntries = reader.GetActivityMap().Monitors.SelectMany(m => m.ReadAllEntries().Select(e => e.Entry)).ToList(); // v5 and v6 did not have the Debug level. if (version <= 6) { var allLevels = allEntries.Select(e => e.LogLevel & ~LogLevel.IsFiltered); allLevels.Should().NotContain(LogLevel.Debug) .And.Contain(new[] { LogLevel.Trace, LogLevel.Info, LogLevel.Warn, LogLevel.Error, LogLevel.Fatal }); } }
private static void DuplicateTestWith6Entries(int nbEntries1, int nbEntries2, bool gzip = false) { var folder = TestHelper.PrepareLogFolder("ReadDuplicates"); var config = new GrandOutputConfiguration() .AddHandler(new Handlers.BinaryFileConfiguration() { Path = folder, MaxCountPerFile = nbEntries1, UseGzipCompression = gzip }) .AddHandler(new Handlers.BinaryFileConfiguration() { Path = folder, MaxCountPerFile = nbEntries2, UseGzipCompression = gzip }); using (var o = new GrandOutput(config)) { var m = new ActivityMonitor(); o.EnsureGrandOutputClient(m); var direct = m.Output.RegisterClient(new CKMonWriterClient(folder, Math.Min(nbEntries1, nbEntries2), LogFilter.Debug, gzip)); // 6 traces that go to the GrandOutput but also to the direct CKMonWriterClient. m.Trace("Trace 1"); m.OpenTrace("OpenTrace 1"); m.Trace("Trace 1.1"); m.Trace("Trace 1.2"); m.CloseGroup(); m.Trace("Trace 2"); Thread.Sleep(100); m.Output.UnregisterClient(direct); } var files = TestHelper.WaitForCkmonFilesInDirectory(folder, 3); for (int pageReadLength = 1; pageReadLength < 10; ++pageReadLength) { using MultiLogReader reader = new MultiLogReader(); reader.Add(files); var map = reader.GetActivityMap(); map.ValidFiles.All(rawFile => rawFile.IsValidFile).Should().BeTrue("All files are correctly closed with the final 0 byte and no exception occurred while reading them."); map.Monitors.Should().HaveCount(2); var allEntries1 = map.Monitors[0].ReadAllEntries().ToList(); var allEntries2 = map.Monitors[1].ReadAllEntries().ToList(); var allEntries = allEntries1.Any(e => e.Entry.Text == "Topic: CK.Monitoring.DispatcherSink") ? allEntries2 : allEntries1; allEntries.Select(e => e.Entry.Text) .SequenceEqual(new[] { "Trace 1", "OpenTrace 1", "Trace 1.1", "Trace 1.2", null, "Trace 2" }) .Should().BeTrue(); } }
private static void DuplicateTestWith6Entries(int nbEntries1, int nbEntries2, bool gzip = false) { var folder = String.Format("{0}\\ReadDuplicates", TestHelper.TestFolder); TestHelper.CleanupFolder(folder); string config = String.Format(@" <GrandOutputConfiguration> <Channel> <Add Type=""BinaryFile"" Name=""All-1"" MaxCountPerFile=""{1}"" Path=""{0}"" UseGzipCompression=""{3}"" /> <Add Type=""BinaryFile"" Name=""All-2"" MaxCountPerFile=""{2}"" Path=""{0}"" UseGzipCompression=""{3}"" /> </Channel> </GrandOutputConfiguration> ", folder, nbEntries1, nbEntries2, gzip); using (var o = new GrandOutput()) { GrandOutputConfiguration c = new GrandOutputConfiguration(); Assert.That(c.Load(XDocument.Parse(config).Root, TestHelper.ConsoleMonitor), Is.True); Assert.That(o.SetConfiguration(c, TestHelper.ConsoleMonitor), Is.True); var m = new ActivityMonitor(); o.Register(m); var direct = m.Output.RegisterClient(new CKMonWriterClient(folder, Math.Min(nbEntries1, nbEntries2), LogFilter.Debug, gzip)); // 6 traces that go to the GrandOutput but also to the direct CKMonWriterClient. m.Trace().Send("Trace 1"); m.OpenTrace().Send("OpenTrace 1"); m.Trace().Send("Trace 1.1"); m.Trace().Send("Trace 1.2"); m.CloseGroup(); m.Trace().Send("Trace 2"); System.Threading.Thread.Sleep(100); m.Output.UnregisterClient(direct); } var files = TestHelper.WaitForCkmonFilesInDirectory(folder, 3); for (int pageReadLength = 1; pageReadLength < 10; ++pageReadLength) { MultiLogReader reader = new MultiLogReader(); reader.Add(files); var map = reader.GetActivityMap(); Assert.That(map.ValidFiles.All(rawFile => rawFile.IsValidFile), Is.True, "All files are correctly closed with the final 0 byte and no exception occurred while reading them."); var readMonitor = map.Monitors.Single(); List <ParentedLogEntry> allEntries = new List <ParentedLogEntry>(); using (var pageReader = readMonitor.ReadFirstPage(pageReadLength)) { do { allEntries.AddRange(pageReader.Entries); }while(pageReader.ForwardPage() > 0); } CollectionAssert.AreEqual(new[] { "Trace 1", "OpenTrace 1", "Trace 1.1", "Trace 1.2", null, "Trace 2" }, allEntries.Select(e => e.Entry.Text).ToArray(), StringComparer.Ordinal); } }
private static void DuplicateTestWith6Entries( int nbEntries1, int nbEntries2, bool gzip = false ) { var folder = String.Format( "{0}\\ReadDuplicates", TestHelper.TestFolder ); TestHelper.CleanupFolder( folder ); string config = String.Format( @" <GrandOutputConfiguration> <Channel> <Add Type=""BinaryFile"" Name=""All-1"" MaxCountPerFile=""{1}"" Path=""{0}"" UseGzipCompression=""{3}"" /> <Add Type=""BinaryFile"" Name=""All-2"" MaxCountPerFile=""{2}"" Path=""{0}"" UseGzipCompression=""{3}"" /> </Channel> </GrandOutputConfiguration> ", folder, nbEntries1, nbEntries2, gzip ); using( var o = new GrandOutput() ) { GrandOutputConfiguration c = new GrandOutputConfiguration(); Assert.That( c.Load( XDocument.Parse( config ).Root, TestHelper.ConsoleMonitor ), Is.True ); Assert.That( o.SetConfiguration( c, TestHelper.ConsoleMonitor ), Is.True ); var m = new ActivityMonitor(); o.Register( m ); var direct = m.Output.RegisterClient( new CKMonWriterClient( folder, Math.Min( nbEntries1, nbEntries2 ), LogFilter.Debug, gzip ) ); // 6 traces that go to the GrandOutput but also to the direct CKMonWriterClient. m.Trace().Send( "Trace 1" ); m.OpenTrace().Send( "OpenTrace 1" ); m.Trace().Send( "Trace 1.1" ); m.Trace().Send( "Trace 1.2" ); m.CloseGroup(); m.Trace().Send( "Trace 2" ); System.Threading.Thread.Sleep( 100 ); m.Output.UnregisterClient( direct ); } var files = TestHelper.WaitForCkmonFilesInDirectory( folder, 3 ); for( int pageReadLength = 1; pageReadLength < 10; ++pageReadLength ) { MultiLogReader reader = new MultiLogReader(); reader.Add( files ); var map = reader.GetActivityMap(); Assert.That( map.ValidFiles.All( rawFile => rawFile.IsValidFile ), Is.True, "All files are correctly closed with the final 0 byte and no exception occurred while reading them." ); var readMonitor = map.Monitors.Single(); List<ParentedLogEntry> allEntries = new List<ParentedLogEntry>(); using( var pageReader = readMonitor.ReadFirstPage( pageReadLength ) ) { do { allEntries.AddRange( pageReader.Entries ); } while( pageReader.ForwardPage() > 0 ); } CollectionAssert.AreEqual( new[] { "Trace 1", "OpenTrace 1", "Trace 1.1", "Trace 1.2", null, "Trace 2" }, allEntries.Select( e => e.Entry.Text ).ToArray(), StringComparer.Ordinal ); } }
public void GrandOutputHasSameCompressedAndUncompressedLogs() { string rootPath = SystemActivityMonitor.RootLogPath + @"\GrandOutputGzip"; TestHelper.CleanupFolder(rootPath); GrandOutputConfiguration c = new GrandOutputConfiguration(); Assert.That(c.Load(XDocument.Parse(@" <GrandOutputConfiguration GlobalDefaultFilter=""Release"" > <Channel> <Add Type=""BinaryFile"" Name=""GzipGlobalCatch"" Path=""" + rootPath + @"\OutputGzip"" MaxCountPerFile=""200000"" UseGzipCompression=""True"" /> <Add Type=""BinaryFile"" Name=""RawGlobalCatch"" Path=""" + rootPath + @"\OutputRaw"" MaxCountPerFile=""200000"" UseGzipCompression=""False"" /> </Channel> </GrandOutputConfiguration>" ).Root, TestHelper.ConsoleMonitor)); Assert.That(c.ChannelsConfiguration.Configurations.Count, Is.EqualTo(2)); using (GrandOutput g = new GrandOutput()) { Assert.That(g.SetConfiguration(c, TestHelper.ConsoleMonitor), Is.True); var taskA = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task A", g)); return(1); }); var taskB = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task B", g)); return(1); }); var taskC = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task C", g)); return(1); }); Task.WaitAll(taskA, taskB, taskC); } string[] gzipCkmons = TestHelper.WaitForCkmonFilesInDirectory(rootPath + @"\OutputGzip", 1); string[] rawCkmons = TestHelper.WaitForCkmonFilesInDirectory(rootPath + @"\OutputRaw", 1); Assert.That(gzipCkmons, Has.Length.EqualTo(1)); Assert.That(rawCkmons, Has.Length.EqualTo(1)); FileInfo gzipCkmonFile = new FileInfo(gzipCkmons.Single()); FileInfo rawCkmonFile = new FileInfo(rawCkmons.Single()); Assert.That(gzipCkmonFile.Exists, Is.True); Assert.That(rawCkmonFile.Exists, Is.True); // Test file size Assert.That(gzipCkmonFile.Length, Is.LessThan(rawCkmonFile.Length)); // Test de-duplication between Gzip and non-Gzip MultiLogReader mlr = new MultiLogReader(); var fileList = mlr.Add(new string[] { gzipCkmonFile.FullName, rawCkmonFile.FullName }); Assert.That(fileList, Has.Count.EqualTo(2)); var map = mlr.GetActivityMap(); Assert.That(map.Monitors.Count, Is.EqualTo(3)); }
public void reading_old_ckmon_V0_files() { var folder = Path.Combine( TestHelper.SolutionFolder, "Tests/CK.Monitoring.Tests/Persistence/CKMon-v0/" ); var files = Directory.GetFiles( folder, "*.ckmon", SearchOption.TopDirectoryOnly ); MultiLogReader reader = new MultiLogReader(); bool newIndex; for( int i = 0; i < files.Length; ++i ) { var f = reader.Add( files[i], out newIndex ); Assert.That( newIndex ); Assert.That( f.Error, Is.Null ); } }
public void reading_old_ckmon_V0_files() { var folder = Path.Combine(TestHelper.SolutionFolder, "Tests/CK.Monitoring.Tests/Persistence/CKMon-v0/"); var files = Directory.GetFiles(folder, "*.ckmon", SearchOption.TopDirectoryOnly); MultiLogReader reader = new MultiLogReader(); bool newIndex; for (int i = 0; i < files.Length; ++i) { var f = reader.Add(files[i], out newIndex); Assert.That(newIndex); Assert.That(f.Error, Is.Null); } }
public static void ReplayLogs(DirectoryInfo directory, bool recurse, Func <MultiLogReader.Monitor, ActivityMonitor> monitorProvider, IActivityMonitor m = null) { var reader = new MultiLogReader(); using (m != null ? m.OpenTrace().Send("Reading files from '{0}' {1}.", directory.FullName, recurse ? "(recursive)" : null) : 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().Send("No *.ckmon files found!"); } } else { var monitors = reader.GetActivityMap().Monitors; if (m != null) { m.Trace().Send(String.Join(Environment.NewLine, files)); m.CloseGroup(String.Format("Found {0} file(s) containing {1} monitor(s).", files.Count, monitors.Count)); m.OpenTrace().Send("Extracting entries."); } foreach (var mon in monitors) { var replay = monitorProvider(mon); if (replay == null) { if (m != null) { m.Info().Send("Skipping activity from '{0}'.", mon.MonitorId); } } else { mon.Replay(replay, m); } } } } }
private static void Main(string[] args) { string inputFilePath = args[0]; if (!Path.HasExtension(inputFilePath)) { using (MultiLogReader multiLogReader = new MultiLogReader()) { multiLogReader.Add(Directory.GetFiles(inputFilePath, "*.ckmon", SearchOption.AllDirectories)); var activityMap = multiLogReader.GetActivityMap(); SortedList <DateTimeStamp, IMulticastLogEntry> list = new SortedList <DateTimeStamp, IMulticastLogEntry>(); foreach (var file in activityMap.ValidFiles) { var readers = file.Monitors.Select(m => m.CreateFilteredReader(0L)); foreach (var reader in readers) { while (reader.MoveNext()) { list.Add(reader.CurrentMulticast.LogTime, reader.CurrentMulticast); } } } MulticastLogEntryTextBuilder b = new MulticastLogEntryTextBuilder(); foreach (var entry in list) { b.AppendEntry(entry.Value); } Console.Out.Write(b.ToString()); } } if (inputFilePath.EndsWith(".ckmon")) { MulticastLogEntryTextBuilder b = new MulticastLogEntryTextBuilder(); CopyTo(b, inputFilePath); } }
public void GrandOutputHasSameCompressedAndUncompressedLogs() { string rootPath = SystemActivityMonitor.RootLogPath + @"\GrandOutputGzip"; TestHelper.CleanupFolder( rootPath ); GrandOutputConfiguration c = new GrandOutputConfiguration(); Assert.That( c.Load( XDocument.Parse( @" <GrandOutputConfiguration GlobalDefaultFilter=""Release"" > <Channel> <Add Type=""BinaryFile"" Name=""GzipGlobalCatch"" Path=""" + rootPath + @"\OutputGzip"" MaxCountPerFile=""200000"" UseGzipCompression=""True"" /> <Add Type=""BinaryFile"" Name=""RawGlobalCatch"" Path=""" + rootPath + @"\OutputRaw"" MaxCountPerFile=""200000"" UseGzipCompression=""False"" /> </Channel> </GrandOutputConfiguration>" ).Root, TestHelper.ConsoleMonitor ) ); Assert.That( c.ChannelsConfiguration.Configurations.Count, Is.EqualTo( 2 ) ); using( GrandOutput g = new GrandOutput() ) { Assert.That( g.SetConfiguration( c, TestHelper.ConsoleMonitor ), Is.True ); var taskA = Task.Factory.StartNew<int>( () => { DumpMonitorOutput( CreateMonitorAndRegisterGrandOutput( "Task A", g ) ); return 1; } ); var taskB = Task.Factory.StartNew<int>( () => { DumpMonitorOutput( CreateMonitorAndRegisterGrandOutput( "Task B", g ) ); return 1; } ); var taskC = Task.Factory.StartNew<int>( () => { DumpMonitorOutput( CreateMonitorAndRegisterGrandOutput( "Task C", g ) ); return 1; } ); Task.WaitAll( taskA, taskB, taskC ); } string[] gzipCkmons = TestHelper.WaitForCkmonFilesInDirectory( rootPath + @"\OutputGzip", 1 ); string[] rawCkmons = TestHelper.WaitForCkmonFilesInDirectory( rootPath + @"\OutputRaw", 1 ); Assert.That( gzipCkmons, Has.Length.EqualTo( 1 ) ); Assert.That( rawCkmons, Has.Length.EqualTo( 1 ) ); FileInfo gzipCkmonFile = new FileInfo( gzipCkmons.Single() ); FileInfo rawCkmonFile = new FileInfo( rawCkmons.Single() ); Assert.That( gzipCkmonFile.Exists, Is.True ); Assert.That( rawCkmonFile.Exists, Is.True ); // Test file size Assert.That( gzipCkmonFile.Length, Is.LessThan( rawCkmonFile.Length ) ); // Test de-duplication between Gzip and non-Gzip MultiLogReader mlr = new MultiLogReader(); var fileList = mlr.Add( new string[] { gzipCkmonFile.FullName, rawCkmonFile.FullName } ); Assert.That( fileList, Has.Count.EqualTo( 2 ) ); var map = mlr.GetActivityMap(); Assert.That( map.Monitors.Count, Is.EqualTo( 3 ) ); }
public static void ReplayLogs( DirectoryInfo directory, bool recurse, Func<MultiLogReader.Monitor, ActivityMonitor> monitorProvider, IActivityMonitor m = null ) { var reader = new MultiLogReader(); using( m != null ? m.OpenTrace().Send( "Reading files from '{0}' {1}.", directory.FullName, recurse ? "(recursive)" : null ) : 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().Send( "No *.ckmon files found!" ); } else { var monitors = reader.GetActivityMap().Monitors; if( m != null ) { m.Trace().Send( String.Join( Environment.NewLine, files ) ); m.CloseGroup( String.Format( "Found {0} file(s) containing {1} monitor(s).", files.Count, monitors.Count ) ); m.OpenTrace().Send( "Extracting entries." ); } foreach( var mon in monitors ) { var replay = monitorProvider( mon ); if( replay == null ) { if( m != null ) m.Info().Send( "Skipping activity from '{0}'.", mon.MonitorId ); } else { mon.Replay( replay, m ); } } } } }