From 33e23b6fb88d83776c422214895d0f66c94c83e3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 11 Jun 2019 13:15:57 -0700 Subject: [PATCH] modules/console: Add a specialized proc smaps enhanced command handler. --- modules/console.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index 51f035d4f..ef05933f7 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -851,6 +851,45 @@ console_cmd__proc(opt &out, const string_view &line) return true; } +// Specialized command, strips lines which have 0 values for shorter output. +bool +console_cmd__proc__smaps(opt &out, const string_view &line) +{ + fs::fd fd + { + "/proc/self/smaps", std::ios::in //TODO: XXX windows + }; + + fs::read_opts opts; + opts.aio = false; + opts.offset = 0; + const unique_buffer buf + { + 4_MiB + }; + + const string_view read + { + fs::read(fd, buf, opts) + }; + + ircd::tokens(read, '\n', [&out] + (const string_view &line) + { + const auto &[key, val] + { + split(line, ':') + }; + + if(lstrip(val, ' ') == "0 kB") + return; + + out << line << std::endl; + }); + + return true; +} + // // mem //