aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.perf/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite/gdb.perf/lib')
-rw-r--r--gdb/testsuite/gdb.perf/lib/perftest/measure.py16
-rw-r--r--gdb/testsuite/gdb.perf/lib/perftest/perftest.py11
-rw-r--r--gdb/testsuite/gdb.perf/lib/perftest/reporter.py25
-rw-r--r--gdb/testsuite/gdb.perf/lib/perftest/testresult.py8
-rw-r--r--gdb/testsuite/gdb.perf/lib/perftest/utils.py3
5 files changed, 39 insertions, 24 deletions
diff --git a/gdb/testsuite/gdb.perf/lib/perftest/measure.py b/gdb/testsuite/gdb.perf/lib/perftest/measure.py
index 7270e8e..2a20c5e 100644
--- a/gdb/testsuite/gdb.perf/lib/perftest/measure.py
+++ b/gdb/testsuite/gdb.perf/lib/perftest/measure.py
@@ -17,6 +17,7 @@ import time
import os
import gc
+
class Measure(object):
"""A class that measure and collect the interesting data for a given testcase.
@@ -55,6 +56,7 @@ class Measure(object):
for m in self.measurements:
m.report(reporter, name)
+
class Measurement(object):
"""A measurement for a certain aspect."""
@@ -63,7 +65,7 @@ class Measurement(object):
Attribute result is the TestResult associated with measurement.
"""
- self.name = name;
+ self.name = name
self.result = result
def start(self, id):
@@ -82,8 +84,10 @@ class Measurement(object):
"""Report the measured data by argument reporter."""
self.result.report(reporter, name + " " + self.name)
+
class MeasurementCpuTime(Measurement):
"""Measurement on CPU time."""
+
# On UNIX, time.clock() measures the amount of CPU time that has
# been used by the current process. On Windows it will measure
# wall-clock seconds elapsed since the first call to the function.
@@ -98,11 +102,12 @@ class MeasurementCpuTime(Measurement):
self.start_time = time.clock()
def stop(self, id):
- if os.name == 'nt':
+ if os.name == "nt":
cpu_time = 0
else:
cpu_time = time.clock() - self.start_time
- self.result.record (id, cpu_time)
+ self.result.record(id, cpu_time)
+
class MeasurementWallTime(Measurement):
"""Measurement on Wall time."""
@@ -116,7 +121,8 @@ class MeasurementWallTime(Measurement):
def stop(self, id):
wall_time = time.time() - self.start_time
- self.result.record (id, wall_time)
+ self.result.record(id, wall_time)
+
class MeasurementVmSize(Measurement):
"""Measurement on memory usage represented by VmSize."""
@@ -143,4 +149,4 @@ class MeasurementVmSize(Measurement):
def stop(self, id):
memory_used = self._compute_process_memory_usage("VmSize:")
- self.result.record (id, memory_used)
+ self.result.record(id, memory_used)
diff --git a/gdb/testsuite/gdb.perf/lib/perftest/perftest.py b/gdb/testsuite/gdb.perf/lib/perftest/perftest.py
index 055d045..0726641 100644
--- a/gdb/testsuite/gdb.perf/lib/perftest/perftest.py
+++ b/gdb/testsuite/gdb.perf/lib/perftest/perftest.py
@@ -65,12 +65,15 @@ class TestCase(object):
self.execute_test()
self.measure.report(reporter.TextReporter(append), self.name)
+
class TestCaseWithBasicMeasurements(TestCase):
"""Test case measuring CPU time, wall time and memory usage."""
def __init__(self, name):
result_factory = testresult.SingleStatisticResultFactory()
- measurements = [MeasurementCpuTime(result_factory.create_result()),
- MeasurementWallTime(result_factory.create_result()),
- MeasurementVmSize(result_factory.create_result())]
- super (TestCaseWithBasicMeasurements, self).__init__ (name, Measure(measurements))
+ measurements = [
+ MeasurementCpuTime(result_factory.create_result()),
+ MeasurementWallTime(result_factory.create_result()),
+ MeasurementVmSize(result_factory.create_result()),
+ ]
+ super(TestCaseWithBasicMeasurements, self).__init__(name, Measure(measurements))
diff --git a/gdb/testsuite/gdb.perf/lib/perftest/reporter.py b/gdb/testsuite/gdb.perf/lib/perftest/reporter.py
index 8617413..5569ece 100644
--- a/gdb/testsuite/gdb.perf/lib/perftest/reporter.py
+++ b/gdb/testsuite/gdb.perf/lib/perftest/reporter.py
@@ -57,29 +57,30 @@ class TextReporter(Reporter):
"""Report results in a plain text file 'perftest.log'."""
def __init__(self, append):
- super (TextReporter, self).__init__(Reporter(append))
+ super(TextReporter, self).__init__(Reporter(append))
self.txt_sum = None
self.txt_log = None
def report(self, test_name, measurement_name, data_points):
if len(data_points) == 0:
- self.txt_sum.write("%s %s *no data recorded*\n" % (
- test_name, measurement_name))
+ self.txt_sum.write(
+ "%s %s *no data recorded*\n" % (test_name, measurement_name)
+ )
return
average = sum(data_points) / len(data_points)
data_min = min(data_points)
data_max = max(data_points)
- self.txt_sum.write("%s %s %s\n" % (
- test_name, measurement_name, average))
- self.txt_log.write("%s %s %s, min %s, max %s, data %s\n" % (
- test_name, measurement_name, average, data_min, data_max,
- data_points))
+ self.txt_sum.write("%s %s %s\n" % (test_name, measurement_name, average))
+ self.txt_log.write(
+ "%s %s %s, min %s, max %s, data %s\n"
+ % (test_name, measurement_name, average, data_min, data_max, data_points)
+ )
def start(self):
mode = "a+" if self.append else "w"
- self.txt_sum = open (SUM_FILE_NAME, mode);
- self.txt_log = open (LOG_FILE_NAME, mode);
+ self.txt_sum = open(SUM_FILE_NAME, mode)
+ self.txt_log = open(LOG_FILE_NAME, mode)
def end(self):
- self.txt_sum.close ()
- self.txt_log.close ()
+ self.txt_sum.close()
+ self.txt_log.close()
diff --git a/gdb/testsuite/gdb.perf/lib/perftest/testresult.py b/gdb/testsuite/gdb.perf/lib/perftest/testresult.py
index db41d5c..fab9b68 100644
--- a/gdb/testsuite/gdb.perf/lib/perftest/testresult.py
+++ b/gdb/testsuite/gdb.perf/lib/perftest/testresult.py
@@ -13,6 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
class TestResult(object):
"""Base class to record and report test results.
@@ -27,12 +28,13 @@ class TestResult(object):
"""Report the test results by reporter."""
raise NotImplementedError("Abstract Method:report.")
+
class SingleStatisticTestResult(TestResult):
"""Test results for the test case with a single statistic."""
def __init__(self):
- super (SingleStatisticTestResult, self).__init__ ()
- self.results = dict ()
+ super(SingleStatisticTestResult, self).__init__()
+ self.results = dict()
def record(self, parameter, result):
if parameter in self.results:
@@ -46,6 +48,7 @@ class SingleStatisticTestResult(TestResult):
reporter.report(name, key, self.results[key])
reporter.end()
+
class ResultFactory(object):
"""A factory to create an instance of TestResult."""
@@ -53,6 +56,7 @@ class ResultFactory(object):
"""Create an instance of TestResult."""
raise NotImplementedError("Abstract Method:create_result.")
+
class SingleStatisticResultFactory(ResultFactory):
"""A factory to create an instance of SingleStatisticTestResult."""
diff --git a/gdb/testsuite/gdb.perf/lib/perftest/utils.py b/gdb/testsuite/gdb.perf/lib/perftest/utils.py
index 6030a81b..fe5ae93 100644
--- a/gdb/testsuite/gdb.perf/lib/perftest/utils.py
+++ b/gdb/testsuite/gdb.perf/lib/perftest/utils.py
@@ -15,6 +15,7 @@
import gdb
+
def safe_execute(command):
"""Execute command, ignoring any gdb errors."""
result = None
@@ -37,7 +38,7 @@ def select_file(file_name):
"""
safe_execute("set confirm off")
safe_execute("kill")
- print ("Selecting file %s" % (file_name))
+ print("Selecting file %s" % (file_name))
if file_name is None:
gdb.execute("file")
else: