on the gateway if you go to the diagnostics tab there should be a tab called scripts where you should be able to see some additional information on the running scripts. there is also a spot to check gateway CPU usage in the overview of the diagnostics tab.
Get rid of that import system, you should never import libraries from within a function, only within the module itself. Importing libraries within functions causes unnecessary performance impacts. However, you should never import the system library itself. This is *always available (except under certain circumstances pre v8.3)
Re the OP, you can check timer and other gateway event scripts execution stats from the Web portal. This function doesn't look like it's doing much though
I actually just noticed a function in a project that was importing 5 libraries inside the function.
I timed the execution of the function (it does some recursive calls in it) both with and without the imports, and it's a bit crazy:
With imports: 250ms
Without imports: 40ms
And this is a function called on a reasonably short period and as part of another function's code, so not the only thing happening. 210ms is a lot of time and resources that I can retrieve!
To check for a stale value, the full qualified value can be read instead of just the value in your script to see when it last changed without having to store these values and timestamps in your globals. The only difference is if the value changes at all (you're ignoring anything smaller than 2 decimals) it will record it as a change.
The code paths are complex, but in my study of jython's import code, I couldn't find a path where the import statement, in any form, doesn't take the system-wide import lock. Using the import statement in hot code paths will destroy performance. It should never be used inside a def of any kind.
Question - is it worth (is it even possible) to have a single gateway script that does all the imports that you need, so they're only imported in one place? Or are all the imports specific to a script?
I am using this on MQTT engine Value tag and timestamp, in such a way that if the value of tag is same for 5 min(in production environment) and if timestamp is same for more than 2 min then it will show stale otherwise it will show fresh data.