# Code analysis

The **Code analysis** screen brings together the collection and the analysis that feed the [Performance › Dataflows](../performance/dataflows.md) and [Performance › Notebooks](../performance/notebooks.md) screens. Once a day, Power Monitor downloads through the Fabric API the definitions of **Dataflows Gen1 and Gen2**, **Notebooks** and **Pipelines** in the monitored workspaces and, when done, analyzes the code offline for patterns that hurt performance. Here you see the latest analysis and the run history, and you can trigger the collection or just the re-analysis without waiting for the next cycle.

**How to access:** *Mapping › Operations › Code analysis* (right after **Spark Sessions**). Only **Administrators** can access the screen and the actions. On the Performance screens, all profiles see the **Code analysis** line with the date of the last run; the **View/manage collection →** link, which leads here, appears only for administrators.

## What it is for

* Seeing whether the code analysis is running and when the last run was.
* **Running the analysis now**, for example after the team published fixes and wants to check that the findings are gone.
* **Reanalyzing only** the definitions already collected, without querying Fabric again.
* Investigating failed or partial runs and knowing how many items were analyzed, how many have findings and how many could not be analyzed.

## Screen components

The screen has a header (*Mapping* and the subtitle *Collection of Dataflow and Notebook definitions, code analysis, manual trigger and history.*) and three cards.

### What is collected card

Describes the source and cadence (*Source, cadence and where the data shows up*) and has the **View collected data in Dataflows →** and **View collected data in Notebooks →** links, which lead to the Performance screens.

### Latest analysis card

**What it is:** the **Latest analysis** card, with the next scheduled run, the two trigger buttons and the summary of the most recent run.

**What it is for:** triggering the collection or the re-analysis and following the progress without leaving the screen.

| Element | What it is for |
| --- | --- |
| **Run analysis now** | Downloads the definitions of dataflows, notebooks and pipelines again and then analyzes the code. It may take a few minutes. |
| **Reanalyze only** | Reanalyzes the definitions already collected, without downloading them from Fabric again. Useful after a rule catalog update or to redo the analysis quickly. |
| **Next scheduled run** | Date and time of the next automatic run. |
| **Started**, **Status** and **Trigger** | Data of the latest analysis: status (**In progress**, **Completed**, **Partial**, **Failed** or **Interrupted**) and trigger (**Scheduled**, **Manual** or *Manual by {user}*). |
| Counters | **Analyzed**, **With findings**, **Not analyzable** and **Failures** of the latest analysis. |
| **Latest definition collection** | Date and status of the latest definition collection, which precedes the analysis. |

**How to use:**

1. Click **Run analysis now** (or **Reanalyze only**).
2. Confirm in the dialog (**Run the analysis now?** or **Reanalyze the code now?**) by clicking **Run**, or **Cancel**.
3. The message *Run queued. This page refreshes on its own when the analysis finishes.* appears. The screen follows the run and, at the end, shows *Analysis finished. The history was refreshed.*

**How it works:**

* The buttons are disabled, with the explanation on hover, while a run is already in progress, when the run was queued and has not started yet or when the collection has just finished and the analysis is queued to start (*Collection finished. The analysis will start shortly.*). If you try to trigger with another run active, *A run is already in progress ({type}). Its progress shows here.* appears.
* **Reanalyze only** is also blocked while the definition collection is running, because the analysis runs automatically at the end of it.
* If the **Notebook, pipeline and dataflow dependencies** collection is off, the card shows **Dependency collection is off** (*Code analysis depends on the "Notebook, pipeline and dataflow dependencies" collection, which is turned off for the organization.*), the buttons are disabled and the **Turn it on in Settings › Monitoring** link leads to the switch.
* If no run starts after a few minutes, the card warns *The run was queued, but no processing has started.* and suggests trying again in a few minutes; the **Check again** button queries the status again. If it still does not start, contact support.

### Analysis history card

**What it is:** the **Analysis history** card (*Most recent runs first*), with two views: **Code analysis** and **Definition collection**, the **Refresh** button and pagination.

