50 sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" % |
50 sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" % |
51 ' '.join(sys.path)) |
51 ' '.join(sys.path)) |
52 sys.stderr.write("(check your install and PYTHONPATH)\n") |
52 sys.stderr.write("(check your install and PYTHONPATH)\n") |
53 sys.exit(-1) |
53 sys.exit(-1) |
54 |
54 |
55 import mercurial.util |
55 from mercurial import ( |
56 import mercurial.dispatch |
56 dispatch, |
|
57 util, |
|
58 ) |
57 |
59 |
58 def timer(func, title=None): |
60 def timer(func, title=None): |
59 results = [] |
61 results = [] |
60 begin = mercurial.util.timer() |
62 begin = util.timer() |
61 count = 0 |
63 count = 0 |
62 while True: |
64 while True: |
63 ostart = os.times() |
65 ostart = os.times() |
64 cstart = mercurial.util.timer() |
66 cstart = util.timer() |
65 r = func() |
67 r = func() |
66 cstop = mercurial.util.timer() |
68 cstop = util.timer() |
67 ostop = os.times() |
69 ostop = os.times() |
68 count += 1 |
70 count += 1 |
69 a, b = ostart, ostop |
71 a, b = ostart, ostop |
70 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
72 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
71 if cstop - begin > 3 and count >= 100: |
73 if cstop - begin > 3 and count >= 100: |
78 sys.stderr.write("! result: %s\n" % r) |
80 sys.stderr.write("! result: %s\n" % r) |
79 m = min(results) |
81 m = min(results) |
80 sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" |
82 sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" |
81 % (m[0], m[1] + m[2], m[1], m[2], count)) |
83 % (m[0], m[1] + m[2], m[1], m[2], count)) |
82 |
84 |
83 orgruncommand = mercurial.dispatch.runcommand |
85 orgruncommand = dispatch.runcommand |
84 |
86 |
85 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): |
87 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): |
86 ui.pushbuffer() |
88 ui.pushbuffer() |
87 lui.pushbuffer() |
89 lui.pushbuffer() |
88 timer(lambda : orgruncommand(lui, repo, cmd, fullargs, ui, |
90 timer(lambda : orgruncommand(lui, repo, cmd, fullargs, ui, |
89 options, d, cmdpats, cmdoptions)) |
91 options, d, cmdpats, cmdoptions)) |
90 ui.popbuffer() |
92 ui.popbuffer() |
91 lui.popbuffer() |
93 lui.popbuffer() |
92 |
94 |
93 mercurial.dispatch.runcommand = runcommand |
95 dispatch.runcommand = runcommand |
94 |
96 |
95 for fp in (sys.stdin, sys.stdout, sys.stderr): |
97 for fp in (sys.stdin, sys.stdout, sys.stderr): |
96 mercurial.util.setbinary(fp) |
98 util.setbinary(fp) |
97 |
99 |
98 mercurial.dispatch.run() |
100 dispatch.run() |