3 #pragma GCC diagnostic push
4 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
5 #include <boost/algorithm/string.hpp>
6 #pragma GCC diagnostic pop
8 #include <boost/tokenizer.hpp>
35 outfile <<
"Event HeapPss mmap OtherPss" << std::endl;
50 std::ifstream smap_stat(
"/proc/self/smaps");
56 getline(smap_stat, instring);
62 std::regex reg(R
"(\s+)");
63 instring = std::regex_replace(instring, reg, " ");
64 std::string firststring = instring.substr(0, instring.find(
' '));
65 if (firststring.find(
'-') != std::string::npos || (firststring.find(
"0000000") != std::string::npos && i == 0))
67 std::vector<std::string> tokens;
68 boost::split(tokens, instring, boost::is_any_of(
" "));
70 if (tokens.size() == 6)
72 libraryname = tokens.back();
82 boost::char_separator<char> sep(
" ");
83 using tokenizer = boost::tokenizer<boost::char_separator<char>>;
84 tokenizer tok(instring, sep);
85 tokenizer::iterator tok_iter = tok.begin();
86 if ((*tok_iter).find(
"Pss") != std::string::npos)
91 if (libraryname.find(
"[heap]") != std::string::npos)
95 else if (libraryname ==
"mmap")
111 std::stringstream smaps;
112 smaps <<
"/proc/" << getpid() <<
"/smaps" <<
std::ends;
113 std::ifstream smap_stat(smaps.str());
117 std::ofstream outfilefilt(fname1);
124 smap_stat >> key_str >> value_str;
125 outfile << smap_stat.rdbuf();
126 if (key_str ==
"Size:")
128 outfilefilt << key_str <<
" " << value_str << std::endl;
129 vmem += std::stol(value_str);
131 else if (key_str ==
"Rss:")
133 rss += std::stol(value_str);
134 outfilefilt << key_str <<
" " << value_str << std::endl;
137 std::cout <<
"vmem: " << vmem <<
", rss: " << rss << std::endl;