aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.perf/lib
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-05-07 10:56:20 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-05-07 10:56:20 -0400
commit13123da89a2c7e06a5312ca6b4b24c68ba1c6c2d (patch)
treeec33a85ccb58f44445608d0cab68020fa588cb74 /gdb/testsuite/gdb.perf/lib
parenta9b49cbcd5935a713da5715799ea3b24e0a52851 (diff)
downloadgdb-13123da89a2c7e06a5312ca6b4b24c68ba1c6c2d.zip
gdb-13123da89a2c7e06a5312ca6b4b24c68ba1c6c2d.tar.gz
gdb-13123da89a2c7e06a5312ca6b4b24c68ba1c6c2d.tar.bz2
gdb: re-format Python files using black 21.4b0
Re-format all Python files using black [1] version 21.4b0. The goal is that from now on, we keep all Python files formatted using black. And that we never have to discuss formatting during review (for these files at least) ever again. One change is needed in gdb.python/py-prettyprint.exp, because it matches the string representation of an exception, which shows source code. So the change in formatting must be replicated in the expected regexp. To document our usage of black I plan on adding this to the "GDB Python Coding Standards" wiki page [2]: --8<-- All Python source files under the `gdb/` directory must be formatted using black version 21.4b0. This specific version can be installed using: $ pip3 install 'black == 21.4b0' All you need to do to re-format files is run `black <file/directory>`, and black will re-format any Python file it finds in there. It runs quite fast, so the simplest is to do: $ black gdb/ from the top-level. If you notice that black produces changes unrelated to your patch, it's probably because someone forgot to run it before you. In this case, don't include unrelated hunks in your patch. Push an obvious patch fixing the formatting and rebase your work on top of that. -->8-- Once this is merged, I plan on setting a up an `ignoreRevsFile` config so that git-blame ignores this commit, as described here: https://github.com/psf/black#migrating-your-code-style-without-ruining-git-blame I also plan on working on a git commit hook (checked in the repo) to automatically check the formatting of the Python files on commit. [1] https://pypi.org/project/black/ [2] https://sourceware.org/gdb/wiki/Internals%20GDB-Python-Coding-Standards gdb/ChangeLog: * Re-format all Python files using black. gdb/testsuite/ChangeLog: * Re-format all Python files using black. * gdb.python/py-prettyprint.exp (run_lang_tests): Adjust. Change-Id: I28588a22c2406afd6bc2703774ddfff47cd61919
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: