Performance testing tools
cover Performance testing tools
Here's the same scripts I posted earlier, but polished and extended.
---
Karl Hasselström (5):
Global performance logging
Log subprocess calls during performance testing Show full command in subprocess profiling Log subproces activity to a file
Add some performance testing scripts
perf/.gitignore | 2 + perf/create_synthetic_repo.py | 61 ++++++++++++++++++++++++++ perf/find_patchbomb.py | 31 +++++++++++++ perf/perftest.py | 96 +++++++++++++++++++++++++++++++++++++++++ perf/setup.sh | 52 ++++++++++++++++++++++ stgit/main.py | 11 ++++- stgit/out.py | 11 +++-- stgit/run.py | 61 +++++++++++++++++++++----- 8 files changed, 306 insertions(+), 19 deletions(-) create mode 100644 perf/.gitignore create mode 100644 perf/create_synthetic_repo.py create mode 100644 perf/find_patchbomb.py create mode 100644 perf/perftest.py create mode 100644 perf/setup.sh
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/5 Add some performance testing scripts
find_patchbomb.py: Given a git repo, finds the longest linear sequence
of commits. Useful for testing StGit on a real repository.
setup.sh: Creates two test repositories, one synthetic and one based
on the Linux kernel repo, with strategically placed tags.
create_synthetic_repo.py: Helper script for setup.sh; it produces
output that is to be fed to git fast-import.
perftest.py: Runs one of a (small) number of hard-coded performance
tests against a copy of one of the repos created by setup.sh. The initial testcases all involve uncommitting a large number of patches and then rebasing them.
---
perf/.gitignore | 2 + perf/create_synthetic_repo.py | 61 ++++++++++++++++++++++++++++ perf/find_patchbomb.py | 31 ++++++++++++++ perf/perftest.py | 88 +++++++++++++++++++++++++++++++++++++++++ perf/setup.sh | 52 ++++++++++++++++++++++++ 5 files changed, 234 insertions(+), 0 deletions(-) create mode 100644 perf/.gitignore create mode 100644 perf/create_synthetic_repo.py create mode 100644 perf/find_patchbomb.py create mode 100644 perf/perftest.py create mode 100644 perf/setup.sh
perf/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/*.orig +/*.trash
perf/create_synthetic_repo.py new file +61 -0
61 lines not on this page · raw message
perf/find_patchbomb.py new file +31 -0
@@ -0,0 +1,31 @@ +# Feed this with git rev-list HEAD --parents + +import sys + +parents = {} +for line in sys.stdin.readlines(): + commits = line.split() + parents[commits[0]] = commits[1:] + +sequence_num = {} +stack = [] +for commit in parents.keys(): + stack.append(commit) + while stack: + c = stack.pop() + if c in sequence_num: + continue + ps = parents[c] + if len(ps) == 1: + p = ps[0] + if p in sequence_num: + sequence_num[c] = 1 + sequence_num[p] + else: + stack.append(c) + stack.append(p) + else: + sequence_num[c] = 0 + +(num, commit) = max((num, commit) for (commit, num) + in sequence_num.iteritems()) +print '%s is a sequence of %d patches' % (commit, num)
perf/perftest.py new file +88 -0
88 lines not on this page · raw message
perf/setup.sh new file +52 -0
52 lines not on this page · raw message
PATCH 2/5 Log subproces activity to a file
In reply to Karl HasselströmIf the user sets $STGIT_SUBPROCESS_LOG to a log mode followed by a colon and a file name, append the log to that file instead of writing it to stdout.
---
stgit/out.py | 11 +++++++---- stgit/run.py | 35 +++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 16 deletions(-)
stgit/out.py +7 -4
@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys, textwrap class MessagePrinter(object): - def __init__(self): + def __init__(self, file = None): class Output(object): def __init__(self, write, flush): self.write = write
@@ -68,9 +68,12 @@ class MessagePrinter(object): self.new_line() self.write(string) self.at_start_of_line = string.endswith('\n') - self.__stderr = Output(sys.stderr.write, sys.stderr.flush) - self.__stdout = Output(sys.stdout.write, sys.stdout.flush) - if sys.stdout.isatty(): + if file: + self.__stdout = self.__stderr = Output(file.write, file.flush) + else: + self.__stdout = Output(sys.stdout.write, sys.stdout.flush) + self.__stderr = Output(sys.stdout.write, sys.stdout.flush) + if file or sys.stdout.isatty(): self.__out = self.__stdout self.__err = self.__stdout else:
stgit/run.py +23 -12
@@ -27,12 +27,22 @@ class RunException(StgException): subprocess.""" pass -_all_log_modes = ['debug', 'profile'] -_log_mode = os.environ.get('STGIT_SUBPROCESS_LOG', '') -if _log_mode and not _log_mode in _all_log_modes: - out.warn(('Unknown log mode "%s" specified in $STGIT_SUBPROCESS_LOG.' - % _log_mode), - 'Valid values are: %s' % ', '.join(_all_log_modes)) +def get_log_mode(spec): + if not ':' in spec: + spec += ':' + (log_mode, outfile) = spec.split(':', 1) + all_log_modes = ['debug', 'profile'] + if log_mode and not log_mode in all_log_modes: + out.warn(('Unknown log mode "%s" specified in $STGIT_SUBPROCESS_LOG.' + % log_mode), + 'Valid values are: %s' % ', '.join(all_log_modes)) + if outfile: + f = MessagePrinter(open(outfile, 'a')) + else: + f = out + return (log_mode, f) + +(_log_mode, _logfile) = get_log_mode(os.environ.get('STGIT_SUBPROCESS_LOG', '')) class Run: exc = RunException
@@ -47,22 +57,23 @@ class Run: self.__discard_stderr = False def __log_start(self): if _log_mode == 'debug': - out.start('Running subprocess %s' % self.__cmd) + _logfile.start('Running subprocess %s' % self.__cmd) if self.__cwd != None: - out.info('cwd: %s' % self.__cwd) + _logfile.info('cwd: %s' % self.__cwd) if self.__env != None: for k in sorted(self.__env.iterkeys()): if k not in os.environ or os.environ[k] != self.__env[k]: - out.info('%s: %s' % (k, self.__env[k])) + _logfile.info('%s: %s' % (k, self.__env[k])) elif _log_mode == 'profile': - out.start('Running subprocess %s' % self.__cmd[0]) + _logfile.start('Running subprocess %s' % self.__cmd[0]) self.__starttime = datetime.datetime.now() def __log_end(self, retcode): if _log_mode == 'debug': - out.done('return code: %d' % retcode) + _logfile.done('return code: %d' % retcode) elif _log_mode == 'profile': duration = datetime.datetime.now() - self.__starttime - out.done('%1.3f s' % (duration.microseconds/1e6 + duration.seconds)) + _logfile.done('%1.3f s' % (duration.microseconds/1e6 + + duration.seconds)) def __check_exitcode(self): if self.__good_retvals == None: return
PATCH 3/5 Show full command in subprocess profiling
In reply to Karl HasselströmShowing just the executable name isn't so useful now that it's always "git".
---
stgit/run.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
stgit/run.py +1 -1
@@ -65,7 +65,7 @@ class Run: if k not in os.environ or os.environ[k] != self.__env[k]: _logfile.info('%s: %s' % (k, self.__env[k])) elif _log_mode == 'profile': - _logfile.start('Running subprocess %s' % self.__cmd[0]) + _logfile.start('Running subprocess %s' % self.__cmd) self.__starttime = datetime.datetime.now() def __log_end(self, retcode): if _log_mode == 'debug':
PATCH 4/5 Log subprocess calls during performance testing
In reply to Karl HasselströmLog each command's subprocess calls to a separate file.
---
perf/perftest.py | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
perf/perftest.py +10 -2
@@ -1,4 +1,4 @@ -import datetime, subprocess, sys +import datetime, os, os.path, subprocess, sys def duration(t1, t2): d = t2 - t1
@@ -8,8 +8,16 @@ class Run(object): def __init__(self): self.__cwd = None self.__log = [] + def __logfile(self, cmd): + fn = os.path.join(os.getcwd(), '%04d.log' % len(self.__log)) + f = open(fn, 'w') + f.write(' '.join(cmd) + '\n' + '-'*70 + '\n\n') + f.close() + return fn def __call__(self, *cmd, **args): - kwargs = { 'cwd': self.__cwd } + env = dict(os.environ) + env['STGIT_SUBPROCESS_LOG'] = 'profile:' + self.__logfile(cmd) + kwargs = { 'cwd': self.__cwd, 'env': env } if args.get('capture_stdout', False): kwargs['stdout'] = subprocess.PIPE start = datetime.datetime.now()
PATCH 5/5 Global performance logging
In reply to Karl HasselströmMeasure the time for the whole program, and how much of that was subprocess calls.
---
stgit/main.py | 11 +++++++++-- stgit/run.py | 32 ++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-)
stgit/main.py +9 -2
@@ -23,7 +23,7 @@ from optparse import OptionParser import stgit.commands from stgit.out import * -from stgit import utils +from stgit import run, utils # # The commands map
@@ -192,7 +192,7 @@ def print_help(): # # The main function (command dispatcher) # -def main(): +def _main(): """The main function """ global prog
@@ -293,3 +293,10 @@ def main(): sys.exit(utils.STGIT_BUG_ERROR) sys.exit(ret or utils.STGIT_SUCCESS) + +def main(): + run.start_logging() + try: + _main() + finally: + run.stop_logging()
stgit/run.py +28 -4
@@ -42,7 +42,27 @@ def get_log_mode(spec): f = out return (log_mode, f) -(_log_mode, _logfile) = get_log_mode(os.environ.get('STGIT_SUBPROCESS_LOG', '')) +def start_logging(): + global _log_mode, _logfile, _log_starttime, _log_subproctime + (_log_mode, _logfile) = get_log_mode( + os.environ.get('STGIT_SUBPROCESS_LOG', '')) + _log_starttime = datetime.datetime.now() + _log_subproctime = 0.0 + +def duration(t1, t2): + d = t2 - t1 + return 86400*d.days + d.seconds + 1e-6*d.microseconds + +def stop_logging(): + if _log_mode != 'profile': + return + ttime = duration(_log_starttime, datetime.datetime.now()) + rtime = ttime - _log_subproctime + _logfile.info('Total time: %1.3f s' % ttime, + 'Time spent in subprocess calls: %1.3f s (%1.1f%%)' + % (_log_subproctime, 100*_log_subproctime/ttime), + 'Remaining time: %1.3f s (%1.1f%%)' + % (rtime, 100*rtime/ttime)) class Run: exc = RunException
@@ -68,12 +88,16 @@ class Run: _logfile.start('Running subprocess %s' % self.__cmd) self.__starttime = datetime.datetime.now() def __log_end(self, retcode): + global _log_subproctime, _log_starttime if _log_mode == 'debug': _logfile.done('return code: %d' % retcode) elif _log_mode == 'profile': - duration = datetime.datetime.now() - self.__starttime - _logfile.done('%1.3f s' % (duration.microseconds/1e6 - + duration.seconds)) + n = datetime.datetime.now() + d = duration(self.__starttime, n) + _logfile.done('%1.3f s' % d) + _log_subproctime += d + _logfile.info('Time since program start: %1.3f s' + % duration(_log_starttime, n)) def __check_exitcode(self): if self.__good_retvals == None: return
Re: [StGit PATCH 2/5] Log subproces activity to a file
In reply to Karl Hasselström2008/7/17 Karl Hasselström <[email protected]>:
Quoted 3 lines
If the user sets $STGIT_SUBPROCESS_LOG to a log mode followed by a colon and a file name, append the log to that file instead of writing it to stdout.
OK.
Signature · 1 line
Catalin
Re: [StGit PATCH 3/5] Show full command in subprocess profiling
In reply to Karl Hasselström2008/7/17 Karl Hasselström <[email protected]>:
Quoted 2 lines
Showing just the executable name isn't so useful now that it's always "git".
Yes, indeed.
Signature · 1 line
Catalin