Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a public API to expose allocation reports #226

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

nical
Copy link
Contributor

@nical nical commented May 14, 2024

This PR adds a public API that exposes enough information for users to build something like the block visualizer without the egui integration. It also adds an offset field in the allocation report.

I would like to integrate (and expose in some form) this in wgpu to debug memory leaks.

The report could expose more information (for example properties of the memory and stack traces) and I haven't added any documentation yet, but it's a good basis for discussing whether the project is OK with exposing something like this and whether the approach is good.

@Jasper-Bekkers
Copy link
Member

Jasper-Bekkers commented May 14, 2024

Tracks towards #203 so very welcome. Also indirectly helps with #59

Copy link
Collaborator

@manon-traverse manon-traverse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really nice change!
The only part I dislike is the name for creating the report.

src/d3d12/mod.rs Outdated Show resolved Hide resolved
src/d3d12/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice stuff, as discussed in the wgpu Matrix! This would definitely help us long-term with generalizing the visualizer completely, after adding more flags like the relevant heap and other backend-specific items in a somewhat generic way 😅

Would love this to have some doc-comments from the start though, given that -for example- allocations are stored globally instead of per-block and findable via a stored Range. Maybe derive(Debug) would help as well, but that might be complicated for the top-level AllocatorReport.

src/allocator/mod.rs Show resolved Hide resolved
src/d3d12/mod.rs Outdated Show resolved Hide resolved
total_reserved_bytes += block.size;
let first_allocation = allocations.len();
allocations.extend(block.sub_allocator.report_allocations());
blocks.push(MemoryBlockReport {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not useful to you yet to report what memory type/heap this block was allocated on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! I was being cautious about exposing internals but I'll take every bit of useful information you are confortable with exposing.

@nical
Copy link
Contributor Author

nical commented May 15, 2024

I made a few notable changes:

  • Added some doc comments
  • reexported AllocatorReport and friends at the crate level so that it's actually public
  • Moved the debug implementation of the two allocators into the report (allocators debug impl now just call generate_report().fmt(f)).

Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice stuff! I'm not sure if the original Debug format is an appropriate text output for this purpose (maybe better suited for Display) but hey, at least it is deduplicated now 🚀

src/allocator/mod.rs Outdated Show resolved Hide resolved
src/allocator/mod.rs Outdated Show resolved Hide resolved
src/allocator/mod.rs Outdated Show resolved Hide resolved
src/allocator/mod.rs Show resolved Hide resolved
src/allocator/mod.rs Show resolved Hide resolved
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotted a CommittedAllocationStatistics in metal, could that be useful for this?

Can you also implement fn generate_report() on our metal backend?

src/allocator/mod.rs Outdated Show resolved Hide resolved
src/allocator/mod.rs Outdated Show resolved Hide resolved
src/allocator/mod.rs Show resolved Hide resolved
@nical
Copy link
Contributor Author

nical commented May 23, 2024

I added metal and made a few other adjustments from the review comments. I still haven't added information about the memory blocks to the report. To do that I need to spend a bit of time looking at each backend, finding the common denominators and storing the right info in the right places for the report to pick up. It's not much but because I am currently juggling a lot of tasks on different projects I'm having some difficulty finding the time to wrap my head around that bit.

Would you be OK with landing the current feature set?
Should I bump the patch version in this PR?

@MarijnS95
Copy link
Member

Should I bump the patch version in this PR?

I'm sure wgpu has special release processes that don't like arbitrary PRs bumping the version either 😉


We currently have a CI failure related to the whole metal-rs "debacle" that might be blocking the merge of this PR. We'll have to resolve that first before this can be merged.

@nical
Copy link
Contributor Author

nical commented May 24, 2024

I'm sure wgpu has special release processes that don't like arbitrary PRs bumping the version either 😉

I don't think there's a specific rule about that but since wgpu's release process is fair bit more involved than most crates, it indeed tends to be done in isolation.

We currently have a CI failure related to the whole metal-rs "debacle"

I wasn't aware of this. I'm not involved with the metal stuff and reading through #224 and linked issues it looks like the interesting stuff might be happening upstream of the metal-rs crate but let me know if I can help by following up with other folks in the gfx-rs org.

@MarijnS95
Copy link
Member

I don't think there's a specific rule about that but since wgpu's release process is fair bit more involved than most crates, it indeed tends to be done in isolation.

So is ours, and I think for every crate it's a much nicer policy to have an explicit "Release XXX" commit in their history rather than doing it within a feature PR.

@MarijnS95
Copy link
Member

@nical would you mind to sign your commits?

@MarijnS95
Copy link
Member

@nical JFYI, despite being subscribed to this repo and PR I don't receive any notifications for your pushes, and just happened to see the update at the right moment by accident. Please ping me once I have to approve the CI again, since GitHub delegates their anti-CI-abuse measures to repository owners and maintainers 😅

@nical
Copy link
Contributor Author

nical commented Jun 17, 2024

Good to know, @MarijnS95. I just pushed another commit to fix the fmt issue

@MarijnS95 MarijnS95 merged commit 4b5c0d4 into Traverse-Research:main Jun 17, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants