# Profiler

PowerShell Pro Tools offers a script performance profiler to time the execution of your script. It helps to locate slow sections of code and provides the number of times particular lines are called.&#x20;

The feature is best defined as an instrumentation profiler that injects cmdlet calls into your script to thoroughly analyze your script. The script is executed with this injected code to accurately time the pipelines within your script.&#x20;

{% embed url="<https://youtu.be/9DkxJ78C5ks>" %}

## Profiling a Script

To profile a script, open the script you wish to profile and execute the `PowerShell: Profile Script` command from within VS Code (Ctrl+Shift+P). The script will be instrumented and then executed within the VS Code PowerShell Session. After execution is complete, script timings will be added directly to the editor on the lines in which they were recorded.&#x20;

![Profiler information](/files/-LRoygTJw92LfHDrEA3x)

The profile information will remain in the editor until you execute the `PowerShell: Clear Profiling Information` command in VS Code.&#x20;

### Limitations <a href="#limitations" id="limitations"></a>

Being an early version of the profiler, there are some limitations.

#### **Single Script Support** <a href="#single-script-support" id="single-script-support"></a>

The profiler only profiles the current script. It will not profile scripts or modules that you reference. If you use functions within pipelines in your profiled script, those functions will be timed but their internal operations will not.

**Hot Path Support**

Although the hot path information is available in the output from the profiler, there is no visual representation of this information.

#### Pipeline Element Timing <a href="#pipeline-element-timing" id="pipeline-element-timing"></a>

The profiler has early support for pipeline element timing but does not expose this in this version. For example, a pipeline like the one below will result in a single timing even though multiple commands are being called.

```
Get-Process | Select-Object Name | Out-String  40.85% (1 calls)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.poshtools.com/powershell-pro-tools-documentation/visual-studio-code/profiler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
