[Libreoffice-commits] online.git: kit/Kit.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Nov 28 04:58:05 UTC 2016
kit/Kit.cpp | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
New commits:
commit 9608935a7c2b64cc5294f491c007d9013d85d12a
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Nov 27 00:58:30 2016 -0500
loolwsd: png cache hit rate and cosmetics
Change-Id: I66ab1738503618002bb05504c608969d5aa7b9a9
Reviewed-on: https://gerrit.libreoffice.org/31290
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 15fd559..68099cf 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -278,6 +278,8 @@ class PngCache
}
} ;
size_t _cacheSize;
+ size_t _cacheHits;
+ size_t _cacheTests;
std::map< uint64_t, CacheEntry > _cache;
void balanceCache()
@@ -291,7 +293,8 @@ class PngCache
avgHits += it->second._hitCount;
LOG_DBG("cache " << _cache.size() << " items total size " <<
- _cacheSize << " total hits " << avgHits << " at balance start");
+ _cacheSize << " current hits " << avgHits << ", total hit rate " <<
+ (_cacheHits * 100. / _cacheTests) << "% at balance start");
avgHits /= _cache.size();
for (auto it = _cache.begin(); it != _cache.end();)
@@ -299,7 +302,7 @@ class PngCache
if (it->second._hitCount <= avgHits)
{
_cacheSize -= it->second._data->size();
- _cache.erase(it++);
+ it = _cache.erase(it);
}
else
{
@@ -320,10 +323,13 @@ class PngCache
{
uint64_t hash = png::hashSubBuffer(pixmap, startX, startY, width, height,
bufferWidth, bufferHeight);
- if (hash) {
+ if (hash)
+ {
+ ++_cacheTests;
auto it = _cache.find(hash);
if (it != _cache.end())
{
+ ++_cacheHits;
LOG_DBG("PNG cache with hash " << hash << " hit.");
output.insert(output.end(),
it->second._data->begin(),
@@ -332,6 +338,7 @@ class PngCache
return true;
}
}
+
LOG_DBG("PNG cache with hash " << hash << " missed.");
CacheEntry newEntry(bufferWidth * bufferHeight * 1);
if (png::encodeSubBufferToPNG(pixmap, startX, startY, width, height,
@@ -340,9 +347,10 @@ class PngCache
{
if (hash)
{
- _cache.insert(std::pair< uint64_t, CacheEntry >( hash, newEntry ));
+ _cache.emplace(hash, newEntry);
_cacheSize += newEntry._data->size();
}
+
output.insert(output.end(),
newEntry._data->begin(),
newEntry._data->end());
@@ -354,9 +362,13 @@ class PngCache
}
public:
- PngCache() : _cacheSize(0)
+ PngCache() :
+ _cacheSize(0),
+ _cacheHits(0),
+ _cacheTests(0)
{
}
+
bool encodeBufferToPNG(unsigned char* pixmap, int width, int height,
std::vector<char>& output, LibreOfficeKitTileMode mode)
{
More information about the Libreoffice-commits
mailing list