Even more memory tracking
This commit is contained in:
parent
442304bc1c
commit
2a878d51fd
|
@ -23,7 +23,7 @@ private:
|
||||||
AliasRegistry() {}
|
AliasRegistry() {}
|
||||||
|
|
||||||
safe_ptr<AliasRegistry> m_parent;
|
safe_ptr<AliasRegistry> m_parent;
|
||||||
UnorderedMap<String, String> m_aliases;
|
UnorderedMap<String, String, MemoryDomain::Aliases> m_aliases;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ private:
|
||||||
DisplayLine m_pending_status_line;
|
DisplayLine m_pending_status_line;
|
||||||
DisplayLine m_mode_line;
|
DisplayLine m_mode_line;
|
||||||
|
|
||||||
Vector<Key> m_pending_keys;
|
Vector<Key, MemoryDomain::Client> m_pending_keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ private:
|
||||||
String generate_name() const;
|
String generate_name() const;
|
||||||
|
|
||||||
Vector<std::unique_ptr<Client>> m_clients;
|
Vector<std::unique_ptr<Client>> m_clients;
|
||||||
Vector<WindowAndSelections> m_free_windows;
|
Vector<WindowAndSelections, MemoryDomain::Client> m_free_windows;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if defined(__GLIBC__)
|
#if defined(__GLIBC__) || defined(__CYGWIN__)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -838,7 +838,7 @@ const CommandDesc debug_cmd = {
|
||||||
write_debug(" "_sv + 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__) || defined(__CYGWIN__)
|
||||||
write_debug(" Malloced: " + to_string(mallinfo().uordblks));
|
write_debug(" Malloced: " + to_string(mallinfo().uordblks));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
class String;
|
class String;
|
||||||
using EnvVarMap = UnorderedMap<String, String>;
|
using EnvVarMap = UnorderedMap<String, String, MemoryDomain::EnvVars>;
|
||||||
|
|
||||||
EnvVarMap get_env_vars();
|
EnvVarMap get_env_vars();
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ private:
|
||||||
FaceOrAlias(Face face = Face{}) : face(face) {}
|
FaceOrAlias(Face face = Face{}) : face(face) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
UnorderedMap<String, FaceOrAlias> m_aliases;
|
UnorderedMap<String, FaceOrAlias, MemoryDomain::Faces> m_aliases;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Face get_face(const String& facedesc)
|
inline Face get_face(const String& facedesc)
|
||||||
|
|
|
@ -144,13 +144,16 @@ void register_env_vars()
|
||||||
|
|
||||||
void register_registers()
|
void register_registers()
|
||||||
{
|
{
|
||||||
using StringList = Vector<String>;
|
using StringList = Vector<String, MemoryDomain::Registers>;
|
||||||
static const struct {
|
static const struct {
|
||||||
char name;
|
char name;
|
||||||
StringList (*func)(const Context&);
|
StringList (*func)(const Context&);
|
||||||
} dyn_regs[] = {
|
} dyn_regs[] = {
|
||||||
{ '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } },
|
{ '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } },
|
||||||
{ '.', [](const Context& context) { return context.selections_content(); } },
|
{ '.', [](const Context& context) {
|
||||||
|
auto content = context.selections_content();
|
||||||
|
return StringList{content.begin(), content.end()};
|
||||||
|
} },
|
||||||
{ '#', [](const Context& context) {
|
{ '#', [](const Context& context) {
|
||||||
StringList res;
|
StringList res;
|
||||||
for (size_t i = 1; i < context.selections().size()+1; ++i)
|
for (size_t i = 1; i < context.selections().size()+1; ++i)
|
||||||
|
@ -167,7 +170,7 @@ void register_registers()
|
||||||
{
|
{
|
||||||
register_manager.register_dynamic_register('0'+i,
|
register_manager.register_dynamic_register('0'+i,
|
||||||
[i](const Context& context) {
|
[i](const Context& context) {
|
||||||
Vector<String> result;
|
StringList result;
|
||||||
for (auto& sel : context.selections())
|
for (auto& sel : context.selections())
|
||||||
result.emplace_back(i < sel.captures().size() ? sel.captures()[i] : "");
|
result.emplace_back(i < sel.captures().size() ? sel.captures()[i] : "");
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -23,6 +23,12 @@ enum class MemoryDomain
|
||||||
Mapping,
|
Mapping,
|
||||||
Commands,
|
Commands,
|
||||||
Hooks,
|
Hooks,
|
||||||
|
Aliases,
|
||||||
|
EnvVars,
|
||||||
|
Faces,
|
||||||
|
Values,
|
||||||
|
Registers,
|
||||||
|
Client,
|
||||||
WordDB,
|
WordDB,
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
@ -42,6 +48,12 @@ inline const char* domain_name(MemoryDomain domain)
|
||||||
case MemoryDomain::Commands: return "Commands";
|
case MemoryDomain::Commands: return "Commands";
|
||||||
case MemoryDomain::Hooks: return "Hooks";
|
case MemoryDomain::Hooks: return "Hooks";
|
||||||
case MemoryDomain::WordDB: return "WordDB";
|
case MemoryDomain::WordDB: return "WordDB";
|
||||||
|
case MemoryDomain::Aliases: return "Aliases";
|
||||||
|
case MemoryDomain::EnvVars: return "EnvVars";
|
||||||
|
case MemoryDomain::Faces: return "Faces";
|
||||||
|
case MemoryDomain::Values: return "Values";
|
||||||
|
case MemoryDomain::Registers: return "Registers";
|
||||||
|
case MemoryDomain::Client: return "Client";
|
||||||
case MemoryDomain::Count: break;
|
case MemoryDomain::Count: break;
|
||||||
}
|
}
|
||||||
kak_assert(false);
|
kak_assert(false);
|
||||||
|
|
|
@ -67,8 +67,8 @@ bool option_add(Vector<T, domain>& opt, const Vector<T, domain>& vec)
|
||||||
return not vec.empty();
|
return not vec.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key, typename Value>
|
template<typename Key, typename Value, MemoryDomain domain>
|
||||||
String option_to_string(const UnorderedMap<Key, Value>& opt)
|
String option_to_string(const UnorderedMap<Key, Value, domain>& opt)
|
||||||
{
|
{
|
||||||
String res;
|
String res;
|
||||||
for (auto it = begin(opt); it != end(opt); ++it)
|
for (auto it = begin(opt); it != end(opt); ++it)
|
||||||
|
@ -82,8 +82,8 @@ String option_to_string(const UnorderedMap<Key, Value>& opt)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key, typename Value>
|
template<typename Key, typename Value, MemoryDomain domain>
|
||||||
void option_from_string(StringView str, UnorderedMap<Key, Value>& opt)
|
void option_from_string(StringView str, UnorderedMap<Key, Value, domain>& opt)
|
||||||
{
|
{
|
||||||
opt.clear();
|
opt.clear();
|
||||||
for (auto& elem : split(str, list_separator, '\\'))
|
for (auto& elem : split(str, list_separator, '\\'))
|
||||||
|
|
|
@ -14,7 +14,7 @@ class StaticRegister : public Register
|
||||||
public:
|
public:
|
||||||
Register& operator=(ArrayView<String> values) override
|
Register& operator=(ArrayView<String> values) override
|
||||||
{
|
{
|
||||||
m_content = Vector<String>(values.begin(), values.end());
|
m_content = Vector<String, MemoryDomain::Registers>(values.begin(), values.end());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public:
|
||||||
return ArrayView<String>(m_content);
|
return ArrayView<String>(m_content);
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
Vector<String> m_content;
|
Vector<String, MemoryDomain::Registers> m_content;
|
||||||
|
|
||||||
static const String ms_empty;
|
static const String ms_empty;
|
||||||
};
|
};
|
||||||
|
@ -53,7 +53,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RegisterRetriever m_function;
|
RegisterRetriever m_function;
|
||||||
};
|
};
|
||||||
|
|
||||||
Register& RegisterManager::operator[](StringView reg)
|
Register& RegisterManager::operator[](StringView reg)
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
using RegisterRetriever = std::function<Vector<String> (const Context&)>;
|
using RegisterRetriever = std::function<Vector<String, MemoryDomain::Registers> (const Context&)>;
|
||||||
|
|
||||||
class RegisterManager : public Singleton<RegisterManager>
|
class RegisterManager : public Singleton<RegisterManager>
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ public:
|
||||||
void register_dynamic_register(char reg, RegisterRetriever function);
|
void register_dynamic_register(char reg, RegisterRetriever function);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UnorderedMap<char, std::unique_ptr<Register>> m_registers;
|
UnorderedMap<char, std::unique_ptr<Register>, MemoryDomain::Registers> m_registers;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,14 +75,14 @@ public:
|
||||||
write(val);
|
write(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T, MemoryDomain domain>
|
||||||
void write(const Vector<T>& vec)
|
void write(const Vector<T, domain>& vec)
|
||||||
{
|
{
|
||||||
write(ArrayView<T>(vec));
|
write(ArrayView<T>(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key, typename Val>
|
template<typename Key, typename Val, MemoryDomain domain>
|
||||||
void write(const UnorderedMap<Key, Val>& map)
|
void write(const UnorderedMap<Key, Val, domain>& map)
|
||||||
{
|
{
|
||||||
write<uint32_t>(map.size());
|
write<uint32_t>(map.size());
|
||||||
for (auto& val : map)
|
for (auto& val : map)
|
||||||
|
@ -229,11 +229,11 @@ DisplayBuffer read<DisplayBuffer>(int socket)
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key, typename Val>
|
template<typename Key, typename Val, MemoryDomain domain>
|
||||||
UnorderedMap<Key, Val> read_map(int socket)
|
UnorderedMap<Key, Val, domain> read_map(int socket)
|
||||||
{
|
{
|
||||||
uint32_t size = read<uint32_t>(socket);
|
uint32_t size = read<uint32_t>(socket);
|
||||||
UnorderedMap<Key, Val> res;
|
UnorderedMap<Key, Val, domain> res;
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
auto key = read<Key>(socket);
|
auto key = read<Key>(socket);
|
||||||
|
@ -519,7 +519,7 @@ void RemoteClient::process_next_message()
|
||||||
m_ui->refresh();
|
m_ui->refresh();
|
||||||
break;
|
break;
|
||||||
case RemoteUIMsg::SetOptions:
|
case RemoteUIMsg::SetOptions:
|
||||||
m_ui->set_ui_options(read_map<String, String>(socket));
|
m_ui->set_ui_options(read_map<String, String, MemoryDomain::Options>(socket));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -595,7 +595,7 @@ private:
|
||||||
}
|
}
|
||||||
if (c == 0) // end of initial command stream, go to interactive ui
|
if (c == 0) // end of initial command stream, go to interactive ui
|
||||||
{
|
{
|
||||||
EnvVarMap env_vars = read_map<String, String>(socket);
|
EnvVarMap env_vars = read_map<String, String, MemoryDomain::EnvVars>(socket);
|
||||||
std::unique_ptr<UserInterface> ui{new RemoteUI{socket}};
|
std::unique_ptr<UserInterface> ui{new RemoteUI{socket}};
|
||||||
ClientManager::instance().create_client(std::move(ui),
|
ClientManager::instance().create_client(std::move(ui),
|
||||||
std::move(env_vars),
|
std::move(env_vars),
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
|
|
||||||
virtual void set_input_callback(InputCallback callback) = 0;
|
virtual void set_input_callback(InputCallback callback) = 0;
|
||||||
|
|
||||||
using Options = UnorderedMap<String, String>;
|
using Options = UnorderedMap<String, String, MemoryDomain::Options>;
|
||||||
virtual void set_ui_options(const Options& options) = 0;
|
virtual void set_ui_options(const Options& options) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,10 @@ private:
|
||||||
const std::type_info& type() const override { return typeid(T); }
|
const std::type_info& type() const override { return typeid(T); }
|
||||||
|
|
||||||
T m_content;
|
T m_content;
|
||||||
|
|
||||||
|
using Alloc = Allocator<Model<T>, MemoryDomain::Values>;
|
||||||
|
static void* operator new (std::size_t sz) { return Alloc{}.allocate(1); }
|
||||||
|
static void operator delete (void* ptr) { Alloc{}.deallocate((Model<T>*)ptr, 1); }
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Concept> m_value;
|
std::unique_ptr<Concept> m_value;
|
||||||
|
@ -78,7 +82,7 @@ struct ValueId : public StronglyTypedNumber<ValueId, int>
|
||||||
|
|
||||||
inline size_t hash_value(ValueId val) { return hash_value((int)val); }
|
inline size_t hash_value(ValueId val) { return hash_value((int)val); }
|
||||||
|
|
||||||
using ValueMap = UnorderedMap<ValueId, Value>;
|
using ValueMap = UnorderedMap<ValueId, Value, MemoryDomain::Values>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user