profile support skynet coroutine

This commit is contained in:
Cloud Wu
2015-12-17 20:41:02 +08:00
parent 4a80a75fd6
commit 9d6bde01a3
3 changed files with 133 additions and 30 deletions

View File

@@ -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)