[Lldb-commits] [lldb] [lldb] Reintroduce ConstString stats (PR #207694)

2026-07-06 Thread Raphael Isemann via lldb-commits

https://github.com/Teemperor closed 
https://github.com/llvm/llvm-project/pull/207694
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Reintroduce ConstString stats (PR #207694)

2026-07-06 Thread Raphael Isemann via lldb-commits

https://github.com/Teemperor auto_merge_enabled 
https://github.com/llvm/llvm-project/pull/207694
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Reintroduce ConstString stats (PR #207694)

2026-07-06 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan approved this pull request.

Seems equivalent

https://github.com/llvm/llvm-project/pull/207694
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Reintroduce ConstString stats (PR #207694)

2026-07-06 Thread via lldb-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-lldb

Author: Raphael Isemann (Teemperor)


Changes

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("bytesTotal", stats.GetBytesTotal());
+  obj.try_emplace("bytesUsed", stats.GetBytesUsed());
+  obj.try_emplace("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 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 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 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)
 

``




https://github.com/llvm/llvm-project/pull/207694
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Reintroduce ConstString stats (PR #207694)

2026-07-06 Thread Raphael Isemann via lldb-commits

https://github.com/Teemperor created 
https://github.com/llvm/llvm-project/pull/207694

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.

>From 96335eb8cd2ae15af980171b7d6e6082e747dcd4 Mon Sep 17 00:00:00 2001
From: Raphael Isemann 
Date: Mon, 6 Jul 2026 11:07:23 +0100
Subject: [PATCH] [lldb] Reintroduce ConstString stats

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.
---
 lldb/include/lldb/Utility/ConstString.h   |  3 +++
 lldb/source/Target/Statistics.cpp |  2 ++
 lldb/source/Utility/ConstString.cpp   | 15 +++
 .../API/commands/statistics/basic/TestStats.py|  2 ++
 4 files changed, 18 insertions(+), 4 deletions(-)

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("bytesTotal", stats.GetBytesTotal());
+  obj.try_emplace("bytesUsed", stats.GetBytesUsed());
+  obj.try_emplace("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 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 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 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)
 

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits