Skip to content

Commit

Permalink
Usage report for mac update proposal.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Dec 7, 2020
1 parent d70e284 commit bf53dca
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions util/usage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:");
Expand All @@ -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)) {
Expand Down

0 comments on commit bf53dca

Please sign in to comment.