Return the virtual memory size that the process is using. Only works for Linux.
| 62 | // Return the virtual memory size that the process is using. |
| 63 | // Only works for Linux. |
| 64 | uint64_t GetProcessVMSize() { |
| 65 | // vm size, https://man7.org/linux/man-pages/man5/proc.5.html |
| 66 | const int vm_size_pos = 22; |
| 67 | ifstream stream("/proc/self/stat"); |
| 68 | string line; |
| 69 | string space_delimiter = " "; |
| 70 | vector<string> words{}; |
| 71 | if (getline(stream, line)) { |
| 72 | size_t pos = 0; |
| 73 | while ((pos = line.find(space_delimiter)) != string::npos) { |
| 74 | words.push_back(line.substr(0, pos)); |
| 75 | line.erase(0, pos + space_delimiter.length()); |
| 76 | } |
| 77 | } |
| 78 | uint64_t value = 0; |
| 79 | if (words.size() <= vm_size_pos) return value; |
| 80 | istringstream iss(words[vm_size_pos]); |
| 81 | iss >> value; |
| 82 | return value; |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | // Testcase for IMPALA-11176 to verify the memory leak issue. |