static void Main(string[] args) { try { using (new TimedSection("Custom.Section")) { String.Format("Final {0}", "section"); using (new TimedSection("Custom.Section")) { var test1 = TimedSection.Run(String.Format, "Hello {0}", "world"); TimedSection.Run(Program.Test, "Hello {0}", "world"); throw new NotImplementedException("Another Exception Here"); } } } catch (Exception) { var test2 = TimedSection.Run(String.Format, "Foo {0}", "bar"); } var test3 = TimedSection.Run(String.Format, "Abra {0}", "kadabra"); }
public CommandExecutor(DbCommand command, PreparedCommand prepared, RetryPolicy retryPolicy, TimedSection timedSection, ITransactionDiagnostic transaction, bool allowSynchronousOperations) { this.command = command; this.prepared = prepared; this.retryPolicy = retryPolicy; this.timedSection = timedSection; this.transaction = transaction; this.allowSynchronousOperations = allowSynchronousOperations; }
async IAsyncEnumerable <TRecord> ProcessReaderAsync <TRecord>(DbDataReader reader, PreparedCommand command, [EnumeratorCancellation] CancellationToken cancellationToken) { using var timed = new TimedSection(ms => configuration.QueryLogger.ProcessReader(ms, name, command.Statement)); var strategy = configuration.ReaderStrategies.Resolve <TRecord>(command); while (await reader.ReadAsync(cancellationToken)) { var(instance, success) = strategy(reader); if (success) { yield return(instance); } } }
IEnumerable <TRecord> ProcessReader <TRecord>(DbDataReader reader, PreparedCommand command) { using var timed = new TimedSection(ms => configuration.QueryLogger.ProcessReader(ms, name, command.Statement)); var strategy = configuration.ReaderStrategies.Resolve <TRecord>(command); while (reader.Read()) { var(instance, success) = strategy(reader); if (success) { yield return(instance); } } }
private static void CloseSection(int index) { if (ts_openSections.Pop() != index) { throw new ArgumentException("TimedSection being closed is not the most recently opened"); } TimedSection section = ts_sections[index]; section.Duration = GetTimeOffset() - section.Start; ts_sections[index] = section; if ((ts_openSections.Count == 0) && (s_startingThread == Thread.CurrentThread)) { Finish(); } }
public static IDisposable Section(string label, string details = "") { if (ts_Sections == null) { InitializeProfilerForCurrentThread(); } if (!m_Started) { Start(); } var section = new TimedSection(label, details); var index = ts_Sections.Count; ts_Sections.Add(section); ts_OpenSections.Push(index); return(new TimedSectionHandle { m_Index = index }); }
IEnumerable <T> Stream <T>(IDbCommand command, DocumentMap mapping) { IDataReader reader = null; try { long msUntilFirstRecord = -1; using (var timedSection = new TimedSection(Log, ms => $"Reader took {ms}ms ({msUntilFirstRecord}ms until the first record) in transaction '{name}': {command.CommandText}", 300)) { try { reader = command.ExecuteReaderWithRetry(); } catch (SqlException ex) { throw WrapException(command, ex); } catch (Exception ex) { Log.DebugException($"Exception in relational transaction '{name}'", ex); throw; } msUntilFirstRecord = timedSection.ElapsedMilliseconds; var idIndex = GetOrdinal(reader, "Id"); var jsonIndex = GetOrdinal(reader, "JSON"); var typeResolver = mapping.InstanceTypeResolver.TypeResolverFromReader(s => GetOrdinal(reader, s)); while (reader.Read()) { T instance; var instanceType = typeResolver(reader); if (jsonIndex >= 0) { var json = reader[jsonIndex].ToString(); var deserialized = JsonConvert.DeserializeObject(json, instanceType, jsonSerializerSettings); // This is to handle polymorphic queries. e.g. Query<AzureAccount>() // If the deserialized object is not the desired type, then we are querying for a specific sub-type // and this record is a different sub-type, and should be excluded from the result-set. if (deserialized is T) { instance = (T)deserialized; } else { continue; } } else { instance = (T)Activator.CreateInstance(instanceType); } var specificMapping = mappings.Get(instanceType); var columnIndexes = specificMapping.IndexedColumns.ToDictionary(c => c, c => GetOrdinal(reader, c.ColumnName)); foreach (var index in columnIndexes) { if (index.Value >= 0) { index.Key.ReaderWriter.Write(instance, reader[index.Value]); } } if (idIndex >= 0) { mapping.IdColumn.ReaderWriter.Write(instance, reader[idIndex]); } yield return(instance); } } } finally { reader?.Dispose(); } }