Update sar command and handle OSError error.
PATCH 1/1 Update sar command and handle OSError error.
This patch do following things:
1. Update sar command in start function in /profilers/sar/sar.py, because when i manual run '/usr/bin/sar -o %s %d 0' command, help message is show up. Sames count number could not be 0, so use default count.
2. Put os.kill in sar.py into try block to avoid traceback. Sometimes it tried to kill an already terminated process which can cause a traceback.
--- client/profilers/sar/sar.py | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
client/profilers/sar/sar.py +5 -2
@@ -21,14 +21,17 @@ class sar(profiler.profiler): logfile = open(os.path.join(test.profdir, "sar"), 'w') # Save the sar data as binary, convert to text after the test. raw = os.path.join(test.profdir, "sar.raw") - cmd = "/usr/bin/sar -o %s %d 0" % (raw, self.interval) + cmd = "/usr/bin/sar -o %s %d " % (raw, self.interval) p = subprocess.Popen(cmd, shell=True, stdout=logfile, \ stderr=subprocess.STDOUT) self.pid = p.pid def stop(self, test): - os.kill(self.pid, 15) + try: + os.kill(self.pid, 15) + except OSError: + pass def report(self, test):
Signature · 1 line
1.5.5.6
Quoted 5 lines · Feng Yang
This patch do following things:
1. Update sar command in start function in /profilers/sar/sar.py, because when i manual run '/usr/bin/sar-o %s %d 0' command, help message is show up. Sames count number could not be 0, so use default count.
The problem here is that the sar command changed its behavior: if you check man pages for older versions of sar (see
http://linux.die.net/man/1/sar), you'll see:
"The default value for the count parameter is 1. If its value is set to zero, then reports are generated continuously."
For newer versions of sar like the ones shipped in recent Fedoras, the behavior is conflicting. From the man page:
"If the interval parameter is specified without the count parameter, then reports are generated continuously."
So, it's clear here that we have to handle the differences, otherwise the profiler won't work on older systems.
Quoted 3 lines
2. Put os.kill in
sar.pyinto try block to avoid traceback. Sometimes it tried to kill an already terminated process which can cause a traceback.
It just occurred to me that since we're using subprocess, we can use the terminate() method of the subprocess object, that doesn't raise exceptions when the process already returned, instead of just picking the PID and sending a sigterm on that PID. I just sent a version of this patch that does things the way I explained, and plan on change the subprocess part for the kvm_stat test profiler as well.
Quoted 37 lines
Signed-off-by Feng Yang <[email protected]>---
client/profilers/sar/sar.py | 7 +++++--1 files changed, 5 insertions(+), 2 deletions(-)client/profilers/sar/sar.py +1
-1@@ -21,14 +21,17 @@ class sar(profiler.profiler): logfile = open(os.path.join(test.profdir, "sar"), 'w') # Save the sar data as binary, convert to text after the test. raw = os.path.join(test.profdir, "sar.raw") - cmd = "/usr/bin/sar -o %s %d 0" % (raw, self.interval) + cmd = "/usr/bin/sar -o %s %d " % (raw, self.interval) p = subprocess.Popen(cmd, shell=True, stdout=logfile, \ stderr=subprocess.STDOUT)self.pid = p.pid
def
stop(self, test):
- os.kill(self.pid, 15)
+ try:
+ os.kill(self.pid, 15)
+ except OSError:
+ passdef
report(self, test):
--
1.5.5.6_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
Signature · 1 line
Lucas
Hi, Lucas
Thanks very much!
Quoted 76 lines · ----- "Lucas Meneghel Rodrigues
From: "Lucas Meneghel Rodrigues" <[email protected]>
To: "Feng Yang" <[email protected]>
Cc: [email protected], [email protected]
Sent: Thursday, April 1, 2010 9:27:44 AM GMT +08:00 Beijing / Chongqing / Hong Kong / Urumqi
Subject: Re: [Autotest] [PATCH] Update sar command and handle OSError error.Quoted 4 lines · Feng Yang
This patch do following things:
1. Update sar command in start function in /profilers/sar/sar.py, because when i manual run '/usr/bin/sar-o %s %d 0' command, help message is show up. Sames count number could not be 0, so usedefault
Quoted 1 line
count.
The problem here is that the sar command changed its behavior: if you check man pages for older versions of sar (see
http://linux.die.net/man/1/sar), you'll see:"The default value for the count parameter is 1. If its value is set to zero, then reports are generated continuously."
For newer versions of sar like the ones shipped in recent Fedoras, the
behavior is conflicting. From the man page:"If the interval parameter is specified without the count parameter, then reports are generated continuously."
So, it's clear here that we have to handle the differences, otherwise the profiler won't work on older systems.
Quoted 3 lines
2. Put os.kill in
sar.pyinto try block to avoid traceback. Sometimes it tried to kill an already terminated process which can cause a traceback.It just occurred to me that since we're using subprocess, we can use the
terminate()method of the subprocess object, that doesn't raise exceptions when the process already returned, instead of just picking the PID and sending a sigterm on that PID. I just sent a version of this patch that does things the way I explained, and plan on change the subprocess part for thekvm_stattest profiler as well.Review
Quoted 6 lines
Signed-off-by Feng Yang <[email protected]>---
client/profilers/sar/sar.py | 7 +++++--1 files changed, 5 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/client/profilers/sar/sar.pyclient/profilers/sar/sar.py class sar(profiler.profiler): · line 22
Quoted 6 lines
index fbe0639..e10156f 100644
client/profilers/sar/sar.py +0
-0@@ -21,14 +21,17 @@ class sar(profiler.profiler): logfile = open(os.path.join(test.profdir, "sar"), 'w') # Save the sar data as binary, convert to text after thetest.
Quoted 20 lines
client/profilers/sar/sar.py +1
-1raw = os.path.join(test.profdir, "sar.raw") - cmd = "/usr/bin/sar -o %s %d 0" % (raw, self.interval) + cmd = "/usr/bin/sar -o %s %d " % (raw, self.interval) p = subprocess.Popen(cmd, shell=True, stdout=logfile, \ stderr=subprocess.STDOUT)self.pid = p.pid
def
stop(self, test):
- os.kill(self.pid, 15)
+ try:
+ os.kill(self.pid, 15)
+ except OSError:
+ passdef
report(self, test):
--
1.5.5.6
Quoted 10 lines
Quoted 5 lines
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotestSignature · 1 line
Lucas
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest