Software / code / prosody
Comparison
plugins/mod_admin_telnet.lua @ 9009:4c745d42c974
mod_admin_telnet: Rename timer:info() -> debug:timers()
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 10 Jul 2018 21:08:32 +0100 |
| parent | 8964:76780f37028d |
| child | 9330:36badabc85ce |
comparison
equal
deleted
inserted
replaced
| 9008:ae3c52419ec1 | 9009:4c745d42c974 |
|---|---|
| 334 print(" Used: "..human(mem.used/1024).." ("..human(lua_mem).." by Lua)"); | 334 print(" Used: "..human(mem.used/1024).." ("..human(lua_mem).." by Lua)"); |
| 335 print(" Free: "..human(mem.unused/1024).." ("..human(mem.returnable/1024).." returnable)"); | 335 print(" Free: "..human(mem.unused/1024).." ("..human(mem.returnable/1024).." returnable)"); |
| 336 return true, "OK"; | 336 return true, "OK"; |
| 337 end | 337 end |
| 338 | 338 |
| 339 def_env.timer = {}; | |
| 340 | |
| 341 function def_env.timer:info() | |
| 342 local socket = require "socket"; | |
| 343 local print = self.session.print; | |
| 344 local add_task = require"util.timer".add_task; | |
| 345 local h, params = add_task.h, add_task.params; | |
| 346 if h then | |
| 347 print("-- util.timer"); | |
| 348 for i, id in ipairs(h.ids) do | |
| 349 if not params[id] then | |
| 350 print(os.date("%F %T", h.priorities[i]), h.items[id]); | |
| 351 elseif not params[id].callback then | |
| 352 print(os.date("%F %T", h.priorities[i]), h.items[id], unpack(params[id])); | |
| 353 else | |
| 354 print(os.date("%F %T", h.priorities[i]), params[id].callback, unpack(params[id])); | |
| 355 end | |
| 356 end | |
| 357 end | |
| 358 if server.event_base then | |
| 359 local count = 0; | |
| 360 for k, v in pairs(debug.getregistry()) do | |
| 361 if type(v) == "function" and v.callback and v.callback == add_task._on_timer then | |
| 362 count = count + 1; | |
| 363 end | |
| 364 end | |
| 365 print(count .. " libevent callbacks"); | |
| 366 end | |
| 367 if h then | |
| 368 local next_time = h:peek(); | |
| 369 if next_time then | |
| 370 return true, os.date("Next event at %F %T (in %%.6fs)", next_time):format(next_time - socket.gettime()); | |
| 371 end | |
| 372 end | |
| 373 return true; | |
| 374 end | |
| 375 | |
| 376 def_env.module = {}; | 339 def_env.module = {}; |
| 377 | 340 |
| 378 local function get_hosts_set(hosts, module) | 341 local function get_hosts_set(hosts, module) |
| 379 if type(hosts) == "table" then | 342 if type(hosts) == "table" then |
| 380 if hosts[1] then | 343 if hosts[1] then |
| 1186 else | 1149 else |
| 1187 events_obj = prosody.events; | 1150 events_obj = prosody.events; |
| 1188 end | 1151 end |
| 1189 return true, helpers.show_events(events_obj, event); | 1152 return true, helpers.show_events(events_obj, event); |
| 1190 end | 1153 end |
| 1154 | |
| 1155 function def_env.debug:timers(filter) | |
| 1156 local socket = require "socket"; | |
| 1157 local print = self.session.print; | |
| 1158 local add_task = require"util.timer".add_task; | |
| 1159 local h, params = add_task.h, add_task.params; | |
| 1160 if h then | |
| 1161 print("-- util.timer"); | |
| 1162 for i, id in ipairs(h.ids) do | |
| 1163 if not params[id] then | |
| 1164 print(os.date("%F %T", h.priorities[i]), h.items[id]); | |
| 1165 elseif not params[id].callback then | |
| 1166 print(os.date("%F %T", h.priorities[i]), h.items[id], unpack(params[id])); | |
| 1167 else | |
| 1168 print(os.date("%F %T", h.priorities[i]), params[id].callback, unpack(params[id])); | |
| 1169 end | |
| 1170 end | |
| 1171 end | |
| 1172 if server.event_base then | |
| 1173 local count = 0; | |
| 1174 for k, v in pairs(debug.getregistry()) do | |
| 1175 if type(v) == "function" and v.callback and v.callback == add_task._on_timer then | |
| 1176 count = count + 1; | |
| 1177 end | |
| 1178 end | |
| 1179 print(count .. " libevent callbacks"); | |
| 1180 end | |
| 1181 if h then | |
| 1182 local next_time = h:peek(); | |
| 1183 if next_time then | |
| 1184 return true, os.date("Next event at %F %T (in %%.6fs)", next_time):format(next_time - socket.gettime()); | |
| 1185 end | |
| 1186 end | |
| 1187 return true; | |
| 1188 end | |
| 1189 | |
| 1190 -- COMPAT: debug:timers() was timer:info() for some time in trunk | |
| 1191 def_env.timer = { info = def_env.debug.timers }; | |
| 1191 | 1192 |
| 1192 module:hook("server-stopping", function(event) | 1193 module:hook("server-stopping", function(event) |
| 1193 for conn, session in pairs(sessions) do | 1194 for conn, session in pairs(sessions) do |
| 1194 session.print("Shutting down: "..(event.reason or "unknown reason")); | 1195 session.print("Shutting down: "..(event.reason or "unknown reason")); |
| 1195 end | 1196 end |