LinuxMallInfo.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_Optional_detail_LinuxMallInfo_h
2 #define art_Framework_Services_Optional_detail_LinuxMallInfo_h
3 
4 //===================================================================
5 //
6 // LinuxMallInfo
7 //
8 //-----------------------------------------------
9 //
10 // This is a helper class for storing information that is available
11 // through a call to mallinfo, the contents of which are:
12 //
13 // struct mallinfo {
14 //
15 // MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system
16 // */ MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */
17 // MALLINFO_FIELD_TYPE smblks; /* always 0 */
18 // MALLINFO_FIELD_TYPE hblks; /* always 0 */
19 // MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */
20 // MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */
21 // MALLINFO_FIELD_TYPE fsmblks; /* always 0 */
22 // MALLINFO_FIELD_TYPE uordblks; /* total allocated space */
23 // MALLINFO_FIELD_TYPE fordblks; /* total free space */
24 // MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */
25 //
26 // };
27 //
28 //===================================================================
29 
30 extern "C" {
31 #include <malloc.h>
32 }
33 
34 namespace art {
35  namespace detail {
36 
37  class LinuxMallInfo {
38  public:
39  LinuxMallInfo() : minfo_(mallinfo()) {}
40 
41  struct mallinfo
43  {
44  return minfo_;
45  }
46 
47  private:
48  struct mallinfo minfo_;
49 
50  friend std::ostream& operator<<(std::ostream& os,
51  LinuxMallInfo const& info);
52  };
53 
54  inline std::ostream&
55  operator<<(std::ostream& os, LinuxMallInfo const& info)
56  {
57  auto const& minfo = info.minfo_;
58  os << " HEAP-ARENA [ SIZE-BYTES " << minfo.arena << " N-UNUSED-CHUNKS "
59  << minfo.ordblks << " TOP-FREE-BYTES " << minfo.keepcost << " ]"
60  << " HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd << " N-CHUNKS "
61  << minfo.hblks << " ]"
62  << " HEAP-USED-BYTES " << minfo.uordblks << " HEAP-UNUSED-BYTES "
63  << minfo.fordblks;
64  return os;
65  }
66 
67  } // namespace detail
68 
69 } // namespace art
70 #endif /* art_Framework_Services_Optional_detail_LinuxMallInfo_h */
71 
72 // Local variables:
73 // mode:c++
74 // End:
friend std::ostream & operator<<(std::ostream &os, LinuxMallInfo const &info)
Definition: LinuxMallInfo.h:55
struct mallinfo get() const
Definition: LinuxMallInfo.h:42