性能监视器

This commit is contained in:
洛洛希雅 2024-05-08 15:14:22 +08:00
parent 52bcd69f41
commit 9a9d533d6e

View File

@ -30,6 +30,7 @@ const publish = reactive({
lastRawTimestamp: 0, lastRawTimestamp: 0,
timeOffset: 0, timeOffset: 0,
timeTicking: 1, timeTicking: 1,
performance: 0,
onlineCars: 0, onlineCars: 0,
percentage: 0, percentage: 0,
pause: false, pause: false,
@ -110,6 +111,7 @@ async function doPublish() {
} }
// if (publishing.pause) return // if (publishing.pause) return
publish.lastTime = Date.now() publish.lastTime = Date.now()
const perStartTime = performance.now()
let item = next() let item = next()
// //
@ -138,6 +140,8 @@ async function doPublish() {
const json = JSON.stringify(item) const json = JSON.stringify(item)
mqttClient!.publish(topic, json, {}) mqttClient!.publish(topic, json, {})
publish.performance = performance.now() - perStartTime
}, 100) }, 100)
} }
@ -217,7 +221,30 @@ function reverse() {
{{ publish.onlineCars }} {{ publish.onlineCars }}
</el-descriptions-item> </el-descriptions-item>
</el-descriptions> </el-descriptions>
<el-progress flex-grow text-inside :stroke-width="20" :percentage="publish.percentage" /> <div flex-grow>
<div text-lg>发送进度{{ publish.percentage }}%</div>
<el-progress w-full :stroke-width="20" :percentage="publish.percentage">
<template #default>&nbsp;</template>
</el-progress>
<template v-if="publish.performance < 1">
<div mt="2" text-lg>性能损耗{{ publish.performance.toFixed(2) }} ms</div>
<el-progress w-full :stroke-width="20" :percentage="publish.performance * 100">
<template #default>&nbsp;</template>
</el-progress>
</template>
<template v-else-if="publish.performance < 10">
<div mt="2" text-lg>性能损耗{{ publish.performance.toFixed(1) }} ms</div>
<el-progress w-full status="warning" :stroke-width="20" :percentage="publish.performance * 10">
<template #default>&nbsp;</template>
</el-progress>
</template>
<template v-else>
<div mt="2" text-lg>性能损耗{{ publish.performance.toFixed(0) }} ms</div>
<el-progress w-full status="exception" :stroke-width="20" :percentage="publish.performance">
<template #default>&nbsp;</template>
</el-progress>
</template>
</div>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button v-if="!publish.status" type="primary" @click="connect">连接</el-button> <el-button v-if="!publish.status" type="primary" @click="connect">连接</el-button>