> For the complete documentation index, see [llms.txt](https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/core-concepts/profiler.md).

# The profiler

StoneForge's profiler shows where each frame goes. Press **Ctrl+Shift+P** in game for an overlay with:

* the frame rate and the worst frame over the last second;
* each mod's time per frame, slowest mod first, with the total of its code and its slowest parts: the average and worst over the last second, and how many times each ran.

StoneForge times every mod handler itself: `Tick`, frame and Draw GUI handlers, script hooks (before and after), code hooks, and so a mod's objects' events. Its own UI (mod screens and windows) is listed under StoneForge. Nothing is timed while the overlay is off.

## Timing parts of your own

Wrap work of your own in `Profiler.Measure` to see it listed under your mod:

```csharp
Profiler.Measure(context, "loot sync", () => SyncLoot());
int count = Profiler.Measure(context, "count enemies", () => Instances.Count((int)GameObjectId.o_enemy));
```

The work runs either way; it's only timed while the overlay shows.

## From code

| `Profiler`                     |                                                                                                                                                                                     |
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Visible`                      | Whether the overlay shows (and timing is on). Setting it switches it.                                                                                                               |
| `Timings`                      | The last second's timings, slowest first (empty while the overlay's off): each a `Timing` with `Mod`, `Name`, `Section`, `Average` and `Worst` (ms per frame), and `CallsPerFrame`. |
| `Fps`, `WorstFrameMs`          | The last second's frame rate and slowest frame.                                                                                                                                     |
| `Measure(context, name, work)` | Times a part of your mod's own.                                                                                                                                                     |


---

# 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://stoneforgeteam.gitbook.io/stoneforgeteam-docs/core-concepts/profiler.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.
