75 std::string
when {
"geometry|sensitives" };
77 void print_status(
const char* tag,
const StatusProcess& sp)
const;
104 #include <sys/types.h>
105 #include <sys/stat.h>
116 class FileDescriptor {
122 FileDescriptor(
int value) : m_fd(value) {}
126 int get()
const {
return m_fd; }
134 SysFile(
const char* name) : m_name(name) {}
136 SysFile(
const std::string& name) : m_name(name) {}
140 int read(
char* buffer,
size_t len)
const;
144 SysFile::FileDescriptor::~FileDescriptor() {
145 if (m_fd > 0) ::close(m_fd);
150 int SysFile::read(
char* buf,
size_t siz)
const {
151 FileDescriptor fd(::open(m_name.c_str(),O_RDONLY));
153 std::string err =
"Failed to open "+m_name+
" ";
154 throw std::runtime_error(err+std::make_error_code(std::errc(errno)).message());
157 while ( tmp < siz ) {
158 int sc = ::read(fd.get(),buf+tmp,siz-tmp);
162 else if ( sc == 0 ) {
166 else if ( errno == EINTR ) {
167 printf(
"EINTR~!!!!\n");
175 std::string err =
"Read of system file "+m_name+
" failed:";
176 throw std::runtime_error(err+std::make_error_code(std::errc(errno)).message());
181 int read_info(Geant4DetectorConstructionResources::StatusProcess& proc,
int proc_id) {
182 char buff[2048], *ptr=buff;
183 std::string fn =
"/proc/"+std::to_string(proc_id)+
"/status";
184 int nitem=0, cnt=SysFile(fn.c_str()).read(buff,
sizeof(buff));
189 while(ptr && ptr<(buff+cnt)) {
190 char* p = ::strchr(ptr,
'\t');
191 char* end = ::strchr(ptr,
'\n');
193 ptr = (end) ? end+1 : 0;
194 if ( 0 == p )
continue;
197 case 1: ::sscanf(p,
"%s",proc.comm);
break;
198 case 2: ::sscanf(p,
"%d",&ival); proc.umask = ival;
break;
199 case 3: ::sscanf(p,
"%c",&proc.state);
break;
200 case 4: ::sscanf(p,
"%d",&ival); proc.tgid = ival;
break;
201 case 5: ::sscanf(p,
"%d",&ival); proc.ngid = ival;
break;
202 case 6: ::sscanf(p,
"%d",&ival); proc.pid = ival;
break;
203 case 7: ::sscanf(p,
"%d",&ival); proc.ppid = ival;
break;
204 case 8: ::sscanf(p,
"%d",&ival); proc.utrace = ival;
break;
205 case 9: ::sscanf(p,
"%d",&ival); proc.uid = ival;
break;
206 case 10: ::sscanf(p,
"%d",&ival); proc.gid = ival;
break;
207 case 11: ::sscanf(p,
"%d",&ival); proc.fdSize = ival;
break;
208 case 17: ::sscanf(p,
"%ld",&lval); proc.vmPeak = lval;
break;
209 case 18: ::sscanf(p,
"%ld",&lval); proc.vmSize = lval;
break;
210 case 19: ::sscanf(p,
"%ld",&lval); proc.vmLock = lval;
break;
211 case 20: ::sscanf(p,
"%ld",&lval); proc.vmPin = lval;
break;
212 case 21: ::sscanf(p,
"%ld",&lval); proc.vmHWM = lval;
break;
213 case 22: ::sscanf(p,
"%ld",&lval); proc.vmRSS = lval;
break;
214 case 23: ::sscanf(p,
"%ld",&lval); proc.vmRSSano= lval;
break;
215 case 24: ::sscanf(p,
"%ld",&lval); proc.vmRSSfil= lval;
break;
216 case 25: ::sscanf(p,
"%ld",&lval); proc.vmRSSshm= lval;
break;
217 case 26: ::sscanf(p,
"%ld",&lval); proc.vmData = lval;
break;
218 case 27: ::sscanf(p,
"%ld",&lval); proc.vmStack = lval;
break;
219 case 28: ::sscanf(p,
"%ld",&lval); proc.vmExe = lval;
break;
220 case 29: ::sscanf(p,
"%ld",&lval); proc.vmLib = lval;
break;
221 case 30: ::sscanf(p,
"%ld",&lval); proc.vmPTE = lval;
break;
222 case 31: ::sscanf(p,
"%ld",&lval); proc.vmSwap = lval;
break;
248 if ( this->
when.find(
"geometry") != std::string::npos ) {
249 this->
snapshot = std::make_unique<StatusProcess>();
250 read_info(*this->
snapshot, ::getpid());
256 this->
always(
"%s Name: \t%s", tag, sp.comm);
257 this->
always(
"%s State: \t%c", tag, sp.state);
258 this->
always(
"%s Umask: \t%8d", tag, sp.umask);
259 this->
always(
"%s Tgid: \t%8d", tag, sp.tgid);
260 this->
always(
"%s Pid: \t%8d", tag, sp.pid);
261 this->
always(
"%s PPid: \t%8d", tag, sp.ppid);
262 this->
always(
"%s utrace: \t%8d", tag, sp.utrace);
263 this->
always(
"%s Uid: \t%8d", tag, sp.uid);
264 this->
always(
"%s Gid: \t%8d", tag, sp.gid);
265 this->
always(
"%s FDSize: \t%8d", tag, sp.fdSize);
266 this->
always(
"%s VmPeak: \t%8ld kB", tag, sp.vmPeak);
267 this->
always(
"%s VmSize: \t%8ld kB", tag, sp.vmSize);
268 this->
always(
"%s VmLck: \t%8ld kB", tag, sp.vmLock);
269 this->
always(
"%s VmHWM: \t%8ld kB", tag, sp.vmHWM);
270 this->
always(
"%s VmRSS: \t%8ld kB", tag, sp.vmRSS);
271 this->
always(
"%s VmRSS anon: \t%8ld kB", tag, sp.vmRSSano);
272 this->
always(
"%s VmRSS file: \t%8ld kB", tag, sp.vmRSSfil);
273 this->
always(
"%s VmRSS shm: \t%8ld kB", tag, sp.vmRSSshm);
274 this->
always(
"%s VmData: \t%8ld kB", tag, sp.vmData);
275 this->
always(
"%s VmStk: \t%8ld kB", tag, sp.vmStack);
276 this->
always(
"%s VmExe: \t%8ld kB", tag, sp.vmExe);
277 this->
always(
"%s VmLib: \t%8ld kB", tag, sp.vmLib);
278 this->
always(
"%s VmPTE: \t%8ld kB", tag, sp.vmPTE);
283 if ( this->
when.find(
"sensitives") != std::string::npos ) {
285 read_info(rd, ::getpid());
290 this->
always(
" --> DIFFERENCE: FDSize: \t%8d", rd.fdSize - snap.fdSize);
291 this->
always(
" --> DIFFERENCE: VmPeak: \t%8ld kB", rd.vmPeak - snap.vmPeak);
292 this->
always(
" --> DIFFERENCE: VmSize: \t%8ld kB", rd.vmSize - snap.vmSize);
293 this->
always(
" --> DIFFERENCE: VmLck: \t%8ld kB", rd.vmLock - snap.vmLock);
294 this->
always(
" --> DIFFERENCE: VmHWM: \t%8ld kB", rd.vmHWM - snap.vmHWM);
295 this->
always(
" --> DIFFERENCE: VmRSS: \t%8ld kB", rd.vmRSS - snap.vmRSS);
296 this->
always(
" --> DIFFERENCE: VmRSS anon: \t%8ld kB", rd.vmRSSano - snap.vmRSSano);
297 this->
always(
" --> DIFFERENCE: VmRSS file: \t%8ld kB", rd.vmRSSfil - snap.vmRSSfil);
298 this->
always(
" --> DIFFERENCE: VmRSS shm: \t%8ld kB", rd.vmRSSshm - snap.vmRSSshm);
299 this->
always(
" --> DIFFERENCE: VmData: \t%8ld kB", rd.vmData - snap.vmData);
300 this->
always(
" --> DIFFERENCE: VmStk: \t%8ld kB", rd.vmStack - snap.vmStack);
301 this->
always(
" --> DIFFERENCE: VmExe: \t%8ld kB", rd.vmExe - snap.vmExe);
302 this->
always(
" --> DIFFERENCE: VmLib: \t%8ld kB", rd.vmLib - snap.vmLib);
303 this->
always(
" --> DIFFERENCE: VmPTE: \t%8ld kB", rd.vmPTE - snap.vmPTE);