2020-05-01 18:47:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
|
|
|
|
|
2022-06-10 08:22:31 +00:00
|
|
|
#if defined(OS_LINUX)
|
2020-05-01 18:47:41 +00:00
|
|
|
struct taskstats;
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/// Provides several essential per-task metrics by reading data from Procfs (when available).
|
|
|
|
class ProcfsMetricsProvider : private boost::noncopyable
|
|
|
|
{
|
|
|
|
public:
|
2022-03-11 21:47:28 +00:00
|
|
|
explicit ProcfsMetricsProvider(pid_t /*tid*/);
|
2020-05-01 18:47:41 +00:00
|
|
|
~ProcfsMetricsProvider();
|
|
|
|
|
|
|
|
/// Updates only a part of taskstats struct's fields:
|
|
|
|
/// - cpu_run_virtual_total, cpu_delay_total (when /proc/thread-self/schedstat is available)
|
|
|
|
/// - blkio_delay_total (when /proc/thread-self/stat is available)
|
2022-06-08 14:30:16 +00:00
|
|
|
/// - rchar, wchar, read_bytes, write_bytes (when /proc/thread-self/io is available)
|
2020-05-01 18:47:41 +00:00
|
|
|
/// See: man procfs
|
|
|
|
void getTaskStats(::taskstats & out_stats) const;
|
|
|
|
|
|
|
|
/// Tells whether this metrics (via Procfs) is provided on the current platform
|
|
|
|
static bool isAvailable() noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void readParseAndSetThreadCPUStat(::taskstats & out_stats, char *, size_t) const;
|
|
|
|
void readParseAndSetThreadBlkIOStat(::taskstats & out_stats, char *, size_t) const;
|
|
|
|
void readParseAndSetThreadIOStat(::taskstats & out_stats, char *, size_t) const;
|
|
|
|
|
|
|
|
int thread_schedstat_fd = -1;
|
|
|
|
int thread_stat_fd = -1;
|
|
|
|
int thread_io_fd = -1;
|
|
|
|
|
|
|
|
/// This field is used for compatibility with TasksStatsCounters::incrementProfileEvents()
|
2022-03-11 21:47:28 +00:00
|
|
|
unsigned short stats_version = 1; /// NOLINT
|
2020-05-01 18:47:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|