summaryrefslogtreecommitdiff
path: root/seivot
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-04-21 11:03:57 +0100
committerLars Wirzenius <liw@liw.fi>2011-04-21 11:03:57 +0100
commit556af7f77a94877e26862da459a9c3521a57ae5b (patch)
tree1d61e8a44df845fb84a30039ea3e48f14b16ef6d /seivot
parenta92fea7f35707a93d3a0c75c4e9a7aeff88ef9d1 (diff)
downloadseivot-556af7f77a94877e26862da459a9c3521a57ae5b.tar.gz
Make --obnam-profile get a filename pattern instead of boolean.
This makes it easier for a caller to specify where the results of each profiling go.
Diffstat (limited to 'seivot')
-rwxr-xr-xseivot39
1 files changed, 28 insertions, 11 deletions
diff --git a/seivot b/seivot
index 13cdb12..56afd79 100755
--- a/seivot
+++ b/seivot
@@ -132,17 +132,26 @@ class Obnam(BackupProgram):
def _run(self, args, nth_gen, **kwargs):
env = dict(os.environ)
if self.settings['obnam-profile']:
- parts = ['obnam']
- parts += [args[0]]
- parts += ['gen%d' % nth_gen]
- basename = ('-'.join(parts)) + '.prof'
- pathname = os.path.join(os.getcwd(), basename)
- env['OBNAM_PROFILE'] = pathname
+ fd, env['OBNAM_PROFILE'] = tempfile.mkstemp()
+ os.close(fd)
if self._larch_branch:
env['PYTHONPATH'] = self._larch_branch
- return runcmd([self._cmd, '--log', '/dev/null',
- '--repository', self.repo] + args,
- cwd=self._branch, env=env, **kwargs)
+ result = runcmd([self._cmd, '--log', '/dev/null',
+ '--repository', self.repo] + args,
+ cwd=self._branch, env=env, **kwargs)
+ if self.settings['obnam-profile']:
+ namepattern = {
+ 'gen': str(nth_gen),
+ 'op': args[0],
+ }
+ for order in ['cumulative', 'time']:
+ namepattern['order'] = order
+ name = self.settings['obnam-profile'] % namepattern
+ f = open(name, 'w')
+ runcmd(['viewprof', env['OBNAM_PROFILE'], order], stdout=f)
+ f.close()
+ os.remove(env['OBNAM_PROFILE'])
+ return result
def prepare(self):
if self._branch:
@@ -266,8 +275,16 @@ class Seivot(cliapp.Application):
self.settings.add_string_setting(['larch-branch'],
'bzr branch from which to use larch '
'(default is installed larch)')
- self.settings.add_boolean_setting(['obnam-profile'],
- 'profile obnam?')
+ self.settings.add_string_setting(['obnam-profile'],
+ 'store Python profiling output '
+ 'in files named after NAMEPATTERN '
+ '(no profiling, unless set); '
+ '%(foo)s in pattern gets filled '
+ 'in, where foo is op (for '
+ 'backup/restore/etc), gen, or '
+ 'order (cumulative/time)',
+ metavar='NAMEPATTERN',
+ default='')
def process_args(self, args):
progname = self.settings['program']