From 39da1251ecd9da1de32b641cee2f2b3f19aef37f Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 13 Oct 2013 15:30:42 +0800 Subject: [PATCH] free blitbuffer as soon as tile is kicked out from cache other than waiting for the lazy garbage collector of lua --- frontend/document/document.lua | 11 +++++++++-- frontend/document/koptinterface.lua | 29 ++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 917124ef7..eeadb287f 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -28,6 +28,14 @@ function DocumentRegistry:openDocument(file) end end +TileCacheItem = CacheItem:new{} + +function TileCacheItem:onFree() + if self.bb.free then + DEBUG("free blitbuffer", self.bb) + self.bb:free() + end +end --[[ This is an abstract interface to a document @@ -216,7 +224,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode) end -- prepare cache item with contained blitbuffer - local tile = CacheItem:new{ + local tile = TileCacheItem:new{ size = size.w * size.h / 2 + 64, -- estimation excerpt = size, pageno = pageno, @@ -296,7 +304,6 @@ function Document:getPageText(pageno) return text end - -- load implementations: require "document/pdfdocument" diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index eb8fab15d..34736b0ab 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -212,6 +212,8 @@ function KoptInterface:getRFPageDimensions(doc, pageno, zoom, rotation) end function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, gamma, render_mode) + --DEBUG("log memory usage at renderPage") + --self:logMemoryUsage(pageno) if doc.configurable.text_wrap == 1 then return self:renderreflowedPage(doc, pageno, rect, zoom, rotation, render_mode) else @@ -240,7 +242,7 @@ function KoptInterface:renderreflowedPage(doc, pageno, rect, zoom, rotation, ren end local page = doc._document:openPage(pageno) -- prepare cache item with contained blitbuffer - local tile = CacheItem:new{ + local tile = TileCacheItem:new{ size = fullwidth * fullheight / 2 + 64, -- estimation excerpt = Geom:new{ w = fullwidth, h = fullheight }, pageno = pageno, @@ -604,7 +606,6 @@ end get word and word box from position in native page ]]-- function KoptInterface:getWordFromNativePosition(doc, boxes, pos) - DEBUG("boxes", boxes) local native_word_box = self:getWordFromBoxes(boxes, pos) local word_box = { word = native_word_box.word, @@ -726,7 +727,7 @@ end helper functions --]] function KoptInterface:logReflowDuration(pageno, dur) - local file = io.open("reflowlog.txt", "a+") + local file = io.open("reflow_dur_log.txt", "a+") if file then if file:seek("end") == 0 then -- write the header only once file:write("PAGE\tDUR\n") @@ -735,3 +736,25 @@ function KoptInterface:logReflowDuration(pageno, dur) file:close() end end + +function KoptInterface:logMemoryUsage(pageno) + local status_file = io.open("/proc/self/status", "r") + local log_file = io.open("reflow_mem_log.txt", "a+") + local data = -1 + if status_file then + for line in status_file:lines() do + local s, n + s, n = line:gsub("VmData:%s-(%d+) kB", "%1") + if n ~= 0 then data = tonumber(s) end + if data ~= -1 then break end + end + status_file:close() + end + if log_file then + if log_file:seek("end") == 0 then -- write the header only once + log_file:write("PAGE\tMEM\n") + end + log_file:write(string.format("%s\t%s\n", pageno, data)) + log_file:close() + end +end