MCPcopy Index your code
hub / github.com/EmbarkStudios/puffin

github.com/EmbarkStudios/puffin @puffin_egui-0.30.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release puffin_egui-0.30.0 ↗ · + Follow
315 symbols 680 edges 23 files 112 documented · 36% updated 2d agopuffin-0.19.0 · 2024-01-17★ 1,71926 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

🐦 puffin

The friendly little instrumentation profiler for Rust

Puffin photo by Richard Bartz

(puffin photo by Richard Bartz)

Embark Embark Crates.io Docs dependency status Build Status

How to use

fn my_function() {
    puffin::profile_function!();
    ...
    if ... {
        puffin::profile_scope!("load_image", image_name);
        ...
    }
}

The Puffin macros write data to a thread-local data stream. When the outermost scope of a thread is closed, the data stream is sent to a global profiler collector. The scopes are pretty light-weight, costing around 50-200 ns.

You have to turn on the profiler before it captures any data with a call to puffin::set_scopes_on(true);. When the profiler is off the profiler scope macros only has an overhead of 1 ns on an M1 MacBook Pro (plus some stack space).

Once per frame you need to call puffin::GlobalProfiler::lock().new_frame();.

Puffin Flamegraph using puffin_egui

Remote profiling

You can use puffin_http to send profile events over TCP to puffin_viewer. This is as easy as:

fn main() {
    let server_addr = format!("127.0.0.1:{}", puffin_http::DEFAULT_PORT);
    let _puffin_server = puffin_http::Server::new(&server_addr).unwrap();
    eprintln!("Run this to view profiling data:  puffin_viewer {server_addr}");
    puffin::set_scopes_on(true);

    …

    // You also need to periodically call
    // `puffin::GlobalProfiler::lock().new_frame();`
    // to flush the profiling events.
}

egui integration

To view the profile data in-game you can use puffin_egui.

If you are using eframe you can look at this example.

Other

Also check out the crate profiling which provides a unifying layer of abstraction on top of puffin and other profiling crates.

Contributing

Contributor Covenant

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started.

Releasing

We use the cargo release tool to manage changelogs, git tags and publishing crates.

Each substantial pull request should add a changelog entry under the [Unreleased] section (see keep a changelog and previous changelog entries). The crate version in Cargo.toml is never updated manually in a PR as it's handled by cargo release.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Core symbols most depended-on inside this repo

len
called by 33
puffin/src/data.rs
frame_index
called by 27
puffin/src/frame_data.rs
new_frame
called by 15
puffin/src/global_profiler.rs
insert
called by 14
puffin/src/scope_details.rs
duration_ns
called by 12
puffin/src/frame_data.rs
name
called by 11
puffin/src/scope_details.rs
is_empty
called by 11
puffin_egui/src/filter.rs
set_scopes_on
called by 10
puffin/src/lib.rs

Shape

Method 186
Function 65
Class 53
Enum 11

Languages

Rust100%

Modules by API surface

puffin/src/profile_view.rs46 symbols
puffin/src/data.rs41 symbols
puffin/src/frame_data.rs37 symbols
puffin_egui/src/lib.rs32 symbols
puffin_egui/src/flamegraph.rs23 symbols
puffin/src/scope_details.rs20 symbols
puffin_viewer/src/lib.rs14 symbols
puffin_egui/src/stats.rs14 symbols
puffin_http/src/server.rs12 symbols
puffin/src/lib.rs12 symbols
puffin/src/global_profiler.rs11 symbols
puffin/src/thread_profiler.rs10 symbols

For agents

$ claude mcp add puffin \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page