]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/MemoryModel.cc
1 #include "MemoryModel.h"
2 #include "include/compat.h"
10 #define dout_subsys ceph_subsys_
14 MemoryModel::MemoryModel(CephContext
*cct_
)
19 void MemoryModel::_sample(snap
*psnap
)
23 f
.open(PROCPREFIX
"/proc/self/status");
25 ldout(cct
, 0) << "check_memory_usage unable to open " PROCPREFIX
"/proc/self/status" << dendl
;
32 if (strncmp(line
.c_str(), "VmSize:", 7) == 0)
33 psnap
->size
= atol(line
.c_str() + 7);
34 else if (strncmp(line
.c_str(), "VmRSS:", 6) == 0)
35 psnap
->rss
= atol(line
.c_str() + 7);
36 else if (strncmp(line
.c_str(), "VmHWM:", 6) == 0)
37 psnap
->hwm
= atol(line
.c_str() + 7);
38 else if (strncmp(line
.c_str(), "VmLib:", 6) == 0)
39 psnap
->lib
= atol(line
.c_str() + 7);
40 else if (strncmp(line
.c_str(), "VmPeak:", 7) == 0)
41 psnap
->peak
= atol(line
.c_str() + 7);
42 else if (strncmp(line
.c_str(), "VmData:", 7) == 0)
43 psnap
->data
= atol(line
.c_str() + 7);
47 f
.open(PROCPREFIX
"/proc/self/maps");
49 ldout(cct
, 0) << "check_memory_usage unable to open " PROCPREFIX
"/proc/self/maps" << dendl
;
54 while (f
.is_open() && !f
.eof()) {
57 //ldout(cct, 0) << "line is " << line << dendl;
59 const char *start
= line
.c_str();
60 const char *dash
= start
;
61 while (*dash
&& *dash
!= '-') dash
++;
64 const char *end
= dash
+ 1;
65 while (*end
&& *end
!= ' ') end
++;
68 unsigned long long as
= strtoll(start
, 0, 16);
69 unsigned long long ae
= strtoll(dash
+1, 0, 16);
71 //ldout(cct, 0) << std::hex << as << " to " << ae << std::dec << dendl;
74 const char *mode
= end
;
79 while (*end
&& *end
!= ' ') end
++;
85 //ldout(cct, 0) << "size " << size << " mode is '" << mode << "' end is '" << end << "'" << dendl;
88 * anything 'rw' and anon is assumed to be heap.
90 if (mode
[0] == 'r' && mode
[1] == 'w' && !*end
)
94 psnap
->heap
= heap
>> 10;