summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <maxime.coste@havok.com>2015-01-13 13:48:16 +0000
committerMaxime Coste <maxime.coste@havok.com>2015-01-13 13:48:16 +0000
commitbeb3390334fc4e7071645c89018e45eaa81f47ba (patch)
tree485ae729cd6a15f887a76880f09ee36c2cab589e /src
parentb9c4fc2d8c455991d1ffda250df5acacf5949a82 (diff)
Add interned string stats in debug command
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc12
-rw-r--r--src/interned_string.cc20
-rw-r--r--src/interned_string.hh2
3 files changed, 30 insertions, 4 deletions
diff --git a/src/commands.cc b/src/commands.cc
index 9e88d76d..e9fc5fa2 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -805,7 +805,7 @@ const CommandDesc debug_cmd = {
PerArgumentCommandCompleter({
[](const Context& context, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos) -> Completions {
- auto c = {"info", "buffers", "options", "memory"};
+ auto c = {"info", "buffers", "options", "memory", "interned-strings"};
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
} }),
[](const ParametersParser& parser, Context& context)
@@ -835,13 +835,17 @@ const CommandDesc debug_cmd = {
{
size_t count = domain_allocated_bytes[domain];
total += count;
- write_debug(domain_name((MemoryDomain)domain) + (": " + to_string(count)));
+ write_debug(" "_sv + domain_name((MemoryDomain)domain) + ": " + to_string(count));
}
- write_debug("Total: " + to_string(total));
+ write_debug(" Total: " + to_string(total));
#if defined(__GLIBC__)
- write_debug("Malloced: " + to_string(mallinfo().uordblks));
+ write_debug(" Malloced: " + to_string(mallinfo().uordblks));
#endif
}
+ else if (parser[0] == "interned-strings")
+ {
+ StringRegistry::instance().debug_stats();
+ }
else
throw runtime_error("unknown debug command '" + parser[0] + "'");
}
diff --git a/src/interned_string.cc b/src/interned_string.cc
index 3646e2f8..fb6898c0 100644
--- a/src/interned_string.cc
+++ b/src/interned_string.cc
@@ -1,8 +1,28 @@
#include "interned_string.hh"
+#include "debug.hh"
namespace Kakoune
{
+void StringRegistry::debug_stats() const
+{
+ write_debug("Interned Strings stats:");
+ write_debug(" slots: " + to_string(m_storage.size()) + " allocated, " + to_string(m_free_slots.size()) + " free");
+ size_t total_refcount = 0;
+ size_t total_size = 0;
+ size_t count = 0;
+ for (auto& st : m_storage)
+ {
+ if (st.refcount == 0)
+ continue;
+ total_refcount += st.refcount;
+ total_size += st.data.size();
+ ++count;
+ }
+ write_debug(" data size: " + to_string(total_size) + ", mean: " + to_string((float)total_size/count));
+ write_debug(" refcounts: " + to_string(total_refcount) + ", mean: " + to_string((float)total_refcount/count));
+}
+
InternedString StringRegistry::acquire(StringView str)
{
auto it = m_slot_map.find(str);
diff --git a/src/interned_string.hh b/src/interned_string.hh
index 8357ba85..66c7bd58 100644
--- a/src/interned_string.hh
+++ b/src/interned_string.hh
@@ -13,6 +13,8 @@ class InternedString;
class StringRegistry : public Singleton<StringRegistry>
{
+public:
+ void debug_stats() const;
private:
friend class InternedString;