[Lldb-commits] [lldb] [lldb] Reintroduce ConstString stats (PR #207694)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Jul 6 03:24:44 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Raphael Isemann (Teemperor)
<details>
<summary>Changes</summary>
These stats were removed in ca59c69132eef55cc42bf8854706590dfddf5584 . This patch restores the stats in their original form by tracking the removed value in our own LLDB-specific counter.
---
Full diff: https://github.com/llvm/llvm-project/pull/207694.diff
4 Files Affected:
- (modified) lldb/include/lldb/Utility/ConstString.h (+3)
- (modified) lldb/source/Target/Statistics.cpp (+2)
- (modified) lldb/source/Utility/ConstString.cpp (+11-4)
- (modified) lldb/test/API/commands/statistics/basic/TestStats.py (+2)
``````````diff
diff --git a/lldb/include/lldb/Utility/ConstString.h b/lldb/include/lldb/Utility/ConstString.h
index 4452df1ecc6b1..1bfefec9638a5 100644
--- a/lldb/include/lldb/Utility/ConstString.h
+++ b/lldb/include/lldb/Utility/ConstString.h
@@ -393,7 +393,10 @@ class ConstString {
struct MemoryStats {
size_t GetBytesTotal() const { return bytes_total; }
+ size_t GetBytesUsed() const { return bytes_used; }
+ size_t GetBytesUnused() const { return bytes_total - bytes_used; }
size_t bytes_total = 0;
+ size_t bytes_used = 0;
};
static MemoryStats GetMemoryStats();
diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index 6227d099642f2..9fee5108e736a 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -111,6 +111,8 @@ json::Value ModuleStats::ToJSON() const {
llvm::json::Value ConstStringStats::ToJSON() const {
json::Object obj;
obj.try_emplace<int64_t>("bytesTotal", stats.GetBytesTotal());
+ obj.try_emplace<int64_t>("bytesUsed", stats.GetBytesUsed());
+ obj.try_emplace<int64_t>("bytesUnused", stats.GetBytesUnused());
return obj;
}
diff --git a/lldb/source/Utility/ConstString.cpp b/lldb/source/Utility/ConstString.cpp
index 8def38c03dceb..8e97b7bb382a2 100644
--- a/lldb/source/Utility/ConstString.cpp
+++ b/lldb/source/Utility/ConstString.cpp
@@ -139,6 +139,7 @@ class Pool {
}
std::lock_guard<PoolMutex> lock(pool.m_mutex);
+ pool.used_bytes += string_ref.size();
StringPoolEntryType &entry =
*pool.m_string_map
.insert(std::make_pair(string_ref, nullptr), string_hash)
@@ -160,13 +161,15 @@ class Pool {
// Make or update string pool entry with the mangled counterpart
StringPool &map = pool.m_string_map;
- StringPoolEntryType &entry =
- *map.try_emplace_with_hash(demangled, demangled_hash).first;
+ auto [entry, inserted] =
+ map.try_emplace_with_hash(demangled, demangled_hash);
+ if (inserted)
+ pool.used_bytes += demangled.size();
- entry.second = mangled_ccstr;
+ entry->second = mangled_ccstr;
// Extract the const version of the demangled_cstr
- demangled_ccstr = entry.getKeyData();
+ demangled_ccstr = entry->getKeyData();
}
{
@@ -196,6 +199,7 @@ class Pool {
std::shared_lock<PoolMutex> lock(pool.m_mutex);
const Allocator &alloc = pool.m_string_map.getAllocator();
stats.bytes_total += alloc.getTotalMemory();
+ stats.bytes_used += pool.used_bytes;
}
return stats;
}
@@ -204,6 +208,9 @@ class Pool {
struct PoolEntry {
mutable PoolMutex m_mutex;
StringPool m_string_map;
+ /// The exact number of bytes used by this pool.
+ /// This excludes alignment, padding and redzones.
+ std::size_t used_bytes = 0;
};
std::array<PoolEntry, 256> m_string_pools;
diff --git a/lldb/test/API/commands/statistics/basic/TestStats.py b/lldb/test/API/commands/statistics/basic/TestStats.py
index c65d1d8785160..a32b8feecc5cf 100644
--- a/lldb/test/API/commands/statistics/basic/TestStats.py
+++ b/lldb/test/API/commands/statistics/basic/TestStats.py
@@ -348,6 +348,8 @@ def test_memory(self):
strings = memory["strings"]
strings_keys = [
"bytesTotal",
+ "bytesUsed",
+ "bytesUnused",
]
self.verify_keys(strings, '"strings"', strings_keys, None)
``````````
</details>
https://github.com/llvm/llvm-project/pull/207694
More information about the lldb-commits
mailing list