summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/common-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r--libglusterfs/src/common-utils.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index b2e91608b7a..2d4415f506d 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1896,3 +1896,34 @@ gf_path_strip_trailing_slashes (char *path)
return;
}
+
+uint64_t
+get_mem_size ()
+{
+ uint64_t memsize = -1;
+
+#ifdef __linux__
+ FILE *fp = NULL;
+ char line[1028] = {0,};
+
+ fp = fopen ("/proc/meminfo", "r");
+ if (!fp) {
+ gf_log ("common-utils", GF_LOG_DEBUG,
+ "Could not open /proc/meminfo");
+ return memsize;
+ }
+
+ while (fgets (line, sizeof (line), fp) != 0) {
+ if (strncmp (line, "MemTotal:", 9) == 0) {
+ sscanf (line, "%*s %"SCNu64" kB", &memsize);
+ memsize *= 1024; //convert to bytes
+ gf_log ("common-utils", GF_LOG_INFO,
+ "Total Mem: %"PRIu64, memsize);
+ break;
+ }
+ }
+#endif
+ // TODO: Methods for other platforms
+
+ return memsize;
+}