Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:46

0001 #include <string>
0002 #include <boost/predef/os.h>
0003 
0004 #if BOOST_OS_LINUX
0005 // Linux
0006 #include <fstream>
0007 #include <regex>
0008 #endif  // BOOST_OS_LINUX
0009 
0010 #if BOOST_OS_BSD || BOOST_OS_MACOS
0011 // OSX or BSD
0012 #include <sys/types.h>
0013 #include <sys/sysctl.h>
0014 #endif  // BOOST_OS_BSD || BOOST_OS_MACOS
0015 
0016 #include "HLTrigger/Timer/interface/processor_model.h"
0017 
0018 std::string read_processor_model() {
0019 #if BOOST_OS_LINUX
0020   // on Linux, read the processor  model from /proc/cpuinfo
0021   static const std::regex pattern("^model name\\s*:\\s*(.*)", std::regex::optimize);
0022   std::smatch match;
0023 
0024   std::ifstream cpuinfo("/proc/cpuinfo", std::ios::in);
0025   std::string line;
0026   while (cpuinfo.good()) {
0027     std::getline(cpuinfo, line);
0028     if (std::regex_match(line, match, pattern)) {
0029       return match[1];
0030     }
0031   }
0032 #endif  // BOOST_OS_LINUX
0033 
0034 #if BOOST_OS_BSD || BOOST_OS_MACOS
0035   // on BSD and OS X, read the processor  model via sysctlbyname("machdep.cpu.brand_string", ...)
0036   std::string result;
0037   size_t len;
0038   sysctlbyname("machdep.cpu.brand_string", nullptr, &len, NULL, 0);
0039   result.resize(len);
0040   sysctlbyname("machdep.cpu.brand_string", result.data(), &len, NULL, 0);
0041   return result;
0042 #endif  // BOOST_OS_BSD || BOOST_OS_MACOS
0043 
0044   return "unknown";
0045 }
0046 
0047 const std::string processor_model = read_processor_model();