From a3866435bf2e9b76d56fc79c2505e89373c76852 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Sat, 3 Mar 2018 18:32:59 +0000
Subject: [PATCH] Add function to return the memory use of process tree

---
 src/tools.c | 13 +++++++++++++
 src/tools.h |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/src/tools.c b/src/tools.c
index 682ebd0ad7..4653c2ef79 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -27,6 +27,8 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/resource.h>
+#include <sys/time.h>
 
 /* This object's header. */
 #include "tools.h"
@@ -701,3 +703,14 @@ int compare_particles(struct part a, struct part b, double threshold) {
 
 #endif
 }
+
+/**
+ * @brief return the resident memory use of the process and its children.
+ *
+ * @result memory use in Kb.
+ */
+long get_maxrss() {
+  struct rusage usage;
+  getrusage(RUSAGE_SELF, &usage);
+  return usage.ru_maxrss;
+}
diff --git a/src/tools.h b/src/tools.h
index 4d9e8d3ef8..bb141101a3 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -52,4 +52,6 @@ int compare_values(double a, double b, double threshold, double *absDiff,
                    double *absSum, double *relDiff);
 int compare_particles(struct part a, struct part b, double threshold);
 
+long get_maxrss();
+
 #endif /* SWIFT_TOOL_H */
-- 
GitLab