add a 'buffers' debug command to get info on alive buffers

This commit is contained in:
Maxime Coste 2014-09-22 19:19:34 +01:00
parent 1296b5d46a
commit e440adbcf4
3 changed files with 38 additions and 1 deletions

View File

@ -519,4 +519,33 @@ ByteCoord Buffer::last_modification_coord() const
return m_history.back().back().coord;
}
String Buffer::debug_description() const
{
String res = display_name() + "\n";
res += " Flags: ";
if (m_flags & Flags::File)
res += "File (" + name() + ") ";
if (m_flags & Flags::New)
res += "New ";
if (m_flags & Flags::Fifo)
res += "Fifo ";
if (m_flags & Flags::NoUndo)
res += "NoUndo ";
res += "\n";
size_t content_size = 0;
for (auto& line : m_lines)
content_size += (int)line.length();
size_t additional_size = 0;
for (auto& undo_group : m_history)
additional_size += undo_group.size() * sizeof(Modification);
additional_size += m_changes.size() * sizeof(Change);
res += " Used mem: content=" + to_string(content_size) +
" additional=" + to_string(additional_size) + "\n";
return res;
}
}

View File

@ -172,6 +172,8 @@ public:
bool at_end;
};
memoryview<Change> changes_since(size_t timestamp) const;
String debug_description() const;
private:
void on_option_changed(const Option& option) override;

View File

@ -754,7 +754,7 @@ const CommandDesc debug_cmd = {
"debug",
nullptr,
"debug <command>: write some debug informations in the debug buffer\n"
" existing commands: info",
" existing commands: info, buffers",
ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::SwitchesOnlyAtStart, 1 },
CommandFlags::None,
CommandCompleter{},
@ -765,6 +765,12 @@ const CommandDesc debug_cmd = {
write_debug("pid: " + to_string(getpid()));
write_debug("session: " + Server::instance().session());
}
if (parser[0] == "buffers")
{
write_debug("Buffers:");
for (auto& buffer : BufferManager::instance())
write_debug(buffer->debug_description());
}
else
throw runtime_error("unknown debug command '" + parser[0] + "'");
}