Returns the string found in /proc/cpuinfo under the key "model name" or "Processor". "model name" is used in Linux 3.8 and later (3.7 and later for arm64) and is shown once per CPU. "Processor" is used in earler versions and is shown only once at the top of /proc/cpuinfo regardless of the number CPUs.
| 103 | // arm64) and is shown once per CPU. "Processor" is used in earler versions and |
| 104 | // is shown only once at the top of /proc/cpuinfo regardless of the number CPUs. |
| 105 | std::string ParseCpuInfo() { |
| 106 | const char kModelNamePrefix[] = "model name\t: "; |
| 107 | const char kProcessorPrefix[] = "Processor\t: "; |
| 108 | std::string contents; |
| 109 | ReadFileToString(FilePath("/proc/cpuinfo"), &contents); |
| 110 | DCHECK(!contents.empty()); |
| 111 | std::string cpu_brand; |
| 112 | if (!contents.empty()) { |
| 113 | std::istringstream iss(contents); |
| 114 | std::string line; |
| 115 | while (std::getline(iss, line)) { |
| 116 | if (line.compare(0, strlen(kModelNamePrefix), kModelNamePrefix) == 0) { |
| 117 | cpu_brand.assign(line.substr(strlen(kModelNamePrefix))); |
| 118 | break; |
| 119 | } |
| 120 | if (line.compare(0, strlen(kProcessorPrefix), kProcessorPrefix) == 0) { |
| 121 | cpu_brand.assign(line.substr(strlen(kProcessorPrefix))); |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | return cpu_brand; |
| 127 | } |
| 128 | |
| 129 | class LazyCpuInfoValue { |
| 130 | public: |
no test coverage detected