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.
- Retrace Now Integrates with Axosoft: Track Errors and Save Time Fixing Bugs - November 14, 2017
- Build It, Buy It, or Open Source: The Software Dilemma - November 14, 2017
- Top ASP.NET Performance Counters and How to Monitor Them - November 13, 2017
- How to Use Performance Counters with .NET Core: Current Solution, Alternatives, and the Future - November 7, 2017
- Top 13 ASP.NET Core Features You Need to Know - October 31, 2017