GeoModel - GeoModelCore
GeoPerfUtils.cxx
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GeoModelKernel/GeoPerfUtils.h"
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <sstream>
9 #include <fstream>
10 int GeoPerfUtils::getMem() {
11  int memSize = 0;
12  {
13  pid_t pid = getpid();
14  std::ostringstream procstream;
15  procstream << "/proc/" << pid << "/status";
16  std::ifstream memfile(procstream.str().c_str());
17 
18 
19  std::string line;
20  while ((memfile >> line)) {
21  if (line=="VmSize:") {
22  memfile >> line;
23  std::istringstream istream(line);
24  istream >> memSize;
25  }
26  }
27  }
28  return memSize;
29 }
30 
31 int GeoPerfUtils::getCpu() {
32 
33  pid_t pid = getpid();
34  std::ostringstream procstream;
35  procstream << "/proc/" << pid << "/stat";
36  std::ifstream memfile(procstream.str().c_str());
37 
38  int nblancks=0;
39  int uTime = 0;
40  int sTime = 0;
41 
42  char line[256];
43  while ((memfile >> line)) {
44  nblancks++;
45 
46  if (nblancks==13) {
47  memfile >> line;
48  std::istringstream istream(line);
49  istream >> uTime;
50 
51  memfile >> line;
52  std::istringstream istream1(line);
53  istream1 >> sTime;
54 
55  return uTime+sTime;
56  }
57  }
58  return 0;
59 }