cprover
memory_info.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "memory_info.h"
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
20 
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 #endif
27 #include <windows.h>
28 #include <psapi.h>
29 #include <util/pragma_pop.def>
30 #endif
31 
32 #include <ostream>
33 
34 void memory_info(std::ostream &out)
35 {
36 #if defined(__linux__) && defined(__GLIBC__)
37  // NOLINTNEXTLINE(readability/identifiers)
38  struct mallinfo m = mallinfo();
39  out << " non-mmapped space allocated from system: " << m.arena << "\n";
40  out << " number of free chunks: " << m.ordblks << "\n";
41  out << " number of fastbin blocks: " << m.smblks << "\n";
42  out << " number of mmapped regions: " << m.hblks << "\n";
43  out << " space in mmapped regions: " << m.hblkhd << "\n";
44  out << " maximum total allocated space: " << m.usmblks << "\n";
45  out << " space available in freed fastbin blocks: " << m.fsmblks << "\n";
46  out << " total allocated space: " << m.uordblks << "\n";
47  out << " total free space: " << m.fordblks << "\n";
48 #endif
49 
50 #ifdef _WIN32
51  (void)out; // unused parameter
52 #if 0
53  PROCESS_MEMORY_COUNTERS pmc;
54  if(GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
55  {
56  out << " PeakWorkingSetSize: " << pmc.PeakWorkingSetSize << "\n";
57  out << " WorkingSetSize: " << pmc.WorkingSetSize << "\n";
58  }
59 #endif
60 #endif
61 
62 #ifdef __APPLE__
63  // NOLINTNEXTLINE(readability/identifiers)
64  struct task_basic_info t_info;
65  mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
66  task_info(
67  current_task(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
68  out << " virtual size: "
69  << static_cast<double>(t_info.virtual_size)/1000000 << "m\n";
70 
71  malloc_statistics_t t;
72  malloc_zone_statistics(NULL, &t);
73  out << " max_size_in_use: "
74  << static_cast<double>(t.max_size_in_use)/1000000 << "m\n";
75  out << " size_allocated: "
76  << static_cast<double>(t.size_allocated)/1000000 << "m\n";
77 #endif
78 }
void memory_info(std::ostream &out)
Definition: memory_info.cpp:34