ATLAS Offline Software
PerfUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <sys/types.h>
8 #include <unistd.h>
9 
10 #include <algorithm>
11 #include <fstream>
12 #include <iostream>
13 #include <sstream>
14 
15 // copied and modified from GEOMODELKERNEL GeoPerfUtils
16 
18  int memSize = 0;
19  pid_t pid = getpid();
20  std::ostringstream procstream;
21  procstream << "/proc/" << pid << "/status";
22  std::ifstream memfile(procstream.str());
23  std::string line;
24  if (memfile.is_open()) {
25  while (std::getline(memfile, line)) {
26  std::size_t pos = line.find("VmSize:");
27  if (pos != std::string::npos) {
28  std::string myStr = line.substr(pos + 7);
29  myStr.erase(std::remove(myStr.begin(), myStr.end(), ' '), myStr.end());
30  myStr.erase(std::remove(myStr.begin(), myStr.end(), '\t'), myStr.end());
31  memSize = std::atoi(myStr.substr(0, myStr.find("kB")).c_str());
32  }
33  }
34  memfile.close();
35  }
36  return memSize;
37 }
38 
39 void PerfUtils::getCpu(int& uTime, int& sTime) {
40  // return ms
41  pid_t pid = getpid();
42  std::ostringstream procstream;
43  procstream << "/proc/" << pid << "/stat";
44  std::ifstream memfile(procstream.str());
45  std::string longString;
46  memfile >> longString;
47 
48  int nblancks = 0;
49  uTime = 0;
50  sTime = 0;
51 
52  char line[256];
53  while ((memfile >> line)) {
54  nblancks++;
55  if (nblancks == 13) {
56  memfile >> line;
57  std::istringstream istream(line);
58  istream >> uTime;
59  uTime = uTime * 10;
60  memfile >> line;
61  std::istringstream istream1(line);
62  istream1 >> sTime;
63  sTime = sTime * 10;
64  return;
65  }
66  }
67 }
checkxAOD.memSize
memSize
Definition: Tools/PyUtils/bin/checkxAOD.py:156
pid_t
int32_t pid_t
Definition: FPGATrackSimTypes.h:19
checkFileSG.line
line
Definition: checkFileSG.py:75
PerfUtils::getCpu
static void getCpu(int &uTime, int &sTime)
Definition: PerfUtils.cxx:39
PerfUtils.h
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
PerfUtils::getMem
static int getMem()
Definition: PerfUtils.cxx:17