Fix pretty_size and pretty_duration right below a unit boundary by qodelicious · Pull Request #8498 · mitmproxy/mitmproxy · GitHub
Skip to content

Fix pretty_size and pretty_duration right below a unit boundary - #8498

Open
qodelicious wants to merge 2 commits into
mitmproxy:mainfrom
qodelicious:fix-pretty-size-duration-rounding
Open

qodelicious wants to merge 2 commits into
mitmproxy:mainfrom
qodelicious:fix-pretty-size-duration-rounding

Conversation

@qodelicious

Copy link
Copy Markdown
Contributor

Description

pretty_size and pretty_duration pick the unit before rounding, so values just under a boundary come out in the wrong unit once they're formatted.

  • pretty_size(1024 * 1024 - 1) gives 1024k instead of 1.0m
  • pretty_duration(0.9996) gives 1000ms instead of 1.00s
  • pretty_duration(9.996) gives 10.00s instead of 10.0s
  • pretty_duration(99.96) gives 100.0s instead of 100s

These show up in the console flow list and in the dumper output. The fix compares the rounded value against the limit, so the unit and precision match what actually gets printed. I also swept a few million sizes and durations around the boundaries to make sure none of the odd outputs are left and pretty_size still stays at 5 characters or less.

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

@mhils mhils left a comment

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.

Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants