Debian Codegraph @

tests/test-profile.t

raw
1
2 test --time
3
4 $ hg --time help -q help 2>&1 | grep time > /dev/null
5 $ hg init a
6 $ cd a
7
8 Function to check that statprof ran
9 $ statprofran () {
10 > grep -E 'Sample count:|No samples recorded' > /dev/null
11 > }
12
13 test --profile
14
15 $ hg st --profile 2>&1 | statprofran
16
17 Abreviated version
18
19 $ hg st --prof 2>&1 | statprofran
20
21 In alias
22
23 $ hg --config "alias.profst=status --profile" profst 2>&1 | statprofran
24
25 #if lsprof
26
27 $ prof () {
28 > hg --config profiling.type=ls --profile $@
29 > }
30
31 $ prof st 2>../out
32 $ grep CallCount ../out > /dev/null || cat ../out
33
34 $ prof --config profiling.output=../out st
35 $ grep CallCount ../out > /dev/null || cat ../out
36
37 $ prof --config profiling.output-dir=../profiles st
38 profiling output directory does not exist: ../profiles
39
40 $ prof --config profiling.output=../out \
41 > --config profiling.output-dir=../profiles st
42 $ grep CallCount ../out > /dev/null || cat ../out
43
44 $ prof --config profiling.output-dir=../profiles \
45 > --config profiling.output-dir:create=true st
46 $ ls ../profiles/*.prof | wc -l
47 \s*1 (re)
48 $ grep CallCount ../profiles/*.prof > /dev/null \
49 > || cat ../profiles/*.prof
50
51 $ prof --config profiling.output-dir=../profiles st
52 $ ls ../profiles/*.prof | wc -l
53 \s*2 (re)
54
55 $ prof --config profiling.output=blackbox --config extensions.blackbox= st
56 $ grep CallCount .hg/blackbox.log > /dev/null || cat .hg/blackbox.log
57
58 $ prof --config profiling.format=text st 2>../out
59 $ grep CallCount ../out > /dev/null || cat ../out
60
61 $ echo "[profiling]" >> $HGRCPATH
62 $ echo "format=kcachegrind" >> $HGRCPATH
63
64 $ prof st 2>../out
65 $ grep 'events: Ticks' ../out > /dev/null || cat ../out
66
67 $ prof --config profiling.output=../out st
68 $ grep 'events: Ticks' ../out > /dev/null || cat ../out
69
70 #endif
71
72 #if serve
73
74 Profiling of HTTP requests works
75
76 $ stats_prof () {
77 > hg --config profiling.type=stat --profile $@
78 > }
79
80 $ stats_prof \
81 > --config profiling.format=text \
82 > --config profiling.output=../profile.log \
83 > serve -d \
84 > -p $HGPORT \
85 > --pid-file ../hg.pid \
86 > -A ../access.log \
87 > --errorlog ../error.log
88 $ cat ../hg.pid >> $DAEMON_PIDS
89 $ hg -q clone -U http://localhost:$HGPORT ../clone
90 $ cat ../error.log
91
92 A single profile is logged because file logging doesn't append
93 $ grep 'Sample count:' ../profile.log | wc -l
94 \s*1 (re)
95 $ grep 'Total time:' ../profile.log | wc -l
96 \s*1 (re)
97
98 #endif
99
100 Install an extension that can sleep and guarantee a profiler has time to run
101
102 $ cat >> sleepext_with_a_long_filename.py << EOF
103 > import time
104 > from mercurial import registrar
105 > cmdtable = {}
106 > command = registrar.command(cmdtable)
107 > @command(b'sleep', [], b'hg sleep')
108 > def sleep_for_at_least_one_stat_cycle(ui, *args, **kwargs):
109 > t = time.time() # don't use time.sleep because we need CPU time
110 > while time.time() - t < 0.5:
111 > pass
112 > EOF
113
114 $ cat >> $HGRCPATH << EOF
115 > [extensions]
116 > sleep = `pwd`/sleepext_with_a_long_filename.py
117 > EOF
118
119 statistical profiler works
120
121 $ hg --profile sleep 2>../out
122 $ cat ../out | statprofran
123
124 Various statprof formatters work
125
126 $ hg --profile --config profiling.statformat=byline sleep 2>../out || cat ../out
127 $ grep -v _path_stat ../out | grep -v "frozen importlib._bootstrap_external" | head -n 3
128 % cumulative self
129 time seconds seconds name
130 * sleepext_with_a_long_filename.py:*:sleep_for_at_least_one_stat_cycle (glob)
131 $ cat ../out | statprofran
132
133 $ hg --profile --config profiling.statformat=bymethod sleep 2>../out || cat ../out
134 $ head -n 1 ../out
135 % cumulative self
136 $ cat ../out | statprofran
137
138 Windows real time tracking is broken, only use CPU
139
140 #if no-windows
141 $ hg --profile --config profiling.time-track=real --config profiling.statformat=hotpath sleep 2>../out || cat ../out
142 $ cat ../out | statprofran
143 $ grep sleepext_with_a_long_filename.py ../out | head -n 1
144 .* [0-9.]+% [0-9.]+s sleepext_with_a_long_filename.py:\s*sleep_for_at_least_one_stat_cycle, line \d+:\s+(while|pass).* (re)
145 #endif
146
147 $ hg --profile --config profiling.time-track=cpu --config profiling.statformat=hotpath sleep 2>../out || cat ../out
148 $ cat ../out | statprofran
149 $ grep sleepext_with_a_long_filename.py ../out | head -n 1
150 .* [0-9.]+% [0-9.]+s sleepext_with_a_long_filename.py:\s*sleep_for_at_least_one_stat_cycle, line \d+:\s+(while|pass).* (re)
151
152 $ hg --profile --config profiling.statformat=json sleep 2>../out || cat ../out
153 $ cat ../out
154 \[\[-?\d+.* (re)
155
156 statprof can be used as a standalone module
157
158 $ "$PYTHON" -m mercurial.statprof hotpath
159 must specify --file to load
160 [1]
161
162
163 Rust tracing output
164 ===================
165
166 Make sure rust tracing doesn't pollute the stdout:
167
168 $ touch some-file
169
170 traced command should not display their trace on stdout
171
172 $ RUST_LOG=trace hg status some-file 2> ../rust-trace.txt
173 ? some-file
174
175 some trace should exist on stderr (if rust is used)
176
177 $ wc -l ../rust-trace.txt
178 *[1-9][0-9]* \.\./rust-trace.txt (re) (rust !)
179 *[1-9][0-9]* \.\./rust-trace.txt (re) (rhg no-rust !)
180 *0 \.\./rust-trace.txt (re) (no-rhg no-rust !)
181
182 That output should should looks like traces
183
184 $ grep -E "close.*time.busy.*time.idle" ../rust-trace.txt | wc -l
185 *[1-9][0-9]* (re) (rust !)
186 *[1-9][0-9]* (re) (rhg no-rust !)
187 *0 (re) (no-rhg no-rust !)
188
189 $ cd ..
190
191
192
193 profiler extensions
194 ===================
195
196 #if no-chg
197 profiler extension could be loaded before other extensions
198
199 $ cat > fooprof.py <<EOF
200 > import contextlib
201 > import sys
202 > @contextlib.contextmanager
203 > def profile(ui, fp):
204 > print('fooprof: start profile')
205 > sys.stdout.flush()
206 > yield
207 > print('fooprof: end profile')
208 > sys.stdout.flush()
209 > def extsetup(ui):
210 > ui.write(b'fooprof: loaded\n')
211 > EOF
212
213 $ cat > otherextension.py <<EOF
214 > def extsetup(ui):
215 > ui.write(b'otherextension: loaded\n')
216 > EOF
217
218 $ hg init b
219 $ cd b
220 $ cat >> .hg/hgrc <<EOF
221 > [extensions]
222 > other = $TESTTMP/otherextension.py
223 > fooprof = $TESTTMP/fooprof.py
224 > EOF
225
226 $ hg root
227 otherextension: loaded
228 fooprof: loaded
229 $TESTTMP/b
230 $ HGPROF=fooprof hg root --profile
231 fooprof: loaded
232 fooprof: start profile
233 otherextension: loaded
234 $TESTTMP/b
235 fooprof: end profile
236
237 $ HGPROF=other hg root --profile 2>&1 | head -n 2
238 otherextension: loaded
239 unrecognized profiler 'other' - ignored
240
241 $ HGPROF=unknown hg root --profile 2>&1 | head -n 1
242 unrecognized profiler 'unknown' - ignored
243
244 $ cd ..
245 #endif