| | | @@ -0,0 +1,214 @@ |
| 1 | + | |
| 2 | + | local statsWindow = nil |
| 3 | + | local statsButton = nil |
| 4 | + | local luaStats = nil |
| 5 | + | local luaCallback = nil |
| 6 | + | local mainStats = nil |
| 7 | + | local dispatcherStats = nil |
| 8 | + | local render = nil |
| 9 | + | local atlas = nil |
| 10 | + | local adaptiveRender = nil |
| 11 | + | local slowMain = nil |
| 12 | + | local slowRender = nil |
| 13 | + | local widgetsInfo = nil |
| 14 | + | |
| 15 | + | local updateEvent = nil |
| 16 | + | local monitorEvent = nil |
| 17 | + | local iter = 0 |
| 18 | + | local lastSend = 0 |
| 19 | + | local sendInterval = 60 -- 1 m |
| 20 | + | local fps = {} |
| 21 | + | local ping = {} |
| 22 | + | local lastSleepTimeReset = 0 |
| 23 | + | |
| 24 | + | function init() |
| 25 | + | statsButton = modules.client_topmenu.addLeftButton('statsButton', 'Debug Info', '/images/topbuttons/debug', toggle) |
| 26 | + | statsButton:setOn(false) |
| 27 | + | |
| 28 | + | statsWindow = g_ui.displayUI('stats') |
| 29 | + | statsWindow:hide() |
| 30 | + | |
| 31 | + | g_keyboard.bindKeyDown('Ctrl+Alt+D', toggle) |
| 32 | + | |
| 33 | + | luaStats = statsWindow:recursiveGetChildById('luaStats') |
| 34 | + | luaCallback = statsWindow:recursiveGetChildById('luaCallback') |
| 35 | + | mainStats = statsWindow:recursiveGetChildById('mainStats') |
| 36 | + | dispatcherStats = statsWindow:recursiveGetChildById('dispatcherStats') |
| 37 | + | render = statsWindow:recursiveGetChildById('render') |
| 38 | + | atlas = statsWindow:recursiveGetChildById('atlas') |
| 39 | + | adaptiveRender = statsWindow:recursiveGetChildById('adaptiveRender') |
| 40 | + | slowMain = statsWindow:recursiveGetChildById('slowMain') |
| 41 | + | slowRender = statsWindow:recursiveGetChildById('slowRender') |
| 42 | + | widgetsInfo = statsWindow:recursiveGetChildById('widgetsInfo') |
| 43 | + | |
| 44 | + | lastSend = os.time() |
| 45 | + | g_stats.resetSleepTime() |
| 46 | + | lastSleepTimeReset = g_clock.micros() |
| 47 | + | |
| 48 | + | updateEvent = scheduleEvent(update, 2000) |
| 49 | + | monitorEvent = scheduleEvent(monitor, 1000) |
| 50 | + | end |
| 51 | + | |
| 52 | + | function terminate() |
| 53 | + | statsWindow:destroy() |
| 54 | + | statsButton:destroy() |
| 55 | + | |
| 56 | + | g_keyboard.unbindKeyDown('Ctrl+Alt+D') |
| 57 | + | |
| 58 | + | removeEvent(updateEvent) |
| 59 | + | removeEvent(monitorEvent) |
| 60 | + | end |
| 61 | + | |
| 62 | + | function onClose() |
| 63 | + | statsButton:setOn(false) |
| 64 | + | end |
| 65 | + | |
| 66 | + | function toggle() |
| 67 | + | if statsButton:isOn() then |
| 68 | + | statsWindow:hide() |
| 69 | + | statsButton:setOn(false) |
| 70 | + | else |
| 71 | + | statsWindow:show() |
| 72 | + | statsWindow:raise() |
| 73 | + | statsWindow:focus() |
| 74 | + | statsButton:setOn(true) |
| 75 | + | end |
| 76 | + | end |
| 77 | + | |
| 78 | + | function monitor() |
| 79 | + | if #fps > 1000 then |
| 80 | + | fps = {} |
| 81 | + | end |
| 82 | + | if #ping > 1000 then |
| 83 | + | ping = {} |
| 84 | + | end |
| 85 | + | table.insert(fps, g_app.getFps()) |
| 86 | + | table.insert(ping, g_game.getPing()) |
| 87 | + | monitorEvent = scheduleEvent(monitor, 1000) |
| 88 | + | end |
| 89 | + | |
| 90 | + | function sendStats() |
| 91 | + | lastSend = os.time() |
| 92 | + | local localPlayer = g_game.getLocalPlayer() |
| 93 | + | local playerData = nil |
| 94 | + | if localPlayer ~= nil then |
| 95 | + | playerData = { |
| 96 | + | name = localPlayer:getName(), |
| 97 | + | position = localPlayer:getPosition() |
| 98 | + | } |
| 99 | + | end |
| 100 | + | local data = { |
| 101 | + | uid = G.UUID, |
| 102 | + | stats = {}, |
| 103 | + | slow = {}, |
| 104 | + | render = g_adaptiveRenderer.getDebugInfo(), |
| 105 | + | player = playerData, |
| 106 | + | fps = fps, |
| 107 | + | ping = ping, |
| 108 | + | sleepTime = math.round(g_stats.getSleepTime() / math.max(1, g_clock.micros() - lastSleepTimeReset), 2), |
| 109 | + | proxy = {}, |
| 110 | + | |
| 111 | + | details = { |
| 112 | + | report_delay = sendInterval, |
| 113 | + | os = g_app.getOs(), |
| 114 | + | graphics_vendor = g_graphics.getVendor(), |
| 115 | + | graphics_renderer = g_graphics.getRenderer(), |
| 116 | + | graphics_version = g_graphics.getVersion(), |
| 117 | + | fps = g_app.getFps(), |
| 118 | + | maxFps = g_app.getMaxFps(), |
| 119 | + | atlas = g_atlas.getStats(), |
| 120 | + | classic = tostring(g_settings.getBoolean("classicView")), |
| 121 | + | fullscreen = tostring(g_window.isFullscreen()), |
| 122 | + | vsync = tostring(g_settings.getBoolean("vsync")), |
| 123 | + | autoReconnect = tostring(g_settings.getBoolean("autoReconnect")), |
| 124 | + | window_width = g_window.getWidth(), |
| 125 | + | window_height = g_window.getHeight(), |
| 126 | + | player_name = g_game.getCharacterName(), |
| 127 | + | world_name = g_game.getWorldName(), |
| 128 | + | otserv_host = G.host, |
| 129 | + | otserv_protocol = g_game.getProtocolVersion(), |
| 130 | + | otserv_client = g_game.getClientVersion(), |
| 131 | + | build_version = g_app.getVersion(), |
| 132 | + | build_revision = g_app.getBuildRevision(), |
| 133 | + | build_commit = g_app.getBuildCommit(), |
| 134 | + | build_date = g_app.getBuildDate(), |
| 135 | + | display_width = g_window.getDisplayWidth(), |
| 136 | + | display_height = g_window.getDisplayHeight(), |
| 137 | + | cpu = g_platform.getCPUName(), |
| 138 | + | mem = g_platform.getTotalSystemMemory(), |
| 139 | + | mem_usage = g_platform.getMemoryUsage(), |
| 140 | + | lua_mem_usage = gcinfo(), |
| 141 | + | os_name = g_platform.getOSName(), |
| 142 | + | platform = g_window.getPlatformType(), |
| 143 | + | uptime = g_clock.seconds(), |
| 144 | + | layout = g_resources.getLayout(), |
| 145 | + | packets = g_game.getRecivedPacketsCount(), |
| 146 | + | packets_size = g_game.getRecivedPacketsSize() |
| 147 | + | } |
| 148 | + | } |
| 149 | + | if g_proxy then |
| 150 | + | data["proxy"] = g_proxy.getProxiesDebugInfo() |
| 151 | + | end |
| 152 | + | lastSleepTimeReset = g_clock.micros() |
| 153 | + | g_stats.resetSleepTime() |
| 154 | + | for i = 1, g_stats.types() do |
| 155 | + | table.insert(data.stats, g_stats.get(i - 1, 10, false)) |
| 156 | + | table.insert(data.slow, g_stats.getSlow(i - 1, 50, 10, false)) |
| 157 | + | g_stats.clear(i - 1) |
| 158 | + | g_stats.clearSlow(i - 1) |
| 159 | + | end |
| 160 | + | data.widgets = g_stats.getWidgetsInfo(10, false) |
| 161 | + | data = json.encode(data, 1) |
| 162 | + | -- Envoi des statistiques desactive (envoyait nom du perso, serveur et infos PC a otclient.ovh) |
| 163 | + | -- if Services.stats ~= nil and Services.stats:len() > 3 then |
| 164 | + | -- g_http.post(Services.stats, data) |
| 165 | + | -- end |
| 166 | + | -- g_http.post("http://otclient.ovh/api/stats.php", data) |
| 167 | + | fps = {} |
| 168 | + | ping = {} |
| 169 | + | end |
| 170 | + | |
| 171 | + | function update() |
| 172 | + | updateEvent = scheduleEvent(update, 20) |
| 173 | + | if lastSend + sendInterval < os.time() then |
| 174 | + | sendStats() |
| 175 | + | end |
| 176 | + | |
| 177 | + | if not statsWindow:isVisible() then |
| 178 | + | return |
| 179 | + | end |
| 180 | + | |
| 181 | + | iter = (iter + 1) % 8 -- some functions are slow (~5ms), it will avoid lags |
| 182 | + | if iter == 0 then |
| 183 | + | statsWindow.debugPanel.sleepTime:setText("GFPS: " .. g_app.getGraphicsFps() .. " PFPS: " .. g_app.getProcessingFps() .. " Packets: " .. g_game.getRecivedPacketsCount() .. " , " .. (g_game.getRecivedPacketsSize() / 1024) .. " KB") |
| 184 | + | statsWindow.debugPanel.luaRamUsage:setText("Ram usage by lua: " .. gcinfo() .. " kb") |
| 185 | + | elseif iter == 1 then |
| 186 | + | local adaptive = "Adaptive: " .. g_adaptiveRenderer.getLevel() .. " | " .. g_adaptiveRenderer.getDebugInfo() |
| 187 | + | adaptiveRender:setText(adaptive) |
| 188 | + | atlas:setText("Atlas: " .. g_atlas.getStats()) |
| 189 | + | elseif iter == 2 then |
| 190 | + | render:setText(g_stats.get(2, 10, true)) |
| 191 | + | mainStats:setText(g_stats.get(1, 5, true)) |
| 192 | + | dispatcherStats:setText(g_stats.get(3, 5, true)) |
| 193 | + | elseif iter == 3 then |
| 194 | + | luaStats:setText(g_stats.get(4, 5, true)) |
| 195 | + | luaCallback:setText(g_stats.get(5, 5, true)) |
| 196 | + | elseif iter == 4 then |
| 197 | + | slowMain:setText(g_stats.getSlow(3, 10, 10, true) .. "\n\n\n" .. g_stats.getSlow(1, 20, 20, true)) |
| 198 | + | elseif iter == 5 then |
| 199 | + | slowRender:setText(g_stats.getSlow(2, 10, 10, true)) |
| 200 | + | elseif iter == 6 then |
| 201 | + | --disabled because takes a lot of cpu |
| 202 | + | --widgetsInfo:setText(g_stats.getWidgetsInfo(10, true)) |
| 203 | + | elseif iter == 7 then |
| 204 | + | if g_proxy then |
| 205 | + | local text = "" |
| 206 | + | local proxiesDebug = g_proxy.getProxiesDebugInfo() |
| 207 | + | for proxy_name, proxy_debug in pairs(proxiesDebug) do |
| 208 | + | text = text .. proxy_name .. " - " .. proxy_debug .. "\n" |
| 209 | + | end |
| 210 | + | statsWindow.debugPanel.proxies:setText(text) |
| 211 | + | end |
| 212 | + | end |
| 213 | + | end |
| 214 | + | |