1 00:00:00,430 --> 00:00:04,580 To audit EF queries, we'll install and use a tool called Glimpse. 2 00:00:04,580 --> 00:00:09,120 Once installed, Glimpse will give us the ability to easily inspect web requests, 3 00:00:09,120 --> 00:00:11,900 including the EF queries that are executed. 4 00:00:11,900 --> 00:00:14,876 To install Glimpse, we use the NuGet Package Manager. 5 00:00:16,732 --> 00:00:19,580 Select the Browse tab and search for Glimpse. 6 00:00:21,574 --> 00:00:26,161 Glimpse is the main base package, so we'll start with installing that. 7 00:00:32,060 --> 00:00:36,412 When the Glimpse package is finished installing, it'll open a Readme file that 8 00:00:36,412 --> 00:00:39,868 contains information on how to get started with using Glimpse. 9 00:00:42,033 --> 00:00:44,747 To get the most out of using Glimpse with our web app, 10 00:00:44,747 --> 00:00:47,820 we'll install two additional Glimpse packages. 11 00:00:47,820 --> 00:00:52,870 The Glimpse EF6 package, for auditing Entity Framework queries and commands, and 12 00:00:52,870 --> 00:00:59,640 the Glimpse Mvc5 package, for auditing events related to the MVC web framework. 13 00:00:59,640 --> 00:01:03,070 Since the Glimpse EF6 package is right here in this list, 14 00:01:03,070 --> 00:01:04,420 let's start with installing that. 15 00:01:05,720 --> 00:01:09,729 Then, search for Glimpse.mvc, and 16 00:01:09,729 --> 00:01:13,871 install the Glimpse.Mvc5 package. 17 00:01:15,929 --> 00:01:18,970 Every time that you install a Glimpse related package, 18 00:01:18,970 --> 00:01:23,370 the installer will inspect your Glimpse packages, and update the Readme file to 19 00:01:23,370 --> 00:01:26,560 let you know if any are out of date, and need to be updated. 20 00:01:27,670 --> 00:01:31,159 Looks like there's an update for the Glimpse.AspNet package. 21 00:01:34,071 --> 00:01:37,826 Let's select the Updates tab, and update the package. 22 00:01:43,299 --> 00:01:48,464 Now that we have all of the necessary packages installed, we can run our 23 00:01:48,464 --> 00:01:53,905 application and configure Glimpse by browsing to the path glimpse.axd. 24 00:01:53,905 --> 00:01:58,373 Glimpse.axd looks like it'd be a file in our project, but it's not, 25 00:01:58,373 --> 00:02:02,110 it's a special path that maps to the Glimpse HTTP handler. 26 00:02:03,478 --> 00:02:07,230 In the Web.config file that's located in the root of our project, 27 00:02:07,230 --> 00:02:11,100 we can see the HTTP handler configuration that was added 28 00:02:11,100 --> 00:02:13,890 when we installed the Glimpse NuGet package. 29 00:02:13,890 --> 00:02:18,850 The way that ASP.NET handles processing requests can be customized through the use 30 00:02:18,850 --> 00:02:24,490 of custom HTTP handlers or modules, Glimpse makes use of both. 31 00:02:24,490 --> 00:02:28,850 For more information about HTTP handlers and modules, see the teacher's notes. 32 00:02:30,080 --> 00:02:35,770 To enable Glimpse, we simply click the large Turn Glimpse On button. 33 00:02:35,770 --> 00:02:39,260 Once the page is reloaded, we can see here on the right, 34 00:02:39,260 --> 00:02:42,560 in this green box, that the Glimpse cookie is set to on. 35 00:02:45,440 --> 00:02:50,130 An HTTP cookie is a little piece of data that the browser sends to the web server 36 00:02:50,130 --> 00:02:51,770 on every request. 37 00:02:51,770 --> 00:02:55,000 Glimpse uses a cookie to determine when it's enabled. 38 00:02:55,000 --> 00:02:57,930 For more information on cookies, see the teacher's notes. 39 00:02:59,380 --> 00:03:03,840 Now that we've enabled Glimpse, we can remove glimpse.axd from our path, 40 00:03:03,840 --> 00:03:05,770 to return to our web app's home page. 41 00:03:07,900 --> 00:03:12,110 And here's our home page, but notice here in the lower-right, 42 00:03:12,110 --> 00:03:17,040 we now have the glimpse Heads-Up Display, or HUD, being displayed. 43 00:03:17,040 --> 00:03:21,120 The glimpse HUD will give us some basic information about our request, 44 00:03:21,120 --> 00:03:24,630 how long the request took to complete in milliseconds. 45 00:03:24,630 --> 00:03:28,860 And a breakdown of how much time that was spent communicating between the client and 46 00:03:28,860 --> 00:03:34,440 the server, processing on the server, and processing on the client. 47 00:03:35,840 --> 00:03:39,520 We can also see a breakdown of the server processing time, 48 00:03:39,520 --> 00:03:44,140 how much spent in the action method, and rendering the view. 49 00:03:44,140 --> 00:03:47,410 We can also see which controller and action was called, and 50 00:03:47,410 --> 00:03:52,070 just to right of that, how many database queries were ran, and how long they took. 51 00:03:53,070 --> 00:03:56,770 We can hover over each section to get a quick look at some additional information. 52 00:03:57,950 --> 00:04:06,200 Here's a closer look at the HTTP section, And the Host section. 53 00:04:07,560 --> 00:04:12,201 Clicking on the g in the lower right-hand corner opens up the full Glimpse panel. 54 00:04:14,036 --> 00:04:17,350 Glimpse gives you detailed information about the request. 55 00:04:17,350 --> 00:04:20,120 For now, let's select the SQL tab, and take a look at 56 00:04:20,120 --> 00:04:25,160 the information that Glimpse provides about EF queries and commands. 57 00:04:25,160 --> 00:04:28,630 We can see that a single query was executed, and 58 00:04:28,630 --> 00:04:33,440 how long it took to complete, and the SQL that EF generated for the query. 59 00:04:35,450 --> 00:04:39,034 Let's look at another example by browsing to the ADD COMIC BOOK page. 60 00:04:43,364 --> 00:04:48,190 Now, we can see that 3 queries were executed, and the total execution time. 61 00:04:49,410 --> 00:04:52,823 Then, below that, we can see the SQL for each query, and 62 00:04:52,823 --> 00:04:54,683 how long each took to execute. 63 00:04:56,827 --> 00:05:01,709 Glimpse is a powerful, easy-to-use tool that can help you to not only understand 64 00:05:01,709 --> 00:05:06,400 how a request is being processed, but how each part is performing. 65 00:05:06,400 --> 00:05:09,610 We'll continue to use Glimpse throughout the rest of this workshop, 66 00:05:09,610 --> 00:05:13,930 as we take a closer look at some common EF query performance issues.