Forum Discussion
Sebastian,
I agree with Alexei. I did some investigating on my computer. I created a 500-ms timer, ran an empty loop and checked the periods when the timer fired:
function TestFunction()
{
var i;
var timePeriod = 5000;
var periodNumber = 10;
var timer = Utils.Timers.Add(timePeriod, "Unit1.TimerFunc", true);
for(i = 0; i < periodNumber; i++)
{
Delay(timePeriod);
Log.Message("i = " + i.toString());
}
}
The timer worked closely to what I expected. The deviations were about 10 ms (or 2%). A 1000-ms timer gave similar results (the maximum deviation was about 20 ms, or 2%). A 5000-ms timer showed even better results (a ~20 ms deviation, or 0.4%).
Then I changed the test conditions: in the loop, I called a script routine that simulated simple user actions with a Notepad window.
The deviations increased. While a 5000-ms timer worked quite stably, 500-ms and 1000-ms timers gave huge deviations (up to 40-50%).
As far as I can see, the cause is related to the nature of timers and the Windows operating system. Timer objects are script wrappers for ordinary operating system timers. As you may know, Windows uses the event-based approach and timers post the WM_TIMER message to the message queue of a window. When an application processes the queue and comes to the timer message, it executes the timer's function. However, it's quite possible that processing of earlier messages takes longer, so the WM_TIMER message will not be processed at the moment when it is expected.
TestComplete processes tons of window messages, especially during test recording and playback, and there are operations that don't check the message queue at this time as they cannot be interrupted. This makes timers inappropriate means for monitoring performance and memory usage in scripts.
You wrote that you wanted to monitor the CPU and memory usage. In this case, you can try using perfmon. To run it, simply type perfmon in the command line.
The following code snippet demonstrates how to run perfmon and use its data from script:
function Test()
{
PostProcessInfo(".", "Explorer");
}
function PostProcessInfo(computer, process)
{
var objWMIService = GetObject("winmgmts:\\\\" + computer + "\\root\\cimv2");
var PerfProcess = objWMIService.Get(
"Win32_PerfFormattedData_PerfProc_Process.Name='" + process + "'");
PerfProcess.Refresh_();
Delay(1000);
PerfProcess.Refresh_();
Log.Message("Memory: " + PerfProcess.WorkingSet);
Log.Message("Virtual: " + PerfProcess.VirtualBytes);
Log.Message("CPU Load: " + PerfProcess.PercentProcessorTime);
Log.Message("Page Faults / Sec: " + PerfProcess.PageFaultsPerSec);
}
Related Content
- 7 years ago
- 14 years ago
- 6 years ago
Recent Discussions
- 14 hours ago