mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 11:33:09 +00:00
profile support skynet coroutine
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
local skynet = require "skynet"
|
||||
-- You should use skynet.coroutine instead of origin coroutine in skynet
|
||||
local coroutine = require "skynet.coroutine"
|
||||
local profile = require "profile"
|
||||
|
||||
local function status(co)
|
||||
repeat
|
||||
@@ -18,21 +19,35 @@ end
|
||||
|
||||
local function test(n)
|
||||
local co = coroutine.running()
|
||||
print ("begin", coroutine.isskynetcoroutine(co))
|
||||
print ("begin", co, coroutine.thread(co)) -- false
|
||||
skynet.fork(status, co)
|
||||
for i=1,n do
|
||||
skynet.sleep(100)
|
||||
coroutine.yield(i)
|
||||
end
|
||||
print "end"
|
||||
print ("end", co)
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
print("Is the main thead a skynet coroutine ?", coroutine.isskynetcoroutine()) -- always false
|
||||
print(coroutine.resume(coroutine.running())) -- always return false
|
||||
local function main()
|
||||
local f = coroutine.wrap(test)
|
||||
coroutine.yield "begin"
|
||||
for i=1,3 do
|
||||
local n = f(5)
|
||||
print("main thread",n)
|
||||
end
|
||||
coroutine.yield "end"
|
||||
print("main thread time:", profile.stop(coroutine.thread()))
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
print("Main thead :", coroutine.thread()) -- true
|
||||
print(coroutine.resume(coroutine.running())) -- always return false
|
||||
|
||||
profile.start()
|
||||
|
||||
local f = coroutine.wrap(main)
|
||||
print("main step", f())
|
||||
print("main step", f())
|
||||
print("main step", f())
|
||||
-- print("main thread time:", profile.stop())
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user