diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-13 00:18:40 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-13 00:18:40 +0000 |
commit | b35158128c6f2b40a28da5ece610677831a74306 (patch) | |
tree | 1f9d54d421255d475c74497bfa7daf9f29e7be33 | |
parent | 47e9115e77b8b3eebbf908104bf26685a133fc4d (diff) | |
parent | e628b3c5d6cba32e043f1c05388dc2dbf4e66f09 (diff) | |
download | scudo-android14-qpr2-s3-release.tar.gz |
Snap for 11211173 from e628b3c5d6cba32e043f1c05388dc2dbf4e66f09 to 24Q1-releaseandroid-14.0.0_r37android-14.0.0_r36android-14.0.0_r35android-14.0.0_r34android-14.0.0_r33android-14.0.0_r32android-14.0.0_r31android-14.0.0_r30android-14.0.0_r29android14-qpr2-s5-releaseandroid14-qpr2-s4-releaseandroid14-qpr2-s3-releaseandroid14-qpr2-s2-releaseandroid14-qpr2-s1-releaseandroid14-qpr2-release
Change-Id: I7cbcca4f3379ec32ce4cf2767fa4ee87bea55a2c
-rw-r--r-- | standalone/common.h | 15 | ||||
-rw-r--r-- | standalone/primary32.h | 8 | ||||
-rw-r--r-- | standalone/primary64.h | 8 | ||||
-rw-r--r-- | standalone/secondary.h | 14 |
4 files changed, 32 insertions, 13 deletions
diff --git a/standalone/common.h b/standalone/common.h index 3581c946d16..ae45683f1ee 100644 --- a/standalone/common.h +++ b/standalone/common.h @@ -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) { + *Integral = 100; + *Fractional = 0; + return; + } + + *Integral = Numerator * Digits / Denominator; + *Fractional = + (((Numerator * Digits) % Denominator) * Digits + Denominator / 2) / + Denominator; +} + // Platform specific functions. extern uptr PageSizeCached; diff --git a/standalone/primary32.h b/standalone/primary32.h index 8281e02ba16..4d03b282d00 100644 --- a/standalone/primary32.h +++ b/standalone/primary32.h @@ -931,10 +931,14 @@ private: AllocatedPagesCount - Recorder.getReleasedPagesCount(); const uptr InUseBytes = InUsePages * PageSize; + uptr Integral; + uptr Fractional; + computePercentage(BlockSize * InUseBlocks, InUsePages * PageSize, &Integral, + &Fractional); Str->append(" %02zu (%6zu): inuse/total blocks: %6zu/%6zu inuse/total " - "pages: %6zu/%6zu inuse bytes: %6zuK\n", + "pages: %6zu/%6zu inuse bytes: %6zuK util: %3zu.%02zu%%\n", ClassId, BlockSize, InUseBlocks, TotalBlocks, InUsePages, - AllocatedPagesCount, InUseBytes >> 10); + AllocatedPagesCount, InUseBytes >> 10, Integral, Fractional); } NOINLINE uptr releaseToOSMaybe(SizeClassInfo *Sci, uptr ClassId, diff --git a/standalone/primary64.h b/standalone/primary64.h index d1929ff7212..9a642d23620 100644 --- a/standalone/primary64.h +++ b/standalone/primary64.h @@ -1130,10 +1130,14 @@ private: AllocatedPagesCount - Recorder.getReleasedPagesCount(); const uptr InUseBytes = InUsePages * PageSize; + uptr Integral; + uptr Fractional; + computePercentage(BlockSize * InUseBlocks, InUsePages * PageSize, &Integral, + &Fractional); Str->append(" %02zu (%6zu): inuse/total blocks: %6zu/%6zu inuse/total " - "pages: %6zu/%6zu inuse bytes: %6zuK\n", + "pages: %6zu/%6zu inuse bytes: %6zuK util: %3zu.%02zu%%\n", ClassId, BlockSize, InUseBlocks, TotalBlocks, InUsePages, - AllocatedPagesCount, InUseBytes >> 10); + AllocatedPagesCount, InUseBytes >> 10, Integral, Fractional); } NOINLINE uptr releaseToOSMaybe(RegionInfo *Region, uptr ClassId, diff --git a/standalone/secondary.h b/standalone/secondary.h index 8dc4c87fa7c..f52a4188bcf 100644 --- a/standalone/secondary.h +++ b/standalone/secondary.h @@ -155,20 +155,16 @@ public: void getStats(ScopedString *Str) { ScopedLock L(Mutex); - u32 Integral = 0; - u32 Fractional = 0; - if (CallsToRetrieve != 0) { - Integral = SuccessfulRetrieves * 100 / CallsToRetrieve; - Fractional = (((SuccessfulRetrieves * 100) % CallsToRetrieve) * 100 + - CallsToRetrieve / 2) / - CallsToRetrieve; - } + uptr Integral; + uptr Fractional; + computePercentage(SuccessfulRetrieves, CallsToRetrieve, &Integral, + &Fractional); Str->append("Stats: MapAllocatorCache: EntriesCount: %d, " "MaxEntriesCount: %u, MaxEntrySize: %zu\n", EntriesCount, atomic_load_relaxed(&MaxEntriesCount), atomic_load_relaxed(&MaxEntrySize)); Str->append("Stats: CacheRetrievalStats: SuccessRate: %u/%u " - "(%u.%02u%%)\n", + "(%zu.%02zu%%)\n", SuccessfulRetrieves, CallsToRetrieve, Integral, Fractional); for (CachedBlock Entry : Entries) { if (!Entry.isValid()) |