#include "system_metrics.h" #include "lib/config/config.h" #include "lib/config/protos/system_config.pb.h" #include #include #include #include namespace bts { namespace metrics { struct ProcessStats { int pid; std::string name, state, ppid, pgrp, session, tty_nr; std::string tpgid, flags, minflt, cminflt, majflt, cmajflt; // utime - user time // stime - kernel time // cutime - cumulative user time // cstime - cumulative system time long utime, stime, cutime, cstime, priority, nice; std::string O, itrealvalue, starttime; // virtual size uint64_t vsize; // resident set int64_t rss; }; void read_stats(ProcessStats &stats) { std::ifstream stat_stream("/proc/self/stat", std::ios_base::in); stat_stream >> stats.pid >> stats.name >> stats.state >> stats.ppid >> stats.pgrp >> stats.session >> stats.tty_nr >> stats.tpgid >> stats.flags >> stats.minflt >> stats.cminflt >> stats.majflt >> stats.cmajflt >> stats.utime >> stats.stime >> stats.cutime >> stats.cstime >> stats.priority >> stats.nice >> stats.O >> stats.itrealvalue >> stats.starttime >> stats.vsize >> stats.rss; stat_stream.close(); } void process_mem_usage(double &vm, double &resident) { using std::ifstream; using std::ios_base; vm = resident = 0.0; ProcessStats stats; read_stats(stats); long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; vm = stats.vsize / 1024.0; resident = stats.rss * page_size_kb; } void publish_system_metrics(MetricsContainer &stats) { auto version = std::make_shared>( "spark_version", std::vector