scarleberg_1
14 years agoNew Contributor
Timer event fires irregurarly
I'm trying to create a simple performance logging function in my script tests. What I want to do is to set a timer that will call this logging function regularly during the entire program run, and each time the function is called it writes CPU- and memory usage of the process to a simple text document.
What I have now is this, in my setup function that is called in the beginning of the test:
var performanceTimer = Utils.Timers.Add(1000, "Utils_Logging.performanceLog", true);
The way I see it, the timer should fire its event once every second and call the performanceLog function every time. Or have I missed something here?
In a very stripped down version of my performance logging function, this is the only thing being done:
Log.Message("Performance log");
What I would expect of this is to get one such log message every second. So for a test that runs for ~20 seconds I would get ~20 performance log messages. Oddly enough, this is not what happens!
I can use my last run as an example. The test unit's start time was 9:41:04 and its end time was 9.42:06, so it ran for about a minute. From my other log messages I can see that the timer was added at 9:41.30 - about half way through the test. From this, I except the callback function to be called approximately 30 times, since it's 36 seconds left of the test at this point.
However, I don't get anywhere near 30 calls to this function! I only get three. At each call I write a note to the log and also a short string to a text file, so there's not much being done. The related output in the log consists of three messages posted at the following times:
- 9:41:42
- 9:42:04
- 9:42:04
As you can see, two of the three messages have been sent the very same second. I just don't understand how to use the timer objects properly when they seem to operate at random. This is the one and only timer I have. The callback function just performs some simple string printing. It does not help if I increase the interval to, say 5 seconds, it's still very few calls to the function.
Am I missing something or are the timer objects just completely useless?
What I have now is this, in my setup function that is called in the beginning of the test:
var performanceTimer = Utils.Timers.Add(1000, "Utils_Logging.performanceLog", true);
The way I see it, the timer should fire its event once every second and call the performanceLog function every time. Or have I missed something here?
In a very stripped down version of my performance logging function, this is the only thing being done:
Log.Message("Performance log");
What I would expect of this is to get one such log message every second. So for a test that runs for ~20 seconds I would get ~20 performance log messages. Oddly enough, this is not what happens!
I can use my last run as an example. The test unit's start time was 9:41:04 and its end time was 9.42:06, so it ran for about a minute. From my other log messages I can see that the timer was added at 9:41.30 - about half way through the test. From this, I except the callback function to be called approximately 30 times, since it's 36 seconds left of the test at this point.
However, I don't get anywhere near 30 calls to this function! I only get three. At each call I write a note to the log and also a short string to a text file, so there's not much being done. The related output in the log consists of three messages posted at the following times:
- 9:41:42
- 9:42:04
- 9:42:04
As you can see, two of the three messages have been sent the very same second. I just don't understand how to use the timer objects properly when they seem to operate at random. This is the one and only timer I have. The callback function just performs some simple string printing. It does not help if I increase the interval to, say 5 seconds, it's still very few calls to the function.
Am I missing something or are the timer objects just completely useless?