Skip to content

Repo sync for protected CLA branch #9504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2fd07bc
created lut v2 docs in separate files
vritant24 Aug 22, 2022
05f071d
Add a note on ProjFS and DevDrive
drognanar Jul 31, 2023
eca857c
Add a note on LUT cancellation
drognanar Jul 31, 2023
8c3fa94
Hide the large solution UI for VS 2022
drognanar Jul 31, 2023
b96a856
Merge remote-tracking branch 'origin/main' into dev/vrbhardw/lut/V2
drognanar Jul 31, 2023
cc9c005
Update confiuration and playlist editing sections
drognanar Aug 1, 2023
19ab0e6
Add moniker ranges to LUT docs
drognanar Aug 1, 2023
5cd0617
Update LUT documentation
drognanar Aug 1, 2023
deefbcc
Rename LUT documents
drognanar Aug 1, 2023
777deac
Update the ms.date property
drognanar Aug 1, 2023
c5b34b7
Remove the old moniker ranges for LUT v2 doc
drognanar Aug 1, 2023
f587ea1
Update the FAQ-2019 links to point to 2019 version of LUT doc
drognanar Aug 1, 2023
01c31e7
Add notes to link v1/v2 docs
drognanar Aug 1, 2023
b716a7f
Update the version document note
drognanar Aug 1, 2023
ebcd02b
Resolve learn build warnings
drognanar Aug 1, 2023
a494632
Escape the <custom> text
drognanar Aug 1, 2023
00052ea
Apply suggestions from code review for lut-faq.md
drognanar Aug 2, 2023
aaf8384
Apply suggestions from code review for lut.md
drognanar Aug 2, 2023
bc7a9cb
Update monikerRange
drognanar Aug 2, 2023
4a0be34
Move note below the first paragraph for LUT doc
drognanar Aug 2, 2023
d5c283e
Update docs/test/live-unit-testing-faq-2019.yml
Mikejo5000 Aug 2, 2023
5a67d5d
Add 2019 LUT entries to toc
drognanar Aug 2, 2023
5cf35c2
Apply review suggestions
drognanar Aug 2, 2023
5c98271
redirect web perf and load testing
Aug 3, 2023
c6fe87c
removed key articles
Aug 3, 2023
d960e23
removed archived files
Aug 3, 2023
699c1d4
Update alt text
drognanar Aug 3, 2023
c65ee64
Fix wording
drognanar Aug 3, 2023
d253e2c
Change image casing
drognanar Aug 3, 2023
ab97fd7
fixed warnings
Aug 3, 2023
5682178
updated TOC
Aug 3, 2023
be89acb
Add links to archive
Aug 3, 2023
466b3d2
test
Aug 3, 2023
f9c6f40
toc edit
Aug 3, 2023
43e6b40
correction
Aug 3, 2023
687ba09
re-added file
Aug 3, 2023
449f368
Refactor ClickOnce security settings
Mikejo5000 Aug 4, 2023
3783348
removed files
Mikejo5000 Aug 4, 2023
47e92d0
TOC updates
Mikejo5000 Aug 4, 2023
5d22025
link updates
Mikejo5000 Aug 4, 2023
315031c
minor edit
Mikejo5000 Aug 4, 2023
05ad9ac
TOC updates
Mikejo5000 Aug 4, 2023
33012d2
TOC updates
Mikejo5000 Aug 4, 2023
d8226cc
TOC updates
Mikejo5000 Aug 4, 2023
e575033
tweak
Mikejo5000 Aug 4, 2023
b927e4d
link fixes
Mikejo5000 Aug 4, 2023
3d567f0
Correct typo: is display > is displayed
denrea Aug 4, 2023
b858724
Merge branch 'main' of https://github.com/MicrosoftDocs/visualstudio-…
Mikejo5000 Aug 7, 2023
ea8eceb
Rename the media asset files
drognanar Aug 7, 2023
2149417
Clarify the use of collected data in Optimizing code article
Mikejo5000 Aug 7, 2023
da1feb2
Merge branch 'mikejo-br21' of https://github.com/Mikejo5000/visualstu…
Mikejo5000 Aug 7, 2023
83a33c8
edits
Mikejo5000 Aug 7, 2023
bd057e9
fixed art reference
Mikejo5000 Aug 7, 2023
070280c
tweak
Mikejo5000 Aug 7, 2023
3fcbe8c
tweak
Mikejo5000 Aug 7, 2023
011575d
Merge pull request #11503 from drognanar/lut_v2_docs
v-regandowner Aug 7, 2023
1345585
Lightbox coding
v-dirichards Aug 7, 2023
5d24f95
Merge pull request #11523 from Mikejo5000/mikejo-br21
v-dirichards Aug 7, 2023
ca34a98
Merge pull request #11512 from Mikejo5000/mikejo-br20
v-dirichards Aug 7, 2023
81e1bf1
Merging changes synced from https://github.com/MicrosoftDocs/visualst…
Aug 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
425 changes: 425 additions & 0 deletions .openpublishing.redirection.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 13 additions & 7 deletions docs/profiling/optimize-code-using-profiling-tools.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Reduce compute costs using profiling tools"
description: "Learn how to optimize code using Visual Studio profiling tools such as the CPU Usage tool, Database tool, and the .NET Object Allocation tool."
ms.date: 07/21/2023
ms.date: 08/07/2023
ms.topic: conceptual
dev_langs:
- "CSharp"
Expand All @@ -20,12 +20,12 @@ ms.workload:

[!INCLUDE [Visual Studio](~/includes/applies-to-version/vs-windows-only.md)]

Reducing your compute time means reducing costs, so optimizing your code can save money. In this article, we also show how you can use various profiling tools, including CPU Usage, NET Object Allocation, and the Database tool, to help you accomplish this task.The CPU Usage tool can help you capture and visualize where compute resources are used in your application. The CPU Usage views such as the call tree and flame chart provide a nice graphical visualization of where time is spent in your app. In addition, auto insights may show precise optimizations that can have a large impact. Other tools can help you isolate issues.
Reducing your compute time means reducing costs, so optimizing your code can save money. In this article, we show how you can use various profiling tools, including CPU Usage, NET Object Allocation, and the Database tool, to help you accomplish this task. Rather than providing step-by-step instructions, the intent here is to show you how to use the profiling tools effectively and how to interpret the data. The CPU Usage tool can help you capture and visualize where compute resources are used in your application. The CPU Usage views such as the call tree and flame chart provide a nice graphical visualization of where time is spent in your app. In addition, auto insights may show precise optimizations that can have a large impact. Other tools can help you isolate issues.

## Start an investigation

- To reduce compute costs, start your investigation by taking a CPU usage trace. The CPU Usage tool is often helpful to begin performance investigations and to optimize code to reduce cost.
- If you would like additional insights to help isolate issues or improve the performance, considering collecting a trace using one of the other profiling tools. For example:
- Next, if you would like additional insights to help isolate issues or improve the performance, considering collecting a trace using one of the other profiling tools. For example:
- Take a look at the memory usage. For .NET, try the .NET Object Allocation tool first. For either .NET or C++, you can look at the Memory Usage tool.
- If your app is using File I/O, use the File I/O tool.
- If you're using ADO.NET or Entity Framework, you can try the Database tool to examine SQL queries, precise query time, et al.
Expand All @@ -47,29 +47,35 @@ Start by collecting a trace with the CPU Usage tool. When the diagnostic data lo

You can also view the hot path in the **Call Tree** view. To open this view, use the **Open details** link in the report and then select **Call Tree**.

In this view, you see the hot path again, which shows high CPU usage for the `GetBlogTitleX` method in the app, using about a 60% share of the app's CPU usage. Two external calls to LINQ DLLs are using most of the CPU time. This is the first clue that you may want to look for a LINQ query as an area to optimize.
In this view, you see the hot path again, which shows high CPU usage for the `GetBlogTitleX` method in the app, using about a 60% share of the app's CPU usage. However, the **Self CPU** value for `GetBlogTitleX` is low, only about .10%. Unlike **Total CPU**, the **Self CPU** value excludes time spent in other functions, so we know to look farther down the Call Tree view for the real bottleneck.

