From ed41c67908b8d6289f0e5eb49f101c851d9adc75 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 17 May 2011 03:56:13 +0300 Subject: Debug option to dump loaded images names. --- src/commandhandler.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'src/commandhandler.cpp') 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(iter->second)) + type = "S"; + else if (dynamic_cast(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 -- cgit v1.2.3-60-g2f50