ukui-search/ukui-search-service/cgroup-helper.h

73 lines
2.8 KiB
C
Raw Normal View History

#ifndef CGROUPHELPER_H
#define CGROUPHELPER_H
#include <QString>
#include <QtDBus/QDBusInterface>
#include <memory>
#include <functional>
class CgroupHelper
{
private:
/**
* @brief getUserPathV2 cgroup分组下的用户服务分组绝对路径
* @param groupPath: cgroup根路径"/sys/fs/cgroup"
* @return user@xxx.service的绝对路径xxx为用户uid
*/
static QString getUserPathV2(QString groupPath);
/**
* @brief getPath cgroup分组的相对路径
* @return cgroup分组的相对路径
*/
static QString getPath();
/**
* @brief getCgroupVerson cgroup的版本
* @return cgroup版本1cgroupV1 2cgroupV2 -1:
*/
static int getCgroupVerson();
/**
* @brief createProcessGroup cgroup分组
* @return cgroup分组的相对路径
*/
static bool createProcessGroup(QDBusInterface *interface);
/**
* @brief moveProcessToGroup pid添加到指定cgroup分组下
* @param interface: kylin-ProcessManagerDaemon的DBus接口
* @return true false
*/
static bool moveProcessToGroup(QDBusInterface *interface);
/**
* @brief setProcessGroupCPULimit cgroup版本设置CPU管控
* @param interface: kylin-ProcessManagerDaemon的DBus接口
* @return true false
*/
static bool setProcessGroupCPULimit(QDBusInterface *interface);
/**
* @brief addProcessManagerWhiteList ID添加到kylin-process-manager的白名单中
* kylin-procsss-manager管控而产生冲突
* @param interface: kylin-ProcessManagerDaemon的DBus接口
* @return true false
*/
static bool addProcessManagerWhiteList();
/**
* @brief setProcessGroupCPULimitV2 cgroupV2版本限制进程的CPU占用
* @param interface: kylin-ProcessManagerDaemon的DBus接口
* @return true false
*/
static bool setProcessGroupCPULimitV2(QDBusInterface *interface);
/**
* @brief setProcessGroupCPULimitV1 cgroupV1版本限制进程的CPU占用
* @param interface: kylin-ProcessManagerDaemon的DBus接口
* @return true false
*/
static bool setProcessGroupCPULimitV1(QDBusInterface *interface);
//用于调用kylin-ProcessManagerDaemon的DBus接口的智能指针
using CgroupUniquePtr = std::unique_ptr<QDBusInterface, std::function<void(QDBusInterface *)>>;
public:
/**
* @brief setServiceCpuLimit ukui-search-service设置CPU管控
* @return true false
*/
static bool setServiceCpuLimit();
};
#endif // CGROUPHELPER_H