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 38 of file CPU.cc.

Constructor & Destructor Documentation

◆ CPU()

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

Definition at line 140 of file CPU.cc.

141  : reportCPUProperties_(iPS.getUntrackedParameter<bool>("reportCPUProperties")) {
142  iRegistry.watchPostEndJob(this, &CPU::postEndJob);
143  }

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

◆ ~CPU()

edm::service::CPU::~CPU ( )
override

Definition at line 145 of file CPU.cc.

145 {}

Member Function Documentation

◆ cpuInfo()

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 196 of file CPU.cc.

196  {
197  std::vector<std::pair<std::string, std::string>> info;
198  if (!parseCPUInfo(info)) {
199  return false;
200  }
201 
202  models = getModels(info);
203  avgSpeed = getAverageSpeed(info);
204  return true;
205  }

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

◆ cpuInfoImpl()

bool edm::service::CPU::cpuInfoImpl ( std::string &  models,
double &  avgSpeed,
Service< JobReport > *  reportSvc 
)
private

◆ fillDescriptions()

void edm::service::CPU::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 147 of file CPU.cc.

147  {
149  desc.addUntracked<bool>("reportCPUProperties", false);
150  descriptions.add("CPU", desc);
151  }

References edm::ConfigurationDescriptions::add(), and submitPVResolutionJobs::desc.

◆ getAverageSpeed()

double edm::service::CPU::getAverageSpeed ( const std::vector< std::pair< std::string, std::string >> &  info)
private

Definition at line 270 of file CPU.cc.

270  {
271  double averageCoreSpeed = 0.0;
272  unsigned coreCount = 0;
273  for (const auto &entry : info) {
274  if (entry.first == "cpu MHz") {
275  averageCoreSpeed += str2d(entry.second);
276  coreCount++;
277  }
278  }
279  if (!coreCount) {
280  return 0;
281  }
282  return averageCoreSpeed / static_cast<double>(coreCount);
283  }

References mps_splice::entry, and info().

Referenced by cpuInfo(), and postEndJob().

◆ getModels()

std::string edm::service::CPU::getModels ( const std::vector< std::pair< std::string, std::string >> &  info)
private

Definition at line 252 of file CPU.cc.

252  {
253  std::set<std::string> models;
254  for (const auto &entry : info) {
255  if (entry.first == "model name") {
256  models.insert(entry.second);
257  }
258  }
259  std::stringstream ss;
260  int model = 0;
261  for (const auto &modelname : models) {
262  if (model++ != 0) {
263  ss << ", ";
264  }
265  ss << modelname;
266  }
267  return ss.str();
268  }

References mps_splice::entry, info(), ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi::model, and contentValuesCheck::ss.

Referenced by cpuInfo(), and postEndJob().

◆ parseCPUInfo()

bool edm::service::CPU::parseCPUInfo ( std::vector< std::pair< std::string, std::string >> &  info)
private

Definition at line 207 of file CPU.cc.

207  {
208  info.clear();
209  std::ifstream fcpuinfo("/proc/cpuinfo");
210  if (!fcpuinfo.is_open()) {
211  return false;
212  }
213  while (!fcpuinfo.eof()) {
215  std::getline(fcpuinfo, buf);
216 
217  std::istringstream iss(buf);
219  std::string property;
221 
222  int time = 1;
223 
224  while (std::getline(iss, token, ':')) {
225  switch (time) {
226  case 1:
227  property = token;
228  break;
229  case 2:
230  value = token;
231  break;
232  default:
233  value += token;
234  break;
235  }
236  time++;
237  }
238  trim(property);
239  trim(value);
240  if (property.empty()) {
241  continue;
242  }
243 
244  if (property == "model name") {
245  value = eraseExtraSpaces(value);
246  }
247  info.emplace_back(property, value);
248  }
249  return true;
250  }

References visDQMUpload::buf, info(), AlCaHLTBitMon_QueryRunRegistry::string, protons_cff::time, unpackBuffers-CaloStage2::token, trim(), and relativeConstraints::value.

Referenced by cpuInfo(), and postEndJob().

◆ postEndJob()

void edm::service::CPU::postEndJob ( )
private

Definition at line 153 of file CPU.cc.

153  {
154  Service<JobReport> reportSvc;
155 
156  std::vector<std::pair<std::string, std::string>> info;
157  if (!parseCPUInfo(info)) {
158  return;
159  }
160 
162  double avgSpeed = getAverageSpeed(info);
163  unsigned totalNumberCPUs = 0;
164  std::map<std::string, std::string> currentCoreProperties;
165  std::string currentCore;
166 
167  for (const auto &entry : info) {
168  if (entry.first == "processor") {
169  if (reportCPUProperties_) {
170  if (currentCore.empty()) { // first core
171  currentCore = entry.second;
172  } else {
173  reportSvc->reportPerformanceForModule("SystemCPU", "CPU-" + currentCore, currentCoreProperties);
174  currentCoreProperties.clear();
175  currentCore = entry.second;
176  }
177  }
178  totalNumberCPUs++;
179  } else if (reportCPUProperties_) {
180  currentCoreProperties.insert(entry);
181  }
182  }
183  if (!currentCore.empty() && reportCPUProperties_) {
184  reportSvc->reportPerformanceForModule("SystemCPU", "CPU-" + currentCore, currentCoreProperties);
185  }
186 
187  std::map<std::string, std::string> reportCPUProperties{
188  {"totalCPUs", i2str(totalNumberCPUs)}, {"averageCoreSpeed", d2str(avgSpeed)}, {"CPUModels", models}};
189  unsigned set_size = -1;
190  if (getCpuSetSize(set_size)) {
191  reportCPUProperties.insert(std::make_pair("cpusetCount", i2str(set_size)));
192  }
193  reportSvc->reportPerformanceSummary("SystemCPU", reportCPUProperties);
194  }

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

Referenced by CPU().

Member Data Documentation

◆ reportCPUProperties_

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

Definition at line 48 of file CPU.cc.

Referenced by postEndJob().

models
Definition: models.py:1
mps_splice.entry
entry
Definition: mps_splice.py:68
edm::service::CPU::reportCPUProperties_
const bool reportCPUProperties_
Definition: CPU.cc:48
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
protons_cff.time
time
Definition: protons_cff.py:39
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi.model
model
Definition: ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi.py:11
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::service::d2str
static std::string d2str(double d)
Definition: SimpleMemoryCheck.cc:277
edm::service::CPU::getModels
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:252
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::service::CPU::getAverageSpeed
double getAverageSpeed(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:270
Service
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::service::CPU::postEndJob
void postEndJob()
Definition: CPU.cc:153
value
Definition: value.py:1
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
edm::service::i2str
static std::string i2str(int i)
Definition: SimpleMemoryCheck.cc:283
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::service::CPU::parseCPUInfo
bool parseCPUInfo(std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:207
trim
static void trim(std::string &s)
Definition: DTCCablingMapProducer.cc:67
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316