public void GetEntry_ParsesEachColumn()
        {
            var provider = CreateProvider();
            var row = CreateDataRow();

            row["QueryName"] = "Name";
            row["QueryText"] = "Text";
            row["QueryParameters"] = "Parameters";
            row["ConnectionString"] = "CustomConnectionString";
            row["Context"] = "StackTrace";
            row["QueryResults"] = "Result";
            row["QueryDuration"] = TimeSpan.FromSeconds(1).TotalSeconds;
            row["QueryResultsSize"] = 10;
            row["QueryParametersSize"] = 20;

            var entry = provider.GetEntry(row);

            var expected = new CommandEntry
            {
                BytesReceived = 10,
                BytesSent = 20,
                CustomConnectionStringName = "Custom",
                Duration = TimeSpan.FromSeconds(1),
                IsDuplicate = false,
                Name = "Name",
                Parameters = "Parameters",
                Result = "Result",
                StackTrace = "StackTrace",
                Text = "Text"
            };

            var printer = new Stateprinter();
            Assert.AreEqual(printer.PrintObject(expected), printer.PrintObject(entry));
        }
        public object GetEntry(DataRow row)
        {
            var entry = new CommandEntry
            {
                Name = GetName(row),
                Text = GetText(row),
                Parameters = GetParameters(row),
                CustomConnectionStringName = GetCustomConnectionStringName(row),
                StackTrace = GetStackTrace(row),
                Duration = GetDuration(row),
                BytesReceived = GetBytesReceived(row),
                BytesSent = GetBytesSent(row),
                Result = GetResult(row),
                IsDuplicate = false
            };

            // Detect duplicate queries using a hash that is a concatenation of query name, text and the text representation of query parameters and result
            string hash = GetEntryHash(entry);
            if (mEntryHashes.Contains(hash))
            {
                entry.IsDuplicate = true;
            }
            else
            {
                mEntryHashes.Add(hash);
            }

            return entry;
        }
 private string GetEntryHash(CommandEntry entry)
 {
     return String.Join("|", entry.Name, entry.Text, entry.Parameters, entry.Result);
 }
Example #4
0
 private string GetBytesSentChart(RequestMetadata metadata, CommandEntry entry)
 {
     return new HtmlChartBuilder(entry.BytesSent, metadata.Statistics.TotalBytesSent).WithThresholdValue(512).Build();
 }
Example #5
0
 private string GetDurationChart(RequestMetadata metadata, CommandEntry entry)
 {
     return new HtmlChartBuilder(entry.Duration.Ticks, metadata.Statistics.TotalDuration.Ticks).WithThresholdValue(5 * TimeSpan.TicksPerMillisecond).Build();
 }
Example #6
0
        private string GetText(CommandEntry entry)
        {
            if (entry.Name != null)
            {
                if (entry.CustomConnectionStringName != null)
                {
                    return String.Format("-- [{0}] {1}\r\n{2}", entry.CustomConnectionStringName, entry.Name, entry.Text);
                }

                return String.Format("-- {0}\r\n{1}", entry.Name, entry.Text);
            }

            return entry.Text;
        }
Example #7
0
        private string GetResult(CommandEntry entry)
        {
            if (String.IsNullOrEmpty(entry.Result))
            {
                return String.Empty;
            }

            var index = entry.Result.IndexOf(']');

            return entry.Result.Substring(0, index + 1) + ')';
        }
Example #8
0
        private string GetInformation(CommandEntry entry)
        {
            if (entry.IsDuplicate)
            {
                return "Duplicate query";
            }

            return String.Empty;
        }
        /// <summary>
        /// Returns debug information that will be sent to the Glimpse client.
        /// </summary>
        /// <param name="context">The tab context.</param>
        /// <returns>An object with debug information that the Glimpse client can display.</returns>
        public override object GetData(ITabContext context)
        {
            var connectionStringRegistry = new ConnectionStringRegistry();
            var entryFactory             = new EntryFactory(connectionStringRegistry);
            var requestMetadataProvider  = new RequestMetadataProvider(entryFactory);
            var requestMetadata          = requestMetadataProvider.GetRequestMetadata(SqlDebug.CurrentRequestLog);

            var items = new List <object[]>
            {
                new object[] { "Ordinal", "Information", "Text", "Result", "Received", "Sent", "Duration", "Stack trace" }
            };

            var nextOrdinal = 1;

            foreach (var entry in requestMetadata.Entries)
            {
                CommandEntry commandEntry = entry as CommandEntry;
                if (commandEntry != null)
                {
                    items.Add(new object[] {
                        String.Format(CultureInfo.InvariantCulture, "{0:N0}", nextOrdinal++),
                        GetInformation(commandEntry),
                        GetText(commandEntry),
                        GetResult(commandEntry),
                        String.Format(CultureInfo.InvariantCulture, "!{0:N0} B {1}!", commandEntry.BytesReceived, GetBytesReceivedChart(requestMetadata, commandEntry)),
                        String.Format(CultureInfo.InvariantCulture, "!{0:N0} B {1}!", commandEntry.BytesSent, GetBytesSentChart(requestMetadata, commandEntry)),
                        String.Format(CultureInfo.InvariantCulture, "!{0:N0} ms {1}!", commandEntry.Duration.TotalMilliseconds, GetDurationChart(requestMetadata, commandEntry)),
                        commandEntry.StackTrace,
                        commandEntry.IsDuplicate ? "warn" : String.Empty
                    });
                    continue;
                }

                ConnectionEntry connectionEntry = entry as ConnectionEntry;
                if (connectionEntry != null)
                {
                    items.Add(new object[] {
                        String.Empty,
                        GetInformation(connectionEntry),
                        String.Empty,
                        null,
                        null,
                        null,
                        null,
                        connectionEntry.StackTrace,
                        "quiet"
                    });
                    continue;
                }

                InformationEntry informationEntry = entry as InformationEntry;
                if (informationEntry != null)
                {
                    items.Add(new object[] {
                        String.Empty,
                        GetInformation(informationEntry),
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        "info"
                    });
                    continue;
                }
            }

            var statictics = new object[] {
                new object[] { "Name", "Value" },
                new object[] { "Queries", String.Format(CultureInfo.InvariantCulture, "{0:N0}", requestMetadata.Statistics.TotalCommands) },
                new object[] { "Duplicate queries", String.Format(CultureInfo.InvariantCulture, "{0:N0}", requestMetadata.Statistics.TotalDuplicateCommands) },
                new object[] { "Duration", String.Format(CultureInfo.InvariantCulture, "{0:N0} ms", requestMetadata.Statistics.TotalDuration.TotalMilliseconds) },
                new object[] { "Received", String.Format(CultureInfo.InvariantCulture, "{0:N0} B", requestMetadata.Statistics.TotalBytesReceived) },
                new object[] { "Sent", String.Format(CultureInfo.InvariantCulture, "{0:N0} B", requestMetadata.Statistics.TotalBytesSent) }
            };

            return(new Dictionary <string, object>
            {
                { SECTION_KEY_STATISTICS, statictics },
                { SECTION_KEY_QUERIES, items }
            });
        }
 private string GetDurationChart(RequestMetadata metadata, CommandEntry entry)
 {
     return(new HtmlChartBuilder(entry.Duration.Ticks, metadata.Statistics.TotalDuration.Ticks).WithThresholdValue(5 * TimeSpan.TicksPerMillisecond).Build());
 }
 private string GetBytesSentChart(RequestMetadata metadata, CommandEntry entry)
 {
     return(new HtmlChartBuilder(entry.BytesSent, metadata.Statistics.TotalBytesSent).WithThresholdValue(512).Build());
 }
 private string GetEntryHash(CommandEntry entry)
 {
     return(String.Join("|", entry.Name, entry.Text, entry.Parameters, entry.Result));
 }