diff options
author | Chia-hung Duan <chiahungduan@google.com> | 2023-04-20 04:28:42 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-04-20 04:28:42 +0000 |
commit | 8f637a54c5929491950b7aaf43d6d3c58ff5ca37 (patch) | |
tree | 39463b230996af2ad2e2d8ce744bf0f630cb3fc0 | |
parent | f312eb75e88182622abf4d304fc5444a72080897 (diff) | |
parent | 2d01d63d93114406002bc2eab155e2affd5cc48f (diff) | |
download | scudo-8f637a54c5929491950b7aaf43d6d3c58ff5ca37.tar.gz |
[scudo] Support printing the status of cached blocks am: a9f90d3123 am: 66f182ffe4 am: 2d01d63d93
Original change: https://android-review.googlesource.com/c/platform/external/scudo/+/2549531
Change-Id: Ib573aaa2ed49e8ea52a8331da82229179b365873
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | standalone/combined.h | 1 | ||||
-rw-r--r-- | standalone/local_cache.h | 24 | ||||
-rw-r--r-- | standalone/tests/combined_test.cpp | 2 | ||||
-rw-r--r-- | standalone/tsd_exclusive.h | 9 | ||||
-rw-r--r-- | standalone/tsd_shared.h | 15 |
5 files changed, 51 insertions, 0 deletions
diff --git a/standalone/combined.h b/standalone/combined.h index 250eba0f4dd..d5365b689aa 100644 --- a/standalone/combined.h +++ b/standalone/combined.h @@ -1483,6 +1483,7 @@ private: Primary.getStats(Str); Secondary.getStats(Str); Quarantine.getStats(Str); + TSDRegistry.getStats(Str); return Str->length(); } diff --git a/standalone/local_cache.h b/standalone/local_cache.h index 92869ea36f8..c97095d6be9 100644 --- a/standalone/local_cache.h +++ b/standalone/local_cache.h @@ -14,6 +14,7 @@ #include "platform.h" #include "report.h" #include "stats.h" +#include "string_utils.h" namespace scudo { @@ -164,6 +165,29 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache { LocalStats &getStats() { return Stats; } + void getStats(ScopedString *Str) { + bool EmptyCache = true; + for (uptr I = 0; I < NumClasses; ++I) { + if (PerClassArray[I].Count == 0) + continue; + + EmptyCache = false; + // The size of BatchClass is set to 0 intentionally. See the comment in + // initCache() for more details. + const uptr ClassSize = I == BatchClassId + ? SizeClassAllocator::getSizeByClassId(I) + : PerClassArray[I].ClassSize; + // Note that the string utils don't support printing u16 thus we cast it + // to a common use type uptr. + Str->append(" %02zu (%6zu): cached: %4zu max: %4zu\n", I, ClassSize, + static_cast<uptr>(PerClassArray[I].Count), + static_cast<uptr>(PerClassArray[I].MaxCount)); + } + + if (EmptyCache) + Str->append(" No block is cached.\n"); + } + private: static const uptr NumClasses = SizeClassMap::NumClasses; static const uptr BatchClassId = SizeClassMap::BatchClassId; diff --git a/standalone/tests/combined_test.cpp b/standalone/tests/combined_test.cpp index 7bf580e3770..33a309e42d6 100644 --- a/standalone/tests/combined_test.cpp +++ b/standalone/tests/combined_test.cpp @@ -167,6 +167,8 @@ void ScudoCombinedTest<Config>::BasicTest(scudo::uptr SizeLog) { Allocator->deallocate(P, Origin, Size); } } + + Allocator->printStats(); } #define SCUDO_MAKE_BASIC_TEST(SizeLog) \ diff --git a/standalone/tsd_exclusive.h b/standalone/tsd_exclusive.h index 62da8aeb537..aca9fc9b4e8 100644 --- a/standalone/tsd_exclusive.h +++ b/standalone/tsd_exclusive.h @@ -11,6 +11,8 @@ #include "tsd.h" +#include "string_utils.h" + namespace scudo { struct ThreadState { @@ -104,6 +106,13 @@ template <class Allocator> struct TSDRegistryExT { bool getDisableMemInit() { return State.DisableMemInit; } + void getStats(ScopedString *Str) { + // We don't have a way to iterate all thread local `ThreadTSD`s. Instead of + // printing only self `ThreadTSD` which may mislead the usage, we just skip + // it. + Str->append("Exclusive TSD don't support iterating each TSD\n"); + } + private: // Using minimal initialization allows for global initialization while keeping // the thread specific structure untouched. The fallback structure will be diff --git a/standalone/tsd_shared.h b/standalone/tsd_shared.h index 64b3bd844b0..e193281fc73 100644 --- a/standalone/tsd_shared.h +++ b/standalone/tsd_shared.h @@ -11,6 +11,8 @@ #include "tsd.h" +#include "string_utils.h" + #if SCUDO_HAS_PLATFORM_TLS_SLOT // This is a platform-provided header that needs to be on the include path when // Scudo is compiled. It must declare a function with the prototype: @@ -102,6 +104,19 @@ struct TSDRegistrySharedT { bool getDisableMemInit() const { return *getTlsPtr() & 1; } + void getStats(ScopedString *Str) EXCLUDES(MutexTSDs) { + ScopedLock L(MutexTSDs); + + Str->append("Stats: SharedTSDs: %u available; total %u\n", NumberOfTSDs, + TSDsArraySize); + for (uptr I = 0; I < NumberOfTSDs; ++I) { + TSDs[I].lock(); + Str->append(" Shared TSD[%zu]:\n", I); + TSDs[I].getCache().getStats(Str); + TSDs[I].unlock(); + } + } + private: ALWAYS_INLINE uptr *getTlsPtr() const { #if SCUDO_HAS_PLATFORM_TLS_SLOT |