1 #include "MemoryModel.h"
2 #include "include/compat.h"
10 #define dout_subsys ceph_subsys_
12 MemoryModel::MemoryModel(CephContext *cct_)
17 void MemoryModel::_sample(snap *psnap)
21 f.open(PROCPREFIX "/proc/self/status");
23 ldout(cct, 0) << "check_memory_usage unable to open " PROCPREFIX "/proc/self/status" << dendl;
30 if (strncmp(line.c_str(), "VmSize:", 7) == 0)
31 psnap->size = atol(line.c_str() + 7);
32 else if (strncmp(line.c_str(), "VmRSS:", 6) == 0)
33 psnap->rss = atol(line.c_str() + 7);
34 else if (strncmp(line.c_str(), "VmHWM:", 6) == 0)
35 psnap->hwm = atol(line.c_str() + 7);
36 else if (strncmp(line.c_str(), "VmLib:", 6) == 0)
37 psnap->lib = atol(line.c_str() + 7);
38 else if (strncmp(line.c_str(), "VmPeak:", 7) == 0)
39 psnap->peak = atol(line.c_str() + 7);
40 else if (strncmp(line.c_str(), "VmData:", 7) == 0)
41 psnap->data = atol(line.c_str() + 7);
45 f.open(PROCPREFIX "/proc/self/maps");
47 ldout(cct, 0) << "check_memory_usage unable to open " PROCPREFIX "/proc/self/maps" << dendl;
52 while (f.is_open() && !f.eof()) {
55 //ldout(cct, 0) << "line is " << line << dendl;
57 const char *start = line.c_str();
58 const char *dash = start;
59 while (*dash && *dash != '-') dash++;
62 const char *end = dash + 1;
63 while (*end && *end != ' ') end++;
66 unsigned long long as = strtoll(start, 0, 16);
67 unsigned long long ae = strtoll(dash+1, 0, 16);
69 //ldout(cct, 0) << std::hex << as << " to " << ae << std::dec << dendl;
72 const char *mode = end;
77 while (*end && *end != ' ') end++;
83 //ldout(cct, 0) << "size " << size << " mode is '" << mode << "' end is '" << end << "'" << dendl;
86 * anything 'rw' and anon is assumed to be heap.
88 if (mode[0] == 'r' && mode[1] == 'w' && !*end)
92 psnap->heap = heap >> 10;