2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00

Footer: added "memory usage" item

Helps following KOReader memory usage (and memory leaks).
This commit is contained in:
poire-z 2017-03-11 13:22:44 +01:00 committed by Qingping Hou
parent 8b295b5837
commit 4316284260

View File

@ -27,11 +27,14 @@ local MODE = {
book_time_to_read = 6,
chapter_time_to_read = 7,
frontlight = 8,
mem_usage = 9,
}
local MODE_NB = 0
local MODE_INDEX = {}
for k,v in pairs(MODE) do
MODE_INDEX[v] = k
MODE_NB = MODE_NB + 1
end
-- functions that generates footer text for each mode
@ -85,6 +88,18 @@ local footerTextGeneratorMap = {
return footer:getDataFromStatistics(
"TC: ", (left and left or footer.pages - footer.pageno))
end,
mem_usage = function(footer)
local statm = io.open("/proc/self/statm", "r")
if statm then
local infos = statm:read("*all")
statm:close()
local rss = infos:match("^%S+ (%S+) ")
-- we got the nb of 4Kb-pages used, that we convert to Mb
rss = math.floor(tonumber(rss) * 4096 / 1024 / 1024)
return string.format("M:%d", rss)
end
return ""
end,
}
local ReaderFooter = WidgetContainer:extend{
@ -120,6 +135,7 @@ function ReaderFooter:init()
book_time_to_read = true,
chapter_time_to_read = true,
frontlight = false,
mem_usage = false,
}
if self.settings.disabled then
@ -304,6 +320,7 @@ local option_titles = {
book_time_to_read = _("Book time to read"),
chapter_time_to_read = _("Chapter time to read"),
frontlight = _("Frontlight level"),
mem_usage = _("KOReader memory usage"),
}
function ReaderFooter:addToMainMenu(tab_item_table)
@ -400,6 +417,7 @@ function ReaderFooter:addToMainMenu(tab_item_table)
table.insert(sub_items, getMinibarOption("book_time_to_read"))
table.insert(sub_items, getMinibarOption("chapter_time_to_read"))
table.insert(sub_items, getMinibarOption("frontlight"))
table.insert(sub_items, getMinibarOption("mem_usage"))
end
-- this method will be updated at runtime based on user setting
@ -530,6 +548,7 @@ function ReaderFooter:applyFooterMode(mode)
-- 6 for from statistics book time to read
-- 7 for from statistics chapter time to read
-- 8 for front light level
-- 9 for memory usage
if mode ~= nil then self.mode = mode end
self.view.footer_visible = (self.mode ~= MODE.off)
if not self.view.footer_visible or self.settings.all_at_once then return end
@ -568,14 +587,14 @@ function ReaderFooter:onTapFooter(arg, ges)
self.mode = MODE.page_progress
end
else
self.mode = (self.mode + 1) % 9
self.mode = (self.mode + 1) % MODE_NB
for i, m in ipairs(MODE_INDEX) do
if self.mode == MODE.off then break end
if self.mode == i then
if self.settings[m] then
break
else
self.mode = (self.mode + 1) % 9
self.mode = (self.mode + 1) % MODE_NB
end
end
end