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 { +public: + void debug_stats() const; private: friend class InternedString;