> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/it/sviluppo/profiling.md).

# Profilazione

Attivi il profiler delle prestazioni di PowerShell Universal per diagnosticare dashboard, API e job lenti utilizzando Measure-PSUBlock e la dashboard dei risultati del profiler.

{% hint style="info" %}
La profilazione funziona solo per l'ambiente integrato.
{% endhint %}

PowerShell Universal offre un profiler delle prestazioni per il debug dei problemi in cui la piattaforma può presentare risposte lente. Questo è utile principalmente durante la creazione di Dashboard.

## Abilitare la profilazione

La profilazione aumenta l'utilizzo della memoria poiché i dati di profilazione vengono archiviati in memoria. È possibile abilitare la profilazione configurando la proprietà `Profiling` di appsettings.json. Per impostazione predefinita è `false`. Sarà necessario riavviare PowerShell Universal dopo aver abilitato o disabilitato la profilazione.

```json
"Profiling": true
```

## Accedere ai dati di profilazione

È possibile accedere ai dati di profilazione navigando su `/profiler/results-index` . Sarà necessario aver effettuato l'accesso come amministratore prima di poter accedere a questo URL.

Vedrà un elenco di richieste e le relative tempistiche.

Facendo clic sulla richiesta verrà visualizzata una suddivisione delle tempistiche.

## Profilare un endpoint API

È possibile profilare un endpoint API utilizzando `Measure-PSUBlock`. L'API sarà elencata per URL nell'indice dei risultati.

Ad esempio, si supponga di avere un'API chiamata `/process`.

```powershell
New-PSUEndpoint -Url "/process" -Endpoint {
    Measure-PSUBlock -Name 'Api' -ScriptBlock {
        Get-Process | Select-Object name
    }
} -Authentication -Timeout 0 
```

Il risultato della profilazione di questa API sarebbe elencato per URL.

Visualizzando il profilo di questa API verrebbe elencato il blocco che abbiamo misurato.

## Profilare un'app

{% hint style="info" %}
`Measure-UDBlock` è un alias di `Measure-PSUBlock`
{% endhint %}

È possibile utilizzare il profiler integrato con le App. Per impostazione predefinita, vengono registrate determinate tempistiche di azioni interne. È inoltre possibile utilizzare il cmdlet `Measure-PSUBlock` per misurare blocchi specifici all'interno della dashboard.

Ad esempio, questa app utilizza `Measure-PSUBlock` per misurare le prestazioni del cmdlet `Start-Sleep`. Il risultato è che il blocco richiederà un secondo per l'esecuzione.

```powershell
New-UDApp -Title 'App' -Content {
    New-UDDynamic -Id 'MyElement' -Content {
        Measure-PSUBlock -Name 'WithinDashboard' -ScriptBlock {
            Start-Sleep 1
        }
    }
}
```

Quando esamina le richieste all'interno del profiler, dovrà cercare `UDComponent\ElementPost` e `UDComponent\Element`. Queste sono richieste per elementi all'interno delle App.

Di seguito è riportato l'output di esempio dell'app mostrata sopra. Noti che l'URL include l'ID dell'elemento `MyElement`. Noterà anche che il blocco `WithinDashboard` richiede circa 1 secondo.

Non tutte le tempistiche vengono visualizzate per impostazione predefinita. È possibile fare clic su `show trivial` per espandere tutte le tempistiche.

## Profilare un job

È possibile profilare i job utilizzando `Measure-PSUBlock` all'interno dello script.

Ad esempio, si supponga di avere uno script che chiama `Get-Service`.

```powershell
Measure-PSUBlock -ScriptBlock {
    Get-Service
} -Name 'Get-Service'
```

L'esecuzione di un profilo su questo script elencherà il job come `JobProfiler/{id}`. L'id corrisponderà all'ID del job mostrato nella console di amministrazione.

Il profilo includerà il blocco che è stato misurato.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/powershell-universal/it/sviluppo/profiling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
