f27a123653
This patch adds a basic framework to do performance testing for GDB. perftest.py is about the test case, testresult.py is about test results, and how are they saved. reporter.py is about how results are reported (in what format). measure.py is about measuring the execution of tests by a collection of measurements. In V5: - Simplify perftest.exp. In V4: - Rename MeasurementCPUTime to MeasurementCpuTime, - Add 'pass' in empty method, - Simplify string comparison in perftest.exp. - Rename GDB_PERFORMANCE to GDB_PERFTEST_MODE and rename GDB_PERFORMANCE_TIMEOUT to GDB_PERFTEST_TIMEOUT. In V3, there are some changes, - Add wall time measurement, cpu time measurement and vmsize measurement. - Rename SingleStatisticTestCase to TestCaseWithBasicMeasurements, which measures cpu time, wall time, and memory (vmsize). - GDB_PERFORMANCE=run|compile|both to control the mode of perf testing. - New GDB_PERFORMANCE_TIMEOUT to specify the timeout. - Split proc prepare to proc compile and startup. - Disable GC while doing measurements. In V2, there are several changes to address Doug and Sanimir's comments. - Add copyright header and docstring in perftest/__init__.py - Remove config.py. - Fix docstring format. - Rename classes "SingleVariable" to "SingleStatistic". - Don't extend gdb.Function in class TestCase. Add a new method run to run the test case so that we can pass parameters to test. - Allow to customize whether to warm up and to append test log. - Move time measurement into test harness. Add a new class Measurement for a specific measurement and a new class Measure to measure them for a given test case. - A new class ResultFactory to create instances of TestResult. - New file lib/perftest.exp, which is to do some preparations and cleanups to simplify each *.exp file. - Skip compilation step if GDB_PERFORMANCE_SKIP_COMPILE is set. gdb/testsuite/ 2013-11-06 Yao Qi <yao@codesourcery.com> * lib/perftest.exp: New. * gdb.perf/lib/perftest/__init__.py: New. * gdb.perf/lib/perftest/measure.py: New. * gdb.perf/lib/perftest/perftest.py: New. * gdb.perf/lib/perftest/reporter.py: New. * gdb.perf/lib/perftest/testresult.py: New.
73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
# Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import testresult
|
|
import reporter
|
|
from measure import Measure
|
|
from measure import MeasurementCpuTime
|
|
from measure import MeasurementWallTime
|
|
from measure import MeasurementVmSize
|
|
|
|
class TestCase(object):
|
|
"""Base class of all performance testing cases.
|
|
|
|
Each sub-class should override methods execute_test, in which
|
|
several GDB operations are performed and measured by attribute
|
|
measure. Sub-class can also override method warm_up optionally
|
|
if the test case needs warm up.
|
|
"""
|
|
|
|
def __init__(self, name, measure):
|
|
"""Constructor of TestCase.
|
|
|
|
Construct an instance of TestCase with a name and a measure
|
|
which is to measure the test by several different measurements.
|
|
"""
|
|
|
|
self.name = name
|
|
self.measure = measure
|
|
|
|
def execute_test(self):
|
|
"""Abstract method to do the actual tests."""
|
|
raise NotImplementedError("Abstract Method.")
|
|
|
|
def warm_up(self):
|
|
"""Do some operations to warm up the environment."""
|
|
pass
|
|
|
|
def run(self, warm_up=True, append=True):
|
|
"""Run this test case.
|
|
|
|
It is a template method to invoke method warm_up,
|
|
execute_test, and finally report the measured results.
|
|
If parameter warm_up is True, run method warm_up. If parameter
|
|
append is True, the test result will be appended instead of
|
|
overwritten.
|
|
"""
|
|
if warm_up:
|
|
self.warm_up()
|
|
|
|
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))
|