Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Add upb_Arena_SpaceAllocated function#729

Merged
copybara-service[bot] merged 1 commit intoprotocolbuffers:mainfrom
casperisfine:arena-space-allocated
Sep 13, 2022
Merged

Add upb_Arena_SpaceAllocated function#729
copybara-service[bot] merged 1 commit intoprotocolbuffers:mainfrom
casperisfine:arena-space-allocated

Conversation

@casperisfine
Copy link
Copy Markdown

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
Copy Markdown
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 casperisfine force-pushed the arena-space-allocated branch from 1a70918 to ca423cb Compare August 10, 2022 14:47
@casperisfine
Copy link
Copy Markdown
Author

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

Done.

Comment thread upb/arena.h Outdated
@casperisfine casperisfine force-pushed the arena-space-allocated branch 2 times, most recently from fa81616 to 84e8f0c Compare August 11, 2022 09:14
Comment thread upb/arena.c Outdated
@casperisfine casperisfine force-pushed the arena-space-allocated branch from 84e8f0c to c144cc6 Compare August 11, 2022 17:07
Comment thread upb/arena.h Outdated
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
Copy Markdown
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 casperisfine force-pushed the arena-space-allocated branch from c144cc6 to 7980b53 Compare August 16, 2022 06:57
@casperisfine
Copy link
Copy Markdown
Author

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

@haberman
Copy link
Copy Markdown
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.

Comment thread upb/arena.c Outdated
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
Copy Markdown
Author

@haberman rebased

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

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants