This article is meant to illustrate a high-level comparison of how Prefix and Glimpse track SQL queries. While the two tools are similar (they’re both designed to help us understand different elements of our code’s performance) the two products have some unique pros and cons. Here’s a comparison based on our own experience with both tools.
How to enable Glimpse for SQL queries
Glimpse requires you to install various extensions via nuGet packages to support different providers. For example, there are packages for ADO, Entity Framework 5, 6, and potentially others.
To download Glimpse visit: http://getglimpse.com/
First try: I started out trying to test a query that uses basic SqlConnection and SqlCommand objects, but I found out that doesn’t work at all, which is a huge shortcoming. You have to modify your code everywhere you use SqlConnection objects to create one through a special factory class. Yuck. Result: It doesn’t work with basic Sql Commands.
Second try: My favorite ORM right now has to be Dapper, and I’m not the only one. It has over 1 million downloads on NuGet. It is easy to use and extremely fast. Unfortunately, Glimpse neither supports Dapper automatically nor with a NuGet package. It looks like the only solution is to use the factory provider to get the special SqlConnection object and then to use that with Dapper. Result: Dapper works with special Glimpse connection object, just like my first try.
Third try: So I used the Entity Framework designed to pull all my database tables in so I could easily query them. On my first try to query with EF, I got this error: “Unable to cast object of type ‘Glimpse.Ado.AlternateType.GlimpseDbConnection’ to type ‘System.Data.SqlClient.SqlConnection’”. Installing package Glimpse.EF6 fixed this, and I was able to get EF working. Result: It worked with EF.
How to enable Prefix to track SQL queries
To download Prefix visit: http://www.stackify.com/prefix
The good news is you literally have to do nothing but install Prefix as a windows app on your PC. It works as a .NET profiler and therefore can automatically collect all of your SQL queries for SQL Server, Mysql, Postgresql, Oracle and others across multiple ORMs auto-magically.
Differences between Prefix & Glimpse
Overall, they both accomplish the same goal of letting you see which SQL queries your code just executed. Glimpse shows them in the “SQL” tab. Prefix shows them more inline with the rest of the key methods it tracks. Both work with async database calls.
One key difference is that Prefix can show you how long it took to execute the query versus fully iterating the results. You can see this where it shows “Download Query Result”. I wrote an entire blog post on this topic: How to measure real world SQL performance for ASP.NET
The winner? Prefix.
Prefix wins hands down due to how easy it is to install and the wide support it has. Basic Sql Commands, EF, Dapper, and others work with Prefix with ZERO code or config changes. Glimpse doesn’t support the most basic of SqlCommand objects and requires separate NuGet packages for the ORMs it does support. The way it abstracts the SqlConnection and SqlCommand objects can also cause some other weird problems with apps. Prefix also gets big brownie points for showing how long it takes to even initialize Entity Framework and download the entire query result.
You can use Prefix and Glimpse at the same time. They don’t interfere with each other.
- Stackify Prefix & Retrace Featured on the On .NET Show - March 10, 2017
- Big Stackify .NET APM Update is Here! v4.6 of Windows Agent Release - March 8, 2017
- How to Troubleshoot High .NET App CPU in Production With ANTS and Process Hacker - March 7, 2017
- Comparison: Azure App Services vs Cloud Services - March 6, 2017
- Azure App Services: 3 Limitations & 9 Awesome Features - March 6, 2017