CPU Debug
-
Is there a recommended way to debug CPU usage ?
My script occasionally spikes into red, and I do not see anything unusual about it.
-
Use
Game.getUsedCpu()
like I did here https://github.com/avdg/screeps/blob/master/scripts/main.jsSimple subtract times to measure the time spend on a certain part like
Game.getUsedCpu() - prevousCp
I'm using a custom function though, which allows me to pretty print times (instead of having to deal with reading a lot of decimals), which is this function: https://github.com/avdg/screeps/blob/b11f9951f34c8ab6ff5f91f10bf54398c49aa8bb/scripts/_generics.js#L77