Leakcanary: Display retain object size using human readable output

Created on 2 Oct 2020  路  8Comments  路  Source: square/leakcanary

Problem description

Since v2.5, retained objects size is displayed ( 馃憤 ) as byte amount, would be nice to have a more user friendly output like du -h does for instance.
Having MB of leak vs bytes might be more alerting.

Potential solutions

If this part of the code depends on Android APIs, Formatter.formatFileSize might be used.
Otherwise, implementing should be feasible using this kind of algorithm: https://stackoverflow.com/a/3758880

help wanted enhancement

All 8 comments

The size is current printed here: https://github.com/square/leakcanary/blob/main/shark/src/main/java/shark/LeakTrace.kt#L143

That module does not have access to the Android APIs.

We should probably go with the SI (ie 1 KB = 1000 B)

Ok I'll try implementing it myself given this output.

@pyricau RenderHeapDumpScreen currently doesn't use SI, shouldn't we align both usage? (ie SI everywhere as you suggested in your previous comment).

Another question, where should I put the impl of humanReadableByteCount? Do you have a common module for such utils or should I duplicate impl in the :shark module?

I've also noticed such output in DisplayLeakAdapter, so might worth extracting a shared impl of humanReadableByteCount somewhere.

@pyricau maybe I missed something regarding GitHub issues flow but the issue is still opened despite being referenced in a commit message of a merged PR.
Should I close it myself?
Is it your responsibility as maintainer of the repo?

Maybe I should have used a verb like "closes" or "fixes" while mentioning the issue in my commit message?

(Note: Sorry if it's silly questions, I'm not used to GitHub PR from forks, I use BitBucket server at work and use GitHub on my own with self review for personal projects, not used to collaborate a lot with GitHub)

Yep the best way is to include "Fixes #number " in the commit message, then when its merge the issue auto closes. I should have closed it manually but forgot.

Thanks for explanation and your patience 馃檱

Was this page helpful?
0 / 5 - 0 ratings