CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
edm::service::CPU Class Reference
Inheritance diagram for edm::service::CPU:
edm::CPUServiceBase

Public Member Functions

 CPU (ParameterSet const &, ActivityRegistry &)
 
bool cpuInfo (std::string &models, double &avgSpeed) override
 CPU information - the models present and average speed. More...
 
 ~CPU () override
 
- Public Member Functions inherited from edm::CPUServiceBase
 CPUServiceBase ()
 
virtual ~CPUServiceBase ()
 

Static Public Member Functions

static void fillDescriptions (ConfigurationDescriptions &descriptions)
 

Private Member Functions

bool cpuInfoImpl (std::string &models, double &avgSpeed, Service< JobReport > *reportSvc)
 
double getAverageSpeed (const std::vector< std::pair< std::string, std::string >> &info)
 
std::string getModels (const std::vector< std::pair< std::string, std::string >> &info)
 
bool parseCPUInfo (std::vector< std::pair< std::string, std::string >> &info)
 
void postEndJob ()
 

Private Attributes

const bool reportCPUProperties_
 

Detailed Description

Definition at line 39 of file CPU.cc.

Constructor & Destructor Documentation

edm::service::CPU::CPU ( ParameterSet const &  ,
ActivityRegistry  
)

Definition at line 144 of file CPU.cc.

References postEndJob(), and edm::ActivityRegistry::watchPostEndJob().

144  :
145  reportCPUProperties_(iPS.getUntrackedParameter<bool>("reportCPUProperties"))
146  {
147  iRegistry.watchPostEndJob(this,&CPU::postEndJob);
148  }
void postEndJob()
Definition: CPU.cc:161
const bool reportCPUProperties_
Definition: CPU.cc:49
edm::service::CPU::~CPU ( )
override

Definition at line 151 of file CPU.cc.

152  {
153  }

Member Function Documentation

bool edm::service::CPU::cpuInfo ( std::string &  models,
double &  avgSpeed 
)
overridevirtual

CPU information - the models present and average speed.

Implements edm::CPUServiceBase.

Definition at line 206 of file CPU.cc.

References getAverageSpeed(), getModels(), info(), and parseCPUInfo().

