Add interned string stats in debug command

This commit is contained in:
Maxime Coste 2015-01-13 13:48:16 +00:00
parent b9c4fc2d8c
commit beb3390334
3 changed files with 30 additions and 4 deletions

View File

@ -805,7 +805,7 @@ const CommandDesc debug_cmd = {
PerArgumentCommandCompleter({ PerArgumentCommandCompleter({
[](const Context& context, CompletionFlags flags, [](const Context& context, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos) -> Completions { 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) }; return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
} }), } }),
[](const ParametersParser& parser, Context& context) [](const ParametersParser& parser, Context& context)
@ -835,13 +835,17 @@ const CommandDesc debug_cmd = {
{ {
size_t count = domain_allocated_bytes[domain]; size_t count = domain_allocated_bytes[domain];
total += count; 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__) #if defined(__GLIBC__)
write_debug("Malloced: " + to_string(mallinfo().uordblks)); write_debug(" Malloced: " + to_string(mallinfo().uordblks));
#endif #endif
} }
else if (parser[0] == "interned-strings")
{
StringRegistry::instance().debug_stats();
}
else else
throw runtime_error("unknown debug command '" + parser[0] + "'"); throw runtime_error("unknown debug command '" + parser[0] + "'");
} }

View File

@ -1,8 +1,28 @@
#include "interned_string.hh" #include "interned_string.hh"
#include "debug.hh"
namespace Kakoune 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) InternedString StringRegistry::acquire(StringView str)
{ {
auto it = m_slot_map.find(str); auto it = m_slot_map.find(str);

View File

@ -13,6 +13,8 @@ class InternedString;
class StringRegistry : public Singleton<StringRegistry> class StringRegistry : public Singleton<StringRegistry>
{ {
public:
void debug_stats() const;
private: private:
friend class InternedString; friend class InternedString;