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 upb_Arena_SpaceAllocated function #729

Merged

Conversation

casperisfine
Copy link

Ref: protocolbuffers/protobuf#10291

Ruby types defined though native extensions should register
a function that report their memory footprint in bytes.

This feature is used by various memory profiling tools.

As suggested by @haberman.

NB: the implementation is a bit simpler than what we had in protocolbuffers/protobuf#10291, here we return the arena allocated size, but we don't care about fused arenas. I think dividing by the number of fused arena is an implementation detail of the Ruby extension.

@haberman
Copy link
Member

This looks good. We should also expose a upb_Arena_DebugRefCount() that just returns the ref count. The members of upb_Arena should be private from the perspective of the Ruby extension. Putting Debug in the name will make clear that the return is for informational purposes only, and shouldn't be used to control any logic.

@casperisfine
Copy link
Author

We should also expose a upb_Arena_DebugRefCount() that just returns the ref count.

Done.

upb/arena.h Outdated Show resolved Hide resolved
@casperisfine casperisfine force-pushed the arena-space-allocated branch 2 times, most recently from fa81616 to 84e8f0c Compare August 11, 2022 09:14
upb/arena.c Outdated Show resolved Hide resolved
upb/arena.h Outdated
@@ -72,6 +72,8 @@ void upb_Arena_Free(upb_Arena* a);
bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func);
bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b);
void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size);
size_t upb_Arena_SpaceAllocated(upb_Arena *arena);
uint_32_t upb_Arena_DebugRefCount(upb_Arena *arena);
Copy link
Member

Choose a reason for hiding this comment

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

Same issue here.

Are you able to run the tests? If you install Bazel you should be able to run:

$ bazel test :all

@casperisfine
Copy link
Author

@haberman apologies for not double checking, should be good to go now.

@haberman
Copy link
Member

Would you be able to pull the latest changes from main? I've fixed the GitHub Actions to work properly for external contributors. Sorry for the hassle on this CL, we were still in the process of getting our CI system healthy.

upb/arena.c Outdated Show resolved Hide resolved
Ref: protocolbuffers/protobuf#10291

Ruby types defined though native extensions should register
a function that report their memory footprint in bytes.

This feature is used by various memory profiling tools.
@casperisfine
Copy link
Author

@haberman rebased

@copybara-service copybara-service bot merged commit 1ad98e9 into protocolbuffers:main Sep 13, 2022
@casperisfine
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants