sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #04701
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:
RaiMans patience is one of the things, people really love ;-)
And people who want to learn get even more patience (at least as long as
I have the impression, my help is used too move further down the road).
So you are always welcome.
your thing - quick and dirty:
import os
theApp = 'top'
cpuMax = 100
test = True
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 test: print cpu; break
if cpu < cpuMax : break
wait(5)
the command returns 2 lines, each containing the app name and the cpu
usage percentage. Since we take only 2 samples, the second has the
relevant value. the line is stripped (get rid of leading/trailing white
space) and split at the middle (whitespace). The second value should be
the cpu usage value. We check against a threshold, if not below, wait 5
seconds and check again.
the var test is for testing purposes: if True, only one loop turn and
print out of the cpu value.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.