add test trace

This commit is contained in:
云风
2013-08-20 18:07:26 +08:00
parent 97a4844094
commit 8455c45b83
2 changed files with 30 additions and 5 deletions

28
service/testtrace.lua Normal file
View 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)