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