Mercurial > public > mercurial-scm > hg
comparison contrib/perf.py @ 36766:d382344c69aa
perf: teach perfbdiff to call blocks() and to use xdiff
Differential Revision: https://phab.mercurial-scm.org/D2624
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 03 Mar 2018 18:55:43 -0500 |
parents | c25290b98190 |
children | 14cd5290c4e6 |
comparison
equal
deleted
inserted
replaced
36765:04d64163039a | 36766:d382344c69aa |
---|---|
937 for p in s.fncache.entries: | 937 for p in s.fncache.entries: |
938 s.encode(p) | 938 s.encode(p) |
939 timer(d) | 939 timer(d) |
940 fm.end() | 940 fm.end() |
941 | 941 |
942 def _bdiffworker(q, ready, done): | 942 def _bdiffworker(q, blocks, xdiff, ready, done): |
943 while not done.is_set(): | 943 while not done.is_set(): |
944 pair = q.get() | 944 pair = q.get() |
945 while pair is not None: | 945 while pair is not None: |
946 mdiff.textdiff(*pair) | 946 if xdiff: |
947 mdiff.bdiff.xdiffblocks(*pair) | |
948 elif blocks: | |
949 mdiff.bdiff.blocks(*pair) | |
950 else: | |
951 mdiff.textdiff(*pair) | |
947 q.task_done() | 952 q.task_done() |
948 pair = q.get() | 953 pair = q.get() |
949 q.task_done() # for the None one | 954 q.task_done() # for the None one |
950 with ready: | 955 with ready: |
951 ready.wait() | 956 ready.wait() |
952 | 957 |
953 @command('perfbdiff', revlogopts + formatteropts + [ | 958 @command('perfbdiff', revlogopts + formatteropts + [ |
954 ('', 'count', 1, 'number of revisions to test (when using --startrev)'), | 959 ('', 'count', 1, 'number of revisions to test (when using --startrev)'), |
955 ('', 'alldata', False, 'test bdiffs for all associated revisions'), | 960 ('', 'alldata', False, 'test bdiffs for all associated revisions'), |
956 ('', 'threads', 0, 'number of thread to use (disable with 0)'), | 961 ('', 'threads', 0, 'number of thread to use (disable with 0)'), |
962 ('', 'blocks', False, 'test computing diffs into blocks'), | |
963 ('', 'xdiff', False, 'use xdiff algorithm'), | |
957 ], | 964 ], |
958 | 965 |
959 '-c|-m|FILE REV') | 966 '-c|-m|FILE REV') |
960 def perfbdiff(ui, repo, file_, rev=None, count=None, threads=0, **opts): | 967 def perfbdiff(ui, repo, file_, rev=None, count=None, threads=0, **opts): |
961 """benchmark a bdiff between revisions | 968 """benchmark a bdiff between revisions |
967 | 974 |
968 With ``--alldata``, assume the requested revision is a changeset and | 975 With ``--alldata``, assume the requested revision is a changeset and |
969 measure bdiffs for all changes related to that changeset (manifest | 976 measure bdiffs for all changes related to that changeset (manifest |
970 and filelogs). | 977 and filelogs). |
971 """ | 978 """ |
979 opts = pycompat.byteskwargs(opts) | |
980 | |
981 if opts['xdiff'] and not opts['blocks']: | |
982 raise error.CommandError('perfbdiff', '--xdiff requires --blocks') | |
983 | |
972 if opts['alldata']: | 984 if opts['alldata']: |
973 opts['changelog'] = True | 985 opts['changelog'] = True |
974 | 986 |
975 if opts.get('changelog') or opts.get('manifest'): | 987 if opts.get('changelog') or opts.get('manifest'): |
976 file_, rev = None, file_ | 988 file_, rev = None, file_ |
977 elif rev is None: | 989 elif rev is None: |
978 raise error.CommandError('perfbdiff', 'invalid arguments') | 990 raise error.CommandError('perfbdiff', 'invalid arguments') |
979 | 991 |
992 blocks = opts['blocks'] | |
993 xdiff = opts['xdiff'] | |
980 textpairs = [] | 994 textpairs = [] |
981 | 995 |
982 r = cmdutil.openrevlog(repo, 'perfbdiff', file_, opts) | 996 r = cmdutil.openrevlog(repo, 'perfbdiff', file_, opts) |
983 | 997 |
984 startrev = r.rev(r.lookup(rev)) | 998 startrev = r.rev(r.lookup(rev)) |
1005 | 1019 |
1006 withthreads = threads > 0 | 1020 withthreads = threads > 0 |
1007 if not withthreads: | 1021 if not withthreads: |
1008 def d(): | 1022 def d(): |
1009 for pair in textpairs: | 1023 for pair in textpairs: |
1010 mdiff.textdiff(*pair) | 1024 if xdiff: |
1025 mdiff.bdiff.xdiffblocks(*pair) | |
1026 elif blocks: | |
1027 mdiff.bdiff.blocks(*pair) | |
1028 else: | |
1029 mdiff.textdiff(*pair) | |
1011 else: | 1030 else: |
1012 q = util.queue() | 1031 q = util.queue() |
1013 for i in xrange(threads): | 1032 for i in xrange(threads): |
1014 q.put(None) | 1033 q.put(None) |
1015 ready = threading.Condition() | 1034 ready = threading.Condition() |
1016 done = threading.Event() | 1035 done = threading.Event() |
1017 for i in xrange(threads): | 1036 for i in xrange(threads): |
1018 threading.Thread(target=_bdiffworker, args=(q, ready, done)).start() | 1037 threading.Thread(target=_bdiffworker, |
1038 args=(q, blocks, xdiff, ready, done)).start() | |
1019 q.join() | 1039 q.join() |
1020 def d(): | 1040 def d(): |
1021 for pair in textpairs: | 1041 for pair in textpairs: |
1022 q.put(pair) | 1042 q.put(pair) |
1023 for i in xrange(threads): | 1043 for i in xrange(threads): |