Even more memory tracking

This commit is contained in:
Maxime Coste 2015-01-14 19:16:32 +00:00
parent 442304bc1c
commit 2a878d51fd
14 changed files with 49 additions and 30 deletions

View File

@ -23,7 +23,7 @@ private:
AliasRegistry() {}
safe_ptr<AliasRegistry> m_parent;
UnorderedMap<String, String> m_aliases;
UnorderedMap<String, String, MemoryDomain::Aliases> m_aliases;
};
}

View File

@ -70,7 +70,7 @@ private:
DisplayLine m_pending_status_line;
DisplayLine m_mode_line;
Vector<Key> m_pending_keys;
Vector<Key, MemoryDomain::Client> m_pending_keys;
};
}

View File

@ -49,7 +49,7 @@ private:
String generate_name() const;
Vector<std::unique_ptr<Client>> m_clients;
Vector<WindowAndSelections> m_free_windows;
Vector<WindowAndSelections, MemoryDomain::Client> m_free_windows;
};
}

View File

@ -30,7 +30,7 @@
#include <fcntl.h>
#include <unistd.h>
#if defined(__GLIBC__)
#if defined(__GLIBC__) || defined(__CYGWIN__)
#include <malloc.h>
#endif
@ -838,7 +838,7 @@ const CommandDesc debug_cmd = {
write_debug(" "_sv + domain_name((MemoryDomain)domain) + ": " + to_string(count));
}
write_debug(" Total: " + to_string(total));
#if defined(__GLIBC__)
#if defined(__GLIBC__) || defined(__CYGWIN__)
write_debug(" Malloced: " + to_string(mallinfo().uordblks));
#endif
}

View File

@ -7,7 +7,7 @@ namespace Kakoune
{
class String;
using EnvVarMap = UnorderedMap<String, String>;
using EnvVarMap = UnorderedMap<String, String, MemoryDomain::EnvVars>;
EnvVarMap get_env_vars();

View File

@ -29,7 +29,7 @@ private:
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)

View File

@ -144,13 +144,16 @@ void register_env_vars()
void register_registers()
{
using StringList = Vector<String>;
using StringList = Vector<String, MemoryDomain::Registers>;
static const struct {
char name;
StringList (*func)(const Context&);
} dyn_regs[] = {
{ '%', [](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) {
StringList res;
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,
[i](const Context& context) {
Vector<String> result;
StringList result;
for (auto& sel : context.selections())
result.emplace_back(i < sel.captures().size() ? sel.captures()[i] : "");
return result;

View File

@ -23,6 +23,12 @@ enum class MemoryDomain
Mapping,
Commands,
Hooks,
Aliases,
EnvVars,
Faces,
Values,
Registers,
Client,
WordDB,
Count
};
@ -42,6 +48,12 @@ inline const char* domain_name(MemoryDomain domain)
case MemoryDomain::Commands: return "Commands";
case MemoryDomain::Hooks: return "Hooks";
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;
}
kak_assert(false);

View File

@ -67,8 +67,8 @@ bool option_add(Vector<T, domain>& opt, const Vector<T, domain>& vec)
return not vec.empty();
}
template<typename Key, typename Value>
String option_to_string(const UnorderedMap<Key, Value>& opt)
template<typename Key, typename Value, MemoryDomain domain>
String option_to_string(const UnorderedMap<Key, Value, domain>& opt)
{
String res;
for (auto it = begin(opt); it != end(opt); ++it)
@ -82,8 +82,8 @@ String option_to_string(const UnorderedMap<Key, Value>& opt)
return res;
}
template<typename Key, typename Value>
void option_from_string(StringView str, UnorderedMap<Key, Value>& opt)
template<typename Key, typename Value, MemoryDomain domain>
void option_from_string(StringView str, UnorderedMap<Key, Value, domain>& opt)
{
opt.clear();
for (auto& elem : split(str, list_separator, '\\'))

View File

@ -14,7 +14,7 @@ class StaticRegister : public Register
public:
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;
}
@ -26,7 +26,7 @@ public:
return ArrayView<String>(m_content);
}
protected:
Vector<String> m_content;
Vector<String, MemoryDomain::Registers> m_content;
static const String ms_empty;
};

View File

@ -11,7 +11,7 @@
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>
{
@ -21,7 +21,7 @@ public:
void register_dynamic_register(char reg, RegisterRetriever function);
protected:
UnorderedMap<char, std::unique_ptr<Register>> m_registers;
UnorderedMap<char, std::unique_ptr<Register>, MemoryDomain::Registers> m_registers;
};
}

View File

@ -75,14 +75,14 @@ public:
write(val);
}
template<typename T>
void write(const Vector<T>& vec)
template<typename T, MemoryDomain domain>
void write(const Vector<T, domain>& vec)
{
write(ArrayView<T>(vec));
}
template<typename Key, typename Val>
void write(const UnorderedMap<Key, Val>& map)
template<typename Key, typename Val, MemoryDomain domain>
void write(const UnorderedMap<Key, Val, domain>& map)
{
write<uint32_t>(map.size());
for (auto& val : map)
@ -229,11 +229,11 @@ DisplayBuffer read<DisplayBuffer>(int socket)
return db;
}
template<typename Key, typename Val>
UnorderedMap<Key, Val> read_map(int socket)
template<typename Key, typename Val, MemoryDomain domain>
UnorderedMap<Key, Val, domain> read_map(int socket)
{
uint32_t size = read<uint32_t>(socket);
UnorderedMap<Key, Val> res;
UnorderedMap<Key, Val, domain> res;
while (size--)
{
auto key = read<Key>(socket);
@ -519,7 +519,7 @@ void RemoteClient::process_next_message()
m_ui->refresh();
break;
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;
}
}
@ -595,7 +595,7 @@ private:
}
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}};
ClientManager::instance().create_client(std::move(ui),
std::move(env_vars),

View File

@ -63,7 +63,7 @@ public:
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;
};

View File

@ -60,6 +60,10 @@ private:
const std::type_info& type() const override { return typeid(T); }
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;
@ -78,7 +82,7 @@ struct ValueId : public StronglyTypedNumber<ValueId, int>
inline size_t hash_value(ValueId val) { return hash_value((int)val); }
using ValueMap = UnorderedMap<ValueId, Value>;
using ValueMap = UnorderedMap<ValueId, Value, MemoryDomain::Values>;
}