|
| 1 | +--- |
| 2 | +title: The Sampling Feature |
| 3 | +weight: 3 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +The Sampling feature in the WindowsPerf GUI extension is a powerful tool for analyzing and optimizing your code's performance. This tutorial guides you through the entire process, from setting up your sampling preferences to analyzing the results and implementing changes. |
| 12 | + |
| 13 | +## How to Open Sampling Explorer |
| 14 | + |
| 15 | +1. **Accessing Sampling Explorer**: |
| 16 | + - In Visual Studio 2022, go to the `View` menu. |
| 17 | + - Select `Sampling Explorer` from the dropdown. |
| 18 | + |
| 19 | +## Setting Your Sampling Preferences |
| 20 | + |
| 21 | +1. **Opening Sampling Settings**: |
| 22 | + - Inside the Sampling Explorer window, find and click on the `settings wheel` icon. |
| 23 | + - This action will open the Sampling Settings Dialog. |
| 24 | + |
| 25 | +## Configuring the Sampling Parameters |
| 26 | + |
| 27 | +1. **Filling in Necessary Fields**: |
| 28 | + |
| 29 | + - The dialog presents multiple fields for configuration. Essential fields to fill in include: |
| 30 | + - File payload |
| 31 | + - CPU core selection |
| 32 | + - Event choice |
| 33 | + - Desired frequency |
| 34 | + - Fill these in according to the specifics of the sampling you wish to perform. |
| 35 | + |
| 36 | +2. **Optional Parameters**: |
| 37 | + |
| 38 | + - You can also set other parameters as per your requirements. |
| 39 | + |
| 40 | +3. **Command Preview**: |
| 41 | + |
| 42 | + - As you configure the settings, the dialog provides a real-time preview of the WindowsPerf command that will be executed. |
| 43 | + |
| 44 | +4. **Saving Your Settings**: |
| 45 | + - Once you are satisfied with your configurations, click `save`. |
| 46 | + |
| 47 | + |
| 48 | +_Sampling overview UI_ |
| 49 | + |
| 50 | +## Initiating the Sampling Process |
| 51 | + |
| 52 | +1. **Starting the Sampling**: |
| 53 | + |
| 54 | + - Click on the play button to kickstart the sampling. |
| 55 | + |
| 56 | + - If you’ve set a timeout, the process will run for the specified duration. Otherwise, you have the flexibility to end the sampling manually using the stop button. |
| 57 | + |
| 58 | + - The stop button can also be used to interrupt the process even if the timeout hasn’t lapsed and the collected samples will be shown in the next screen. |
| 59 | + |
| 60 | +## Delving into the Sampling Results |
| 61 | + |
| 62 | +1. **Analyzing the Results**: |
| 63 | + |
| 64 | + - Post-sampling, you’ll notice the window divides into two sections: a tree view and a detailed analysis section. |
| 65 | + |
| 66 | + - Navigate through the tree view by clicking on the nodes. This will reveal functions triggered, selected events, line numbers in the source code, and the responsible source files. |
| 67 | + |
| 68 | + - An added convenience: Any accessible source file appears as a clickable hyperlink. Selecting it will directly open the file within the IDE. |
| 69 | + |
| 70 | +## Implementing Code Adjustments |
| 71 | + |
| 72 | + |
| 73 | +_Sampling settings UI_ |
| 74 | + |
| 75 | +1. **Optimizing Your Code**: |
| 76 | + - Based on the insights gathered from the sampling results, proceed to make any required optimizations or edits to your source code. |
| 77 | + |
| 78 | + |
| 79 | +_Sampling results shown in the code editor_ |
| 80 | + |
| 81 | +## Re-evaluating Post Edits |
| 82 | + |
| 83 | +1. **Comparing Results**: |
| 84 | + |
| 85 | + - Post editing, run the sampling process again. |
| 86 | + |
| 87 | + - This allows you to instantly compare and contrast the results before and after your code modifications, ensuring optimal performance improvements. |
| 88 | + |
| 89 | + - With these steps, you are well-equipped to make the best of the sampling feature in the WindowsPerf GUI extension. Happy coding and optimizing! |
| 90 | + |
| 91 | +## Lock Unlock |
| 92 | + |
| 93 | +When WindowsPerf communicates with its Kernel Driver, the driver acquires lock and will deny access to other instances of WindowsPerf accessing the driver and its resources. This prevents others from interfering with the current WindowsPerf execution and protects you from interference with your count. |
| 94 | + |
| 95 | +When another WindowsPerf process has “locked” access to the driver you will no longer be able to use WindowsPerf, you will instead receive the following error message: |
| 96 | + |
| 97 | +```shell |
| 98 | +warning: other WindowsPerf process acquired the WindowsPerf-driver. |
| 99 | +Operation canceled! |
| 100 | +``` |
| 101 | + |
| 102 | +In order to force the release of the lock, a new --force-lock command argument was introduced to both WindowsPerf and the extension that lets you interrupt the ongoing WindowsPerf process and take over the lock. |
| 103 | + |
| 104 | +However, interrupting a running wperf process would result in losing all the collected data. If interrupted, WidowsPerf will show the following error message: |
| 105 | + |
| 106 | +```shell |
| 107 | +warning: other WindowsPerf process hijacked (forced lock) the wperf-driver, see --force-lock. |
| 108 | +Operation terminated, your data was lost! |
| 109 | + |
| 110 | +Received ERROR_BAD_COMMAND, driver status: |
| 111 | +STATUS_INVALID_DEVICE_STATE |
| 112 | +error: PMU_CTL_LOCK_RELEASE can't be release |
| 113 | +``` |
0 commit comments