Skip to content

Commit

Permalink
feat: add deepin-system-monitor log adaptation work
Browse files Browse the repository at this point in the history
add deepin-system-monitor log adaptation work

Log: add deepin-system-monitor log adaptation work

Task: https://pms.uniontech.com/task-view-341559.html
  • Loading branch information
add-uos authored and deepin-bot[bot] committed May 11, 2024
1 parent d0933a6 commit db7af04
Show file tree
Hide file tree
Showing 73 changed files with 2,235 additions and 1,288 deletions.
5 changes: 5 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Files: *.toml *.json *conf *.yaml *.sh *.xml *.pc.in
Copyright: None
License: CC0-1.0

# assets
Files: assets/*
Copyright: UnionTech Software Technology Co., Ltd.
License: GPL-3.0-or-later

# debian
Files: debian/*
Copyright: None
Expand Down
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,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"
}
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
deepin-system-monitor (6.0.20) unstable; urgency=medium

* New version 6.0.20.

-- shuaijie <[email protected]> Sat, 11 May 2024 10:10:42 +0800

deepin-system-monitor (6.0.19) unstable; urgency=medium

* New version 6.0.19.
Expand Down
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
15 changes: 15 additions & 0 deletions deepin-system-monitor-daemon/src/ddlog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#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
68 changes: 68 additions & 0 deletions deepin-system-monitor-daemon/src/logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#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");
}
28 changes: 28 additions & 0 deletions deepin-system-monitor-daemon/src/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#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;
};
Loading

0 comments on commit db7af04

Please sign in to comment.