added dump of icon cache

This commit is contained in:
csoler 2021-02-24 11:26:15 +01:00
parent 3356509044
commit 1a4585ccee
2 changed files with 57 additions and 15 deletions

View File

@ -405,6 +405,9 @@ const QPixmap GxsIdDetails::makeDefaultIcon(const RsGxsId& id, AvatarSize size)
// now look for the icon // now look for the icon
if(id.isNull())
std::cerr << "Weird: null ID" << std::endl;
QMutexLocker lock(&mIconCacheMutex); QMutexLocker lock(&mIconCacheMutex);
auto& it = mDefaultIconCache[id]; auto& it = mDefaultIconCache[id];
@ -432,6 +435,31 @@ const QPixmap GxsIdDetails::makeDefaultIcon(const RsGxsId& id, AvatarSize size)
return image; return image;
} }
void GxsIdDetails::debug_dumpImagesCache()
{
QMutexLocker lock(&mIconCacheMutex);
std::cerr << "Current icon cache:" << std::endl;
for(auto it:mDefaultIconCache)
{
std::cerr << " Identity " << it.first << ":" << std::endl;
for(uint32_t i=0;i<4;++i)
{
std::cerr << " Size #" << i << ": " ;
if(it.second[i].first>0)
{
int s = it.second[i].second.width()*it.second[i].second.height()*4;
std::cerr << " Present. Size=" << s << " bytes. Age: " << time(nullptr)-it.second[i].first << " secs. ago. Used: " << !it.second[i].second.isDetached() << std::endl;
}
else
std::cerr << " None." << std::endl;
}
}
}
void GxsIdDetails::checkCleanImagesCache() void GxsIdDetails::checkCleanImagesCache()
{ {
time_t now = time(NULL); time_t now = time(NULL);
@ -450,8 +478,11 @@ void GxsIdDetails::checkCleanImagesCache()
for(auto it(mDefaultIconCache.begin());it!=mDefaultIconCache.end();) for(auto it(mDefaultIconCache.begin());it!=mDefaultIconCache.end();)
{ {
bool all_empty = true ; bool all_empty = true ;
std::cerr << " Examining pixmaps sizes for " << it->first << "." << std::endl;
for(int i=0;i<4;++i) for(int i=0;i<4;++i)
if(it->second[i].first>0)
{
if(it->second[i].first + ICON_CACHE_STORAGE_TIME < now && it->second[i].second.isDetached()) if(it->second[i].first + ICON_CACHE_STORAGE_TIME < now && it->second[i].second.isDetached())
{ {
int s = it->second[i].second.width()*it->second[i].second.height()*4; int s = it->second[i].second.width()*it->second[i].second.height()*4;
@ -459,6 +490,7 @@ void GxsIdDetails::checkCleanImagesCache()
std::cerr << " Deleting pixmap " << it->first << " size " << i << " " << s << " bytes." << std::endl; std::cerr << " Deleting pixmap " << it->first << " size " << i << " " << s << " bytes." << std::endl;
it->second[i].second = QPixmap(); it->second[i].second = QPixmap();
it->second[i].first = 0;
++nb_deleted; ++nb_deleted;
size_deleted += s; size_deleted += s;
} }
@ -466,10 +498,15 @@ void GxsIdDetails::checkCleanImagesCache()
{ {
all_empty = false; all_empty = false;
total_size += it->second[i].second.width()*it->second[i].second.height()*4; total_size += it->second[i].second.width()*it->second[i].second.height()*4;
std::cerr << " Keeking " << it->first << " size " << i << std::endl;
}
} }
if(all_empty) if(all_empty)
{
std::cerr << " Deleting entry " << it->first << " because no pixmaps are stored here. " << std::endl;
it = mDefaultIconCache.erase(it); it = mDefaultIconCache.erase(it);
}
else else
++it; ++it;
} }
@ -490,10 +527,14 @@ bool GxsIdDetails::loadPixmapFromData(const unsigned char *data,size_t data_len,
Sha1CheckSum chksum = RsDirUtil::sha1sum(data,data_len); Sha1CheckSum chksum = RsDirUtil::sha1sum(data,data_len);
RsGxsId id(chksum.toByteArray()); RsGxsId id(chksum.toByteArray());
if(id.isNull())
std::cerr << "Weird: null ID" << std::endl;
// We use a cache for images. QImage has its own smart pointer system, but it does not prevent // We use a cache for images. QImage has its own smart pointer system, but it does not prevent
// the same image to be allocated many times. We do this using a cache. The cache is also cleaned-up // the same image to be allocated many times. We do this using a cache. The cache is also cleaned-up
// on a regular time basis so as to get rid of unused images. // on a regular time basis so as to get rid of unused images.
debug_dumpImagesCache();
checkCleanImagesCache(); checkCleanImagesCache();
// now look for the icon // now look for the icon

View File

@ -114,6 +114,7 @@ public:
static const QPixmap makeDefaultIcon(const RsGxsId& id, AvatarSize size = MEDIUM); static const QPixmap makeDefaultIcon(const RsGxsId& id, AvatarSize size = MEDIUM);
static bool loadPixmapFromData(const unsigned char *data, size_t data_len, QPixmap& pix, AvatarSize size = MEDIUM); static bool loadPixmapFromData(const unsigned char *data, size_t data_len, QPixmap& pix, AvatarSize size = MEDIUM);
static void checkCleanImagesCache(); static void checkCleanImagesCache();
static void debug_dumpImagesCache();
/* Processing */ /* Processing */
static void enableProcess(bool enable); static void enableProcess(bool enable);