}
#ifndef _WIN32
-bool ceph::read_process_cpu_ticks(uint64_t* total, ceph::proc_stat_error* error)
+bool ceph::read_process_cpu_ticks(uint64_t* total, std::string* error)
{
ceph_assert(total != nullptr);
- if (error) {
- *error = ceph::proc_stat_error::none;
- }
const char* stat_path = PROCPREFIX "/proc/self/stat";
std::ifstream stat_file(stat_path);
if (!stat_file.is_open()) {
if (error) {
- *error = ceph::proc_stat_error::not_found;
+ *error = std::string("failed to open '") + stat_path + "'";
}
return false;
}
std::istream_iterator<std::string>());
if (stat_vec.size() < 15) {
if (error) {
- *error = ceph::proc_stat_error::not_resolvable;
+ *error = std::string("failed to parse '") + stat_path + "'";
}
return false;
}
return true;
}
#else
-bool ceph::read_process_cpu_ticks(uint64_t* total, ceph::proc_stat_error* error)
+bool ceph::read_process_cpu_ticks(uint64_t* total, std::string* error)
{
if (error) {
- *error = ceph::proc_stat_error::not_found;
+ *error = "/proc/self/stat not available on this platform";
}
return false;
}
namespace ceph {
-enum class proc_stat_error {
- none,
- not_found,
- not_resolvable
-};
-
/// Read user+system CPU ticks for the current process from /proc/self/stat
-bool read_process_cpu_ticks(uint64_t* total, proc_stat_error* error = nullptr);
+bool read_process_cpu_ticks(uint64_t* total, std::string* error = nullptr);
namespace util {
uint64_t cpu_time = 1;
{
uint64_t ticks = 0;
- ceph::proc_stat_error err;
+ std::string err;
if (ceph::read_process_cpu_ticks(&ticks, &err)) {
cpu_time = ticks;
} else {
- constexpr const char* stat_path = PROCPREFIX "/proc/self/stat";
- if (err == ceph::proc_stat_error::not_resolvable) {
- derr << "input file '" << stat_path << "' not resolvable" << dendl_impl;
- } else if (err == ceph::proc_stat_error::not_found) {
- derr << "input file '" << stat_path << "' not found" << dendl_impl;
- }
+ derr << err << dendl_impl;
}
}
void MetricsHandler::sample_cpu_usage() {
uint64_t current_ticks = 0;
- ceph::proc_stat_error err;
+ std::string err;
if (clk_tck <= 0) {
rank_telemetry.metrics.cpu_usage_percent = 0;
if (rank_perf_counters) {
rank_perf_counters->set(l_mds_rank_perf_cpu_usage, 0);
}
- constexpr const char* stat_path = PROCPREFIX "/proc/self/stat";
- if (err == ceph::proc_stat_error::not_resolvable) {
- dout(5) << "input file '" << stat_path << "' not resolvable" << dendl;
- } else if (err == ceph::proc_stat_error::not_found) {
- dout(5) << "input file '" << stat_path << "' not found" << dendl;
- }
+ dout(5) << err << dendl;
return;
}