Skip to content

test: add memory profiler test #5329

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jmayclin
Copy link
Contributor

Description of changes:

Our current memory usage unit test is incredibly fuzzy. We can improve the accuracy by using an actual memory profiler to get the exact amount allocated.

Testing:

Ran locally. Also numbers relatively closely match our existing memory tests.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label May 23, 2025
@jmayclin jmayclin marked this pull request as ready for review May 23, 2025 16:37
@jmayclin jmayclin requested review from lrstewart and goatgoose June 3, 2025 00:59
Comment on lines +36 to +38
/// Because the s2n-tls rust bindings set the s2n-tls memory callbacks to use the
/// rust allocator, this does give a good picture of s2n-tls allocations. However
/// this will _not_ report the allocations done by the libcrypto.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this why you're not removing the existing memory usage test?

Comment on lines +20 to +21
/// This isn't totally accurate because it doesn't account for any indirection that
/// may be present.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand why this wouldn't be accurate. capacity() should be accurate, right? Is this saying that server_tx_stream or client_tx_stream might be pointing to some other LocalDataBuffer, so it may not be returning the size of the actual TestPairIO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, it's saying that there may be sneaky other allocations hidden :). Specifically, this method fails to account for 80 heap allocated bytes because the RefCell and it's contents are also heap allocated

memory_diagram

pair.io.client_tx_stream.borrow().capacity() + pair.io.server_tx_stream.borrow().capacity()
}

fn fuzzy_equals(actual: usize, expected: usize) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is fuzzy_equals needed? Is this test nondeterministic, or do you just not want to update it all the time?

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

Successfully merging this pull request may close these issues.

2 participants