summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-23 21:57:56 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-23 21:57:56 +0800
commit88cdad4998bd2c0f644451e755accc8bdfb0f80c (patch)
treecfb05207fa55f25d84c7414a796f69b6a19ac288 /server-beta/src
parentdc082612c918f1618d78fb123457ac64e40e5d27 (diff)
downloadlua-language-server-88cdad4998bd2c0f644451e755accc8bdfb0f80c.zip
体检协程数量
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/service/service.lua32
-rw-r--r--server-beta/src/task.lua4
2 files changed, 36 insertions, 0 deletions
diff --git a/server-beta/src/service/service.lua b/server-beta/src/service/service.lua
index 2c576a72..be486594 100644
--- a/server-beta/src/service/service.lua
+++ b/server-beta/src/service/service.lua
@@ -26,12 +26,44 @@ function m.reportMemory()
return table.concat(lines, '\n')
end
+function m.reportTask()
+ local total = 0
+ local running = 0
+ local suspended = 0
+ local normal = 0
+ local dead = 0
+
+ for co in pairs(task.coTracker) do
+ total = total + 1
+ local status = coroutine.status(co)
+ if status == 'running' then
+ running = running + 1
+ elseif status == 'suspended' then
+ suspended = suspended + 1
+ elseif status == 'normal' then
+ normal = normal + 1
+ elseif status == 'dead' then
+ dead = dead + 1
+ end
+ end
+
+ local lines = {}
+ lines[#lines+1] = ' --------------- Coroutine ---------------'
+ lines[#lines+1] = (' Total: %d'):format(total)
+ lines[#lines+1] = (' Running: %d'):format(running)
+ lines[#lines+1] = (' Suspended: %d'):format(suspended)
+ lines[#lines+1] = (' Normal: %d'):format(normal)
+ lines[#lines+1] = (' Dead: %d'):format(dead)
+ return table.concat(lines, '\n')
+end
+
function m.report()
local t = timer.loop(60.0, function ()
local lines = {}
lines[#lines+1] = ''
lines[#lines+1] = '========= Medical Examination Report ========='
lines[#lines+1] = m.reportMemory()
+ lines[#lines+1] = m.reportTask()
lines[#lines+1] = '=============================================='
log.debug(table.concat(lines, '\n'))
diff --git a/server-beta/src/task.lua b/server-beta/src/task.lua
index 5b7fb8dd..ba7bec94 100644
--- a/server-beta/src/task.lua
+++ b/server-beta/src/task.lua
@@ -1,9 +1,12 @@
local timer = require 'timer'
+
---@class task
local m = {}
m.type = 'task'
+m.coTracker = setmetatable({}, { __mode = 'k' })
+
--- 设置错误处理器
---@param errHandle function {comment = '当有错误发生时,会以错误堆栈为参数调用该函数'}
function m.setErrorHandle(errHandle)
@@ -13,6 +16,7 @@ end
--- 创建一个任务
function m.create(callback)
local co = coroutine.create(callback)
+ m.coTracker[co] = true
local suc, err = coroutine.resume(co)
if not suc and m.errHandle then
m.errHandle(debug.traceback(co, err))