Profiler_Tips.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ---@class Profiler
  2. Profiler = {}
  3. local this = Profiler
  4. ENABLE_PROFILER = CS.UnityEngine.Debug.isDebugBuild
  5. local LuaProfiler = CS.TCFramework.LuaProfiler
  6. local MikuLuaProfiler = CS.MikuLuaProfiler.LuaProfiler
  7. ENABLE_PROFILER = false
  8. --ENABLE_LUA_PROFILER = true
  9. function Profiler.BeginSample(name,isMikuLua)
  10. if ENABLE_PROFILER then
  11. LuaProfiler.BeginSample(StringPool.ToID(name))
  12. end
  13. if isMikuLua then
  14. MikuLuaProfiler.BeginSampleCSharp(name)
  15. end
  16. end
  17. function Profiler.BeginSampleFunc(func)
  18. if ENABLE_PROFILER then
  19. local info = debug.getinfo(func, "nSl")
  20. local text = info.source .. ":" .. info.linedefined
  21. if info.name then
  22. text = info.name .. "@" .. text
  23. end
  24. Profiler.BeginSample(text)
  25. end
  26. end
  27. function Profiler.EndSample(isMikuLua)
  28. if ENABLE_PROFILER then
  29. LuaProfiler.EndSample()
  30. end
  31. if isMikuLua then
  32. MikuLuaProfiler.EndSampleCSharp()
  33. end
  34. end
  35. function Profiler.BeginTime()
  36. this.preTime = os.clock()*1000
  37. end
  38. function Profiler.EndTime(name, isError)
  39. this.nextTime = os.clock() * 1000
  40. if isError then
  41. logError(name .. ' time = ' .. (this.nextTime - this.preTime) .. ' ms')
  42. else
  43. if DebugFlag.LogEnable then
  44. log(name .. ' time = ' .. (this.nextTime - this.preTime) .. ' ms')
  45. end
  46. end
  47. end