MCPcopy Create free account
hub / github.com/apache/brpc / ParseCpuInfo

Function ParseCpuInfo

src/butil/cpu.cc:105–127  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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.
105std::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
129class LazyCpuInfoValue {
130 public:

Callers 1

LazyCpuInfoValueMethod · 0.85

Calls 6

ReadFileToStringFunction · 0.85
compareMethod · 0.80
substrMethod · 0.80
FilePathClass · 0.50
emptyMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected