bloomberg / pytest-memray

pytest plugin for easy integration of memray memory profiler
https://pytest-memray.readthedocs.io/en/latest/
Apache License 2.0
323 stars 23 forks source link

fix: Don't break at calculating log of numbers close to zero #103

Closed gnufede closed 4 months ago

gnufede commented 7 months ago

Issue number of the reported bug or feature request: #102

Describe your changes Manage the case when calculating log of numbers too close to zero.

Testing performed None yet.

gnufede commented 7 months ago

@pablogsal I know my math teacher wouldn't be very proud of this PR, but I'd love your feedback anyway

pablogsal commented 7 months ago

Thanks for the PR @gnufede! I’m currently on vacation but I’m sure @godlygeek can take a look soon :)

godlygeek commented 4 months ago

Thanks for the bug report. I've gone with a different fix, though. This case would only come up when the program performed an allocation of zero bytes. If we hadn't been causing an exception by calling math.log(0) when that happened, we still would have been handling those zero-byte allocations in an odd way, excluding them from the histogram entirely.

Instead, I've updated this PR to just pretend that zero-byte allocations were one-byte allocations, so that they still get counted in the histogram, and just get slotted into the smallest bin.

@pablogsal Mind giving me a review here, since I've rewritten this PR?