MCPcopy Create free account
hub / github.com/ceph/ceph / read_thread_stat

Method read_thread_stat

src/mgr/ThreadMonitor.cc:201–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201bool ThreadMonitor::read_thread_stat(pid_t tid, long long& utime, long long& stime) {
202 std::string stat_path = "/proc/self/task/" + std::to_string(tid) + "/stat";
203 std::ifstream stat_file(stat_path);
204 if (!stat_file.is_open()) {
205 dout(20) << __func__ << "Could not open " << stat_path << dendl;
206 return false;
207 }
208 std::string line;
209 std::getline(stat_file, line);
210 size_t start = line.find('(');
211 size_t end = line.rfind(')');
212 if (start == std::string::npos || end == std::string::npos) {
213 dout(20) << __func__ << "Malformed stat file for TID " << tid << dendl;
214 return false;
215 }
216
217 std::string remainder = line.substr(end + 2); // +2 to skip ") "
218 std::stringstream ss(remainder);
219 std::string val;
220
221 // skip 11 fields before utime/stime:
222 // state ppid pgrp session tty_nr tpgid flags minflt cminflt majflt cmajflt
223 for (int i = 0; i < 11; ++i) {
224 ss >> val;
225 }
226 ss >> utime >> stime;
227 return true;
228}
229
230bool ThreadMonitor::read_process_statm(long long& rss_pages) {
231 std::string statm_path = "/proc/self/statm";

Callers

nothing calls this directly

Calls 5

rfindMethod · 0.80
substrMethod · 0.80
to_stringFunction · 0.70
is_openMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected