17 extern src::severity_logger<severity_level>
lg;
46 void update(std::vector<std::string>& prop_vec, std::string sort_key);
74 DIR* dirp = opendir(
"/proc");
77 BOOST_LOG_SEV(
lg, debug)<<
log_spacer<<
"ProcInfo-"<<
uuid<<
"_read::, failed to open directory";
78 throw std::runtime_error(
"ProcInfo::read, failed to open directory\n");
87 std::string str(dp->d_name);
88 if (str.find_first_not_of(
"0123456789") == std::string::npos)
92 if (closedir(dirp) == -1)
94 BOOST_LOG_SEV(
lg, fatal)<<
log_spacer<<
"ProcInfo-"<<
uuid<<
"_read::, failed to close /proc directory";
95 throw std::runtime_error(
"ProcInfo::read, failed to closed /proc directory\n");
103 std::stringstream ss(std::ios_base::out | std::ios_base::in | std::ios_base::ate);
104 ss.exceptions(std::ios::failbit);
105 std::ifstream ifs_stat, ifs_cmdline, ifs_status;
116 ss<<
"/proc/"<<pid<<
"/stat";
117 ifs_stat.open(ss.str());
120 ss<<
"/proc/"<<pid<<
"/cmdline";
121 ifs_cmdline.open(ss.str());
124 ss<<
"/proc/"<<pid<<
"/status";
125 ifs_status.open(ss.str());
127 if (!ifs_stat || !ifs_cmdline || !ifs_status)
130 BOOST_LOG_SEV(
lg, error)<<
log_spacer<<
"/proc/"<<pid<<
"/stat "<<strerror(errno);
132 BOOST_LOG_SEV(
lg, error)<<
log_spacer<<
"/proc/"<<pid<<
"/cmdline "<<strerror(errno);
134 BOOST_LOG_SEV(
lg, error)<<
log_spacer<<
"/proc/"<<pid<<
"/status "<<strerror(errno);
142 std::string line, cmdline_str, status_line;
145 std::getline(ifs_cmdline, cmdline_str);
149 if (cmdline_str ==
"")
151 BOOST_LOG_SEV(
lg, debug)<<
log_spacer<<
"/proc/"<<pid<<
"/cmdline"<<
" empty";
152 std::string tmpstr =
"";
155 std::getline(ifs_status, status_line);
161 cmdline_str += tmpstr;
167 std::getline(ifs_stat, line);
170 std::string discard_str;
192 catch(std::runtime_error e)
197 strval = std::to_string(d_val);
205 if (loc == 14 || loc == 15)
208 strval = std::to_string(l_val);
240 v.push_back(std::stoi(item.Val()));
249 v.push_back(std::stol(item.Val()));
ProcInfo(int id)
ProcInfo constructor. Instantiates ProcInfo object with provided unique identifier.
int dbsize
size of property vector i.e. number of processes whose properties are being maintained
void read()
reads property values specified in ProcInfo::prop_set for each process and stores result in ProcDb::d...
std::unordered_set< int > pid_set
hashset for storing processs PIDs
std::string msecToTimeStr(unsigned long msec)
converts msec to TimerStr for display as min:sec.secs_fraction
data structure that hold property values for processes. contains facilities to enable their proper ac...
std::vector< int > sorted_indices
vector that holds the permutation order to parse property vectors in sorted order
src::severity_logger< severity_level > lg
void delSpace()
deletes one white-space from white-space string corresponding to invoking thread
ProcDb * proc_database
pointer to access ProcDb data structure
std::map< std::string, std::vector< InfoProc< std::string > > > database
dictionary that holds vector of values corresponding to each property name string
void sort()
sorts property value vector corresponding to sortkey, and stores resulting permutation vector in Proc...
std::vector< int > sort_permutation(const std::vector< T > &vec, Compare compare)
returns permutation vector after sorting the given vector based on the provided compare function
void addSpace()
adds one white-space to white-space string corresponding to invoking thread
std::map< int, std::pair< std::string, std::string > > field_prop_dict
dictionary that holds property locations in /proc/pid/stat file, and correspondingg prop name and typ...
std::unordered_set< std::string > prop_set
hashset for storing property names, whose corresponding vectors in ProcDb need to be updated
std::map< std::string, std::string > prop_type_dict
dictionary hold property name and corresponding type
enables indentation of logs for easy viewing
data structure that defines type of entry from which panel menu entries obtain their c-string data
interfaces with linux API to read process information and update ProcDb with it
void update(std::vector< std::string > &prop_vec, std::string sort_key)
invoked by Columns::read. reads process prop values, sorts them and then updates ProcDb
std::string sortkey
variable to hold property name to be sorted. used by ProcInfo::sort to sort process values correspond...