15 os <<
"proc rc: " << pdata.
rc <<
" output: " << pdata.
output;
23 return !(rhs == *
this);
31 std::array<char, 8192> scratch {};
33 FILE *pipe = popen(proc.c_str(),
"r");
34 if (pipe ==
nullptr) {
35 throw std::runtime_error(
"popen() fails: " + proc);
39 while ((inbytes = std::fread(scratch.data(),
sizeof(scratch.at(0)),
sizeof(scratch), pipe)) != 0) {
40 text += std::string(scratch.data(), inbytes);
46 int res = pclose(pipe);
47 rc = WEXITSTATUS(res);
57 pipe_data lscpu = out_pipe::run(
"lscpu -J");
58 std::cout << lscpu.rc << std::endl;
59 std::cout << lscpu.output << std::endl;
65available: 8 nodes (0-7)
66node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 112 113 114 115 116 117 118 119 120 121 122 123 124 125
73 static bool shell_done;
76 size_t numa_node_count = 0;
77 std::vector<std::string> sizes;
78 std::vector<std::string> cpulist;
80 pipe_data numactl = out_pipe::run(
"numactl -H");
83 std::istringstream nss(numactl.output);
84 while (std::getline(nss, line)) {
85 size_t cp = line.find(
':');
86 std::string name = line.substr(0, cp);
87 if (name ==
"available") {
88 std::istringstream iss(line.substr(cp+1));
89 iss >> numa_node_count;
91 if (name.substr(name.length()-4) ==
"cpus" ) {
92 cpulist.push_back(line.substr(cp+2));
94 if (name.substr(name.length()-4) ==
"size" ) {
95 sizes.push_back(line.substr(cp+2));
97 if (name.substr(name.length()-4) ==
"nces" )
100 if (sizes.size() != numa_node_count || cpulist.size() != numa_node_count)
102 std::cout << numa_node_count << std::endl;
103 for (
size_t i = 0; i < numa_node_count; i++) {
104 std::cout << sizes[i] <<std::endl;
105 std::cout << cpulist[i] <<std::endl;
static pipe_data run(const std::string &proc)
int main(int argc, char **argv)
friend std::ostream & operator<<(std::ostream &os, const pipe_data &pdata)
bool operator!=(const pipe_data &rhs) const
bool operator==(const pipe_data &rhs) const