| Column | Content |
| --- | --- |
| **Started** / **Duration** | When the run started and how long it took (live while in progress) |
| **Status** | **In progress**, **Paused**, **Completed**, **Partial**, **Failed** or **Interrupted** |
| **Trigger** | **Scheduled** or **Manual** (with the name of who triggered it) |
| **Analyzed**, **With findings**, **Not analyzable**, **Failures** | Counters of the **Code analysis** view |
| **Items processed**, **Failures** | Counters of the **Definition collection** view |
| **Detail** | **View detail** opens the run message and, for the analysis, the counters by **Item type** (**Dataflow Gen1**, **Dataflow Gen2** and **Notebook**); **Hide** closes it |

**How it works:** **Partial** means *Completed with pending work: some items failed or the run stopped at the continuation limit. The rest goes into the next run.* The same runs also appear in the **Code collectors** section of [Scan Logs](logs-de-scans-e-re-execucoes.md).

## Rules and behavior

* **Two stages:** the **definition collection** reads, through the Fabric API, the definition of each Dataflow, Notebook and Pipeline (the same collection that feeds [Data Lineage](../qualidade-de-dados/linhagem-de-dados.md#how-dependencies-are-collected)); the **code analysis** runs right after, on the stored definitions, without querying Fabric. Only Dataflows and Notebooks have code analysis.
* **Frequency:** automatic, once a day (at around 23:15, Brasília time). The automatic run is controlled by the **Notebook, pipeline and dataflow dependencies** switch in [Settings › Monitoring](../configuracoes/monitoramento.md#scans-and-collections), **Inventory** group, where you can also choose the **Frequency**. Unlike other collections, here the manual buttons do **not** work with the switch off.
* **Prerequisite:** the Service Principal needs write permission (**Contributor** or higher) on the workspaces, because Fabric only delivers an item's definition to whoever can edit it. Without it, the item's definition is not read: it stays **Pending** on the Performance screens or, if it had been read before, gets the **Definition read failed** badge.
* **The code does not leave Power Monitor:** the analysis is done on the protected copy of the definition; findings store only the rule, the query or cell and the line, and nothing is sent to AI.
* **Automatic re-analysis:** when the rule catalog is updated, the definitions already collected are reanalyzed on the next run, without a new download (items show the **Re-analysis pending** badge until then).
* **Concurrency:** there is only one active collection and one active analysis per organization. Triggers while a run is active are refused with a warning.

## Step by step

{% stepper %}
{% step %}
### Open the screen

Go to *Mapping › Operations › Code analysis* with an administrator account, or click **View/manage collection →** in *Performance › Dataflows* or *Performance › Notebooks*.
{% endstep %}

{% step %}
### Choose the type of run

Use **Run analysis now** if the code changed in Fabric and you want up-to-date findings. Use **Reanalyze only** if the definitions are already up to date and you only want to redo the analysis.
{% endstep %}

{% step %}
### Confirm and follow

Confirm in the dialog and follow the status in the **Latest analysis** card. You can leave the screen: the run continues in the background.
{% endstep %}

{% step %}
### Check the result

When it finishes, open the history and use **View detail** to see the counters by item type. Then open [Performance › Dataflows](../performance/dataflows.md) or [Performance › Notebooks](../performance/notebooks.md) and click **Refresh**.
{% endstep %}
{% endstepper %}

## Frequently asked questions

<details>

<summary>The buttons are disabled. Why?</summary>

Hover over the button to see the reason: a run is already in progress, the run was queued and has not started yet, the analysis is queued right after a collection, or the **Notebook, pipeline and dataflow dependencies** collection is off in *Settings › Monitoring*.

</details>

<details>

<summary>What is the difference between "Run analysis now" and "Reanalyze only"?</summary>

**Run analysis now** downloads the definitions from Fabric again (which reflects the latest code changes) and then analyzes them. **Reanalyze only** uses the definitions already stored, is faster and does not query Fabric, but does not see changes made after the last collection.

</details>

<details>

<summary>Many items show as "Not analyzable".</summary>

The definition is too large to be stored, could not be read or the analysis failed on it. Failed items are analyzed again when the definition changes. If the collection cannot read the items, check the Service Principal's **Contributor** permission on the workspaces.

</details>

## Related pages

* [Performance › Dataflows](../performance/dataflows.md)
* [Performance › Notebooks](../performance/notebooks.md)
* [Settings › Monitoring](../configuracoes/monitoramento.md)
* [Data Lineage](../qualidade-de-dados/linhagem-de-dados.md)
* [Scan Logs](logs-de-scans-e-re-execucoes.md)
* [Mapping](README.md)
