aboutsummaryrefslogtreecommitdiffstats
path: root/testing/opencascade/no_mallinfo.patch
blob: ac0ebd7e3c6daa010038ccb3a47aa3d8a4adf11d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
mallinfo() is not provided in musl. This patch uses getrusage() instead to use
the maximum resident set size as a (poor) approximation of the heap usage.
--- occt-V7_3_0p3.bin/src/OSD/OSD_MemInfo.cxx
+++ occt-V7_3_0p3/src/OSD/OSD_MemInfo.cxx
@@ -35,6 +35,9 @@
 #include <sstream>
 #include <fstream>

+#include <sys/time.h>
+#include <sys/resource.h>
+
 #include <OSD_MemInfo.hxx>

 #if defined(__EMSCRIPTEN__)
@@ -161,18 +164,22 @@
    || IsActive (MemWorkingSetPeak))
   {
     // /proc/%d/status is not emulated - get more info from mallinfo()
-    const struct mallinfo aMI = mallinfo();
+    // mallinfo() not available with musl. We use getrusage to approximate it
+    // with the maximum resident set size
+    struct rusage ru = { .ru_maxrss = 0 };
+    getrusage(RUSAGE_SELF, &ru);
     if (IsActive (MemHeapUsage))
     {
-      myCounters[MemHeapUsage] = aMI.uordblks;
+      myCounters[MemHeapUsage] = ru.ru_maxrss;
     }
     if (IsActive (MemWorkingSet))
     {
-      myCounters[MemWorkingSet] = aMI.uordblks;
+      myCounters[MemWorkingSet] = ru.ru_maxrss;
     }
     if (IsActive (MemWorkingSetPeak))
     {
-      myCounters[MemWorkingSetPeak] = aMI.usmblks;
+      //usmblks is always 0
+      myCounters[MemWorkingSetPeak] = 0;
     }
   }
   if (IsActive (MemVirtual))
@@ -182,8 +189,9 @@
 #elif (defined(__linux__) || defined(__linux))
   if (IsActive (MemHeapUsage))
   {
-    const struct mallinfo aMI = mallinfo();
-    myCounters[MemHeapUsage] = aMI.uordblks;
+    struct rusage ru = { .ru_maxrss = 0 };
+    getrusage(RUSAGE_SELF, &ru);
+    myCounters[MemHeapUsage] = ru.ru_maxrss;
   }

   if (!IsActive (MemVirtual)