23 #include <sys/resource.h> 81 if (p != std::string::npos) {
84 s = s.erase(0, s.find_first_not_of(
drop));
90 for (std::string::const_iterator iter = s.begin(); iter != s.end(); iter++) {
111 bool getCpuSetSize(
unsigned &set_size) {
114 unsigned current_size = 128;
115 unsigned cpu_count = 0;
116 while (current_size * 2 > current_size) {
117 cpusetp = CPU_ALLOC(current_size);
118 CPU_ZERO_S(CPU_ALLOC_SIZE(current_size), cpusetp);
120 if (sched_getaffinity(0, CPU_ALLOC_SIZE(current_size), cpusetp)) {
122 if (errno == EINVAL) {
128 cpu_count = CPU_COUNT_S(CPU_ALLOC_SIZE(current_size), cpusetp);
132 set_size = cpu_count;
150 descriptions.
add(
"CPU", desc);
156 std::vector<std::pair<std::string, std::string>>
info;
163 unsigned totalNumberCPUs = 0;
164 std::map<std::string, std::string> currentCoreProperties;
167 for (
const auto &
entry : info) {
168 if (
entry.first ==
"processor") {
170 if (currentCore.empty()) {
171 currentCore =
entry.second;
173 reportSvc->reportPerformanceForModule(
"SystemCPU",
"CPU-" + currentCore, currentCoreProperties);
174 currentCoreProperties.clear();
175 currentCore =
entry.second;
180 currentCoreProperties.insert(
entry);
184 reportSvc->reportPerformanceForModule(
"SystemCPU",
"CPU-" + currentCore, currentCoreProperties);
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)));
193 reportSvc->reportPerformanceSummary(
"SystemCPU", reportCPUProperties);
197 std::vector<std::pair<std::string, std::string>>
info;
209 std::ifstream fcpuinfo(
"/proc/cpuinfo");
210 if (!fcpuinfo.is_open()) {
213 while (!fcpuinfo.eof()) {
215 std::getline(fcpuinfo, buf);
217 std::istringstream iss(buf);
224 while (std::getline(iss, token,
':')) {
240 if (property.empty()) {
244 if (property ==
"model name") {
245 value = eraseExtraSpaces(value);
247 info.emplace_back(property, value);
253 std::set<std::string>
models;
255 if (
entry.first ==
"model name") {
256 models.insert(
entry.second);
259 std::stringstream ss;
261 for (
const auto &modelname : models) {
271 double averageCoreSpeed = 0.0;
272 unsigned coreCount = 0;
274 if (
entry.first ==
"cpu MHz") {
275 averageCoreSpeed += str2d(
entry.second);
282 return averageCoreSpeed /
static_cast<double>(coreCount);
static std::string i2str(int i)
double getAverageSpeed(const std::vector< std::pair< std::string, std::string >> &info)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
bool isProcessWideService(TFileService const *)
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
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)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
const bool reportCPUProperties_
std::string getModels(const std::vector< std::pair< std::string, std::string >> &info)