Moved to_seconds, extract_all_time_results to autotest_utils.py for reuse
Signed-off-by: Ryan Stutsman <[email protected]>
Patch comes as a request from mbligh. This simply moves to_seconds and
the time results extraction to autotest_utils.py and adds a small bit of
documentation.
git-svn-id: http://test.kernel.org/svn/autotest/trunk@582 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/bin/autotest_utils.py b/client/bin/autotest_utils.py
index 2d4dd43..a3bf50b 100755
--- a/client/bin/autotest_utils.py
+++ b/client/bin/autotest_utils.py
@@ -494,3 +494,18 @@
nodes = max(len(numa_nodes()), 1)
return ((memtotal() * 1024) / nodes)
+
+def to_seconds(time_string):
+ """Converts a string in M+:SS.SS format to S+.SS"""
+ elts = time_string.split(':')
+ if len(elts) == 1:
+ return time_string
+ return str(int(elts[0]) * 60 + float(elts[1]))
+
+
+def extract_all_time_results(results_string):
+ """Extract user, system, and elapsed times into a list of tuples"""
+ pattern = re.compile(r"(.*?)user (.*?)system (.*?)elapsed")
+ results = []
+ for result in pattern.findall(results):
+ results.append(tuple([to_seconds(elt) for elt in result]))
diff --git a/client/tests/kernbench/kernbench.py b/client/tests/kernbench/kernbench.py
index 543d6c6..746163d 100755
--- a/client/tests/kernbench/kernbench.py
+++ b/client/tests/kernbench/kernbench.py
@@ -2,14 +2,6 @@
from autotest_utils import *
import re
-
-def to_seconds(time_string):
- elts = time_string.split(':')
- if len(elts) == 1:
- return time_string
- return str(int(elts[0]) * 60 + float(elts[1]))
-
-
class kernbench(test.test):
version = 1
@@ -72,8 +64,6 @@
def __format_results(self, results):
out = open('keyval', 'w')
- pattern = re.compile(r"(.*?)user (.*?)system (.*?)elapsed")
- for result in pattern.findall(results):
- result = tuple([to_seconds(elt) for elt in result])
+ for result in extract_all_time_results(results):
print >> out, "user=%s\nsystem=%s\nelapsed=%s\n" % result
out.close()