26 #include <boost/lexical_cast.hpp> 56 unsigned long cminflt;
58 unsigned long cmajflt;
71 unsigned long startcode;
72 unsigned long endcode;
73 unsigned long startstack;
74 unsigned long kstkesp;
75 unsigned long kstkeip;
77 unsigned long blocked;
78 unsigned long sigignore;
79 unsigned long sigcatch;
87 friend Fetcher&
operator>>(Fetcher&,
unsigned int&);
88 friend Fetcher&
operator>>(Fetcher&,
unsigned long&);
89 friend Fetcher&
operator>>(Fetcher&,
unsigned long long&);
93 explicit Fetcher(
char*
buffer) : buffer_(buffer), save_(
nullptr), delims_(
" \t\n\f\v\r") {}
97 const char*
t = getItem();
99 return boost::lexical_cast<
int>(
t);
102 const char*
t = getItem();
104 return boost::lexical_cast<
long>(
t);
106 unsigned int getUInt() {
107 const char*
t = getItem();
109 return boost::lexical_cast<
unsigned int>(
t);
111 unsigned long getULong() {
112 const char*
t = getItem();
114 return boost::lexical_cast<
unsigned long>(
t);
116 unsigned long long getULongLong() {
117 const char*
t = getItem();
119 return boost::lexical_cast<
unsigned long long>(
t);
121 char getChar() {
return *getItem(); }
124 char* item = strtok_r(buffer_, delims_, &
save());
135 char const*
const delims_;
138 Fetcher&
operator>>(Fetcher& iFetch,
int& oValue) {
139 oValue = iFetch.getInt();
142 Fetcher&
operator>>(Fetcher& iFetch,
long& oValue) {
143 oValue = iFetch.getLong();
146 Fetcher&
operator>>(Fetcher& iFetch,
unsigned int& oValue) {
147 oValue = iFetch.getUInt();
150 Fetcher&
operator>>(Fetcher& iFetch,
unsigned long& oValue) {
151 oValue = iFetch.getULong();
154 Fetcher&
operator>>(Fetcher& iFetch,
unsigned long long& oValue) {
155 oValue = iFetch.getULongLong();
158 Fetcher&
operator>>(Fetcher& iFetch,
char& oValue) {
159 oValue = iFetch.getChar();
163 oValue = iFetch.getString();
171 ProcInfoFetcher::ProcInfoFetcher() : pg_size_(sysconf(_SC_PAGESIZE)) {
173 std::ostringstream ost;
174 ost <<
"/proc/" << getpid() <<
"/stat";
176 if ((
fd_ = open(ost.str().c_str(), O_RDONLY)) < 0) {
190 double pr_size = 0.0, pr_rssize = 0.0;
195 lseek(
fd_, 0, SEEK_SET);
197 if ((cnt = read(
fd_,
buf_,
sizeof(
buf_) - 1)) < 0) {
198 perror(
"Read of Proc file failed:");
206 Fetcher fetcher(
buf_);
207 fetcher >> pinfo.pid >> pinfo.comm >> pinfo.state >> pinfo.ppid >> pinfo.pgrp >> pinfo.session >> pinfo.tty >>
208 pinfo.tpgid >> pinfo.flags >> pinfo.minflt >> pinfo.cminflt >> pinfo.majflt >> pinfo.cmajflt >>
209 pinfo.utime >> pinfo.stime >> pinfo.cutime >> pinfo.cstime >> pinfo.priority >> pinfo.nice >>
210 pinfo.num_threads >> pinfo.itrealvalue >> pinfo.starttime >> pinfo.vsize >> pinfo.rss >> pinfo.rlim >>
211 pinfo.startcode >> pinfo.endcode >> pinfo.startstack >> pinfo.kstkesp >> pinfo.kstkeip >> pinfo.signal >>
212 pinfo.blocked >> pinfo.sigignore >> pinfo.sigcatch >> pinfo.wchan;
213 }
catch (boost::bad_lexical_cast& iE) {
214 LogWarning(
"ProcInfoFetcher") <<
"Parsing of Prof file failed:" << iE.what() << std::endl;
219 pr_size = (double)pinfo.vsize;
220 pr_rssize = (
double)pinfo.rss;
222 ret.
vsize = pr_size / (1024.0 * 1024.0);
223 ret.
rss = (pr_rssize *
pg_size_) / (1024.0 * 1024.0);
std::vector< Variable::Flags > flags
int getInt(ResultSet *rset, int ipar)
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
std::istream & operator>>(std::istream &input, CLHEP::HepGenMatrix &matrix)