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 simple memory profiler #93

Open
emilk opened this issue Oct 19, 2020 · 6 comments
Open

Add a simple memory profiler #93

emilk opened this issue Oct 19, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@emilk
Copy link

emilk commented Oct 19, 2020

I want to know how much memory PhysX is using.

It seems like physx-rs could overload PxAllocatorCallback to add simple tracking of used memory. This could then be queried like scene.bytes_allocated(). I would assume such an overload would have so little overhead that it wouldn't need to be feature-gated, but if it does have overhead then maybe a simple SceneBuilder flag to turn it on could be considered.

PxAllocatorCallback also supplies a typeName for the allocated resource, so in the future one could consider returning a more detailed HashMap<String, usize> describing what is using memory, though I am not sure if such detail would be useful in practice.

@emilk emilk added the enhancement New feature or request label Oct 19, 2020
@hrydgard
Copy link
Contributor

I'm going to add a simple interface that lets you pass in callbacks that will be called on alloc/dealloc. That lets users of the library implement their own tracking, with zero overhead if you don't use it.

@repi
Copy link
Contributor

repi commented Oct 19, 2020

Assume PhysX does support overriding their allocator also? Could be quite nice to support overriding it and connect it to the Rust global memory allocator (or rather: A Rust memory allocator of the users choosing) through the standard trait or a custom one. This is what we use in our engine and great to have most heap allocations in the same main allocator. Assuming the interfaces and needs are similar.

@hrydgard
Copy link
Contributor

Yeah, we can also replace the whole allocator. Can try that instead. Physx does send in a bit of extra metadata that we really want to track separately (as Emil mentions), but can then pass through to a Rust alloc.

@repi
Copy link
Contributor

repi commented Oct 19, 2020

Cool, worth a shot

@Hentropy
Copy link
Contributor

I implemented a super rudimentary tracking allocator here.
If the allocation name feature works, that would enable a proper type aware allocator which would be amazing, but IIRC it's debug only, and debug doesn't work or something. I'd love to be wrong there though.
Without that, the allocator is a C-style void-pointer allocator, and wrapping Rust's lovely type aware one in that feels dirty.

@hrydgard
Copy link
Contributor

The allocation name feature actually kinda mostly works in release mode, you just have to call
foundation.set_report_allocation_names(true);. PhysX does a quite good job of pooling internally so most of what you'll see are pools of various types.

In our application we implemented a tracker on top of the trampoline I added in #94 , actually very similar to yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants