fix: force clear stream state introduced by rdbuf
This commit is contained in:
parent
d573c588b0
commit
d7e29edd02
27
cgroup2.cc
27
cgroup2.cc
@ -280,30 +280,41 @@ void dumpCgroupStats(nsjconf_t *nsjconf, const std::string &cgroup_path) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto res_name = [&](const std::string &res) -> std::string {
|
||||
return cgroup_path + "/" + res;
|
||||
};
|
||||
auto get_length = [&](std::ifstream &f) -> size_t {
|
||||
f.seekg(0, std::ios::end);
|
||||
auto sz = f.tellg();
|
||||
f.seekg(0, std::ios::beg);
|
||||
return sz;
|
||||
};
|
||||
|
||||
const auto stats = {"cpu.stat", "io.stat", "memory.stat"};
|
||||
for (const auto &res : stats) {
|
||||
std::ifstream f(cgroup_path + "/" + res);
|
||||
auto path = res_name(res);
|
||||
std::ifstream f(path);
|
||||
if (!f.is_open()) {
|
||||
PLOG_W("Failed to open cgroup resource file '%s'",
|
||||
(cgroup_path + "/" + res).c_str());
|
||||
PLOG_W("Invalid cgroup resource file '%s'", path.c_str());
|
||||
continue;
|
||||
}
|
||||
dump_file << f.rdbuf();
|
||||
dump_file << std::endl;
|
||||
dump_file << f.rdbuf() << std::endl;
|
||||
dump_file.clear();
|
||||
f.close();
|
||||
}
|
||||
|
||||
const auto mem_stats = {"memory.peak", "memory.swap.peak"};
|
||||
for (const auto &res : mem_stats) {
|
||||
std::ifstream f(cgroup_path + "/" + res);
|
||||
auto path = res_name(res);
|
||||
std::ifstream f(path);
|
||||
if (!f.is_open()) {
|
||||
PLOG_W("Failed to open cgroup resource file '%s'",
|
||||
(cgroup_path + "/" + res).c_str());
|
||||
PLOG_W("Invalid cgroup resource file '%s'", path.c_str());
|
||||
continue;
|
||||
}
|
||||
std::string line;
|
||||
std::getline(f, line);
|
||||
dump_file << res << ' ' << line << std::endl;
|
||||
dump_file.clear();
|
||||
f.close();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user