← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #168326]: Watching process utilization to augment PSL

 

Question #168326 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/168326

RaiMan proposed the following answer:
sorry, might have mis leaded you.

The loop, how it works on my Mac (if I had your RegiS application) would
look like this (no test output):

import os
theApp = 'RegiS'
cpuMax = 100
cmd = 'top -l 2 -stats "command,cpu" | grep '+ theApp
while True:
    lines = os.popen(cmd).readlines()
    if not len(lines) == 2: exit(1)
    cpu = float(lines[1].strip().split()[1])
    if cpu < cpuMax : break
    wait(5)

But you do not have the command top that is available on ..X-Systems.

I understand: Your commands return on line containing the CPU usage percent:
ps ux | gawk '/RegiS/ {print $3}'

So for you in the end it should look like this:

import os
theApp = 'RegiS'
cpuMax = 100
cmd = "ps ux | gawk '/RegiS/ {print $3}'"
while True:
    lines = os.popen(cmd).readlines()
    if not len(lines) == 1: exit(1)
    cpu = float(lines[1].strip())
    if cpu < cpuMax : break
    wait(5)

While testing/evaluating, it is the easiest way:

import os
theApp = 'RegiS'
cpuMax = 100
cmd = "ps ux | gawk '/RegiS/ {print $3}'"
for i in range(2): # for test: loops 2 times
#while True: # for production
    lines = os.popen(cmd).readlines()
    if not len(lines) == 1: exit(1)
    cpu = float(lines[1].strip())
    print cpu # delete when tested 
    if cpu < cpuMax : break
    wait(5)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.