2018-05-17 16:01:41 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Core/Types.h>
|
|
|
|
|
|
|
|
struct taskstats;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-06-14 14:29:42 +00:00
|
|
|
class Exception;
|
|
|
|
|
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
/// Get taskstat infor from OS kernel via Netlink protocol
|
|
|
|
class TaskStatsInfoGetter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TaskStatsInfoGetter();
|
|
|
|
TaskStatsInfoGetter(const TaskStatsInfoGetter &) = delete;
|
|
|
|
|
2018-06-14 14:29:42 +00:00
|
|
|
void getStat(::taskstats & stat, int tid = -1);
|
|
|
|
bool tryGetStat(::taskstats & stat, int tid = -1);
|
|
|
|
|
|
|
|
~TaskStatsInfoGetter();
|
2018-05-17 16:01:41 +00:00
|
|
|
|
2018-06-14 14:29:42 +00:00
|
|
|
/// Make a syscall and returns Linux thread id
|
2018-05-17 16:01:41 +00:00
|
|
|
static int getCurrentTID();
|
|
|
|
|
2018-06-14 14:29:42 +00:00
|
|
|
/// Whether the current process has permissions (sudo or cap_net_admin capabilties) to get taskstats info
|
|
|
|
static bool checkProcessHasRequiredPermissions();
|
2018-05-17 16:01:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-06-14 14:29:42 +00:00
|
|
|
/// Caches current thread tid to avoid extra sys calls
|
|
|
|
int getDefaultTid();
|
|
|
|
int default_tid = -1;
|
|
|
|
|
|
|
|
bool getStatImpl(int tid, ::taskstats & out_stats, bool throw_on_error = false);
|
|
|
|
void init();
|
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
int netlink_socket_fd = -1;
|
2018-06-14 14:29:42 +00:00
|
|
|
UInt16 netlink_family_id = 0;
|
2018-05-17 16:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|