Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
To audit Entity Framework queries, let's install a tool called Glimpse.
-
0:00
To audit EF queries, we'll install and use a tool called Glimpse.
-
0:04
Once installed, Glimpse will give us the ability to easily inspect web requests,
-
0:09
including the EF queries that are executed.
-
0:11
To install Glimpse, we use the NuGet Package Manager.
-
0:16
Select the Browse tab and search for Glimpse.
-
0:21
Glimpse is the main base package, so we'll start with installing that.
-
0:32
When the Glimpse package is finished installing, it'll open a Readme file that
-
0:36
contains information on how to get started with using Glimpse.
-
0:42
To get the most out of using Glimpse with our web app,
-
0:44
we'll install two additional Glimpse packages.
-
0:47
The Glimpse EF6 package, for auditing Entity Framework queries and commands, and
-
0:52
the Glimpse Mvc5 package, for auditing events related to the MVC web framework.
-
0:59
Since the Glimpse EF6 package is right here in this list,
-
1:03
let's start with installing that.
-
1:05
Then, search for Glimpse.mvc, and
-
1:09
install the Glimpse.Mvc5 package.
-
1:15
Every time that you install a Glimpse related package,
-
1:18
the installer will inspect your Glimpse packages, and update the Readme file to
-
1:23
let you know if any are out of date, and need to be updated.
-
1:27
Looks like there's an update for the Glimpse.AspNet package.
-
1:34
Let's select the Updates tab, and update the package.
-
1:43
Now that we have all of the necessary packages installed, we can run our
-
1:48
application and configure Glimpse by browsing to the path glimpse.axd.
-
1:53
Glimpse.axd looks like it'd be a file in our project, but it's not,
-
1:58
it's a special path that maps to the Glimpse HTTP handler.
-
2:03
In the Web.config file that's located in the root of our project,
-
2:07
we can see the HTTP handler configuration that was added
-
2:11
when we installed the Glimpse NuGet package.
-
2:13
The way that ASP.NET handles processing requests can be customized through the use
-
2:18
of custom HTTP handlers or modules, Glimpse makes use of both.
-
2:24
For more information about HTTP handlers and modules, see the teacher's notes.
-
2:30
To enable Glimpse, we simply click the large Turn Glimpse On button.
-
2:35
Once the page is reloaded, we can see here on the right,
-
2:39
in this green box, that the Glimpse cookie is set to on.
-
2:45
An HTTP cookie is a little piece of data that the browser sends to the web server
-
2:50
on every request.
-
2:51
Glimpse uses a cookie to determine when it's enabled.
-
2:55
For more information on cookies, see the teacher's notes.
-
2:59
Now that we've enabled Glimpse, we can remove glimpse.axd from our path,
-
3:03
to return to our web app's home page.
-
3:07
And here's our home page, but notice here in the lower-right,
-
3:12
we now have the glimpse Heads-Up Display, or HUD, being displayed.
-
3:17
The glimpse HUD will give us some basic information about our request,
-
3:21
how long the request took to complete in milliseconds.
-
3:24
And a breakdown of how much time that was spent communicating between the client and
-
3:28
the server, processing on the server, and processing on the client.
-
3:35
We can also see a breakdown of the server processing time,
-
3:39
how much spent in the action method, and rendering the view.
-
3:44
We can also see which controller and action was called, and
-
3:47
just to right of that, how many database queries were ran, and how long they took.
-
3:53
We can hover over each section to get a quick look at some additional information.
-
3:57
Here's a closer look at the HTTP section, And the Host section.
-
4:07
Clicking on the g in the lower right-hand corner opens up the full Glimpse panel.
-
4:14
Glimpse gives you detailed information about the request.
-
4:17
For now, let's select the SQL tab, and take a look at
-
4:20
the information that Glimpse provides about EF queries and commands.
-
4:25
We can see that a single query was executed, and
-
4:28
how long it took to complete, and the SQL that EF generated for the query.
-
4:35
Let's look at another example by browsing to the ADD COMIC BOOK page.
-
4:43
Now, we can see that 3 queries were executed, and the total execution time.
-
4:49
Then, below that, we can see the SQL for each query, and
-
4:52
how long each took to execute.
-
4:56
Glimpse is a powerful, easy-to-use tool that can help you to not only understand
-
5:01
how a request is being processed, but how each part is performing.
-
5:06
We'll continue to use Glimpse throughout the rest of this workshop,
-
5:09
as we take a closer look at some common EF query performance issues.
You need to sign up for Treehouse in order to download course files.
Sign up