mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
add test trace
This commit is contained in:
28
service/testtrace.lua
Normal file
28
service/testtrace.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
local skynet = require "skynet"
|
||||
|
||||
local trace_cache = {}
|
||||
|
||||
skynet.trace_callback(function(handle, ti)
|
||||
-- skynet will call this function when the thread which create handle(traceid) end, and pass the time (ti)
|
||||
print("TRACE",trace_cache[handle],ti)
|
||||
trace_cache[handle] = nil
|
||||
end)
|
||||
|
||||
local function f (i)
|
||||
-- create a trace object
|
||||
local traceid = skynet.trace()
|
||||
-- name traceid in trace_cache[]
|
||||
trace_cache[traceid] = "thread " .. i
|
||||
|
||||
for i=1,i do
|
||||
skynet.sleep(i)
|
||||
end
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
for i = 1 , 100 do
|
||||
skynet.fork(f, i)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user