summaryrefslogtreecommitdiff
path: root/src/commandhandler.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-17 03:56:13 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-17 03:56:39 +0300
commited41c67908b8d6289f0e5eb49f101c851d9adc75 (patch)
tree527d3352b2b4d6aca56d89dac5913de36aba6c4b /src/commandhandler.cpp
parente9a8a46fc92669236e37dd096f5a849aed74ca6a (diff)
downloadmanaplus-ed41c67908b8d6289f0e5eb49f101c851d9adc75.tar.gz
manaplus-ed41c67908b8d6289f0e5eb49f101c851d9adc75.tar.bz2
manaplus-ed41c67908b8d6289f0e5eb49f101c851d9adc75.tar.xz
manaplus-ed41c67908b8d6289f0e5eb49f101c851d9adc75.zip
Debug option to dump loaded images names.
Diffstat (limited to 'src/commandhandler.cpp')
-rw-r--r--src/commandhandler.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 9371fd493..14a1a3044 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -52,6 +52,12 @@
#include "net/partyhandler.h"
#include "net/tradehandler.h"
+#ifdef DEBUG_DUMP_LEAKS
+#include "resources/image.h"
+#include "resources/resource.h"
+#include "resources/resourcemanager.h"
+#endif
+
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -276,6 +282,10 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
{
handleAddIgnoreAttack(args, tab);
}
+ else if (type == "dump")
+ {
+ handleDump(args, tab);
+ }
else if (tab->handleCommand(type, args))
{
// Nothing to do
@@ -1088,3 +1098,66 @@ void CommandHandler::handleCacheInfo(const std::string &args _UNUSED_,
_("Deleted:"), font->getDeleteCounter()));
#endif
}
+
+#ifdef DEBUG_DUMP_LEAKS
+void showRes(std::string str, ResourceManager::Resources *res);
+
+void showRes(std::string str, ResourceManager::Resources *res)
+{
+ if (debugChatTab)
+ debugChatTab->chatLog(str + toString(res->size()));
+ logger->log(str + toString(res->size()));
+ ResourceManager::ResourceIterator iter = res->begin();
+ while (iter != res->end())
+ {
+ if (iter->second && iter->second->getRefCount())
+ {
+ std::string type = " ";
+ std::string isNew = "N";
+ if (iter->second->getDumped())
+ isNew = "O";
+ else
+ iter->second->setDumped(true);
+
+ if (dynamic_cast<SubImage*>(iter->second))
+ type = "S";
+ else if (dynamic_cast<Image*>(iter->second))
+ type = "I";
+ logger->log("Resource %s%s: %s (%d)", type.c_str(),
+ isNew.c_str(), iter->second->getIdPath().c_str(),
+ iter->second->getRefCount());
+ }
+ ++ iter;
+ }
+}
+
+void CommandHandler::handleDump(const std::string &args,
+ ChatTab *tab _UNUSED_)
+{
+ if (!debugChatTab)
+ return;
+
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ if (!args.empty())
+ {
+ ResourceManager::Resources *res = resman->getResources();
+ showRes(_("Resource images:"), res);
+ res = resman->getOrphanedResources();
+ showRes(_("Resource orphaned images:"), res);
+ }
+ else
+ {
+ ResourceManager::Resources *res = resman->getResources();
+ debugChatTab->chatLog(_("Resource images:") + toString(res->size()));
+ res = resman->getOrphanedResources();
+ debugChatTab->chatLog(_("Resource orphaned images:")
+ + toString(res->size()));
+ }
+}
+#else
+void CommandHandler::handleDump(const std::string &args _UNUSED_,
+ ChatTab *tab _UNUSED_)
+{
+}
+#endif