-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[scudo] Add utilization percentages for stats. #75101
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,21 @@ template <typename T> inline void shuffle(T *A, u32 N, u32 *RandState) { | |
*RandState = State; | ||
} | ||
|
||
inline void computePercentage(uptr Numerator, uptr Denominator, uptr *Integral, | ||
uptr *Fractional) { | ||
constexpr uptr Digits = 100; | ||
if (Denominator == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we want to assert a non-zero denominator. It seems to give the impression that 0/1 and 0/0 are the same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another case I saw in real life, and I was wondering if I should say 100% when the denominator is 0. Since 0% feels like the wrong value, 100% also seems kind of wrong, but more correct than 0%. My other thought was doing NA, but that seems like it would be very difficult to implement without changing a lot of things. I would think setting this to 100% seems the least bad and the most correct, but what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I think 100% is better! (Given that NA is more complicated) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set to 100, and modified the two locations that use it to reserve enough space for that 100%. |
||
*Integral = 0; | ||
*Fractional = 0; | ||
return; | ||
} | ||
|
||
*Integral = Numerator * Digits / Denominator; | ||
*Fractional = | ||
(((Numerator * Digits) % Denominator) * Digits + Denominator / 2) / | ||
Denominator; | ||
} | ||
|
||
// Platform specific functions. | ||
|
||
extern uptr PageSizeCached; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking if we want a
Pair
in Scudo but I didn't get a good use case to add it. This form works for me too. Will leave it to you to make the decision.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was hoping I could use std::pair, but I think that would be a bad idea. And adding our own definition feels like a lot of work for a single case that's not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree with this