mirror of
https://github.com/borgbackup/borg.git
synced 2024-09-19 08:18:10 +03:00
replace external script with "borg debug convert-profile"
This commit is contained in:
parent
a07463c96a
commit
6d6ae65be3
@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import marshal
|
||||
import sys
|
||||
|
||||
import msgpack
|
||||
|
||||
if len(sys.argv) not in (2, 3):
|
||||
print('Synopsis:', sys.argv[0], '<msgpack input>', '[marshal output]', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
outfile = sys.stdout
|
||||
else:
|
||||
outfile = open(sys.argv[2], 'wb')
|
||||
|
||||
with outfile:
|
||||
with open(sys.argv[1], 'rb') as infile:
|
||||
marshal.dump(msgpack.unpack(infile, use_list=False, encoding='utf-8'), outfile)
|
@ -1576,6 +1576,13 @@ def do_debug_refcount_obj(self, args, repository, manifest, key, cache):
|
||||
print("object %s not found [info from chunks cache]." % hex_id)
|
||||
return EXIT_SUCCESS
|
||||
|
||||
def do_debug_convert_profile(self, args):
|
||||
"""convert Borg profile to Python profile"""
|
||||
import marshal
|
||||
with args.output, args.input:
|
||||
marshal.dump(msgpack.unpack(args.input, use_list=False, encoding='utf-8'), args.output)
|
||||
return EXIT_SUCCESS
|
||||
|
||||
@with_repository(lock=False, manifest=False)
|
||||
def do_break_lock(self, args, repository):
|
||||
"""Break the repository lock (e.g. in case it was left by a dead borg."""
|
||||
@ -2050,7 +2057,7 @@ def define_common_options(add_common_option):
|
||||
action='store_true', default=False,
|
||||
help='treat part files like normal files (e.g. to list/extract them)')
|
||||
add_common_option('--debug-profile', dest='debug_profile', default=None, metavar='FILE',
|
||||
help='Write Python profile in msgpack format into FILE. For local use a cProfile-'
|
||||
help='Write execution profile in Borg format into FILE. For local use a Python-'
|
||||
'compatible file can be generated by suffixing FILE with ".pyprof".')
|
||||
|
||||
parser = argparse.ArgumentParser(prog=self.prog, description='Borg - Deduplicated Backups',
|
||||
@ -3390,6 +3397,20 @@ def define_common_options(add_common_option):
|
||||
subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
|
||||
help='hex object ID(s) to show refcounts for')
|
||||
|
||||
debug_convert_profile_epilog = process_epilog("""
|
||||
Convert a Borg profile to a Python cProfile compatible profile.
|
||||
""")
|
||||
subparser = debug_parsers.add_parser('convert-profile', parents=[common_parser], add_help=False,
|
||||
description=self.do_debug_convert_profile.__doc__,
|
||||
epilog=debug_convert_profile_epilog,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
help='convert Borg profile to Python profile (debug)')
|
||||
subparser.set_defaults(func=self.do_debug_convert_profile)
|
||||
subparser.add_argument('input', metavar='INPUT', type=argparse.FileType('rb'),
|
||||
help='Borg profile')
|
||||
subparser.add_argument('output', metavar='OUTPUT', type=argparse.FileType('wb'),
|
||||
help='Output file')
|
||||
|
||||
benchmark_epilog = process_epilog("These commands do various benchmarks.")
|
||||
|
||||
subparser = subparsers.add_parser('benchmark', parents=[mid_common_parser], add_help=False,
|
||||
@ -3551,7 +3572,7 @@ def run(self, args):
|
||||
import marshal
|
||||
logger.debug('Writing execution profile to %s', args.debug_profile)
|
||||
# Open the file early, before running the main program, to avoid
|
||||
# a very late crash in case the specified path is invalid
|
||||
# a very late crash in case the specified path is invalid.
|
||||
with open(args.debug_profile, 'wb') as fd:
|
||||
profiler = cProfile.Profile()
|
||||
variables = dict(locals())
|
||||
|
@ -1686,9 +1686,8 @@ def test_debug_profile(self):
|
||||
self.create_test_files()
|
||||
self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||
self.cmd('create', self.repository_location + '::test', 'input', '--debug-profile=create.prof')
|
||||
stats = pstats.Stats()
|
||||
with open('create.prof', 'rb') as fd:
|
||||
stats.stats = msgpack.unpack(fd, use_list=False, encoding='utf-8')
|
||||
self.cmd('debug', 'convert-profile', 'create.prof', 'create.pyprof')
|
||||
stats = pstats.Stats('create.pyprof')
|
||||
stats.strip_dirs()
|
||||
stats.sort_stats('cumtime')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user