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 &)
 
 ~CPU () override=default
 
- 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

std::string formatModels (const std::vector< std::string > &models) const
 
double getAverageSpeed (const CPUInfoType &info) const
 
std::string getModelFromCPUFeatures () const
 
std::vector< std::string > getModels (const CPUInfoType &info) const
 
bool parseCPUInfo (CPUInfoType &info) const
 
void postEndJob ()
 

Private Attributes

const bool disableJobReportOutput_
 
const bool reportCPUProperties_
 

Detailed Description

Definition at line 52 of file CPU.cc.

Constructor & Destructor Documentation

◆ CPU()

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

Definition at line 124 of file CPU.cc.

References formatModels(), getAverageSpeed(), getModels(), info(), edm::Service< T >::isAvailable(), parseCPUInfo(), postEndJob(), edm::ResourceInformation::setCpuAverageSpeed(), edm::ResourceInformation::setCPUModels(), edm::ResourceInformation::setCpuModelsFormatted(), and edm::ActivityRegistry::watchPostEndJob().

125  : reportCPUProperties_(iPS.getUntrackedParameter<bool>("reportCPUProperties")),
126  disableJobReportOutput_(iPS.getUntrackedParameter<bool>("disableJobReportOutput")) {
127  edm::Service<edm::ResourceInformation> resourceInformationService;
128  if (resourceInformationService.isAvailable()) {
130  if (parseCPUInfo(info)) {
131  const auto models{getModels(info)};
132  resourceInformationService->setCPUModels(models);
133  resourceInformationService->setCpuModelsFormatted(formatModels(models));
134  resourceInformationService->setCpuAverageSpeed(getAverageSpeed(info));
135  }
136  }
137  iRegistry.watchPostEndJob(this, &CPU::postEndJob);
138  }
std::vector< std::pair< std::string, std::string > > CPUInfoType
Definition: CPU.cc:49
static const TGPicture * info(bool iBackgroundIsBlack)
void postEndJob()
Definition: CPU.cc:147
Definition: models.py:1
std::string formatModels(const std::vector< std::string > &models) const
Definition: CPU.cc:276
virtual void setCPUModels(std::vector< std::string > const &)=0
std::vector< std::string > getModels(const CPUInfoType &info) const
Definition: CPU.cc:260
virtual void setCpuModelsFormatted(std::string const &)=0
virtual void setCpuAverageSpeed(double)=0
const bool reportCPUProperties_
Definition: CPU.cc:60
bool isAvailable() const
Definition: Service.h:40
bool parseCPUInfo(CPUInfoType &info) const
Definition: CPU.cc:195
const bool disableJobReportOutput_
Definition: CPU.cc:61
double getAverageSpeed(const CPUInfoType &info) const
Definition: CPU.cc:288

◆ ~CPU()

edm::service::CPU::~CPU ( )
overridedefault

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 140 of file CPU.cc.

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

140  {
142  desc.addUntracked<bool>("reportCPUProperties", false);
143  desc.addUntracked<bool>("disableJobReportOutput", false);
144  descriptions.add("CPU", desc);
145  }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ formatModels()

std::string edm::service::CPU::formatModels ( const std::vector< std::string > &  models) const
private

Definition at line 276 of file CPU.cc.

References ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi::model, and contentValuesCheck::ss.

Referenced by CPU(), and postEndJob().

276  {
277  std::stringstream ss;
278  int model = 0;
279  for (const auto &modelname : models) {
280  if (model++ != 0) {
281  ss << ", ";
282  }
283  ss << modelname;
284  }
285  return ss.str();
286  }
Definition: models.py:1

◆ getAverageSpeed()

double edm::service::CPU::getAverageSpeed ( const CPUInfoType info) const
private

Definition at line 288 of file CPU.cc.

References MillePedeFileConverter_cfg::e, mps_splice::entry, and info().

Referenced by CPU(), and postEndJob().

288  {
289  double averageCoreSpeed = 0.0;
290  unsigned coreCount = 0;
291  for (const auto &entry : info) {
292  if (entry.first == "cpu MHz") {
293  try {
294  averageCoreSpeed += std::stod(entry.second);
295  } catch (const std::logic_error &e) {
296  LogWarning("CPU::getAverageSpeed") << "stod(" << entry.second << ") conversion error: " << e.what();
297  }
298  coreCount++;
299  }
300  }
301  if (!coreCount) {
302  return 0;
303  }
304  return averageCoreSpeed / static_cast<double>(coreCount);
305  }
static const TGPicture * info(bool iBackgroundIsBlack)
Log< level::Warning, false > LogWarning

◆ getModelFromCPUFeatures()

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

Definition at line 240 of file CPU.cc.

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

Referenced by getModels().

240  {
241  using namespace cpu_features;
242 
244 #if defined(CPU_FEATURES_ARCH_X86)
245  const auto info{GetX86Info()};
246  model = info.brand_string;
247 #elif defined(CPU_FEATURES_ARCH_ARM)
248  const auto info{GetArmInfo()};
249  model = fmt::format("ARM {} {} {}", info.implementer, info.architecture, info.variant);
250 #elif defined(CPU_FEATURES_ARCH_AARCH64)
251  const auto info{GetAarch64Info()};
252  model = fmt::format("aarch64 {} {}", info.implementer, info.variant);
253 #elif defined(CPU_FEATURES_ARCH_PPC)
254  const auto strings{GetPPCPlatformStrings()};
255  model = strings.machine;
256 #endif
257  return model;
258  }
static const TGPicture * info(bool iBackgroundIsBlack)

