#include <sys/utsname.h>
#endif
+#include <cstdlib>
#include <fstream>
+#include <iterator>
+#include <vector>
#include <boost/algorithm/string.hpp>
+#include "acconfig.h"
#include "include/compat.h"
#include "include/util.h"
#include "common/debug.h"
snprintf(str, sizeof str, "%" PRIu64 "%sB", count, s[i]);
return std::string(str);
}
+
+#ifndef _WIN32
+bool ceph::read_process_cpu_ticks(uint64_t* total, ceph::proc_stat_error* 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;
+ }
+ return false;
+ }
+
+ std::vector<std::string> stat_vec((std::istream_iterator<std::string>{stat_file}),
+ std::istream_iterator<std::string>());
+ if (stat_vec.size() < 15) {
+ if (error) {
+ *error = ceph::proc_stat_error::not_resolvable;
+ }
+ return false;
+ }
+
+ uint64_t utime = std::strtoull(stat_vec[13].c_str(), nullptr, 10);
+ uint64_t stime = std::strtoull(stat_vec[14].c_str(), nullptr, 10);
+ *total = utime + stime;
+ return true;
+}
+#else
+bool ceph::read_process_cpu_ticks(uint64_t* total, ceph::proc_stat_error* error)
+{
+ if (error) {
+ *error = ceph::proc_stat_error::not_found;
+ }
+ return false;
+}
+#endif
std::string cleanbin(ceph::buffer::list &bl, bool &b64, bool show = false);
std::string cleanbin(std::string &str);
-namespace ceph::util {
+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);
+
+namespace util {
// Returns true if s matches any parameters:
template <typename ...XS>
return ((s == xs) || ...);
}
-} // namespace ceph::util
+} // namespace util
+} // namespace ceph
#endif /* CEPH_UTIL_H */
#include "common/config.h"
#include "common/debug.h"
#include "common/errno.h"
+#include "include/util.h"
/* Note, by default debug_mds_balancer is 1/5. For debug messages 1<lvl<=5,
* should_gather (below) will be true; so, debug_mds will be ignored even if
uint64_t cpu_time = 1;
{
uint64_t ticks = 0;
- ceph::mds::proc_stat_error err;
- if (ceph::mds::read_process_cpu_ticks(&ticks, &err)) {
+ ceph::proc_stat_error 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::mds::proc_stat_error::not_resolvable) {
+ if (err == ceph::proc_stat_error::not_resolvable) {
derr << "input file '" << stat_path << "' not resolvable" << dendl_impl;
- } else if (err == ceph::mds::proc_stat_error::not_found) {
+ } else if (err == ceph::proc_stat_error::not_found) {
derr << "input file '" << stat_path << "' not found" << dendl_impl;
}
}
using TOPNSPC::common::cmd_getval;
using TOPNSPC::common::cmd_getval_or;
-namespace ceph::mds {
-bool read_process_cpu_ticks(uint64_t* total, proc_stat_error* error)
-{
- ceph_assert(total != nullptr);
- if (error) {
- *error = 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 = proc_stat_error::not_found;
- }
- return false;
- }
-
- std::vector<std::string> stat_vec((std::istream_iterator<std::string>{stat_file}),
- std::istream_iterator<std::string>());
- if (stat_vec.size() < 15) {
- if (error) {
- *error = proc_stat_error::not_resolvable;
- }
- return false;
- }
-
- uint64_t utime = std::strtoull(stat_vec[13].c_str(), nullptr, 10);
- uint64_t stime = std::strtoull(stat_vec[14].c_str(), nullptr, 10);
- *total = utime + stime;
- return true;
-}
-}
-
class C_Flush_Journal : public MDSInternalContext {
public:
C_Flush_Journal(MDCache *mdcache, MDLog *mdlog, MDSRank *mds,
l_mdm_last,
};
-namespace ceph::mds {
-enum class proc_stat_error {
- none,
- not_found,
- not_resolvable
-};
-bool read_process_cpu_ticks(uint64_t* total, proc_stat_error* error = nullptr);
-}
-
namespace ceph {
struct heartbeat_handle_d;
}
#include "common/errno.h"
#include "common/perf_counters.h"
#include "common/perf_counters_key.h"
+#include "include/util.h"
#include "include/fs_types.h"
#include "include/stringify.h"
void MetricsHandler::sample_cpu_usage() {
uint64_t current_ticks = 0;
- ceph::mds::proc_stat_error err;
+ ceph::proc_stat_error err;
if (clk_tck <= 0) {
rank_telemetry.metrics.cpu_usage_percent = 0;
return;
}
- if (!ceph::mds::read_process_cpu_ticks(¤t_ticks, &err)) {
+ if (!ceph::read_process_cpu_ticks(¤t_ticks, &err)) {
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::mds::proc_stat_error::not_resolvable) {
+ if (err == ceph::proc_stat_error::not_resolvable) {
dout(5) << "input file '" << stat_path << "' not resolvable" << dendl;
- } else if (err == ceph::mds::proc_stat_error::not_found) {
+ } else if (err == ceph::proc_stat_error::not_found) {
dout(5) << "input file '" << stat_path << "' not found" << dendl;
}
return;