2018-05-17 16:01:41 +00:00
|
|
|
#pragma once
|
2018-08-21 23:56:55 +00:00
|
|
|
|
2018-08-22 00:05:06 +00:00
|
|
|
#include <sys/types.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2018-08-22 00:05:06 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
2018-05-17 16:01:41 +00:00
|
|
|
|
|
|
|
struct taskstats;
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-08-17 18:57:07 +00:00
|
|
|
/// Get taskstat info from OS kernel via Netlink protocol.
|
2022-04-25 05:47:45 +00:00
|
|
|
///
|
|
|
|
/// NOTE: unlike procfs interface, netlink interface, rounds some values to KiBs [1].
|
|
|
|
///
|
|
|
|
/// [1]: https://elixir.bootlin.com/linux/v5.18-rc4/source/kernel/tsacct.c#L101
|
|
|
|
///
|
2018-08-22 00:05:06 +00:00
|
|
|
class TaskStatsInfoGetter : private boost::noncopyable
|
2018-05-17 16:01:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-08-22 00:24:55 +00:00
|
|
|
TaskStatsInfoGetter();
|
2018-06-14 14:29:42 +00:00
|
|
|
~TaskStatsInfoGetter();
|
2018-05-17 16:01:41 +00:00
|
|
|
|
2020-04-22 05:39:31 +00:00
|
|
|
void getStat(::taskstats & out_stats, pid_t tid) const;
|
2018-08-22 00:24:55 +00:00
|
|
|
|
2020-08-08 00:47:03 +00:00
|
|
|
/// Whether the current process has permissions (sudo or cap_net_admin capabilities) to get taskstats info
|
2018-08-21 21:05:30 +00:00
|
|
|
static bool checkPermissions();
|
2018-05-17 16:01:41 +00:00
|
|
|
|
2019-12-22 17:20:33 +00:00
|
|
|
#if defined(OS_LINUX)
|
2018-05-17 16:01:41 +00:00
|
|
|
private:
|
|
|
|
int netlink_socket_fd = -1;
|
2018-08-22 00:24:55 +00:00
|
|
|
UInt16 taskstats_family_id = 0;
|
2018-08-22 05:56:06 +00:00
|
|
|
#endif
|
2018-05-17 16:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|