207  {
208  std::vector<std::pair<std::string, std::string>> info;
209  if (!parseCPUInfo(info)) {return false;}
210 
211  models = getModels(info);
212  avgSpeed = getAverageSpeed(info);
213  return true;
214  }
static const TGPicture * info(bool iBackgroundIsBlack)
double getAverageSpeed(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:277
Definition: models.py:1
bool parseCPUInfo(std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:216
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:260
bool edm::service::CPU::cpuInfoImpl ( std::string &  models,
double &  avgSpeed,
Service< JobReport > *  reportSvc 
)
private
void edm::service::CPU::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 155 of file CPU.cc.

References edm::ConfigurationDescriptions::add(), and edm::ParameterSetDescription::addUntracked().

155  {
157  desc.addUntracked<bool>("reportCPUProperties", false);
158  descriptions.add("CPU", desc);
159  }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double edm::service::CPU::getAverageSpeed ( const std::vector< std::pair< std::string, std::string >> &  info)
private

Definition at line 277 of file CPU.cc.

References mps_splice::entry, and info().

Referenced by cpuInfo(), and postEndJob().

278  {
279  double averageCoreSpeed = 0.0;
280  unsigned coreCount = 0;
281  for (const auto &entry : info) {
282  if (entry.first == "cpu MHz") {
283  averageCoreSpeed += str2d(entry.second);
284  coreCount ++;
285  }
286  }
287  if (!coreCount) {return 0;}
288  return averageCoreSpeed / static_cast<double>(coreCount);
289  }
static const TGPicture * info(bool iBackgroundIsBlack)
std::string edm::service::CPU::getModels ( const std::vector< std::pair< std::string, std::string >> &  info)
private

Definition at line 260 of file CPU.cc.

References mps_splice::entry, and info().

Referenced by cpuInfo(), and postEndJob().

261  {
262  std::set<std::string> models;
263  for (const auto &entry : info) {
264  if (entry.first == "model name") {
265  models.insert(entry.second);
266  }
267  }
268  std::stringstream ss;
269  int model = 0;
270  for (const auto &modelname : models) {
271  if (model++ != 0) {ss << ", ";}
272  ss << modelname;
273  }
274  return ss.str();
275  }
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: models.py:1
bool edm::service::CPU::parseCPUInfo ( std::vector< std::pair< std::string, std::string >> &  info)
private

Definition at line 216 of file CPU.cc.

References info(), AlCaHLTBitMon_QueryRunRegistry::string, ntuplemaker::time, and relativeConstraints::value.

Referenced by cpuInfo(), and postEndJob().

217  {
218  info.clear();
219  std::ifstream fcpuinfo ("/proc/cpuinfo");
220  if (!fcpuinfo.is_open()) {
221  return false;
222  }
223  while (!fcpuinfo.eof()) {
224  std::string buf;
225  std::getline(fcpuinfo, buf);
226 
227  std::istringstream iss(buf);
228  std::string token;
229  std::string property;
231 
232  int time = 1;
233 
234  while(std::getline(iss, token, ':')) {
235  switch(time){
236  case 1:
237  property = token;
238  break;
239  case 2:
240  value = token;
241  break;
242  default:
243  value += token;
244  break;
245  }
246  time++;
247  }
248  trim(property);
249  trim(value);
250  if (property.empty()) {continue;}
251 
252  if (property == "model name"){
253  value = eraseExtraSpaces(value);
254  }
255  info.emplace_back(property, value);
256  }
257  return true;
258  }
static const TGPicture * info(bool iBackgroundIsBlack)
void edm::service::CPU::postEndJob ( )
private

Definition at line 161 of file CPU.cc.

References edm::service::d2str(), mps_splice::entry, getAverageSpeed(), getModels(), edm::service::i2str(), info(), parseCPUInfo(), reportCPUProperties_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CPU().

161  {
162  Service<JobReport> reportSvc;
163 
164  std::vector<std::pair<std::string, std::string>> info;
165  if (!parseCPUInfo(info)) {return;}
166 
167  std::string models = getModels(info);
168  double avgSpeed = getAverageSpeed(info);
169  unsigned totalNumberCPUs = 0;
170  std::map<std::string, std::string> currentCoreProperties;
171  std::string currentCore;
172 
173  for (const auto &entry : info) {
174  if (entry.first == "processor") {
175  if (reportCPUProperties_) {
176  if (currentCore.empty()) { // first core
177  currentCore = entry.second;
178  } else {
179  reportSvc->reportPerformanceForModule("SystemCPU", "CPU-"+currentCore, currentCoreProperties);
180  currentCoreProperties.clear();
181  currentCore = entry.second;
182  }
183  }
184  totalNumberCPUs++;
185  } else if (reportCPUProperties_) {
186  currentCoreProperties.insert(entry);
187  }
188  }
189  if (!currentCore.empty() && reportCPUProperties_) {
190  reportSvc->reportPerformanceForModule("SystemCPU", "CPU-"+currentCore, currentCoreProperties);
191  }
192 
193 
194  std::map<std::string, std::string> reportCPUProperties{
195  {"totalCPUs", i2str(totalNumberCPUs)},
196  {"averageCoreSpeed", d2str(avgSpeed)},
197  {"CPUModels", models}
198  };
199  unsigned set_size = -1;
200  if (getCpuSetSize(set_size)) {
201  reportCPUProperties.insert(std::make_pair("cpusetCount", i2str(set_size)));
202  }
203  reportSvc->reportPerformanceSummary("SystemCPU", reportCPUProperties);
204  }
static std::string i2str(int i)
static const TGPicture * info(bool iBackgroundIsBlack)
double getAverageSpeed(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:277
Definition: models.py:1
bool parseCPUInfo(std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:216
static std::string d2str(double d)
const bool reportCPUProperties_
Definition: CPU.cc:49
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:260

Member Data Documentation

const bool edm::service::CPU::reportCPUProperties_
private

Definition at line 49 of file CPU.cc.

Referenced by postEndJob().