public async Task Dataflow_CorrectlyRecordsTheSessionAsync() { // arrange var profiler_results_storage = new TestProfilerResultsStorage(); ProfilingLibrary.Setup(() => null); ProfilingLibrary.Container.RegisterSingleton <IProfilerLogger, TestsProfilerLogger>(); ProfilingLibrary.Container.RegisterInstance <IProfilerResultsStorage>(profiler_results_storage); ProfilingLibrary.Container.RegisterSingleton <IProfilerConfiguration, TestProfilerConfiguration>(); var exceptions = new List <Exception>(); var dataflow = DataflowFluent .ReceiveDataOfType <int>() .TransformAsync(async id => { var item = new DataflowItemContext { Id = id, ProfileSession = ProfilingLibrary.StartProfiling() }; using (ProfilingLibrary.Profile(item.ProfileSession, new ProfileOperationSpecification("a"))) { await Task.Delay(50).ConfigureAwait(true); } return(item); }) .ProcessAsync(async item => { using (ProfilingLibrary.Profile(item.ProfileSession, new ProfileOperationSpecification("b"))) { await Task.Delay(50).ConfigureAwait(true); } }) .ActionAsync(item => { ProfilingLibrary.StopProfiling(item.ProfileSession); return(Task.CompletedTask); }) .WithDefaultExceptionLogger((ex, obj) => exceptions.Add(ex)) .CreateDataflow(); // act await dataflow.ProcessAsync(Enumerable.Range(0, 10)).ConfigureAwait(false); // assert exceptions.Should().BeEmpty(); profiler_results_storage.ProfileSessions.ToArray() .SelectMany(x => x.Operations) .Select(x => x.Name) .GroupBy(x => x) .Select(x => new { Name = x.Key, Count = x.Count() }) .Should().BeEquivalentTo(new { Name = "a", Count = 10 }, new { Name = "b", Count = 10 }); }
public static async Task Main() { try { ConfigurationManager.AppSettings["Profiling.Enabled"] = "true"; ConfigurationManager.AppSettings["Profiling.ResultsProcessBatchDelay"] = "00:00:00"; ConfigurationManager.AppSettings["Profiling.ResultsProcessMaxBatchSize"] = "1"; var container = new Container { Options = { AllowOverridingRegistrations = true } }; ProfilingLibrary.Setup(() => null, container); container.RegisterSingleton <IProfilerLogger, ConsoleProfilerLogger>(); container.RegisterSingleton <IProfilerResultsStorage, ConsoleProfileResultsStorage>(); container.Verify(); ProfilingLibrary.StartProfiling(); using (var connection = ConfigurationManager.ConnectionStrings["Test"].CreateDbConnection()) { connection.Execute(@"truncate table TestRocksProfilingTable"); var count = connection.Execute(@"insert TestRocksProfilingTable(Data) values (@data)", new[] { new { data = "123" }, new { data = "456" }, new { data = "789" } } ); Console.WriteLine("Inserted rows: {0}", count); } using (new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { using (var connection = ConfigurationManager.ConnectionStrings["Test"].CreateDbConnection()) { var count = connection.Execute(@"insert TestRocksProfilingTable(Data) values (@data)", new[] { new { data = "2 123" }, new { data = "2 456" }, new { data = "2 789" } } ); Console.WriteLine("Inserted rows: {0}", count); } } using (var connection = ConfigurationManager.ConnectionStrings["Test"] .CreateDbConnection()) { var data = (await connection.QueryAsync <string>("select top 1 Data from TestRocksProfilingTable order by Id;" + "waitfor delay '00:00:01'")).FirstOrDefault(); Console.WriteLine("Selected via ADO: {0}", data); } ProfilingLibrary.StopProfiling(new Dictionary <string, object> { { "name", "test session" } }); Task.Delay(500).Wait(); } catch (Exception ex) { Console.WriteLine("\n\n{0}\n\n", ex); } }
protected void Application_BeginRequest(object sender, EventArgs e) { HttpContextAsyncLocal.Value = new HttpContextWrapper(HttpContext.Current); ProfilingLibrary.StartProfiling(); }
public static void Main() { try { ConfigurationManager.AppSettings["Profiling.Enabled"] = "true"; ConfigurationManager.AppSettings["Profiling.ResultsProcessBatchDelay"] = "00:00:00"; ConfigurationManager.AppSettings["Profiling.ResultsBufferSize"] = "1"; var container = new Container { Options = { AllowOverridingRegistrations = true } }; ProfilingLibrary.Setup(() => null, container); container.RegisterSingleton <IProfilerLogger, ConsoleProfilerLogger>(); container.RegisterSingleton <IProfilerResultsStorage, ConsoleProfileResultsStorage>(); container.RegisterSingleton <IProfilerEventsHandler, ConsoleProfileEventHandlers>(); container.Verify(); ProfilingLibrary.StartProfiling(); using (var connection = ConfigurationManager.ConnectionStrings["Test"].CreateDbConnection()) { var count = connection.Execute(@"insert TestRocksProfilingTable(Data) values (@data)", new[] { new { data = "123" }, new { data = "456" }, new { data = "789" } } ); Console.WriteLine("Inserted rows: {0}", count); } using (new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { using (var connection = ConfigurationManager.ConnectionStrings["Test"].CreateDbConnection()) { var count = connection.Execute(@"insert TestRocksProfilingTable(Data) values (@data)", new[] { new { data = "123" }, new { data = "456" }, new { data = "789" } } ); Console.WriteLine("Inserted rows: {0}", count); } } using (var connection = ConfigurationManager.ConnectionStrings["Test"] .CreateDbConnection()) { var id = connection.Query <int>("select top 1 Id from TestRocksProfilingTable order by Id desc").FirstOrNull(); Console.WriteLine("Selected via ADO: {0}", id); } ProfilingLibrary.StopProfiling(new Dictionary <string, object> { { "name", "test session" } }); Task.Delay(500).Wait(); } // ReSharper disable once CatchAllClause catch (Exception ex) { Console.WriteLine("\n\n{0}\n\n", ex); } }