Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local enable_log = false --- SET TO true TO LOG LAG VALUES EVERY MINUTE
  2. local lag = 0
  3. local am = 0
  4. local minute = os.time() + 60
  5. local lastval = 0.2
  6. local highval = 0
  7. local lasthigh = "?"
  8.  
  9. minetest.register_globalstep(function(dtime)
  10.  
  11. lag = lag + dtime
  12. am = am + 1
  13.  
  14. if dtime > 0.5 then
  15. highval = highval + 1
  16. end
  17.  
  18. if os.time() >= minute then
  19.  
  20. lastval = lag/am
  21. local lagf = ("%.2f"):format(lastval)
  22.  
  23. if enable_log == true then
  24. minetest.log("action","AVG LAG: "..lagf.." ("..highval.."/"..am.." ticks critical)")
  25. end
  26.  
  27. lasthigh = highval
  28. lag = 0
  29. am = 0
  30. minute = os.time() + 60
  31. highval = 0
  32.  
  33.  
  34. end
  35.  
  36. end)
  37.  
  38. minetest.register_chatcommand("lag", {
  39. func = function(name, param)
  40. local avglag = ("%.2f"):format(lastval)
  41. return true,"Average server lag: "..avglag.." seconds ("..lasthigh.." critical server ticks)."
  42. end,
  43. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement