diff options
author | David Carlier <devnexen@gmail.com> | 2020-12-07 17:07:08 +0300 |
---|---|---|
committer | David Carlier <devnexen@gmail.com> | 2020-12-07 17:25:52 +0300 |
commit | bf53dca2f71ee697638afddf20c41cf378496609 (patch) | |
tree | 11e158527477f1d8f1725ebf39eb0ac2bbd85182 | |
parent | d70e28403f07e88b276c6bd9f162d2a428530f2e (diff) |
Usage report for mac update proposal.
-rw-r--r-- | util/usage.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/util/usage.cc b/util/usage.cc index 23288b7..097c8ee 100644 --- a/util/usage.cc +++ b/util/usage.cc @@ -43,6 +43,7 @@ typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*); #include <sys/sysctl.h> #include <mach/task.h> #include <mach/mach.h> +#include <libproc.h> #endif namespace util { @@ -196,6 +197,18 @@ uint64_t RSSMax() { void PrintUsage(std::ostream &out) { #if !defined(_WIN32) && !defined(_WIN64) +#if defined(__MACH__) || defined(__APPLE__) + struct mach_task_basic_info t_info; + char name[2 * MAXCOMLEN] = {0}; + + proc_name(getpid(), name, sizeof(name)); + mach_msg_type_number_t t_info_count = MACH_TASK_BASIC_INFO_COUNT; + task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count); + + out << t_info.resident_size_max << '\t'; + out << t_info.resident_size << '\t'; + out << name << '\t'; +#else // Linux doesn't set memory usage in getrusage :-( std::set<std::string> headers; headers.insert("VmPeak:"); @@ -209,6 +222,7 @@ void PrintUsage(std::ostream &out) { out << header << SkipSpaces(value.c_str()) << '\t'; } } +#endif struct rusage usage; if (getrusage(RUSAGE_SELF, &usage)) { |