# Code metrics

### About

Code metrics help you understand how work moves through your development process, from the first commit to merge and beyond. They highlight how long work takes, where it gets stuck, and how quickly feedback is given. Use these insights to improve flow, reduce delays, and ship smaller changes more frequently.

### Why does it matter?

Code metrics help teams:

* Identify bottlenecks in development, review, or merge stages
* Improve feedback loops and collaboration
* Reduce risk by shipping smaller changes more often
* Separate development speed from deployment delays

If you’re looking to improve delivery performance, start with pull request cycle time and review metrics, then expand into deployment metrics like change lead time.

## Understanding the Code Metrics Page

The Code Metrics page in Swarmia provides a comprehensive view of your team's development process, helping you identify bottlenecks and foster a culture of continuous improvement. This page is designed to provide insights into key aspects of your coding lifecycle, from batch size to review processes. Use these metrics to understand your process and drive meaningful improvements. Focus on trends over time rather than isolated data points to get a true sense of your team's health and progress.

**1. Overview**

The Overview tab provides a high-level summary of your team's key pull request metrics. It also includes a team comparison table where you can see how your team's performance on metrics like Cycle Time and Batch size compares to other teams in the organization.

* Use Case: Use this view to get a quick pulse check on your team's health and to identify areas that might need a deeper look. The team comparison table is especially useful for spotting outliers and understanding your team's performance in the broader organizational context.
* Pro Tip: When using the comparison table, sort by different metrics to find teams that are excelling and could share best practices. Using percentiles like p90 instead of averages may give you a more realistic view, as averages can be skewed by a few unusually long-running pull requests.

**2. Trends**

The Trends tab is your primary tool for visualizing how your team's metrics evolve over time. You can track metrics like Cycle Time, Throughput, and Batch Size to see if your process is improving.

* Use Case: Use this view to spot spikes or dips in performance. For example, a sudden increase in Cycle Time might indicate a new bottleneck in the review process or an issue with the CI/CD pipeline.
* Pro Tip: Don't just look at the last week. Expand the timeframe to a quarter or even a year to identify long-term patterns or measure the impact of process changes you've implemented.

**3. Cycle Time**

This tab offers a visualization to the Cycle Time of your pull requests—the time from first commit to merge.

* Use Case: This view helps you to understand how the cycle times are divided among PRs, and see if there’s some outliers that may skew the average.
* Pro Tip: Use the detailed list of pull requests in this view to investigate anomalies. Click into a PR with an exceptionally long cycle time to understand the context, read the comments, and see what caused the delay.

**4. Review**

The Review tab focuses on the health and efficiency of your code review process. It visualizes metrics like Time to First Review and the number of comments per pull request.

* Use Case: This tab helps you answer questions like, "Are pull requests waiting a long time for a first review?" or "Are our reviews becoming more or less thorough over time?"
* Pro Tip: Look for patterns of long review times on certain days or for certain types of pull requests. This can help you organize your team's workflow better, for example, by setting aside dedicated time for reviews.

**5. Batch Size**

This tab analyzes the size of your pull requests, measured in lines of code changed. Smaller batches are generally preferred as they are easier to review, test, and merge, leading to a faster flow of value.

* Use Case: A wide distribution in batch size might indicate that there isn't a shared understanding of what a "small" pull request looks like. Use this view to have a conversation with your team and establish working agreements on PR size.
* Pro Tip: Filter this view to see if larger pull requests correlate with longer cycle times. This data can provide a compelling case for encouraging smaller, more frequent commits.

**6. Codebase**

The Codebase tab shows you which parts of your codebase are changing and how frequently. It aggregates file changes from pull requests into a tree structure, showing metrics like the number of PRs, lines changed, and contributors for each part of your code.

* Use Case: Use this view to identify "hotspots" in your code—areas that are frequently modified and might be candidates for refactoring. You can also see which teams are contributing to which parts of the codebase.
* Pro Tip: Combine this view with filters to answer specific questions, such as, "Which files have been most frequently edited by AI coding assistants this quarter?" or "Who has contributed to this legacy module recently?".

### How to use code metrics?

Code metrics in Swarmia focus on pull request–based measurements.

#### Pull request cycle time

Pull request cycle time measures how long a pull request takes from the first commit to merge.

In Swarmia, pull request cycle time is the sum of these three components:

* Time in progress — from the first commit or from when the pull request is opened, whichever happens first, to the first review request.
* Time in review — from the first review request (or from when the pull request was opened, if none) to the final approval.
* Time to merge — from the final approval to once the pull request is merged.

You can:

* View aggregate cycle time across pull requests
* Drill down into individual pull requests to understand delays
* Use Pull request insights and overview to identify slow or aging PRs

<figure><img src="/files/oq3RdtLUfKxXP2m28Pjg" alt=""><figcaption></figcaption></figure>

#### Review metrics

Swarmia includes metrics to understand how quickly pull requests are reviewed.

Time to first review

* Measures how long it takes to receive the first review after a review is requested
* Indicates how quickly new work gets picked up

Review time

* Measures how long each individual review takes

You can:

* View time to first review in Code overview, Trends, and Review
* Explore review timelines in the Review view
* Analyze review performance across pull requests

![](https://help.swarmia.com/~gitbook/image?url=https%3A%2F%2F2772466312-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FMa8uBmGhQgR7MTPq9yh7%252Fuploads%252Fgit-blob-5c73dde98add8946d494b7ed2a50873b77a4ff38%252Fimage.png%3Falt%3Dmedia\&width=768\&dpr=3\&quality=100\&sign=4ccd704b\&sv=2)

#### Change lead time

Change lead time extends cycle time to include deployment.

* Pull request cycle time: First commit → merge
* Change lead time: First commit → deployment

Use both metrics together:

* Cycle time shows development and review efficiency
* Change lead time shows end-to-end delivery speed

![](https://help.swarmia.com/~gitbook/image?url=https%3A%2F%2F2772466312-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FMa8uBmGhQgR7MTPq9yh7%252Fuploads%252Fgit-blob-bf7dc1fcf8586dadff076394d860b2e0d2fb2877%252Fimage.png%3Falt%3Dmedia\&width=768\&dpr=3\&quality=100\&sign=1f1971c\&sv=2)

#### How are draft PRs considered in cycle time? <a href="#how-are-draft-prs-considered-in-cycle-time" id="how-are-draft-prs-considered-in-cycle-time"></a>

We consider all PRs the same, regardless of the draft state. Since PR cycle time starts from the first commit (or PR open, whichever happens first), the total cycle time is the same, regardless of whether you open a PR as a draft early or ready to review later.

In other words, we consider the draft status by default to be part of the in-progress time. Our definition is based on the assumption that draft pull requests are used as an early indication of work in progress or to gather feedback before review. We try to catch as much of the in-progress time for pull requests as possible.

If you want to exclude draft PRs from Swarmia until they are ready to review, you can set a "Draft status is Draft" [exclusion rule](https://help.swarmia.com/settings/organization/pull-request-data-quality). This can be useful, for example, if you create proof-of-concept draft PRs with no intention to merge or close them. Another option would be to create a dedicated PR label for this and use it in the exclusion rule.

![](https://help.swarmia.com/~gitbook/image?url=https%3A%2F%2F2772466312-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FMa8uBmGhQgR7MTPq9yh7%252Fuploads%252Fgit-blob-056a79ea2f0e8a67089d152c85f7cd921e55894d%252Fdraft-filter.png%3Falt%3Dmedia\&width=768\&dpr=3\&quality=100\&sign=94e0a909\&sv=2)

### What does good look like?

#### Pull request cycle time benchmarks

* Great: < 24 hours
* Good: < 5 working days
* Needs attention: ≥ 5 working days

### How can we take action?

To improve code metrics, focus on flow and feedback loops.

#### Reduce cycle time

* Limit work in progress (avoid too many open pull requests)
* Split work into smaller pull requests
* Prioritize reviews and merges
* Define clear ownership for moving pull requests forward

#### Improve review responsiveness

* Ensure new pull requests are picked up quickly
* Reduce delays in starting reviews
* Identify and address slow or outlier reviews

#### Use Swarmia to support improvements

* Clean up old or stale pull requests
* Exclude outliers to focus on current work
* Set working agreements (e.g. max PR age, WIP limits)
* Use daily digests to stay aware of aging pull requests
* Review pull request insights regularly as a team

### Where does the data come from?

Code metrics are based on pull request and review events, including:

* Commits
* Pull request creation
* Review requests and submissions
* Approvals and merges

Change lead time additionally requires deployment data.

Only pull requests linked to applications with deployments configured are included in change lead time.

### Metric definitions

Pull request cycle time\
\= Time in progress + Time in review + Time to merge

Time to first review\
\= Review request → first review submission

Review time\
\= Review request → individual review completion

Change lead time\
\= First commit → deployment

<br>

<figure><img src="https://help.swarmia.com/~gitbook/image?url=https%3A%2F%2F2772466312-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FMa8uBmGhQgR7MTPq9yh7%252Fuploads%252Fgit-blob-c493dd694a303df231ca24f0431a24bc4819b70f%252Fimage.png%3Falt%3Dmedia&#x26;width=768&#x26;dpr=3&#x26;quality=100&#x26;sign=1bb125c2&#x26;sv=2" alt=""><figcaption></figcaption></figure>

### Something looks wrong

Common reasons:

* Very old pull requests skewing averages
* Draft PRs included when they shouldn’t be
* Proof-of-concept or abandoned PRs included
* PRs merged without formal approval → review time measured until merge
* Bot reviews not included in aggregates

Possible fixes:

* Exclude outliers
* Add exclusion rules for draft PRs or labels
* Clean up old pull requests


---

# 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://help.swarmia.com/features/metrics/code-metrics.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.
