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