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

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

Definition at line 140 of file CPU.cc.

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

141  : reportCPUProperties_(iPS.getUntrackedParameter<bool>("reportCPUProperties")) {
142  iRegistry.watchPostEndJob(this, &CPU::postEndJob);
143  }
void postEndJob()
Definition: CPU.cc:153
const bool reportCPUProperties_
Definition: CPU.cc:48
edm::service::CPU::~CPU ( )
override

Definition at line 145 of file CPU.cc.

145 {}

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

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

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  }
static const TGPicture * info(bool iBackgroundIsBlack)
double getAverageSpeed(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:270
Definition: models.py:1
bool parseCPUInfo(std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:207
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:252
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 147 of file CPU.cc.

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

147  {
149  desc.addUntracked<bool>("reportCPUProperties", false);
150  descriptions.add("CPU", desc);
151  }
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 270 of file CPU.cc.

References mps_splice::entry, and info().

Referenced by cpuInfo(), and postEndJob().

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

References mps_splice::entry, and info().

Referenced by cpuInfo(), and postEndJob().

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

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

Referenced by cpuInfo(), and postEndJob().

207  {
208  info.clear();
209  std::ifstream fcpuinfo("/proc/cpuinfo");
210  if (!fcpuinfo.is_open()) {
211  return false;
212  }
213  while (!fcpuinfo.eof()) {
214  std::string buf;
215  std::getline(fcpuinfo, buf);
216 
217  std::istringstream iss(buf);
218  std::string token;
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  }
static const TGPicture * info(bool iBackgroundIsBlack)
static void trim(std::string &s)
void edm::service::CPU::postEndJob ( )
private

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

153  {
154  Service<JobReport> reportSvc;
155 
156  std::vector<std::pair<std::string, std::string>> info;
157  if (!parseCPUInfo(info)) {
158  return;
159  }
160 
161  std::string models = getModels(info);
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  }
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:270
Definition: models.py:1
bool parseCPUInfo(std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:207
static std::string d2str(double d)
const bool reportCPUProperties_
Definition: CPU.cc:48
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:252

Member Data Documentation

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

Definition at line 48 of file CPU.cc.

Referenced by postEndJob().