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 getModelFromCPUFeatures ()
 
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 49 of file CPU.cc.

Constructor & Destructor Documentation

◆ CPU()

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

Definition at line 152 of file CPU.cc.

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

153  : reportCPUProperties_(iPS.getUntrackedParameter<bool>("reportCPUProperties")) {
154  iRegistry.watchPostEndJob(this, &CPU::postEndJob);
155  }
void postEndJob()
Definition: CPU.cc:165
const bool reportCPUProperties_
Definition: CPU.cc:59

◆ ~CPU()

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

Definition at line 157 of file CPU.cc.

157 {}

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

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

208  {
209  std::vector<std::pair<std::string, std::string>> info;
210  if (!parseCPUInfo(info)) {
211  return false;
212  }
213 
214  models = getModels(info);
215  avgSpeed = getAverageSpeed(info);
216  return true;
217  }
static const TGPicture * info(bool iBackgroundIsBlack)
double getAverageSpeed(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:307
Definition: models.py:1
bool parseCPUInfo(std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:219
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)
Definition: CPU.cc:284

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

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

159  {
161  desc.addUntracked<bool>("reportCPUProperties", false);
162  descriptions.add("CPU", desc);
163  }
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 307 of file CPU.cc.

References mps_splice::entry, and info().

Referenced by cpuInfo(), and postEndJob().

307  {
308  double averageCoreSpeed = 0.0;
309  unsigned coreCount = 0;
310  for (const auto &entry : info) {
311  if (entry.first == "cpu MHz") {
312  averageCoreSpeed += str2d(entry.second);
313  coreCount++;
314  }
315  }
316  if (!coreCount) {
317  return 0;
318  }
319  return averageCoreSpeed / static_cast<double>(coreCount);
320  }
static const TGPicture * info(bool iBackgroundIsBlack)

◆ getModelFromCPUFeatures()

std::string edm::service::CPU::getModelFromCPUFeatures ( )
private

Definition at line 264 of file CPU.cc.

References dqm-mbProfile::format, info(), ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi::model, AlCaHLTBitMon_QueryRunRegistry::string, and makeListRunsInFiles::strings.

Referenced by getModels().

264  {
265  using namespace cpu_features;
266 
268 #if defined(CPU_FEATURES_ARCH_X86)
269  const auto info{GetX86Info()};
270  model = info.brand_string;
271 #elif defined(CPU_FEATURES_ARCH_ARM)
272  const auto info{GetArmInfo()};
273  model = fmt::format("ARM {} {} {}", info.implementer, info.architecture, info.variant);
274 #elif defined(CPU_FEATURES_ARCH_AARCH64)
275  const auto info{GetAarch64Info()};
276  model = fmt::format("aarch64 {} {}", info.implementer, info.variant);
277 #elif defined(CPU_FEATURES_ARCH_PPC)
278  const auto strings{GetPPCPlatformStrings()};
279  model = strings.machine;
280 #endif
281  return model;
282  }
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 284 of file CPU.cc.

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

Referenced by cpuInfo(), and postEndJob().

284  {
285  std::set<std::string> models;
286  for (const auto &entry : info) {
287  if (entry.first == "model name") {
288  models.insert(entry.second);
289  }
290  }
291  std::stringstream ss;
292  int model = 0;
293  for (const auto &modelname : models) {
294  if (model++ != 0) {
295  ss << ", ";
296  }
297  ss << modelname;
298  }
299  // If "model name" isn't present in /proc/cpuinfo, see what we can get
300  // from cpu_features
301  if (0 == model) {
302  return getModelFromCPUFeatures();
303  }
304  return ss.str();
305  }
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: models.py:1
std::string getModelFromCPUFeatures()
Definition: CPU.cc:264

◆ parseCPUInfo()

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

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

219  {
220  info.clear();
221  std::ifstream fcpuinfo("/proc/cpuinfo");
222  if (!fcpuinfo.is_open()) {
223  return false;
224  }
225  while (!fcpuinfo.eof()) {
227  std::getline(fcpuinfo, buf);
228 
229  std::istringstream iss(buf);
231  std::string property;
233 
234  int time = 1;
235 
236  while (std::getline(iss, token, ':')) {
237  switch (time) {
238  case 1:
239  property = token;
240  break;
241  case 2:
242  value = token;
243  break;
244  default:
245  value += token;
246  break;
247  }
248  time++;
249  }
250  trim(property);
251  trim(value);
252  if (property.empty()) {
253  continue;
254  }
255 
256  if (property == "model name") {
257  value = eraseExtraSpaces(value);
258  }
259  info.emplace_back(property, value);
260  }
261  return true;
262  }
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 165 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().

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

Member Data Documentation

◆ reportCPUProperties_

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

Definition at line 59 of file CPU.cc.

Referenced by postEndJob().