public object GetData(ITabContext context) { var messages = context.GetMessages<AdoMessage>().ToList(); var aggregator = new MessageAggregator(messages); var queryData = aggregator.Aggregate(); SqlStatistics sqlStatistics = SqlStatisticsCalculator.Caluculate(queryData); return new { queryCount = sqlStatistics.QueryCount, connectionCount = sqlStatistics.ConnectionCount, transactionCount = sqlStatistics.TransactionCount, queryExecutionTime = sqlStatistics.QueryExecutionTime, connectionOpenTime = sqlStatistics.ConnectionOpenTime }; }
public override object GetData(ITabContext context) { var sanitizer = new CommandSanitizer(); var messages = context.GetMessages<AdoMessage>().ToList(); var aggregator = new MessageAggregator(messages); var queryMetadata = aggregator.Aggregate(); if (queryMetadata == null) { return null; } var connections = new List<object[]> { new object[] { "Commands per Connection", "Duration" } }; foreach (var connection in queryMetadata.Connections.Values) { if (connection.Commands.Count == 0 && connection.Transactions.Count == 0) { continue; } var commands = new List<object[]> { new object[] { "Transaction Start", "Ordinal", "Command", "Parameters", "Records", "Duration", "Offset", "Async", "Transaction End", "Errors" } }; var commandCount = 1; foreach (var command in connection.Commands.Values) { // Transaction Start List<object[]> headTransaction = null; if (command.HeadTransaction != null) { headTransaction = new List<object[]> { new object[] { "\t▼ Transaction - Started", "Isolation Level - " + command.HeadTransaction.IsolationLevel } }; if (!command.HeadTransaction.Committed.HasValue) { headTransaction.Add(new object[] { string.Empty, "Transaction was never completed", "error" }); } } // Transaction Finish List<object[]> tailTransaction = null; if (command.TailTransaction != null) { tailTransaction = new List<object[]> { new object[] { "\t▲ Transaction - Finished", "Status - " + (command.TailTransaction.Committed.GetValueOrDefault() ? "Committed" : "Rollbacked") } }; } // Parameters List<object[]> parameters = null; if (command.Parameters.Count > 0) { parameters = new List<object[]> { new object[] { "Name", "Value", "Type", "Size" } }; foreach (var parameter in command.Parameters) { parameters.Add(new[] { parameter.Name, parameter.Value, parameter.Type, parameter.Size }); } } else if (command.BatchParameters.Count > 0) { parameters = new List<object[]>(command.BatchParameters.Count + 1); parameters.Add(new object[] { "#", "Name", "Value", "Type", "Size" }); for(int i = 0; i < command.BatchParameters.Count; i++) { foreach(var parameter in command.BatchParameters[i]) { parameters.Add(new object[] { i, parameter.Name, parameter.Value, parameter.Type, parameter.Size }); } } } // Exception List<object[]> errors = null; if (command.Exception != null) { var exception = command.Exception.GetBaseException(); var exceptionName = command.Exception != exception ? command.Exception.Message + ": " + exception.Message : exception.Message; errors = new List<object[]> { new object[] { "Error", "Stack" }, new object[] { exceptionName, exception.StackTrace } }; } // Commands var records = command.RecordsAffected == null || command.RecordsAffected < 0 ? command.TotalRecords : command.RecordsAffected; var status = errors != null ? "error" : (command.IsDuplicate ? "warn" : string.Empty); commands.Add(new object[] { headTransaction, string.Format("{0}{1}", command.HasTransaction ? "\t\t\t" : string.Empty, commandCount++), sanitizer.Process(command.Command, command.Parameters), parameters, records, command.Duration, command.Offset, command.IsAsync, tailTransaction, errors, status }); } connections.Add(new[] { commands, connection.Duration.HasValue ? (object)connection.Duration.Value : null }); } if (connections.Count > 1) { SqlStatistics sqlStatistics = SqlStatisticsCalculator.Caluculate(queryMetadata); return new Dictionary<string, object> { { "SQL Statistics", new object[] { new { sqlStatistics.ConnectionCount, sqlStatistics.QueryCount, sqlStatistics.TransactionCount, sqlStatistics.QueryExecutionTime, sqlStatistics.ConnectionOpenTime } } }, { "Queries", connections } }; } return null; }
public override object GetData(ITabContext context) { var sanitizer = new CommandSanitizer(); var messages = context.GetMessages<AdoMessage>().ToList(); var aggregator = new MessageAggregator(messages); var queryMetadata = aggregator.Aggregate(); if (queryMetadata == null) return null; var connections = new List<object[]> { new[] { "Commands per Connection", "Duration" } }; foreach (var connection in queryMetadata.Connections.Values) { if (connection.Commands.Count == 0 && connection.Transactions.Count == 0) continue; var commands = new List<object[]> { new[] { "Transaction Start", "Ordinal", "Command", "Parameters", "Records", "Duration", "Offset", "Transaction End", "Errors" } }; var commandCount = 1; foreach (var command in connection.Commands.Values) { //Transaction Start List<object[]> headTransaction = null; if (command.HeadTransaction != null) { headTransaction = new List<object[]> { new[] { "\t▼ Transaction - Started", "Isolation Level - " + command.HeadTransaction.IsolationLevel } }; if (!command.HeadTransaction.Committed.HasValue) { headTransaction.Add(new[] { "", "Transaction was never completed", "error" }); } } //Transaction Finish List<object[]> tailTransaction = null; if (command.TailTransaction != null) { tailTransaction = new List<object[]> { new[] { "\t▲ Transaction - Finished", "Status - " + (command.TailTransaction.Committed.GetValueOrDefault() ? "Committed" : "Rollbacked") } }; } //Parameters List<object[]> parameters = null; if (command.Parameters.Count > 0) { parameters = new List<object[]> { new[] { "Name", "Value", "Type", "Size" } }; foreach (var parameter in command.Parameters) { parameters.Add(new[] { parameter.Name, parameter.Value, parameter.Type, parameter.Size }); } } //Exception List<object[]> errors = null; if (command.Exception != null) { var exception = command.Exception.GetBaseException(); var exceptionName = command.Exception != exception ? command.Exception.Message + ": " + exception.Message : exception.Message; errors = new List<object[]> { new[] { "Error", "Stack" }, new[] { exceptionName, exception.StackTrace } }; } //Commands var records = command.RecordsAffected == null || command.RecordsAffected < 0 ? command.TotalRecords : command.RecordsAffected; commands.Add(new object[] { headTransaction, string.Format("{0}{1}", command.HasTransaction ? "\t\t\t" : "", commandCount++), sanitizer.Process(command.Command, command.Parameters), parameters, records, command.Duration, command.Offset, tailTransaction, errors, errors != null ? "error" : "" }); } connections.Add(new [] { commands, connection.Duration.HasValue ? (object)connection.Duration.Value : null }); } return connections.Count > 1 ? connections : null; }