⚗️ 状态debug

This commit is contained in:
yeyang
2024-06-10 10:59:15 +08:00
parent 4d16167fef
commit d4949062dd
4 changed files with 25 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ export class NewState extends plugin {
priority: -1000, priority: -1000,
rule: [ rule: [
{ {
reg: "^#?(椰奶)?状态(pro)?$", reg: "^#?(椰奶)?状态(pro)?(debug)?$",
fnc: "state" fnc: "state"
}, },
{ {

View File

@@ -4,7 +4,6 @@ import Monitor from "./Monitor.js"
/** /**
* 获取硬盘 * 获取硬盘
* @returns {*}
*/ */
export async function getFsSize() { export async function getFsSize() {
// 去重 // 去重

View File

@@ -3,7 +3,7 @@ import { Config } from "../../components/index.js"
import { Circle, getFileSize } from "./utils.js" import { Circle, getFileSize } from "./utils.js"
/** 获取nodejs内存情况 */ /** 获取nodejs内存情况 */
export default function getNodeInfo() { export default async function getNodeInfo() {
if (Config.state.closedNodeInfo) return false if (Config.state.closedNodeInfo) return false
let memory = process.memoryUsage() let memory = process.memoryUsage()
// 总共 // 总共

View File

@@ -17,7 +17,19 @@ import getStyle, { getBackground } from "./style.js"
export async function getData(e) { export async function getData(e) {
e.isPro = e.msg.includes("pro") e.isPro = e.msg.includes("pro")
/** bot列表 */ e.isDebug = e.msg.includes("debug")
const timeStr = []
const _nameMap1 = [ "CPU", "RAM", "SWAP", "GPU", "Node" ]
const _nameMap2 = [ "visualData", "FastFetch", "FsSize", "NetworkTest", "BotState", "Style" ]
function timePromiseExecution(promiseFn, name) {
const start = Date.now()
return promiseFn.then((result) => {
const end = Date.now()
logger.debug(`Promise ${name}: ${end - start} ms`)
timeStr.push(`${name}: ${end - start} ms`)
return result
})
}
const visualDataPromise = Promise.all([ const visualDataPromise = Promise.all([
getCPU(), getCPU(),
@@ -25,7 +37,7 @@ export async function getData(e) {
getSWAP(), getSWAP(),
getGPU(), getGPU(),
getNode() getNode()
]) ].map((v, i) => timePromiseExecution(v, _nameMap1[i])))
const promiseTaskList = [ const promiseTaskList = [
visualDataPromise, visualDataPromise,
getFastFetch(e), getFastFetch(e),
@@ -33,14 +45,20 @@ export async function getData(e) {
getNetworkTestList(e), getNetworkTestList(e),
getBotState(e), getBotState(e),
getStyle() getStyle()
] ].map((v, i) => timePromiseExecution(v, _nameMap2[i]))
const start = Date.now()
const [ const [
visualData, visualData,
FastFetch, FastFetch,
HardDisk, psTest, BotStatusList, style HardDisk, psTest, BotStatusList, style
] = await Promise.all(promiseTaskList) ] = await Promise.all(promiseTaskList).then(res => {
const end = Date.now()
logger.debug(`Promise all: ${end - start} ms`)
timeStr.push(`all: ${end - start} ms`)
return res
})
e.isDebug && e.reply(timeStr.join("\n"))
const chartData = JSON.stringify( const chartData = JSON.stringify(
common.checkIfEmpty(Monitor.chartData, [ "echarts_theme", "cpu", "ram" ]) common.checkIfEmpty(Monitor.chartData, [ "echarts_theme", "cpu", "ram" ])
? "" ? ""