35 |
35 |
36 libdir = '@LIBDIR@' |
36 libdir = '@LIBDIR@' |
37 |
37 |
38 if libdir != '@' 'LIBDIR' '@': |
38 if libdir != '@' 'LIBDIR' '@': |
39 if not os.path.isabs(libdir): |
39 if not os.path.isabs(libdir): |
40 libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), |
40 libdir = os.path.join( |
41 libdir) |
41 os.path.dirname(os.path.realpath(__file__)), libdir |
|
42 ) |
42 libdir = os.path.abspath(libdir) |
43 libdir = os.path.abspath(libdir) |
43 sys.path.insert(0, libdir) |
44 sys.path.insert(0, libdir) |
44 |
45 |
45 # enable importing on demand to reduce startup time |
46 # enable importing on demand to reduce startup time |
46 try: |
47 try: |
47 from mercurial import demandimport; demandimport.enable() |
48 from mercurial import demandimport |
|
49 |
|
50 demandimport.enable() |
48 except ImportError: |
51 except ImportError: |
49 import sys |
52 import sys |
50 sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" % |
53 |
51 ' '.join(sys.path)) |
54 sys.stderr.write( |
|
55 "abort: couldn't find mercurial libraries in [%s]\n" |
|
56 % ' '.join(sys.path) |
|
57 ) |
52 sys.stderr.write("(check your install and PYTHONPATH)\n") |
58 sys.stderr.write("(check your install and PYTHONPATH)\n") |
53 sys.exit(-1) |
59 sys.exit(-1) |
54 |
60 |
55 from mercurial import ( |
61 from mercurial import ( |
56 dispatch, |
62 dispatch, |
57 util, |
63 util, |
58 ) |
64 ) |
|
65 |
59 |
66 |
60 def timer(func, title=None): |
67 def timer(func, title=None): |
61 results = [] |
68 results = [] |
62 begin = util.timer() |
69 begin = util.timer() |
63 count = 0 |
70 count = 0 |
67 r = func() |
74 r = func() |
68 cstop = util.timer() |
75 cstop = util.timer() |
69 ostop = os.times() |
76 ostop = os.times() |
70 count += 1 |
77 count += 1 |
71 a, b = ostart, ostop |
78 a, b = ostart, ostop |
72 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
79 results.append((cstop - cstart, b[0] - a[0], b[1] - a[1])) |
73 if cstop - begin > 3 and count >= 100: |
80 if cstop - begin > 3 and count >= 100: |
74 break |
81 break |
75 if cstop - begin > 10 and count >= 3: |
82 if cstop - begin > 10 and count >= 3: |
76 break |
83 break |
77 if title: |
84 if title: |
78 sys.stderr.write("! %s\n" % title) |
85 sys.stderr.write("! %s\n" % title) |
79 if r: |
86 if r: |
80 sys.stderr.write("! result: %s\n" % r) |
87 sys.stderr.write("! result: %s\n" % r) |
81 m = min(results) |
88 m = min(results) |
82 sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" |
89 sys.stderr.write( |
83 % (m[0], m[1] + m[2], m[1], m[2], count)) |
90 "! wall %f comb %f user %f sys %f (best of %d)\n" |
|
91 % (m[0], m[1] + m[2], m[1], m[2], count) |
|
92 ) |
|
93 |
84 |
94 |
85 orgruncommand = dispatch.runcommand |
95 orgruncommand = dispatch.runcommand |
|
96 |
86 |
97 |
87 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): |
98 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): |
88 ui.pushbuffer() |
99 ui.pushbuffer() |
89 lui.pushbuffer() |
100 lui.pushbuffer() |
90 timer(lambda : orgruncommand(lui, repo, cmd, fullargs, ui, |
101 timer( |
91 options, d, cmdpats, cmdoptions)) |
102 lambda: orgruncommand( |
|
103 lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions |
|
104 ) |
|
105 ) |
92 ui.popbuffer() |
106 ui.popbuffer() |
93 lui.popbuffer() |
107 lui.popbuffer() |
|
108 |
94 |
109 |
95 dispatch.runcommand = runcommand |
110 dispatch.runcommand = runcommand |
96 |
111 |
97 dispatch.run() |
112 dispatch.run() |