19 #include "cpu_features/cpu_features_macros.h" 21 #if defined(CPU_FEATURES_ARCH_X86) 22 #include "cpu_features/cpuinfo_x86.h" 23 #elif defined(CPU_FEATURES_ARCH_ARM) 24 #include "cpu_features/cpuinfo_arm.h" 25 #elif defined(CPU_FEATURES_ARCH_AARCH64) 26 #include "cpu_features/cpuinfo_aarch64.h" 27 #elif defined(CPU_FEATURES_ARCH_PPC) 28 #include "cpu_features/cpuinfo_ppc.h" 33 #include <sys/resource.h> 39 #include <fmt/format.h> 93 if (
p != std::string::npos) {
96 s =
s.erase(0,
s.find_first_not_of(
drop));
100 bool founded =
false;
102 for (std::string::const_iterator iter =
s.begin(); iter !=
s.end(); iter++) {
123 bool getCpuSetSize(
unsigned &set_size) {
126 unsigned current_size = 128;
127 unsigned cpu_count = 0;
128 while (current_size * 2 > current_size) {
129 cpusetp = CPU_ALLOC(current_size);
130 CPU_ZERO_S(CPU_ALLOC_SIZE(current_size), cpusetp);
132 if (sched_getaffinity(0, CPU_ALLOC_SIZE(current_size), cpusetp)) {
134 if (errno == EINVAL) {
140 cpu_count = CPU_COUNT_S(CPU_ALLOC_SIZE(current_size), cpusetp);
144 set_size = cpu_count;
153 : reportCPUProperties_(iPS.getUntrackedParameter<
bool>(
"reportCPUProperties")) {
161 desc.addUntracked<
bool>(
"reportCPUProperties",
false);
168 std::vector<std::pair<std::string, std::string>>
info;
175 unsigned totalNumberCPUs = 0;
176 std::map<std::string, std::string> currentCoreProperties;
180 if (
entry.first ==
"processor") {
182 if (currentCore.empty()) {
183 currentCore =
entry.second;
185 reportSvc->reportPerformanceForModule(
"SystemCPU",
"CPU-" + currentCore, currentCoreProperties);
186 currentCoreProperties.clear();
187 currentCore =
entry.second;
192 currentCoreProperties.insert(
entry);
196 reportSvc->reportPerformanceForModule(
"SystemCPU",
"CPU-" + currentCore, currentCoreProperties);
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)));
205 reportSvc->reportPerformanceSummary(
"SystemCPU", reportCPUProperties);
209 std::vector<std::pair<std::string, std::string>>
info;
221 std::ifstream fcpuinfo(
"/proc/cpuinfo");
222 if (!fcpuinfo.is_open()) {
225 while (!fcpuinfo.eof()) {
227 std::getline(fcpuinfo,
buf);
229 std::istringstream iss(
buf);
236 while (std::getline(iss,
token,
':')) {
252 if (property.empty()) {
256 if (property ==
"model name") {
265 using namespace cpu_features;
268 #if defined(CPU_FEATURES_ARCH_X86) 269 const auto info{GetX86Info()};
271 #elif defined(CPU_FEATURES_ARCH_ARM) 272 const auto info{GetArmInfo()};
274 #elif defined(CPU_FEATURES_ARCH_AARCH64) 275 const auto info{GetAarch64Info()};
277 #elif defined(CPU_FEATURES_ARCH_PPC) 278 const auto strings{GetPPCPlatformStrings()};
285 std::set<std::string>
models;
287 if (
entry.first ==
"model name") {
291 std::stringstream
ss;
293 for (
const auto &modelname :
models) {
308 double averageCoreSpeed = 0.0;
309 unsigned coreCount = 0;
311 if (
entry.first ==
"cpu MHz") {
312 averageCoreSpeed += str2d(
entry.second);
319 return averageCoreSpeed /
static_cast<double>(coreCount);
static std::string i2str(int i)
double getAverageSpeed(const std::vector< std::pair< std::string, std::string >> &info)
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
bool isProcessWideService(TFileService const *)
static void trim(std::string &s)
edm::serviceregistry::AllArgsMaker< edm::CPUServiceBase, CPU > CPUMaker
bool cpuInfo(std::string &models, double &avgSpeed) override
CPU information - the models present and average speed.
bool parseCPUInfo(std::vector< std::pair< std::string, std::string >> &info)
CPU(ParameterSet const &, ActivityRegistry &)
static std::string d2str(double d)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool cpuInfoImpl(std::string &models, double &avgSpeed, Service< JobReport > *reportSvc)
std::string getModelFromCPUFeatures()
static void fillDescriptions(ConfigurationDescriptions &descriptions)
const bool reportCPUProperties_
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)