24 #include <sys/resource.h>
82 return atof(s.c_str());
87 if(p != std::string::npos) {
90 s = s.erase(0, s.find_first_not_of(
drop));
96 for(std::string::const_iterator iter = s.begin(); iter != s.end(); iter++){
98 if(*iter ==
' ') founded =
true;
100 aux +=
" "; aux += *iter;
105 if(*iter ==
' ') founded =
true;
114 bool getCpuSetSize(
unsigned &set_size) {
117 unsigned current_size = 128;
118 unsigned cpu_count = 0;
119 while (current_size*2 > current_size) {
120 cpusetp = CPU_ALLOC(current_size);
121 CPU_ZERO_S(CPU_ALLOC_SIZE(current_size), cpusetp);
123 if (sched_getaffinity(0, CPU_ALLOC_SIZE(current_size), cpusetp)) {
125 if (errno == EINVAL) {
131 cpu_count = CPU_COUNT_S(CPU_ALLOC_SIZE(current_size), cpusetp);
135 set_size = cpu_count;
145 reportCPUProperties_(iPS.getUntrackedParameter<bool>(
"reportCPUProperties"))
158 descriptions.
add(
"CPU", desc);
164 std::vector<std::pair<std::string, std::string>>
info;
169 unsigned totalNumberCPUs = 0;
170 std::map<std::string, std::string> currentCoreProperties;
173 for (
const auto &
entry : info) {
174 if (
entry.first ==
"processor") {
176 if (currentCore.empty()) {
177 currentCore =
entry.second;
179 reportSvc->reportPerformanceForModule(
"SystemCPU",
"CPU-"+currentCore, currentCoreProperties);
180 currentCoreProperties.clear();
181 currentCore =
entry.second;
186 currentCoreProperties.insert(
entry);
190 reportSvc->reportPerformanceForModule(
"SystemCPU",
"CPU-"+currentCore, currentCoreProperties);
194 std::map<std::string, std::string> reportCPUProperties{
195 {
"totalCPUs",
i2str(totalNumberCPUs)},
196 {
"averageCoreSpeed",
d2str(avgSpeed)},
197 {
"CPUModels", models}
199 unsigned set_size = -1;
200 if (getCpuSetSize(set_size)) {
201 reportCPUProperties.insert(std::make_pair(
"cpusetCount",
i2str(set_size)));
203 reportSvc->reportPerformanceSummary(
"SystemCPU", reportCPUProperties);
208 std::vector<std::pair<std::string, std::string>>
info;
219 std::ifstream fcpuinfo (
"/proc/cpuinfo");
220 if (!fcpuinfo.is_open()) {
223 while (!fcpuinfo.eof()) {
225 std::getline(fcpuinfo, buf);
227 std::istringstream iss(buf);
234 while(std::getline(iss, token,
':')) {
250 if (property.empty()) {
continue;}
252 if (property ==
"model name"){
253 value = eraseExtraSpaces(value);
255 info.emplace_back(property, value);
262 std::set<std::string> models;
264 if (
entry.first ==
"model name") {
265 models.insert(
entry.second);
268 std::stringstream
ss;
270 for (
const auto &modelname : models) {
271 if (model++ != 0) {ss <<
", ";}
279 double averageCoreSpeed = 0.0;
280 unsigned coreCount = 0;
282 if (
entry.first ==
"cpu MHz") {
283 averageCoreSpeed += str2d(
entry.second);
287 if (!coreCount) {
return 0;}
288 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)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
bool isProcessWideService(TFileService const *)
virtual 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 &)
edm::serviceregistry::AllArgsMaker< edm::CPUServiceBase, CPU > CPUMaker
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)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
const bool reportCPUProperties_
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)