◆ getModels()

std::vector< std::string > edm::service::CPU::getModels ( const CPUInfoType info) const
private

Definition at line 260 of file CPU.cc.

References mps_splice::entry, getModelFromCPUFeatures(), and info().

Referenced by CPU(), and postEndJob().

260  {
261  std::set<std::string> modelSet;
262  for (const auto &entry : info) {
263  if (entry.first == "model name") {
264  modelSet.insert(entry.second);
265  }
266  }
267  std::vector<std::string> modelsVector(modelSet.begin(), modelSet.end());
268  // If "model name" isn't present in /proc/cpuinfo, see what we can get
269  // from cpu_features
270  if (modelsVector.empty()) {
271  modelsVector.emplace_back(getModelFromCPUFeatures());
272  }
273  return modelsVector;
274  }
static const TGPicture * info(bool iBackgroundIsBlack)
std::string getModelFromCPUFeatures() const
Definition: CPU.cc:240

◆ parseCPUInfo()

bool edm::service::CPU::parseCPUInfo ( CPUInfoType info) const
private

Definition at line 195 of file CPU.cc.

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

Referenced by CPU(), and postEndJob().

195  {
196  info.clear();
197  std::ifstream fcpuinfo("/proc/cpuinfo");
198  if (!fcpuinfo.is_open()) {
199  return false;
200  }
201  while (!fcpuinfo.eof()) {
203  std::getline(fcpuinfo, buf);
204 
205  std::istringstream iss(buf);
207  std::string property;
209 
210  int time = 1;
211 
212  while (std::getline(iss, token, ':')) {
213  switch (time) {
214  case 1:
215  property = token;
216  break;
217  case 2:
218  value = token;
219  break;
220  default:
221  value += token;
222  break;
223  }
224  time++;
225  }
226  trim(property);
227  trim(value);
228  if (property.empty()) {
229  continue;
230  }
231 
232  if (property == "model name") {
233  compressWhitespace(value);
234  }
235  info.emplace_back(property, value);
236  }
237  return true;
238  }
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 147 of file CPU.cc.

References disableJobReportOutput_, mps_splice::entry, formatModels(), getAverageSpeed(), getModels(), info(), parseCPUInfo(), reportCPUProperties_, AlCaHLTBitMon_QueryRunRegistry::string, and cond::impl::to_string().

Referenced by CPU().

147  {
149  return;
150  }
151 
152  Service<JobReport> reportSvc;
153 
155  if (!parseCPUInfo(info)) {
156  return;
157  }
158 
159  const auto models{formatModels(getModels(info))};
160  unsigned totalNumberCPUs = 0;
161  std::map<std::string, std::string> currentCoreProperties;
162  std::string currentCore;
163 
164  for (const auto &entry : info) {
165  if (entry.first == "processor") {
166  if (reportCPUProperties_) {
167  if (currentCore.empty()) { // first core
168  currentCore = entry.second;
169  } else {
170  reportSvc->reportPerformanceForModule("SystemCPU", "CPU-" + currentCore, currentCoreProperties);
171  currentCoreProperties.clear();
172  currentCore = entry.second;
173  }
174  }
175  totalNumberCPUs++;
176  } else if (reportCPUProperties_) {
177  currentCoreProperties.insert(entry);
178  }
179  }
180  if (!currentCore.empty() && reportCPUProperties_) {
181  reportSvc->reportPerformanceForModule("SystemCPU", "CPU-" + currentCore, currentCoreProperties);
182  }
183 
184  std::map<std::string, std::string> reportCPUProperties{
185  {"totalCPUs", std::to_string(totalNumberCPUs)},
186  {"averageCoreSpeed", std::to_string(getAverageSpeed(info))},
187  {"CPUModels", models}};
188  unsigned set_size = -1;
189  if (getCpuSetSize(set_size)) {
190  reportCPUProperties.insert(std::make_pair("cpusetCount", std::to_string(set_size)));
191  }
192  reportSvc->reportPerformanceSummary("SystemCPU", reportCPUProperties);
193  }
std::vector< std::pair< std::string, std::string > > CPUInfoType
Definition: CPU.cc:49
static const TGPicture * info(bool iBackgroundIsBlack)
std::string to_string(const V &value)
Definition: OMSAccess.h:71
Definition: models.py:1
std::string formatModels(const std::vector< std::string > &models) const
Definition: CPU.cc:276
std::vector< std::string > getModels(const CPUInfoType &info) const
Definition: CPU.cc:260
const bool reportCPUProperties_
Definition: CPU.cc:60
bool parseCPUInfo(CPUInfoType &info) const
Definition: CPU.cc:195
const bool disableJobReportOutput_
Definition: CPU.cc:61
double getAverageSpeed(const CPUInfoType &info) const
Definition: CPU.cc:288

Member Data Documentation

◆ disableJobReportOutput_

const bool edm::service::CPU::disableJobReportOutput_
private

Definition at line 61 of file CPU.cc.

Referenced by postEndJob().

◆ reportCPUProperties_

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

Definition at line 60 of file CPU.cc.

Referenced by postEndJob().