Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
add-uos committed May 8, 2024
1 parent c29f67a commit 03299bb
Show file tree
Hide file tree
Showing 66 changed files with 2,018 additions and 1,252 deletions.
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,32 @@ if(DOTEST)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)

#安装日志收集工具配置
set(journel_system_monitor_main assets/logconfig/org.deepin.system-monitor.json)
install(FILES ${journel_system_monitor_main} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/deepin-log-viewer/deepin-log.conf.d/)

#安装DConfig配置
set(APPID org.deepin.system-monitor)
set(system_monitor_main assets/configs/org.deepin.system-monitor.json)
set(system_monitor_daemon assets/configs/org.deepin.system-monitor.daemon.json)
set(system_monitor_plugin assets/configs/org.deepin.system-monitor.plugin.json)
set(system_monitor_plugin_popup assets/configs/org.deepin.system-monitor.plugin.popup.json)
set(system_monitor_plugin_server assets/configs/org.deepin.system-monitor.server.json)

if (DEFINED DSG_DATA_DIR)
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_main})
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_daemon})
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_plugin})
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_plugin_popup})
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_plugin_server})
message("-- DConfig is supported by DTK")
else()
install(FILES ${system_monitor_main} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dsg/configs/${APPID}/)
install(FILES ${system_monitor_daemon} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dsg/configs/${APPID}/)
install(FILES ${system_monitor_plugin} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dsg/configs/${APPID}/)
install(FILES ${system_monitor_plugin_popup} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dsg/configs/${APPID}/)
install(FILES ${system_monitor_plugin_server} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dsg/configs/${APPID}/)

message("-- DConfig is not supported by DTK")
endif()
19 changes: 19 additions & 0 deletions assets/configs/org.deepin.system-monitor.daemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"log_rules": {
"value": "*.debug=false;*.info=false;*.warning=true",
"serial": 0,
"flags": [
"global"
],
"name": "log rules",
"name[zh_CN]": "日志规则",
"description": "log rules",
"description[zh_CN]": "日志规则",
"permissions": "readwrite",
"visibility": "public"
}
}
}
19 changes: 19 additions & 0 deletions assets/configs/org.deepin.system-monitor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"log_rules": {
"value": "*.debug=false;*.info=false;*.warning=true",
"serial": 0,
"flags": [
"global"
],
"name": "log rules",
"name[zh_CN]": "日志规则",
"description": "log rules",
"description[zh_CN]": "日志规则",
"permissions": "readwrite",
"visibility": "public"
}
}
}
19 changes: 19 additions & 0 deletions assets/configs/org.deepin.system-monitor.plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"log_rules": {
"value": "*.debug=false;*.info=false;*.warning=true",
"serial": 0,
"flags": [
"global"
],
"name": "log rules",
"name[zh_CN]": "日志规则",
"description": "log rules",
"description[zh_CN]": "日志规则",
"permissions": "readwrite",
"visibility": "public"
}
}
}
19 changes: 19 additions & 0 deletions assets/configs/org.deepin.system-monitor.plugin.popup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"log_rules": {
"value": "*.debug=false;*.info=false;*.warning=true",
"serial": 0,
"flags": [
"global"
],
"name": "log rules",
"name[zh_CN]": "日志规则",
"description": "log rules",
"description[zh_CN]": "日志规则",
"permissions": "readwrite",
"visibility": "public"
}
}
}
19 changes: 19 additions & 0 deletions assets/configs/org.deepin.system-monitor.server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"log_rules": {
"value": "*.debug=false;*.info=false;*.warning=true",
"serial": 0,
"flags": [
"global"
],
"name": "log rules",
"name[zh_CN]": "日志规则",
"description": "log rules",
"description[zh_CN]": "日志规则",
"permissions": "readwrite",
"visibility": "public"
}
}
}
43 changes: 43 additions & 0 deletions assets/logconfig/org.deepin.system-monitor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "deepin-system-monitor",
"group": "",
"submodules": [
{
"name": "deepin-system-monitor-daemon",
"filter": "",
"exec": "/usr/lib/x86_64-linux-gnu/deepin-service-manager/libdeepin-system-monitor-daemon.so",
"logType": "journal",
"logPath": ""
},
{
"name": "deepin-system-monitor",
"filter": "",
"exec": "/usr/bin/deepin-system-monitor",
"logType": "journal",
"logPath": ""
},
{
"name": "deepin-system-monitor-plugin",
"filter": "",
"exec": "/usr/lib/dde-dock/plugins/libdeepin-system-monitor-plugin.so",
"logType": "journal",
"logPath": ""
},
{
"name": "deepin-system-monitor-plugin-popup",
"filter": "",
"exec": "/usr/bin/deepin-system-monitor-plugin-popup",
"logType": "journal",
"logPath": ""
},
{
"name": "deepin-system-monitor-server",
"filter": "",
"exec": "/usr/bin/deepin-system-monitor-server",
"logType": "journal",
"logPath": ""
}
],
"visible": true,
"version": "V1.0"
}
14 changes: 7 additions & 7 deletions deepin-system-monitor-daemon/src/cpuprofile.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// SPDX-FileCopyrightText: 2011 ~ 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "ddlog.h"
#include "cpuprofile.h"
#include <QFile>
#include <QDebug>
using namespace DDLog;

