gc8 970 Posted February 24, 2019 (edited) Hi I'm interested of making a script that reports how fast are all scheduled scripts called (Called not executed). You know the more scripts you have running the slower all scripts run. Here's my code so far: #define RESP_WAIT 3 lastResponse = time; while { true } do { sleep RESP_WAIT; _respTime = time - lastResponse - RESP_WAIT; // Count how big delay there was before this script was called _respTimeText ctrlSetText format["Script response time: %1 s", _respTime]; lastResponse = time; }; I'm interested to hear what you think about this and what tips you may have. thx! Edited February 24, 2019 by gc8 Clarification Share this post Link to post Share on other sites
Leopard20 813 Posted February 25, 2019 Sleep is not reliable when it comes to script computation time (e.g if the engine is busy the code won't be executed for some time). I recommend using something like: if (time - _lastRun >= 3) then { _lastRun = time; }; But again adding this to the above while loop makes no sense, so...dunno. Share this post Link to post Share on other sites
gc8 970 Posted February 26, 2019 13 hours ago, Leopard20 said: Sleep is not reliable when it comes to script computation time (e.g if the engine is busy the code won't be executed for some time) That's the whole point. I expect the script to sleep 3 seconds and then continue. The time that goes over the 3 seconds is considered lag 🙂 1 Share this post Link to post Share on other sites
Leopard20 813 Posted February 26, 2019 4 hours ago, gc8 said: That's the whole point. I expect the script to sleep 3 seconds and then continue. The time that goes over the 3 seconds is considered lag 🙂 Oh. Right. I think I missed the point! 😉 Share this post Link to post Share on other sites
pierremgi 4739 Posted February 26, 2019 You expect some difference between new time and old time, separated by a single line to execute: _respTimeText ctrlSetText format["Script response time: %1 s", _respTime]; Not sure you will detect a lag with a such short script. Just the exec time of the line. Share this post Link to post Share on other sites
gc8 970 Posted February 27, 2019 13 hours ago, pierremgi said: Not sure you will detect a lag with a such short script. Just the exec time of the line. If there's lot of scripts running in theory the script continue delay should get longer Share this post Link to post Share on other sites
pierremgi 4739 Posted February 27, 2019 7 hours ago, gc8 said: If there's lot of scripts running in theory the script continue delay should get longer Distortion time? Share this post Link to post Share on other sites
gc8 970 Posted February 27, 2019 30 minutes ago, pierremgi said: Distortion time? Script "pause" time, cant explain it any better 😄 Share this post Link to post Share on other sites
pierremgi 4739 Posted February 27, 2019 Ah OK, you want a global "lag" for all the scheduled scripts, not pointing at one specific... Did you have a tour at https://community.bistudio.com/wiki/diag_activeSQFScripts I pointed at some of mine, too many repetitive (copied to clipboard). That led to me adding some timer conditions in some while loops. Share this post Link to post Share on other sites
gc8 970 Posted February 27, 2019 9 minutes ago, pierremgi said: Ah OK, you want a global "lag" for all the scheduled scripts, not pointing at one specific... Yes 🙂 I know the diag_activeSQFScripts command but don't know how that helps with this? Share this post Link to post Share on other sites
pierremgi 4739 Posted February 27, 2019 If you copyToClipboard str diag_activeSqfScripts, you can see your running scripts. Some of them appear several times with their running line. It's a kind of picture of your scheduler. Imho, it's a good way to point at too present scripts. Chase the lowest amount of running scripts. (count diag_activeSQFScript). With heavy scripts, you can see this amount growing in debug console: 10, 100, 1000.... Reading the diag_activeScripts, you will see some evident repetitions (loop, waitUntil or else) which could be optimized. Share this post Link to post Share on other sites
gc8 970 Posted February 28, 2019 @pierremgi Right, that's worth to check. But right now I'm interested on the script call delay so I know how much the scripts are lagging behind. And to see from that if optimizations are needed One of the best/quickers optimizers is the sleep command so that scripts sleep more and dont clog up the scheduler Share this post Link to post Share on other sites
pierremgi 4739 Posted February 28, 2019 That's an interesting point. In most of my code, I'm using uiSleep (and diag_tickTime), instead of sleep (and time). Now, I'm wondering if It's the best way to do. I saw the advantage for preventing some hanged code when game is paused (SP). But, there are probably some consequences on scheduler. That's not clear on my mind. Share this post Link to post Share on other sites