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