• How do I measure the startup impact of addons and/or Lua files?
    6 replies, posted
Greetings Facepunch, I've noticed that some addons are causing an extended start time for my dedicated server, and I would like to be able to pinpoint these addons. I am searching for a lua script that can measure the startup impact of addons and Lua files, and to print the results out neatly. Thank You in advance.
I can't see any addons taking nearly as much time to load as a map start for instance, unless it's doing something very very wrong. I'm not sure of any utility that can track this metric by default because of how things are loaded, but here's one little snippet you can use to track the entire addon+gamemode loading process. It's not by any means perfect but should be "good enough". Put it at the bottom of garrysmod/lua/includes/init.lua and then remove addons one-by-one until you see a big chunk of the load time go away, and you'll have your problem child. I'd give you something better but I'm at work right now. local t1 = SysTime() hook.Add("Initialize", "StartupTime", function() print("[Startup] Addons and gamemode loaded in " .. (SysTime() - t1) * 1000 .. "ms") end)
Thank you for your response; however, the text was not printed to the console. I added the code to lua/includes/init.lua, at the very bottom so it resembled something like this: --[[--------------------------------------------------------- Non-Module includes -----------------------------------------------------------]] include ( "util.lua" ) -- Misc Utilities include ( "util/sql.lua" ) -- Include sql here so it's -- available at loadtime to modules. include( "extensions/net.lua" ) --[[--------------------------------------------------------- Shared Modules -----------------------------------------------------------]] require ( "baseclass" ) require ( "concommand" ) -- Console Commands require ( "saverestore" ) -- Save/Restore require ( "hook" ) -- Gamemode hooks require ( "gamemode" ) -- Gamemode manager require ( "weapons" ) -- SWEP manager require ( "scripted_ents" ) -- Scripted Entities require ( "player_manager" ) -- Player models/class manager require ( "numpad" ) require ( "team" ) require ( "undo" ) require ( "cleanup" ) require ( "duplicator" ) require ( "constraint" ) require ( "construct" ) require ( "usermessage" ) require ( "list" ) require ( "cvars" ) require ( "http" ) require ( "properties" ) require ( "widget" ) require ( "cookie" ) require ( "utf8" ) require ( "drive" ) include ( "drive/drive_base.lua" ) include ( "drive/drive_noclip.lua" ) --[[--------------------------------------------------------- Serverside only modules -----------------------------------------------------------]] if ( SERVER ) then require( "ai_task" ) require( "ai_schedule" ) end --[[--------------------------------------------------------- Clientside only modules -----------------------------------------------------------]] if ( CLIENT ) then require ( "draw" ) -- 2D Draw library require ( "markup" ) -- Text markup library require ( "effects" ) require ( "halo" ) require ( "killicon" ) require ( "spawnmenu" ) require ( "controlpanel" ) require ( "presets" ) require ( "menubar" ) require ( "matproxy" ) include( "util/model_database.lua" ) -- Store information on models as they're loaded include( "util/vgui_showlayout.lua" ) -- VGUI Performance Debug include( "util/tooltips.lua" ) include( "util/client.lua" ) include( "util/javascript_util.lua" ) include( "util/workshop_files.lua" ) include( "gui/icon_progress.lua" ) end --[[--------------------------------------------------------- Shared modules -----------------------------------------------------------]] include( "gmsave.lua" ) --[[--------------------------------------------------------- Extensions Load extensions that we specifically need for the menu, to reduce the chances of loading something that might cause errors. -----------------------------------------------------------]] include ( "extensions/file.lua" ) include ( "extensions/angle.lua" ) include ( "extensions/debug.lua" ) include ( "extensions/entity.lua" ) include ( "extensions/ents.lua" ) include ( "extensions/math.lua" ) include ( "extensions/player.lua" ) include ( "extensions/player_auth.lua" ) include ( "extensions/string.lua" ) include ( "extensions/table.lua" ) include ( "extensions/util.lua" ) include ( "extensions/vector.lua" ) include ( "extensions/game.lua" ) include ( "extensions/motionsensor.lua" ) include ( "extensions/weapon.lua" ) include ( "extensions/coroutine.lua" ) if ( CLIENT ) then include ( "extensions/client/entity.lua" ) include ( "extensions/client/globals.lua" ) include ( "extensions/client/panel.lua" ) include ( "extensions/client/player.lua" ) include ( "extensions/client/render.lua" ) require ( "search" ) end local t1 = SysTime() hook.Add("Initialize", "StartupTime", function() MsgC( Color(0,255,0) , "[LOADER]" , Color(0,255,0) , " Loading complete! \n"); MsgC( Color(0,255,0) , "[LOADER]" , Color(0,255,0) , " Loading complete! \n"); MsgC( Color(0,255,0) , "[LOADER]" , Color(0,255,0) , " Loading complete! \n"); MsgC( Color(0,255,0) , "[LOADER]" , Color(0,255,0) , " Loading complete! \n"); MsgC( Color(0,0,255) , "[LOADER]" , Color(0,255,0) , " Addons and gamemode loaded in " .. (SysTime() - t1) * 1000 .. "ms \n"); MsgC( Color(255,0,0) , "[LOADER]" , Color(0,255,0) , " Loading complete! \n"); MsgC( Color(255,0,0) , "[LOADER]" , Color(0,255,0) , " Loading complete! \n"); MsgC( Color(255,0,0) , "[LOADER]" , Color(0,255,0) , " Loading complete! \n"); MsgC( Color(255,0,0) , "[LOADER]" , Color(0,255,0) , " Loading complete! \n"); end) I tried this with both MsgC() and print(), to no avail. Any ideas?
There's some weird behavior there I see. I got it to print by resaving the file while the server is running, and then just resetting the map.
That is precisely what I was searching for. A bit tedious, but absolutely worth it. Thank You!
Make sure to follow my edited post instead. Copying the Initialize hook will still only give you output after everything has loaded, which wouldn't be accurate.
Ah, I see. Sounds good. Is there a way to insert the snippet in bulk?
Sorry, you need to Log In to post a reply to this thread.