##// END OF EJS Templates
tests: make test-profile.t pass if statprof didn't collect samples...
Martin von Zweigbergk -
r33611:a72b2db1 stable
parent child Browse files
Show More
@@ -1,163 +1,160 b''
1 test --time
1 test --time
2
2
3 $ hg --time help -q help 2>&1 | grep time > /dev/null
3 $ hg --time help -q help 2>&1 | grep time > /dev/null
4 $ hg init a
4 $ hg init a
5 $ cd a
5 $ cd a
6
6
7 Function to check that statprof ran
8 $ statprofran () {
9 > egrep 'Sample count:|No samples recorded' > /dev/null
10 > }
7
11
8 test --profile
12 test --profile
9
13
10 $ hg st --profile 2>&1 | grep Sample
14 $ hg st --profile 2>&1 | statprofran
11 Sample count: \d+ (re)
12
15
13 Abreviated version
16 Abreviated version
14
17
15 $ hg st --prof 2>&1 | grep Sample
18 $ hg st --prof 2>&1 | statprofran
16 Sample count: \d+ (re)
17
19
18 In alias
20 In alias
19
21
20 $ hg --config "alias.profst=status --profile" profst 2>&1 | grep Sample
22 $ hg --config "alias.profst=status --profile" profst 2>&1 | statprofran
21 Sample count: \d+ (re)
22
23
23 #if lsprof
24 #if lsprof
24
25
25 $ prof='hg --config profiling.type=ls --profile'
26 $ prof='hg --config profiling.type=ls --profile'
26
27
27 $ $prof st 2>../out
28 $ $prof st 2>../out
28 $ grep CallCount ../out > /dev/null || cat ../out
29 $ grep CallCount ../out > /dev/null || cat ../out
29
30
30 $ $prof --config profiling.output=../out st
31 $ $prof --config profiling.output=../out st
31 $ grep CallCount ../out > /dev/null || cat ../out
32 $ grep CallCount ../out > /dev/null || cat ../out
32
33
33 $ $prof --config profiling.output=blackbox --config extensions.blackbox= st
34 $ $prof --config profiling.output=blackbox --config extensions.blackbox= st
34 $ grep CallCount .hg/blackbox.log > /dev/null || cat .hg/blackbox.log
35 $ grep CallCount .hg/blackbox.log > /dev/null || cat .hg/blackbox.log
35
36
36 $ $prof --config profiling.format=text st 2>../out
37 $ $prof --config profiling.format=text st 2>../out
37 $ grep CallCount ../out > /dev/null || cat ../out
38 $ grep CallCount ../out > /dev/null || cat ../out
38
39
39 $ echo "[profiling]" >> $HGRCPATH
40 $ echo "[profiling]" >> $HGRCPATH
40 $ echo "format=kcachegrind" >> $HGRCPATH
41 $ echo "format=kcachegrind" >> $HGRCPATH
41
42
42 $ $prof st 2>../out
43 $ $prof st 2>../out
43 $ grep 'events: Ticks' ../out > /dev/null || cat ../out
44 $ grep 'events: Ticks' ../out > /dev/null || cat ../out
44
45
45 $ $prof --config profiling.output=../out st
46 $ $prof --config profiling.output=../out st
46 $ grep 'events: Ticks' ../out > /dev/null || cat ../out
47 $ grep 'events: Ticks' ../out > /dev/null || cat ../out
47
48
48 #endif
49 #endif
49
50
50 #if lsprof serve
51 #if lsprof serve
51
52
52 Profiling of HTTP requests works
53 Profiling of HTTP requests works
53
54
54 $ $prof --config profiling.format=text --config profiling.output=../profile.log serve -d -p $HGPORT --pid-file ../hg.pid -A ../access.log
55 $ $prof --config profiling.format=text --config profiling.output=../profile.log serve -d -p $HGPORT --pid-file ../hg.pid -A ../access.log
55 $ cat ../hg.pid >> $DAEMON_PIDS
56 $ cat ../hg.pid >> $DAEMON_PIDS
56 $ hg -q clone -U http://localhost:$HGPORT ../clone
57 $ hg -q clone -U http://localhost:$HGPORT ../clone
57
58
58 A single profile is logged because file logging doesn't append
59 A single profile is logged because file logging doesn't append
59 $ grep CallCount ../profile.log | wc -l
60 $ grep CallCount ../profile.log | wc -l
60 \s*1 (re)
61 \s*1 (re)
61
62
62 #endif
63 #endif
63
64
64 Install an extension that can sleep and guarantee a profiler has time to run
65 Install an extension that can sleep and guarantee a profiler has time to run
65
66
66 $ cat >> sleepext.py << EOF
67 $ cat >> sleepext.py << EOF
67 > import time
68 > import time
68 > from mercurial import registrar, commands
69 > from mercurial import registrar, commands
69 > cmdtable = {}
70 > cmdtable = {}
70 > command = registrar.command(cmdtable)
71 > command = registrar.command(cmdtable)
71 > @command(b'sleep', [], 'hg sleep')
72 > @command(b'sleep', [], 'hg sleep')
72 > def sleep(ui, *args, **kwargs):
73 > def sleep(ui, *args, **kwargs):
73 > time.sleep(0.1)
74 > time.sleep(0.1)
74 > EOF
75 > EOF
75
76
76 $ cat >> $HGRCPATH << EOF
77 $ cat >> $HGRCPATH << EOF
77 > [extensions]
78 > [extensions]
78 > sleep = `pwd`/sleepext.py
79 > sleep = `pwd`/sleepext.py
79 > EOF
80 > EOF
80
81
81 statistical profiler works
82 statistical profiler works
82
83
83 $ hg --profile sleep 2>../out
84 $ hg --profile sleep 2>../out
84 $ grep Sample ../out
85 $ cat ../out | statprofran
85 Sample count: \d+ (re)
86
86
87 Various statprof formatters work
87 Various statprof formatters work
88
88
89 $ hg --profile --config profiling.statformat=byline sleep 2>../out
89 $ hg --profile --config profiling.statformat=byline sleep 2>../out
90 $ head -n 1 ../out
90 $ head -n 1 ../out
91 % cumulative self
91 % cumulative self
92 $ grep Sample ../out
92 $ cat ../out | statprofran
93 Sample count: \d+ (re)
94
93
95 $ hg --profile --config profiling.statformat=bymethod sleep 2>../out
94 $ hg --profile --config profiling.statformat=bymethod sleep 2>../out
96 $ head -n 1 ../out
95 $ head -n 1 ../out
97 % cumulative self
96 % cumulative self
98 $ grep Sample ../out
97 $ cat ../out | statprofran
99 Sample count: \d+ (re)
100
98
101 $ hg --profile --config profiling.statformat=hotpath sleep 2>../out
99 $ hg --profile --config profiling.statformat=hotpath sleep 2>../out
102 $ grep Sample ../out
100 $ cat ../out | statprofran
103 Sample count: \d+ (re)
104
101
105 $ hg --profile --config profiling.statformat=json sleep 2>../out
102 $ hg --profile --config profiling.statformat=json sleep 2>../out
106 $ cat ../out
103 $ cat ../out
107 \[\[-?\d+.* (re)
104 \[\[-?\d+.* (re)
108
105
109 statprof can be used as a standalone module
106 statprof can be used as a standalone module
110
107
111 $ $PYTHON -m mercurial.statprof hotpath
108 $ $PYTHON -m mercurial.statprof hotpath
112 must specify --file to load
109 must specify --file to load
113 [1]
110 [1]
114
111
115 $ cd ..
112 $ cd ..
116
113
117 profiler extension could be loaded before other extensions
114 profiler extension could be loaded before other extensions
118
115
119 $ cat > fooprof.py <<EOF
116 $ cat > fooprof.py <<EOF
120 > from __future__ import absolute_import
117 > from __future__ import absolute_import
121 > import contextlib
118 > import contextlib
122 > @contextlib.contextmanager
119 > @contextlib.contextmanager
123 > def profile(ui, fp):
120 > def profile(ui, fp):
124 > print('fooprof: start profile')
121 > print('fooprof: start profile')
125 > yield
122 > yield
126 > print('fooprof: end profile')
123 > print('fooprof: end profile')
127 > def extsetup(ui):
124 > def extsetup(ui):
128 > ui.write('fooprof: loaded\n')
125 > ui.write('fooprof: loaded\n')
129 > EOF
126 > EOF
130
127
131 $ cat > otherextension.py <<EOF
128 $ cat > otherextension.py <<EOF
132 > from __future__ import absolute_import
129 > from __future__ import absolute_import
133 > def extsetup(ui):
130 > def extsetup(ui):
134 > ui.write('otherextension: loaded\n')
131 > ui.write('otherextension: loaded\n')
135 > EOF
132 > EOF
136
133
137 $ hg init b
134 $ hg init b
138 $ cd b
135 $ cd b
139 $ cat >> .hg/hgrc <<EOF
136 $ cat >> .hg/hgrc <<EOF
140 > [extensions]
137 > [extensions]
141 > other = $TESTTMP/otherextension.py
138 > other = $TESTTMP/otherextension.py
142 > fooprof = $TESTTMP/fooprof.py
139 > fooprof = $TESTTMP/fooprof.py
143 > EOF
140 > EOF
144
141
145 $ hg root
142 $ hg root
146 otherextension: loaded
143 otherextension: loaded
147 fooprof: loaded
144 fooprof: loaded
148 $TESTTMP/b (glob)
145 $TESTTMP/b (glob)
149 $ HGPROF=fooprof hg root --profile
146 $ HGPROF=fooprof hg root --profile
150 fooprof: loaded
147 fooprof: loaded
151 fooprof: start profile
148 fooprof: start profile
152 otherextension: loaded
149 otherextension: loaded
153 $TESTTMP/b (glob)
150 $TESTTMP/b (glob)
154 fooprof: end profile
151 fooprof: end profile
155
152
156 $ HGPROF=other hg root --profile 2>&1 | head -n 2
153 $ HGPROF=other hg root --profile 2>&1 | head -n 2
157 otherextension: loaded
154 otherextension: loaded
158 unrecognized profiler 'other' - ignored
155 unrecognized profiler 'other' - ignored
159
156
160 $ HGPROF=unknown hg root --profile 2>&1 | head -n 1
157 $ HGPROF=unknown hg root --profile 2>&1 | head -n 1
161 unrecognized profiler 'unknown' - ignored
158 unrecognized profiler 'unknown' - ignored
162
159
163 $ cd ..
160 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now