equal
deleted
inserted
replaced
|
1 module:set_global(); |
|
2 |
|
3 local measure = require"core.statsmanager".measure; |
|
4 local have_pposix, pposix = pcall(require, "util.pposix"); |
|
5 |
|
6 local measures = {}; |
|
7 setmetatable(measures, { |
|
8 __index = function (t, k, m) |
|
9 m = measure("sizes", "memory."..k); t[k] = m; return m; |
|
10 end |
|
11 }); |
|
12 |
|
13 module:hook("stats-update", function () |
|
14 measures.lua(collectgarbage("count")*1024); |
|
15 end); |
|
16 |
|
17 if have_pposix and pposix.meminfo then |
|
18 module:hook_global("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 |
|
26 local statm = io.open("/proc/self/statm"); |
|
27 if statm then |
|
28 statm:close(); |
|
29 local pagesize = module:get_option_number("memory_pagesize", 4096); -- getconf PAGESIZE |
|
30 |
|
31 module:hook("stats-update", function () |
|
32 local statm, err = io.open("/proc/self/statm"); |
|
33 if not statm then |
|
34 module:log("error", tostring(err)); |
|
35 return; |
|
36 end |
|
37 -- virtual memory (caches, opened librarys, everything) |
|
38 measures.total(statm:read("*n") * pagesize); |
|
39 -- resident set size (actually used memory) |
|
40 measures.rss(statm:read("*n") * pagesize); |
|
41 statm:close(); |
|
42 end); |
|
43 end |