From patchwork Sat Jan 9 23:59:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 71961 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0A006vO005515 for ; Sun, 10 Jan 2010 00:00:06 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754763Ab0AIX7v (ORCPT ); Sat, 9 Jan 2010 18:59:51 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754758Ab0AIX7v (ORCPT ); Sat, 9 Jan 2010 18:59:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36278 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754752Ab0AIX7u (ORCPT ); Sat, 9 Jan 2010 18:59:50 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o09NxmOt024556 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 9 Jan 2010 18:59:48 -0500 Received: from localhost.localdomain (vpn-11-228.rdu.redhat.com [10.11.11.228]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o09NxkYb009416; Sat, 9 Jan 2010 18:59:47 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, mtosatti@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH] Add a new profiler to autotest, kvm_stat Date: Sat, 9 Jan 2010 21:59:43 -0200 Message-Id: <1263081583-3277-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/client/profilers/kvm_stat/__init__.py b/client/profilers/kvm_stat/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/client/profilers/kvm_stat/kvm_stat.py b/client/profilers/kvm_stat/kvm_stat.py new file mode 100644 index 0000000..b2c0b32 --- /dev/null +++ b/client/profilers/kvm_stat/kvm_stat.py @@ -0,0 +1,61 @@ +""" +kvm_stat prints statistics generated by the kvm module. +It depends on debugfs. If no debugfs is mounted, the profiler +will try to mount it so it's possible to proceed. + +@copyright: Red Hat 2010 +@author: Lucas Meneghel Rodrigues (lmr@redhat.com) +""" +import time, os, subprocess, commands +from autotest_lib.client.bin import utils, profiler, os_dep + + +class kvm_stat(profiler.profiler): + """ + kvm_stat based profiler. Consists on executing kvm_stat -l during a given + test execution, redirecting its output to a file on the profile dir. + """ + version = 1 + def initialize(self): + """ + Gets path of kvm_stat and verifies if debugfs needs to be mounted. + """ + self.stat_path = os_dep.command('kvm_stat') + (ret, output) = commands.getstatusoutput("%s --batch" % self.stat_path) + if ret != 0: + if 'debugfs' in output: + utils.system('mount -t debugfs debugfs /sys/kernel/debug') + else: + raise error.AutotestError('kvm_stat failed due to an ' + 'unknown reason: %s' % output) + + + def start(self, test): + """ + Starts kvm_stat subprocess. + + @param test: Autotest test on which this profiler will operate on. + """ + cmd = "%s -l" % self.stat_path + logfile = open(os.path.join(test.profdir, "kvm_stat"), 'w') + p = subprocess.Popen(cmd, shell=True, stdout=logfile, + stderr=subprocess.STDOUT) + self.pid = p.pid + + + def stop(self, test): + """ + Stops profiler execution by sending a SIGTERM to kvm_stat process. + + @param test: Autotest test on which this profiler will operate on. + """ + os.kill(self.pid, 15) + + + def report(self, test): + """ + Report function. Does nothing as there's no postprocesing needed. + + @param test: Autotest test on which this profiler will operate on. + """ + return None