#define PROC_CPU_STAT_PATH "/proc/stat"
#define PROC_CPU_INFO_PATH "/proc/cpuinfo"

CpuProfile::CpuProfile(QObject *parent)
: QObject(parent)
, mCpuUsage(0.0)
: QObject(parent), mCpuUsage(0.0)
{
// mLastCpuStat用于记录Cpu状态
// 各项数值是开机后各项工作的时间片总数
Expand Down Expand Up @@ -47,7 +47,7 @@ double CpuProfile::updateSystemCpuUsage()
// |user|nice|sys|idle|iowait|hardqirq|softirq|steal|guest|guest_nice|

// 分割行数据
QStringList cpuStatus = QString(lineData).split(" ", QString::SkipEmptyParts);
QStringList cpuStatus = QString(lineData).split(" ", QString::SkipEmptyParts);

// CPU状态应包含10个数据片段,有效数据 1-10,位置0不使用
if (cpuStatus.size() < 11) {
Expand Down Expand Up @@ -80,10 +80,10 @@ double CpuProfile::updateSystemCpuUsage()
// 通过对当前系统Cpu时间片使用情况和上一次获取的系统Cpu时间片使用情况,来计算上一个时间段内的Cpu使用情况
double calcCpuTotal = curCpuStat["total"] - mLastCpuStat["total"];
double calcCpuIdle =
(curCpuStat["idle"] + curCpuStat["iowait"]) - (mLastCpuStat["idle"] + mLastCpuStat["iowait"]);
(curCpuStat["idle"] + curCpuStat["iowait"]) - (mLastCpuStat["idle"] + mLastCpuStat["iowait"]);

if (calcCpuTotal == 0.0) {
qWarning() << " cpu total usage calc result equal 0 ! cpu stat [" << curCpuStat << "]";
qCWarning(app) << " cpu total usage calc result equal 0 ! cpu stat [" << curCpuStat << "]";
return cpuUsage;
}
// 上一个时间段内的Cpu使用情况
Expand All @@ -95,7 +95,7 @@ double CpuProfile::updateSystemCpuUsage()
// 更新上一次CPU状态
mLastCpuStat = curCpuStat;
} else {
qWarning() << QString(" file %1 open fail !").arg(PROC_CPU_STAT_PATH);
qCWarning(app) << QString(" file %1 open fail !").arg(PROC_CPU_STAT_PATH);
}

return cpuUsage;
Expand Down
11 changes: 11 additions & 0 deletions deepin-system-monitor-daemon/src/ddlog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef DDLOG_H
#define DDLOG_H
#include <DConfig>
#include <DLog>
DCORE_USE_NAMESPACE

namespace DDLog {
inline Q_LOGGING_CATEGORY(app, "org.deepin.system-monitor.daemon")
}

#endif // DDLOG_H
64 changes: 64 additions & 0 deletions deepin-system-monitor-daemon/src/logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "logger.h"
#include "dtkcore_global.h"
#include "qglobal.h"
#include "ddlog.h"
#include <QLoggingCategory>
#include <QObject>

#include <DConfig>
using namespace DDLog;

DCORE_USE_NAMESPACE

MLogger::MLogger(QObject *parent)
: QObject(parent), m_rules(""), m_config(nullptr)
{
QByteArray logRules = qgetenv("QT_LOGGING_RULES");
// qunsetenv 之前一定不要有任何日志打印,否则取消环境变量设置不会生效
qunsetenv("QT_LOGGING_RULES");

// set env
m_rules = logRules;

// set dconfig
m_config = DConfig::create("org.deepin.system-monitor", "org.deepin.system-monitor.daemon");
logRules = m_config->value("log_rules").toByteArray();
appendRules(logRules);
setRules(m_rules);

// watch dconfig
connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) {
qCritical(app) << "value changed:" << key;
if (key == "log_rules") {
setRules(m_config->value(key).toByteArray());
}
});
}

MLogger::~MLogger()
{
m_config->deleteLater();
}

void MLogger::setRules(const QString &rules)
{
auto tmpRules = rules;
m_rules = tmpRules.replace(";", "\n");
QLoggingCategory::setFilterRules(m_rules);
}

void MLogger::appendRules(const QString &rules)
{
QString tmpRules = rules;
tmpRules = tmpRules.replace(";", "\n");
auto tmplist = tmpRules.split('\n');
for (int i = 0; i < tmplist.count(); i++)
if (m_rules.contains(tmplist.at(i))) {
tmplist.removeAt(i);
i--;
}
if (tmplist.isEmpty())
return;
m_rules.isEmpty() ? m_rules = tmplist.join("\n")
: m_rules += "\n" + tmplist.join("\n");
}
23 changes: 23 additions & 0 deletions deepin-system-monitor-daemon/src/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <QObject>
#include <dtkcore_global.h>

DCORE_BEGIN_NAMESPACE
class DConfig;
DCORE_END_NAMESPACE

class MLogger : public QObject {
Q_OBJECT
public:
explicit MLogger(QObject *parent = nullptr);
~MLogger();

inline QString rules() const { return m_rules; }
void setRules(const QString &rules);

private:
void appendRules(const QString &rules);

private:
QString m_rules;
Dtk::Core::DConfig *m_config;
};
18 changes: 8 additions & 10 deletions deepin-system-monitor-daemon/src/memoryprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "memoryprofile.h"

#include "ddlog.h"
#include <QDebug>
#include <QFile>

#define PROC_MEM_INFOI_PATH "/proc/meminfo"

using namespace DDLog;
MemoryProfile::MemoryProfile(QObject *parent)
: QObject(parent)
, mMemUsage(0)
: QObject(parent), mMemUsage(0)
{
}

Expand All @@ -32,7 +31,7 @@ double MemoryProfile::updateSystemMemoryUsage()
// MemFree: 1455488 kB
// MemAvailable: 5931304 kB
if (lineData1.size() == 0 || lineData2.size() == 0 || lineData3.size() == 0) {
qWarning() << QString(" read %1 file fail !").arg(PROC_MEM_INFOI_PATH) << lineData1 << lineData2 << lineData3;
qCWarning(app) << QString(" read %1 file fail !").arg(PROC_MEM_INFOI_PATH) << lineData1 << lineData2 << lineData3;
return memUsage;
}

Expand All @@ -42,7 +41,7 @@ double MemoryProfile::updateSystemMemoryUsage()
QStringList list3 = QString(lineData3).split(" ", QString::SkipEmptyParts);

if (list1.size() < 3 || list2.size() < 3 || list3.size() < 3) {
qWarning() << QString(" parse %1 file fail !").arg(PROC_MEM_INFOI_PATH) << list1 << list2 << list3;
qCWarning(app) << QString(" parse %1 file fail !").arg(PROC_MEM_INFOI_PATH) << list1 << list2 << list3;
return memUsage;
}

Expand All @@ -52,14 +51,14 @@ double MemoryProfile::updateSystemMemoryUsage()
memDataMap[list3.at(0)] = list3.at(1).toInt();

// 为返回值赋值,计算内存占用率
if (memDataMap.contains("MemTotal:") && memDataMap.contains("MemAvailable:") && memDataMap["MemTotal:"] != 0) {
if (memDataMap.contains("MemTotal:") && memDataMap.contains("MemAvailable:") && memDataMap["MemTotal:"] != 0) {
memUsage = (memDataMap["MemTotal:"] - memDataMap["MemAvailable:"]) * 100.0 / memDataMap["MemTotal:"];
mMemUsage = memUsage;
} else {
qWarning() << QString(" extract mem data fail !") << memDataMap;
qCWarning(app) << QString(" extract mem data fail !") << memDataMap;
}
} else {
qWarning() << QString(" file %1 open fail !").arg(PROC_MEM_INFOI_PATH);
qCWarning(app) << QString(" file %1 open fail !").arg(PROC_MEM_INFOI_PATH);
}

return memUsage;
Expand All @@ -69,4 +68,3 @@ double MemoryProfile::getMemUsage()
{
return mMemUsage;
}

Loading

0 comments on commit 03299bb

Please sign in to comment.