summaryrefslogtreecommitdiff
path: root/src/base/hostinfo.cc
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2012-01-16 04:27:10 -0800
committerGabe Black <gblack@eecs.umich.edu>2012-01-16 04:27:10 -0800
commitda2a4acc26ba264c3c4a12495776fd6a1c4fb133 (patch)
treef142100388b9d1403492c97b0d323728ce18ef8a /src/base/hostinfo.cc
parent241cc0c8402f1b9f2ec20d1cc152d96930959b2a (diff)
parenta7394ad6807bd5e85f680184bf308673ca00534a (diff)
downloadgem5-da2a4acc26ba264c3c4a12495776fd6a1c4fb133.tar.xz
Merge yet again with the main repository.
Diffstat (limited to 'src/base/hostinfo.cc')
-rw-r--r--src/base/hostinfo.cc32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/base/hostinfo.cc b/src/base/hostinfo.cc
index 5ff34e603..857ccfa7f 100644
--- a/src/base/hostinfo.cc
+++ b/src/base/hostinfo.cc
@@ -30,6 +30,12 @@
#include <unistd.h>
+#ifdef __APPLE__
+#include <mach/mach_init.h>
+#include <mach/shared_region.h>
+#include <mach/task.h>
+#endif
+
#include <cctype>
#include <cerrno>
#include <cmath>
@@ -82,7 +88,31 @@ procInfo(const char *filename, const char *target)
}
if (fp)
- fclose(fp);
+ fclose(fp);
return 0;
}
+
+uint64_t
+memUsage()
+{
+// For the Mach-based Darwin kernel, use the task_info of the self task
+#ifdef __APPLE__
+ struct task_basic_info t_info;
+ mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
+
+ if (KERN_SUCCESS != task_info(mach_task_self(),
+ TASK_BASIC_INFO, (task_info_t)&t_info,
+ &t_info_count)) {
+ return 0;
+ }
+
+ // Mimic Darwin's implementation of top and subtract
+ // SHARED_REGION_SIZE from the tasks virtual size to account for the
+ // shared memory submap that is incorporated into every process.
+ return (t_info.virtual_size - SHARED_REGION_SIZE) / 1024;
+#else
+ // Linux implementation
+ return procInfo("/proc/self/status", "VmSize:");
+#endif
+}