|
8 | 8 |
|
9 | 9 | #include "memory_info.h"
|
10 | 10 |
|
11 |
| -#ifdef __APPLE__ |
12 |
| -#include <mach/task.h> |
13 |
| -#include <mach/mach_init.h> |
14 |
| -#include <malloc/malloc.h> |
15 |
| -#endif |
16 |
| - |
17 |
| -#ifdef __linux__ |
18 |
| -#include <malloc.h> |
19 |
| -#endif |
| 11 | +#include "invariant.h" |
20 | 12 |
|
21 |
| -#ifdef _WIN32 |
22 |
| -#include <util/pragma_push.def> |
23 |
| -#ifdef _MSC_VER |
24 |
| -#pragma warning(disable:4668) |
25 |
| - // using #if/#elif on undefined macro |
26 |
| -#pragma warning(disable : 5039) |
| 13 | +#ifdef __GLIBC__ |
| 14 | +# include <malloc.h> |
| 15 | +#elif defined(_WIN32) |
| 16 | +# include <util/pragma_push.def> |
| 17 | +# ifdef _MSC_VER |
| 18 | +# pragma warning(disable : 4668) |
| 19 | +// using #if/#elif on undefined macro |
| 20 | +# pragma warning(disable : 5039) |
27 | 21 | // pointer or reference to potentially throwing function passed to extern C
|
28 |
| -#endif |
29 |
| -#include <windows.h> |
30 |
| -#include <psapi.h> |
31 |
| -#include <util/pragma_pop.def> |
| 22 | +# endif |
| 23 | +# include <util/pragma_pop.def> |
| 24 | +// windows.h must be included before psapi.h |
| 25 | +// clang-format off |
| 26 | +# include <windows.h> |
| 27 | +# include <psapi.h> |
| 28 | +// clang-format on |
| 29 | +#elif defined(__APPLE__) |
| 30 | +# include <mach/mach_init.h> |
| 31 | +# include <mach/task.h> |
| 32 | +# include <malloc/malloc.h> |
| 33 | +#else |
| 34 | +# include <sys/resource.h> |
32 | 35 | #endif
|
33 | 36 |
|
34 | 37 | #include <ostream>
|
35 | 38 |
|
36 | 39 | void memory_info(std::ostream &out)
|
37 | 40 | {
|
38 |
| -#if defined(__linux__) && defined(__GLIBC__) |
| 41 | +#ifdef __GLIBC__ |
39 | 42 | // NOLINTNEXTLINE(readability/identifiers)
|
40 | 43 | struct mallinfo m = mallinfo();
|
41 | 44 | out << " non-mmapped space allocated from system: " << m.arena << "\n";
|
@@ -70,5 +73,11 @@ void memory_info(std::ostream &out)
|
70 | 73 | << static_cast<double>(t.max_size_in_use)/1000000 << "m\n";
|
71 | 74 | out << " size_allocated: "
|
72 | 75 | << static_cast<double>(t.size_allocated)/1000000 << "m\n";
|
| 76 | +#else |
| 77 | + // NOLINTNEXTLINE(readability/identifiers) |
| 78 | + struct rusage r_usage; |
| 79 | + int result = getrusage(RUSAGE_SELF, &r_usage); |
| 80 | + CHECK_RETURN(result == 0); |
| 81 | + out << " maximum resident set size [bytes]: " << r_usage.ru_maxrss << '\n'; |
73 | 82 | #endif
|
74 | 83 | }
|
0 commit comments