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 ()
 
 CPUServiceBase (const CPUServiceBase &)=delete
 
const CPUServiceBaseoperator= (const CPUServiceBase &)=delete
 
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 36 of file CPU.cc.

Constructor & Destructor Documentation

◆ CPU()

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

Definition at line 138 of file CPU.cc.

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

139  : reportCPUProperties_(iPS.getUntrackedParameter<bool>("reportCPUProperties")) {
140  iRegistry.watchPostEndJob(this, &CPU::postEndJob);
141  }
void postEndJob()
Definition: CPU.cc:151
const bool reportCPUProperties_
Definition: CPU.cc:46

◆ ~CPU()

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

Definition at line 143 of file CPU.cc.

143 {}

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

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

194  {
195  std::vector<std::pair<std::string, std::string>> info;
196  if (!parseCPUInfo(info)) {
197  return false;
198  }
199 
200  models = getModels(info);
201  avgSpeed = getAverageSpeed(info);
202  return true;
203  }
static const TGPicture * info(bool iBackgroundIsBlack)
double getAverageSpeed(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:268
Definition: models.py:1
bool parseCPUInfo(std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:205
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:250

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

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

145  {
147  desc.addUntracked<bool>("reportCPUProperties", false);
148  descriptions.add("CPU", desc);
149  }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ getAverageSpeed()

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

Definition at line 268 of file CPU.cc.

References mps_splice::entry, and info().

Referenced by cpuInfo(), and postEndJob().

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

◆ getModels()

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

Definition at line 250 of file CPU.cc.

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

Referenced by cpuInfo(), and postEndJob().

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

◆ parseCPUInfo()

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

Definition at line 205 of file CPU.cc.

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

Referenced by cpuInfo(), and postEndJob().

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

◆ postEndJob()

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

Definition at line 151 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().

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

Member Data Documentation

◆ reportCPUProperties_

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

Definition at line 46 of file CPU.cc.

Referenced by postEndJob().