test-profile.t
182 lines
| 4.9 KiB
| text/troff
|
Tads3Lexer
/ tests / test-profile.t
|
r12478 | test --time | ||
|
r16933 | $ hg --time help -q help 2>&1 | grep time > /dev/null | ||
|
r12478 | $ hg init a | ||
$ cd a | ||||
|
r33611 | Function to check that statprof ran | ||
$ statprofran () { | ||||
> egrep 'Sample count:|No samples recorded' > /dev/null | ||||
> } | ||||
|
r16898 | |||
|
r12478 | test --profile | ||
|
r33611 | $ hg st --profile 2>&1 | statprofran | ||
r32787 | ||||
Abreviated version | ||||
|
r33611 | $ hg st --prof 2>&1 | statprofran | ||
r32787 | ||||
In alias | ||||
|
r33611 | $ hg --config "alias.profst=status --profile" profst 2>&1 | statprofran | ||
r32787 | ||||
#if lsprof | ||||
|
r48362 | $ prof () { | ||
> hg --config profiling.type=ls --profile $@ | ||||
> } | ||||
|
r30259 | |||
|
r48362 | $ prof st 2>../out | ||
|
r16898 | $ grep CallCount ../out > /dev/null || cat ../out | ||
|
r48362 | $ prof --config profiling.output=../out st | ||
|
r16898 | $ grep CallCount ../out > /dev/null || cat ../out | ||
|
r48362 | $ prof --config profiling.output=blackbox --config extensions.blackbox= st | ||
|
r26191 | $ grep CallCount .hg/blackbox.log > /dev/null || cat .hg/blackbox.log | ||
|
r48362 | $ prof --config profiling.format=text st 2>../out | ||
|
r16898 | $ grep CallCount ../out > /dev/null || cat ../out | ||
$ echo "[profiling]" >> $HGRCPATH | ||||
$ echo "format=kcachegrind" >> $HGRCPATH | ||||
|
r48362 | $ prof st 2>../out | ||
|
r16898 | $ grep 'events: Ticks' ../out > /dev/null || cat ../out | ||
|
r48362 | $ prof --config profiling.output=../out st | ||
|
r16898 | $ grep 'events: Ticks' ../out > /dev/null || cat ../out | ||
#endif | ||||
|
r16913 | |||
|
r29787 | #if lsprof serve | ||
Profiling of HTTP requests works | ||||
|
r48362 | $ prof --config profiling.format=text --config profiling.output=../profile.log serve -d -p $HGPORT --pid-file ../hg.pid -A ../access.log | ||
|
r29787 | $ cat ../hg.pid >> $DAEMON_PIDS | ||
$ hg -q clone -U http://localhost:$HGPORT ../clone | ||||
A single profile is logged because file logging doesn't append | ||||
$ grep CallCount ../profile.log | wc -l | ||||
\s*1 (re) | ||||
#endif | ||||
|
r30316 | Install an extension that can sleep and guarantee a profiler has time to run | ||
|
r46639 | $ cat >> sleepext_with_a_long_filename.py << EOF | ||
|
r30316 | > import time | ||
|
r40405 | > from mercurial import registrar | ||
|
r30316 | > cmdtable = {} | ||
|
r32337 | > command = registrar.command(cmdtable) | ||
|
r38086 | > @command(b'sleep', [], b'hg sleep') | ||
|
r46639 | > def sleep_for_at_least_one_stat_cycle(ui, *args, **kwargs): | ||
|
r48363 | > t = time.time() # don't use time.sleep because we need CPU time | ||
> while time.time() - t < 0.5: | ||||
> pass | ||||
|
r30316 | > EOF | ||
$ cat >> $HGRCPATH << EOF | ||||
> [extensions] | ||||
|
r46639 | > sleep = `pwd`/sleepext_with_a_long_filename.py | ||
|
r30316 | > EOF | ||
statistical profiler works | ||||
|
r30317 | $ hg --profile sleep 2>../out | ||
|
r33611 | $ cat ../out | statprofran | ||
|
r30316 | |||
Various statprof formatters work | ||||
|
r40517 | $ hg --profile --config profiling.statformat=byline sleep 2>../out || cat ../out | ||
r46208 | $ grep -v _path_stat ../out | head -n 3 | |||
|
r30316 | % cumulative self | ||
|
r40417 | time seconds seconds name | ||
|
r46639 | * sleepext_with_a_long_filename.py:*:sleep_for_at_least_one_stat_cycle (glob) | ||
|
r33611 | $ cat ../out | statprofran | ||
|
r30316 | |||
|
r40517 | $ hg --profile --config profiling.statformat=bymethod sleep 2>../out || cat ../out | ||
|
r30316 | $ head -n 1 ../out | ||
% cumulative self | ||||
|
r33611 | $ cat ../out | statprofran | ||
|
r30316 | |||
|
r48363 | Windows real time tracking is broken, only use CPU | ||
#if no-windows | ||||
$ hg --profile --config profiling.time-track=real --config profiling.statformat=hotpath sleep 2>../out || cat ../out | ||||
|
r33611 | $ cat ../out | statprofran | ||
|
r48363 | $ grep sleepext_with_a_long_filename.py ../out | head -n 1 | ||
.* [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) | ||||
#endif | ||||
$ hg --profile --config profiling.time-track=cpu --config profiling.statformat=hotpath sleep 2>../out || cat ../out | ||||
$ cat ../out | statprofran | ||||
$ grep sleepext_with_a_long_filename.py ../out | head -n 1 | ||||
.* [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) | ||||
|
r30316 | |||
|
r40517 | $ hg --profile --config profiling.statformat=json sleep 2>../out || cat ../out | ||
|
r30316 | $ cat ../out | ||
|
r32060 | \[\[-?\d+.* (re) | ||
|
r30316 | |||
|
r30845 | statprof can be used as a standalone module | ||
|
r39743 | $ "$PYTHON" -m mercurial.statprof hotpath | ||
|
r30845 | must specify --file to load | ||
[1] | ||||
|
r16913 | $ cd .. | ||
|
r32417 | |||
|
r34446 | #if no-chg | ||
|
r32417 | profiler extension could be loaded before other extensions | ||
$ cat > fooprof.py <<EOF | ||||
> from __future__ import absolute_import | ||||
> import contextlib | ||||
|
r40236 | > import sys | ||
|
r32417 | > @contextlib.contextmanager | ||
> def profile(ui, fp): | ||||
> print('fooprof: start profile') | ||||
|
r40236 | > sys.stdout.flush() | ||
|
r32417 | > yield | ||
> print('fooprof: end profile') | ||||
|
r40236 | > sys.stdout.flush() | ||
|
r32417 | > def extsetup(ui): | ||
|
r38086 | > ui.write(b'fooprof: loaded\n') | ||
|
r32417 | > EOF | ||
$ cat > otherextension.py <<EOF | ||||
> from __future__ import absolute_import | ||||
> def extsetup(ui): | ||||
|
r38086 | > ui.write(b'otherextension: loaded\n') | ||
|
r32417 | > EOF | ||
$ hg init b | ||||
$ cd b | ||||
$ cat >> .hg/hgrc <<EOF | ||||
> [extensions] | ||||
> other = $TESTTMP/otherextension.py | ||||
> fooprof = $TESTTMP/fooprof.py | ||||
> EOF | ||||
$ hg root | ||||
otherextension: loaded | ||||
fooprof: loaded | ||||
|
r35394 | $TESTTMP/b | ||
|
r32417 | $ HGPROF=fooprof hg root --profile | ||
fooprof: loaded | ||||
fooprof: start profile | ||||
otherextension: loaded | ||||
|
r35394 | $TESTTMP/b | ||
|
r32417 | fooprof: end profile | ||
$ HGPROF=other hg root --profile 2>&1 | head -n 2 | ||||
otherextension: loaded | ||||
unrecognized profiler 'other' - ignored | ||||
$ HGPROF=unknown hg root --profile 2>&1 | head -n 1 | ||||
unrecognized profiler 'unknown' - ignored | ||||
$ cd .. | ||||
|
r34446 | #endif | ||