common/Util.cpp | 26 ++++++++++++++++++++++++++ common/Util.hpp | 3 +++ kit/Kit.cpp | 6 +++--- 3 files changed, 32 insertions(+), 3 deletions(-)
New commits: commit c16d1985604940c2f35e49ac27a63d973a2a65ea Author: Pranav Kant <pran...@collabora.co.uk> Date: Fri Jan 26 20:02:09 2018 +0530 Print humanized bytes in the logs Change-Id: I2ebdea0c3a360be1573ae13fa9cbe6f432436f29 diff --git a/common/Util.cpp b/common/Util.cpp index 72c150a4..f8c493b9 100644 --- a/common/Util.cpp +++ b/common/Util.cpp @@ -170,6 +170,32 @@ namespace Util return nullptr; } + std::string getHumanizedBytes(unsigned long nBytes) + { + constexpr unsigned factor = 1024; + short count = 0; + float val = nBytes; + while (val >= factor && count < 4) { + val /= factor; + count++; + } + std::string unit; + switch (count) + { + case 0: unit = ""; break; + case 1: unit = "ki"; break; + case 2: unit = "Mi"; break; + case 3: unit = "Gi"; break; + case 4: unit = "Ti"; break; + default: assert(false); + } + + unit += "B"; + std::stringstream ss; + ss << std::fixed << std::setprecision(1) << val << ' ' << unit; + return ss.str(); + } + size_t getTotalSystemMemoryKb() { size_t totalMemKb = 0; diff --git a/common/Util.hpp b/common/Util.hpp index b4eb3504..5118efb6 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -97,6 +97,9 @@ namespace Util #endif } + /// Print given number of bytes in human-understandable form (KB,MB, etc.) + std::string getHumanizedBytes(unsigned long nBytes); + /// Returns the total physical memory (in kB) available in the system size_t getTotalSystemMemoryKb(); diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 4d054427..f38af663 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -2103,17 +2103,17 @@ void lokit_main(const std::string& childRoot, rlimit rlim = { 0, 0 }; if (getrlimit(RLIMIT_AS, &rlim) == 0) - LOG_INF("RLIMIT_AS is " << rlim.rlim_max << " bytes."); + LOG_INF("RLIMIT_AS is " << Util::getHumanizedBytes(rlim.rlim_max) << " (" << rlim.rlim_max << " bytes)"); else LOG_SYS("Failed to get RLIMIT_AS."); if (getrlimit(RLIMIT_STACK, &rlim) == 0) - LOG_INF("RLIMIT_STACK is " << rlim.rlim_max << " bytes."); + LOG_INF("RLIMIT_STACK is " << Util::getHumanizedBytes(rlim.rlim_max) << " (" << rlim.rlim_max << " bytes)"); else LOG_SYS("Failed to get RLIMIT_STACK."); if (getrlimit(RLIMIT_FSIZE, &rlim) == 0) - LOG_INF("RLIMIT_FSIZE is " << rlim.rlim_max << " bytes."); + LOG_INF("RLIMIT_FSIZE is " << Util::getHumanizedBytes(rlim.rlim_max) << " (" << rlim.rlim_max << " bytes)"); else LOG_SYS("Failed to get RLIMIT_FSIZE."); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits