Software / code / prosody-modules
Comparison
mod_measure_memory/mod_measure_memory.lua @ 2708:07d6077d2db7
mod_measure_memory: Split out mallinfo measuring into a separate module, mod_measure_malloc
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 27 Apr 2017 19:52:42 +0200 |
| parent | 2436:a01a3fb96302 |
| child | 3365:a5a5f85d7ca1 |
comparison
equal
deleted
inserted
replaced
| 2707:dea35dfd5808 | 2708:07d6077d2db7 |
|---|---|
| 1 module:set_global(); | 1 module:set_global(); |
| 2 | 2 |
| 3 local measure = require"core.statsmanager".measure; | 3 local measure = require"core.statsmanager".measure; |
| 4 local have_pposix, pposix = pcall(require, "util.pposix"); | |
| 5 | 4 |
| 6 local measures = {}; | 5 local measures = {}; |
| 7 setmetatable(measures, { | 6 setmetatable(measures, { |
| 8 __index = function (t, k) | 7 __index = function (t, k) |
| 9 local m = measure("sizes", "memory."..k); t[k] = m; return m; | 8 local m = measure("sizes", "memory."..k); t[k] = m; return m; |
| 11 }); | 10 }); |
| 12 | 11 |
| 13 module:hook("stats-update", function () | 12 module:hook("stats-update", function () |
| 14 measures.lua(collectgarbage("count")*1024); | 13 measures.lua(collectgarbage("count")*1024); |
| 15 end); | 14 end); |
| 16 | |
| 17 if have_pposix and pposix.meminfo then | |
| 18 module:hook("stats-update", function () | |
| 19 local m = measures; | |
| 20 for k, v in pairs(pposix.meminfo()) do | |
| 21 m[k](v); | |
| 22 end | |
| 23 end); | |
| 24 end | |
| 25 | 15 |
| 26 if require"lfs".attributes("/proc/self/statm", "mode") == "file" then | 16 if require"lfs".attributes("/proc/self/statm", "mode") == "file" then |
| 27 local pagesize = module:get_option_number("memory_pagesize", 4096); -- getconf PAGESIZE | 17 local pagesize = module:get_option_number("memory_pagesize", 4096); -- getconf PAGESIZE |
| 28 | 18 |
| 29 module:hook("stats-update", function () | 19 module:hook("stats-update", function () |