Forum Discussion

shivausum's avatar
shivausum
Occasional Contributor
12 years ago

Limit CPU Usage for a process

How can I limit CPU Usage of a process?



Assume I opened an application(through TestComplete) and trying to perform some operation on it. I observe 100%CPU Usage by process related to application I opened. Now I am running my scripts in a shared environment, VM, where no process is supposed to use 100%CPU usage. How can I limit CPU Usage of a process through TestComplete ?



Any suggestions or solution are appreciated. Thank you in advance.





Thanks

Shiva Krishna Imminni

1 Reply

  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Hi,


    Using 100% CPU resources may indicate problems in the application under test. I'd recommend discussing this with your developers.


    >> How can I limit CPU Usage of a process through TestComplete ?

    Do you know if it is possible in Windows? As far as I know, Windows operates with process priorities, but not with CPU usage. So, perhaps, you have to set a lower priority for this process. You can do this through Task Manager, or you can specify the priority when you start a process with the "start" command-line command of the operating system. For information about its arguments, type start /? in the command line.


    To set the priority from script test, try using the following code snippet (I found it here http://forum.soft32.com/windows/Limit-CPU-usage-ftopict386586.html):




    Const BELOW_NORMAL = 16384

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _

                        & "{impersonationLevel=impersonate}!\\" _

                        & strComputer & "\root\cimv2")

    Set colProcesses = objWMIService.ExecQuery _

                       ("Select * from Win32_Process Where Name = 'Notepad.exe'")

    For Each objProcess In colProcesses

      objProcess.SetPriority(BELOW_NORMAL)

    Next


    For information about the SetPriority function that is used in this code snippet, see the MSDN Library (http://msdn.microsoft.com/en-us/library/aa393587(VS.85).aspx).