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 <windows.h>
23 #include <psapi.h>
24 #endif
25 
26 #include <ostream>
27 
28 void memory_info(std::ostream &out)
29 {
30  #if defined(__linux__) && defined(__GLIBC__)
31  // NOLINTNEXTLINE(readability/identifiers)
32  struct mallinfo m = mallinfo();
33  out << " non-mmapped space allocated from system: " << m.arena << "\n";
34  out << " number of free chunks: " << m.ordblks << "\n";
35  out << " number of fastbin blocks: " << m.smblks << "\n";
36  out << " number of mmapped regions: " << m.hblks << "\n";
37  out << " space in mmapped regions: " << m.hblkhd << "\n";
38  out << " maximum total allocated space: " << m.usmblks << "\n";
39  out << " space available in freed fastbin blocks: " << m.fsmblks << "\n";
40  out << " total allocated space: " << m.uordblks << "\n";
41  out << " total free space: " << m.fordblks << "\n";
42  #endif
43 
44  #ifdef _WIN32
45  #if 0
46  PROCESS_MEMORY_COUNTERS pmc;
47  if(GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
48  {
49  out << " PeakWorkingSetSize: " << pmc.PeakWorkingSetSize << "\n";
50  out << " WorkingSetSize: " << pmc.WorkingSetSize << "\n";
51  }
52  #endif
53  #endif
54 
55  #ifdef __APPLE__
56  // NOLINTNEXTLINE(readability/identifiers)
57  struct task_basic_info t_info;
58  mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
59  task_info(
60  current_task(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
61  out << " virtual size: "
62  << static_cast<double>(t_info.virtual_size)/1000000 << "m\n";
63 
64  malloc_statistics_t t;
65  malloc_zone_statistics(NULL, &t);
66  out << " max_size_in_use: "
67  << static_cast<double>(t.max_size_in_use)/1000000 << "m\n";
68  out << " size_allocated: "
69  << static_cast<double>(t.size_allocated)/1000000 << "m\n";
70  #endif
71 }
void memory_info(std::ostream &out)
Definition: memory_info.cpp:28