Cleanup eye-gouging madness around io.read calls (#7149)

* Don't reinvent the wheel when reading a one-line int or string from sysfs

* Simplify a whole other bunch of read calls
This commit is contained in:
NiLuJe
2021-01-16 04:41:46 +01:00
committed by GitHub
parent f52fffd467
commit dffe86dfe9
17 changed files with 36 additions and 68 deletions

View File

@@ -290,11 +290,10 @@ local footerTextGeneratorMap = {
local prefix = symbol_prefix[symbol_type].mem_usage
local statm = io.open("/proc/self/statm", "r")
if statm then
local infos = statm:read("*all")
local dummy, rss = statm:read("*number", "*number")
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)
rss = math.floor(rss * 4096 / 1024 / 1024)
return (prefix .. " %d"):format(rss)
end
return ""