Show More
@@ -1,30 +1,73 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # |
|
2 | # | |
3 | # check-perf-code - (historical) portability checker for contrib/perf.py |
|
3 | # check-perf-code - (historical) portability checker for contrib/perf.py | |
4 |
|
4 | |||
5 | from __future__ import absolute_import |
|
5 | from __future__ import absolute_import | |
6 |
|
6 | |||
7 | import os |
|
7 | import os | |
8 | import sys |
|
8 | import sys | |
9 |
|
9 | |||
10 | # write static check patterns here |
|
10 | # write static check patterns here | |
11 | perfpypats = [ |
|
11 | perfpypats = [ | |
12 | [ |
|
12 | [ | |
13 | ], |
|
13 | ], | |
14 | # warnings |
|
14 | # warnings | |
15 | [ |
|
15 | [ | |
16 | ] |
|
16 | ] | |
17 | ] |
|
17 | ] | |
18 |
|
18 | |||
|
19 | def modulewhitelist(names): | |||
|
20 | replacement = [('.py', ''), ('.c', ''), # trim suffix | |||
|
21 | ('mercurial%s' % (os.sep), ''), # trim "mercurial/" path | |||
|
22 | ] | |||
|
23 | ignored = set(['__init__']) | |||
|
24 | modules = {} | |||
|
25 | ||||
|
26 | # convert from file name to module name, and count # of appearances | |||
|
27 | for name in names: | |||
|
28 | name = name.strip() | |||
|
29 | for old, new in replacement: | |||
|
30 | name = name.replace(old, new) | |||
|
31 | if name not in ignored: | |||
|
32 | modules[name] = modules.get(name, 0) + 1 | |||
|
33 | ||||
|
34 | # list up module names, which appear multiple times | |||
|
35 | whitelist = [] | |||
|
36 | for name, count in modules.items(): | |||
|
37 | if count > 1: | |||
|
38 | whitelist.append(name) | |||
|
39 | ||||
|
40 | return whitelist | |||
|
41 | ||||
19 | if __name__ == "__main__": |
|
42 | if __name__ == "__main__": | |
|
43 | # in this case, it is assumed that result of "hg files" at | |||
|
44 | # multiple revisions is given via stdin | |||
|
45 | whitelist = modulewhitelist(sys.stdin) | |||
|
46 | assert whitelist, "module whitelist is empty" | |||
|
47 | ||||
|
48 | # build up module whitelist check from file names given at runtime | |||
|
49 | perfpypats[0].append( | |||
|
50 | # this matching pattern assumes importing modules from | |||
|
51 | # "mercurial" package in the current style below, for simplicity | |||
|
52 | # | |||
|
53 | # from mercurial import ( | |||
|
54 | # foo, | |||
|
55 | # bar, | |||
|
56 | # baz | |||
|
57 | # ) | |||
|
58 | ((r'from mercurial import [(][a-z0-9, \n#]*\n(?! *%s,|^[ #]*\n|[)])' | |||
|
59 | % ',| *'.join(whitelist)), | |||
|
60 | "import newer module separately in try clause for early Mercurial" | |||
|
61 | )) | |||
|
62 | ||||
20 | # import contrib/check-code.py as checkcode |
|
63 | # import contrib/check-code.py as checkcode | |
21 | assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script" |
|
64 | assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script" | |
22 | contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib') |
|
65 | contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib') | |
23 | sys.path.insert(0, contribpath) |
|
66 | sys.path.insert(0, contribpath) | |
24 | checkcode = __import__('check-code') |
|
67 | checkcode = __import__('check-code') | |
25 |
|
68 | |||
26 | # register perf.py specific entry with "checks" in check-code.py |
|
69 | # register perf.py specific entry with "checks" in check-code.py | |
27 | checkcode.checks.append(('perf.py', r'contrib/perf.py$', '', |
|
70 | checkcode.checks.append(('perf.py', r'contrib/perf.py$', '', | |
28 | checkcode.pyfilters, perfpypats)) |
|
71 | checkcode.pyfilters, perfpypats)) | |
29 |
|
72 | |||
30 | sys.exit(checkcode.main()) |
|
73 | sys.exit(checkcode.main()) |
@@ -1,155 +1,157 | |||||
1 | #require test-repo |
|
1 | #require test-repo | |
2 |
|
2 | |||
3 | Set vars: |
|
3 | Set vars: | |
4 |
|
4 | |||
5 | $ . "$TESTDIR/helpers-testrepo.sh" |
|
5 | $ . "$TESTDIR/helpers-testrepo.sh" | |
6 | $ CONTRIBDIR="$TESTDIR/../contrib" |
|
6 | $ CONTRIBDIR="$TESTDIR/../contrib" | |
7 |
|
7 | |||
8 | Prepare repo: |
|
8 | Prepare repo: | |
9 |
|
9 | |||
10 | $ hg init |
|
10 | $ hg init | |
11 |
|
11 | |||
12 | $ echo this is file a > a |
|
12 | $ echo this is file a > a | |
13 | $ hg add a |
|
13 | $ hg add a | |
14 | $ hg commit -m first |
|
14 | $ hg commit -m first | |
15 |
|
15 | |||
16 | $ echo adding to file a >> a |
|
16 | $ echo adding to file a >> a | |
17 | $ hg commit -m second |
|
17 | $ hg commit -m second | |
18 |
|
18 | |||
19 | $ echo adding more to file a >> a |
|
19 | $ echo adding more to file a >> a | |
20 | $ hg commit -m third |
|
20 | $ hg commit -m third | |
21 |
|
21 | |||
22 | $ hg up -r 0 |
|
22 | $ hg up -r 0 | |
23 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
23 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
24 | $ echo merge-this >> a |
|
24 | $ echo merge-this >> a | |
25 | $ hg commit -m merge-able |
|
25 | $ hg commit -m merge-able | |
26 | created new head |
|
26 | created new head | |
27 |
|
27 | |||
28 | $ hg up -r 2 |
|
28 | $ hg up -r 2 | |
29 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
29 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
30 |
|
30 | |||
31 | perfstatus |
|
31 | perfstatus | |
32 |
|
32 | |||
33 | $ cat >> $HGRCPATH << EOF |
|
33 | $ cat >> $HGRCPATH << EOF | |
34 | > [extensions] |
|
34 | > [extensions] | |
35 | > perfstatusext=$CONTRIBDIR/perf.py |
|
35 | > perfstatusext=$CONTRIBDIR/perf.py | |
36 | > [perf] |
|
36 | > [perf] | |
37 | > presleep=0 |
|
37 | > presleep=0 | |
38 | > stub=on |
|
38 | > stub=on | |
39 | > parentscount=1 |
|
39 | > parentscount=1 | |
40 | > EOF |
|
40 | > EOF | |
41 | $ hg help perfstatusext |
|
41 | $ hg help perfstatusext | |
42 | perfstatusext extension - helper extension to measure performance |
|
42 | perfstatusext extension - helper extension to measure performance | |
43 |
|
43 | |||
44 | list of commands: |
|
44 | list of commands: | |
45 |
|
45 | |||
46 | perfaddremove |
|
46 | perfaddremove | |
47 | (no help text available) |
|
47 | (no help text available) | |
48 | perfancestors |
|
48 | perfancestors | |
49 | (no help text available) |
|
49 | (no help text available) | |
50 | perfancestorset |
|
50 | perfancestorset | |
51 | (no help text available) |
|
51 | (no help text available) | |
52 | perfannotate (no help text available) |
|
52 | perfannotate (no help text available) | |
53 | perfbranchmap |
|
53 | perfbranchmap | |
54 | benchmark the update of a branchmap |
|
54 | benchmark the update of a branchmap | |
55 | perfcca (no help text available) |
|
55 | perfcca (no help text available) | |
56 | perfchangeset |
|
56 | perfchangeset | |
57 | (no help text available) |
|
57 | (no help text available) | |
58 | perfctxfiles (no help text available) |
|
58 | perfctxfiles (no help text available) | |
59 | perfdiffwd Profile diff of working directory changes |
|
59 | perfdiffwd Profile diff of working directory changes | |
60 | perfdirfoldmap |
|
60 | perfdirfoldmap | |
61 | (no help text available) |
|
61 | (no help text available) | |
62 | perfdirs (no help text available) |
|
62 | perfdirs (no help text available) | |
63 | perfdirstate (no help text available) |
|
63 | perfdirstate (no help text available) | |
64 | perfdirstatedirs |
|
64 | perfdirstatedirs | |
65 | (no help text available) |
|
65 | (no help text available) | |
66 | perfdirstatefoldmap |
|
66 | perfdirstatefoldmap | |
67 | (no help text available) |
|
67 | (no help text available) | |
68 | perfdirstatewrite |
|
68 | perfdirstatewrite | |
69 | (no help text available) |
|
69 | (no help text available) | |
70 | perffncacheencode |
|
70 | perffncacheencode | |
71 | (no help text available) |
|
71 | (no help text available) | |
72 | perffncacheload |
|
72 | perffncacheload | |
73 | (no help text available) |
|
73 | (no help text available) | |
74 | perffncachewrite |
|
74 | perffncachewrite | |
75 | (no help text available) |
|
75 | (no help text available) | |
76 | perfheads (no help text available) |
|
76 | perfheads (no help text available) | |
77 | perfindex (no help text available) |
|
77 | perfindex (no help text available) | |
78 | perfloadmarkers |
|
78 | perfloadmarkers | |
79 | benchmark the time to parse the on-disk markers for a repo |
|
79 | benchmark the time to parse the on-disk markers for a repo | |
80 | perflog (no help text available) |
|
80 | perflog (no help text available) | |
81 | perflookup (no help text available) |
|
81 | perflookup (no help text available) | |
82 | perflrucachedict |
|
82 | perflrucachedict | |
83 | (no help text available) |
|
83 | (no help text available) | |
84 | perfmanifest (no help text available) |
|
84 | perfmanifest (no help text available) | |
85 | perfmergecalculate |
|
85 | perfmergecalculate | |
86 | (no help text available) |
|
86 | (no help text available) | |
87 | perfmoonwalk benchmark walking the changelog backwards |
|
87 | perfmoonwalk benchmark walking the changelog backwards | |
88 | perfnodelookup |
|
88 | perfnodelookup | |
89 | (no help text available) |
|
89 | (no help text available) | |
90 | perfparents (no help text available) |
|
90 | perfparents (no help text available) | |
91 | perfpathcopies |
|
91 | perfpathcopies | |
92 | (no help text available) |
|
92 | (no help text available) | |
93 | perfrawfiles (no help text available) |
|
93 | perfrawfiles (no help text available) | |
94 | perfrevlog Benchmark reading a series of revisions from a revlog. |
|
94 | perfrevlog Benchmark reading a series of revisions from a revlog. | |
95 | perfrevlogrevision |
|
95 | perfrevlogrevision | |
96 | Benchmark obtaining a revlog revision. |
|
96 | Benchmark obtaining a revlog revision. | |
97 | perfrevrange (no help text available) |
|
97 | perfrevrange (no help text available) | |
98 | perfrevset benchmark the execution time of a revset |
|
98 | perfrevset benchmark the execution time of a revset | |
99 | perfstartup (no help text available) |
|
99 | perfstartup (no help text available) | |
100 | perfstatus (no help text available) |
|
100 | perfstatus (no help text available) | |
101 | perftags (no help text available) |
|
101 | perftags (no help text available) | |
102 | perftemplating |
|
102 | perftemplating | |
103 | (no help text available) |
|
103 | (no help text available) | |
104 | perfvolatilesets |
|
104 | perfvolatilesets | |
105 | benchmark the computation of various volatile set |
|
105 | benchmark the computation of various volatile set | |
106 | perfwalk (no help text available) |
|
106 | perfwalk (no help text available) | |
107 |
|
107 | |||
108 | (use "hg help -v perfstatusext" to show built-in aliases and global options) |
|
108 | (use "hg help -v perfstatusext" to show built-in aliases and global options) | |
109 | $ hg perfaddremove |
|
109 | $ hg perfaddremove | |
110 | $ hg perfancestors |
|
110 | $ hg perfancestors | |
111 | $ hg perfancestorset 2 |
|
111 | $ hg perfancestorset 2 | |
112 | $ hg perfannotate a |
|
112 | $ hg perfannotate a | |
113 | $ hg perfbranchmap |
|
113 | $ hg perfbranchmap | |
114 | $ hg perfcca |
|
114 | $ hg perfcca | |
115 | $ hg perfchangeset 2 |
|
115 | $ hg perfchangeset 2 | |
116 | $ hg perfctxfiles 2 |
|
116 | $ hg perfctxfiles 2 | |
117 | $ hg perfdiffwd |
|
117 | $ hg perfdiffwd | |
118 | $ hg perfdirfoldmap |
|
118 | $ hg perfdirfoldmap | |
119 | $ hg perfdirs |
|
119 | $ hg perfdirs | |
120 | $ hg perfdirstate |
|
120 | $ hg perfdirstate | |
121 | $ hg perfdirstatedirs |
|
121 | $ hg perfdirstatedirs | |
122 | $ hg perfdirstatefoldmap |
|
122 | $ hg perfdirstatefoldmap | |
123 | $ hg perfdirstatewrite |
|
123 | $ hg perfdirstatewrite | |
124 | $ hg perffncacheencode |
|
124 | $ hg perffncacheencode | |
125 | $ hg perffncacheload |
|
125 | $ hg perffncacheload | |
126 | $ hg perffncachewrite |
|
126 | $ hg perffncachewrite | |
127 | $ hg perfheads |
|
127 | $ hg perfheads | |
128 | $ hg perfindex |
|
128 | $ hg perfindex | |
129 | $ hg perfloadmarkers |
|
129 | $ hg perfloadmarkers | |
130 | $ hg perflog |
|
130 | $ hg perflog | |
131 | $ hg perflookup 2 |
|
131 | $ hg perflookup 2 | |
132 | $ hg perflrucache |
|
132 | $ hg perflrucache | |
133 | $ hg perfmanifest 2 |
|
133 | $ hg perfmanifest 2 | |
134 | $ hg perfmergecalculate -r 3 |
|
134 | $ hg perfmergecalculate -r 3 | |
135 | $ hg perfmoonwalk |
|
135 | $ hg perfmoonwalk | |
136 | $ hg perfnodelookup 2 |
|
136 | $ hg perfnodelookup 2 | |
137 | $ hg perfpathcopies 1 2 |
|
137 | $ hg perfpathcopies 1 2 | |
138 | $ hg perfrawfiles 2 |
|
138 | $ hg perfrawfiles 2 | |
139 | $ hg perfrevlog .hg/store/data/a.i |
|
139 | $ hg perfrevlog .hg/store/data/a.i | |
140 | $ hg perfrevlogrevision -m 0 |
|
140 | $ hg perfrevlogrevision -m 0 | |
141 | $ hg perfrevrange |
|
141 | $ hg perfrevrange | |
142 | $ hg perfrevset 'all()' |
|
142 | $ hg perfrevset 'all()' | |
143 | $ hg perfstartup |
|
143 | $ hg perfstartup | |
144 | $ hg perfstatus |
|
144 | $ hg perfstatus | |
145 | $ hg perftags |
|
145 | $ hg perftags | |
146 | $ hg perftemplating |
|
146 | $ hg perftemplating | |
147 | $ hg perfvolatilesets |
|
147 | $ hg perfvolatilesets | |
148 | $ hg perfwalk |
|
148 | $ hg perfwalk | |
149 | $ hg perfparents |
|
149 | $ hg perfparents | |
150 |
|
150 | |||
151 | Check perf.py for historical portability |
|
151 | Check perf.py for historical portability | |
152 |
|
152 | |||
153 | $ cd "$TESTDIR/.." |
|
153 | $ cd "$TESTDIR/.." | |
154 |
|
154 | |||
155 | $ "$TESTDIR"/check-perf-code.py contrib/perf.py |
|
155 | $ (hg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py; | |
|
156 | > hg files -r tip glob:mercurial/*.c glob:mercurial/*.py) | | |||
|
157 | > "$TESTDIR"/check-perf-code.py contrib/perf.py |
General Comments 0
You need to be logged in to leave comments.
Login now