Implement OS_DumpMemoryCounters for Linux
authorLoopDawg <sk_opengl@khasekhemwy.net>
Mon, 13 Nov 2017 22:54:12 +0000 (15:54 -0700)
committerJohn Kessenich <cepheus@frii.com>
Tue, 14 Nov 2017 05:22:42 +0000 (22:22 -0700)
glslang/OSDependent/Unix/ossource.cpp

index 24b77e1..f59bbce 100644 (file)
@@ -43,6 +43,9 @@
 #include <assert.h>
 #include <errno.h>
 #include <stdint.h>
+#include <cstdio>
+#include <sys/time.h>
+#include <sys/resource.h>
 
 namespace glslang {
 
@@ -184,8 +187,18 @@ void ReleaseGlobalLock()
   pthread_mutex_unlock(&gMutex);
 }
 
+// #define DUMP_COUNTERS
+
 void OS_DumpMemoryCounters()
 {
+#ifdef DUMP_COUNTERS
+    struct rusage usage;
+
+    if (getrusage(RUSAGE_SELF, &usage) == 0)
+        printf("Working set size: %ld\n", usage.ru_maxrss * 1024);
+#else
+    printf("Recompile with DUMP_COUNTERS defined to see counters.\n");
+#endif
 }
 
 } // end namespace glslang