:::image type="content" source="./media/optimize-code-cpu-usage-call-tree.png" alt-text="Screenshot of Call Tree view in the CPU Usage tool.":::

`GetBlogTitleX` makes external calls to two LINQ DLLs, which are using most of the CPU time, as evidenced by the very high **Self CPU** values. This is the first clue that you may want to look for a LINQ query as an area to optimize.

:::image type="content" source="./media/optimize-code-cpu-usage-call-tree-self-cpu.png" alt-text="Screenshot of Call Tree view in the CPU Usage tool with Self CPU highlighted." lightbox="./media/optimize-code-cpu-usage-call-tree-self-cpu.png":::

To get a visualized call tree and a different view of the data, switch to the **Flame Graph** view (select from the same list as the **Call Tree**). Here again, it looks like the `GetBlogTitleX` method is responsible for a lot of the app's CPU usage (shown in yellow). External calls to the LINQ DLLs show up beneath the `GetBlogTitleX` box, and they are using all of the CPU time for the method.

:::image type="content" source="./media/optimize-code-cpu-usage-flame-graph.png" alt-text="Screenshot of Flame Graph view in the CPU Usage tool.":::

## Gather additional data

If the CPU Usage tool does not provide enough information to isolate the problem, or you would like additional insights to help improve the performance, you may decide to use one of the other profiling tools. For example, since we identified the LINQ DLLs, we'll first try the Database tool. You can multi-select this tool along with CPU Usage. When you've collected a trace, select the **Queries** tab in the diagnostics page.
Often, other tools can provide additional information to help the analysis and isolate the problem. For example, since we identified the LINQ DLLs, we'll first try the Database tool. You can multi-select this tool along with CPU Usage. When you've collected a trace, select the **Queries** tab in the diagnostics page.

In the Queries tab for the Database trace, you can see the first row shows the longest query, 2446 ms. The **Records** column shows how many records the query reads. We can use this information for later comparison.

:::image type="content" source="./media/optimize-code-database.png" alt-text="Screenshot of Database queries in the Database tool.":::

By examining the SELECT statement generated by LINQ in the Query column, you identify the first row as the query associated with the `GetBlogTitleX` method. The full query string in the Query column is:
By examining the SELECT statement generated by LINQ in the Query column, you identify the first row as the query associated with the `GetBlogTitleX` method. To view the full query string, expand the column width if you need to. The full query string is:

```sql
SELECT "b"."Url", "b"."BlogId", "p"."PostId", "p"."Author", "p"."BlogId", "p"."Content", "p"."Date", "p"."MetaData", "p"."Title"
FROM "Blogs" AS "b" LEFT JOIN "Posts" AS "p" ON "b"."BlogId" = "p"."BlogId" ORDER BY "b"."BlogId"
```

Notice that you are retrieving a lot of column values here, perhaps more than you need.

To see what's going on with the app in terms of memory usage, collect a trace using the .NET Object Allocation tool (For C++, use the Memory Usage tool instead). The **Call Tree** view in the memory trace shows the hot path and helps you identify an area of high memory usage. No surprise at this point, the `GetBlogTitleX` method appears to be generating a lot of objects! Over 900,000 object allocations, in fact.

:::image type="content" source="./media/optimize-code-dotnet-object-allocations.png" alt-text="Screenshot of Call Tree view in the .NET Object Allocation tool.":::
Expand Down Expand Up @@ -107,7 +113,7 @@ foreach (var x in db.Posts.Where(p => p.Author.Contains("Fred Smith")).Select(b
In this code, you made several changes to help optimize the query:

- Add the `Where` clause and eliminate one of the `foreach` loops.
- Project only the Title property, which is all you need in this example.
- Project only the Title property in the `Select` statement, which is all you need in this example.

Next, retest using the profiling tools.

Expand Down
286 changes: 0 additions & 286 deletions docs/test/add-a-data-source-to-a-web-performance-test.md

This file was deleted.

Loading