##// END OF EJS Templates
perf: add threading capability to perfbdiff...
Boris Feld -
r35617:af25237b default
parent child Browse files
Show More
@@ -25,7 +25,9 b' import os'
25 import random
25 import random
26 import struct
26 import struct
27 import sys
27 import sys
28 import threading
28 import time
29 import time
30 import util.queue
29 from mercurial import (
31 from mercurial import (
30 changegroup,
32 changegroup,
31 cmdutil,
33 cmdutil,
@@ -933,11 +935,25 b' def perffncacheencode(ui, repo, **opts):'
933 timer(d)
935 timer(d)
934 fm.end()
936 fm.end()
935
937
938 def _bdiffworker(q, ready, done):
939 while not done.is_set():
940 pair = q.get()
941 while pair is not None:
942 mdiff.textdiff(*pair)
943 q.task_done()
944 pair = q.get()
945 q.task_done() # for the None one
946 with ready:
947 ready.wait()
948
936 @command('perfbdiff', revlogopts + formatteropts + [
949 @command('perfbdiff', revlogopts + formatteropts + [
937 ('', 'count', 1, 'number of revisions to test (when using --startrev)'),
950 ('', 'count', 1, 'number of revisions to test (when using --startrev)'),
938 ('', 'alldata', False, 'test bdiffs for all associated revisions')],
951 ('', 'alldata', False, 'test bdiffs for all associated revisions'),
952 ('', 'threads', 0, 'number of thread to use (disable with 0)'),
953 ],
954
939 '-c|-m|FILE REV')
955 '-c|-m|FILE REV')
940 def perfbdiff(ui, repo, file_, rev=None, count=None, **opts):
956 def perfbdiff(ui, repo, file_, rev=None, count=None, threads=0, **opts):
941 """benchmark a bdiff between revisions
957 """benchmark a bdiff between revisions
942
958
943 By default, benchmark a bdiff between its delta parent and itself.
959 By default, benchmark a bdiff between its delta parent and itself.
@@ -983,14 +999,39 b' def perfbdiff(ui, repo, file_, rev=None,'
983 dp = r.deltaparent(rev)
999 dp = r.deltaparent(rev)
984 textpairs.append((r.revision(dp), r.revision(rev)))
1000 textpairs.append((r.revision(dp), r.revision(rev)))
985
1001
1002 withthreads = threads > 0
1003 if not withthreads:
986 def d():
1004 def d():
987 for pair in textpairs:
1005 for pair in textpairs:
988 mdiff.textdiff(*pair)
1006 mdiff.textdiff(*pair)
989
1007 else:
1008 q = util.queue()
1009 for i in xrange(threads):
1010 q.put(None)
1011 ready = threading.Condition()
1012 done = threading.Event()
1013 for i in xrange(threads):
1014 threading.Thread(target=_bdiffworker, args=(q, ready, done)).start()
1015 q.join()
1016 def d():
1017 for pair in textpairs:
1018 q.put(pair)
1019 for i in xrange(threads):
1020 q.put(None)
1021 with ready:
1022 ready.notify_all()
1023 q.join()
990 timer, fm = gettimer(ui, opts)
1024 timer, fm = gettimer(ui, opts)
991 timer(d)
1025 timer(d)
992 fm.end()
1026 fm.end()
993
1027
1028 if withthreads:
1029 done.set()
1030 for i in xrange(threads):
1031 q.put(None)
1032 with ready:
1033 ready.notify_all()
1034
994 @command('perfdiffwd', formatteropts)
1035 @command('perfdiffwd', formatteropts)
995 def perfdiffwd(ui, repo, **opts):
1036 def perfdiffwd(ui, repo, **opts):
996 """Profile diff of working directory changes"""
1037 """Profile diff of working directory changes"""
@@ -175,7 +175,7 b' Check perf.py for historical portability'
175 $ (testrepohg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py;
175 $ (testrepohg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py;
176 > testrepohg files -r tip glob:mercurial/*.c glob:mercurial/*.py) |
176 > testrepohg files -r tip glob:mercurial/*.c glob:mercurial/*.py) |
177 > "$TESTDIR"/check-perf-code.py contrib/perf.py
177 > "$TESTDIR"/check-perf-code.py contrib/perf.py
178 contrib/perf.py:498:
178 contrib/perf.py:\d+: (re)
179 > from mercurial import (
179 > from mercurial import (
180 import newer module separately in try clause for early Mercurial
180 import newer module separately in try clause for early Mercurial
181 [1]
181 [1]
General Comments 0
You need to be logged in to leave comments. Login now