mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
54cd73b41b
Summary: The debugshell command can be long running and contains uninteresting stuff. Do not profile it. Practically this hides showing the background statprof thread when using `%trace`. Reviewed By: DurhamG Differential Revision: D23278597 fbshipit-source-id: bad97de22e1be2be8b866bee705ea3a6755aa54b
112 lines
2.7 KiB
Perl
112 lines
2.7 KiB
Perl
test --time
|
|
|
|
$ hg --time help -q help 2>&1 | grep time > /dev/null
|
|
$ hg init a
|
|
$ cd a
|
|
|
|
Function to check that statprof ran
|
|
$ statprofran () {
|
|
> egrep 'Sample count:|No samples recorded' > /dev/null
|
|
> }
|
|
|
|
test --profile
|
|
|
|
$ hg log -r . --profile 2>&1 | statprofran
|
|
|
|
Abreviated version
|
|
|
|
$ hg log -r . --prof 2>&1 | statprofran
|
|
|
|
In alias
|
|
|
|
$ hg --config "alias.proflog=log -r . --profile" proflog 2>&1 | statprofran
|
|
|
|
#if normal-layout
|
|
statprof can be used as a standalone module
|
|
|
|
$ hg debugpython -- -m edenscm.mercurial.statprof hotpath
|
|
must specify --file to load
|
|
[1]
|
|
#endif
|
|
|
|
$ cd ..
|
|
|
|
#if no-chg
|
|
profiler extension could be loaded before other extensions
|
|
|
|
$ cat > fooprof.py <<EOF
|
|
> from __future__ import absolute_import
|
|
> import contextlib, sys
|
|
> @contextlib.contextmanager
|
|
> def profile(ui, fp, section):
|
|
> print('fooprof: start profile')
|
|
> sys.stdout.flush()
|
|
> yield
|
|
> print('fooprof: end profile')
|
|
> sys.stdout.flush()
|
|
> def extsetup(ui):
|
|
> ui.write('fooprof: loaded\n')
|
|
> EOF
|
|
|
|
$ cat > otherextension.py <<EOF
|
|
> from __future__ import absolute_import
|
|
> def extsetup(ui):
|
|
> ui.write('otherextension: loaded\n')
|
|
> EOF
|
|
|
|
$ hg init b
|
|
$ cd b
|
|
$ cat >> .hg/hgrc <<EOF
|
|
> [extensions]
|
|
> other = $TESTTMP/otherextension.py
|
|
> fooprof = $TESTTMP/fooprof.py
|
|
> EOF
|
|
|
|
$ hg log -r null -T "foo\n"
|
|
otherextension: loaded
|
|
fooprof: loaded
|
|
foo
|
|
$ HGPROF=fooprof hg log -r null -T "foo\n" --profile
|
|
fooprof: loaded
|
|
fooprof: start profile
|
|
otherextension: loaded
|
|
foo
|
|
fooprof: end profile
|
|
|
|
$ HGPROF=other hg log -r null -T "foo\n" --profile 2>&1 | head -n 2
|
|
otherextension: loaded
|
|
unrecognized profiler 'other' - ignored
|
|
|
|
$ HGPROF=unknown hg log -r null -T "foo\n" --profile 2>&1 | head -n 1
|
|
unrecognized profiler 'unknown' - ignored
|
|
|
|
$ cd ..
|
|
#endif
|
|
|
|
Test minelapsed config option
|
|
(This cannot be tested because profiling is disabled for 'debugshell')
|
|
|
|
Test other config sections
|
|
|
|
$ hg --config profiling:background.enabled=1 --config profiling:background.output=z debugshell -c '1'
|
|
unrecognized profiler 'None' - ignored
|
|
invalid sampling frequency 'None' - ignoring
|
|
unknown profiler output format: None
|
|
$ [ -f z ]
|
|
|
|
$ hg --profile --config profiling.output=x --config profiling:background.enabled=1 --config profiling:background.output=y debugshell -c '1'
|
|
$ [ -f x ]
|
|
$ [ -f y ]
|
|
[1]
|
|
|
|
Test statprof will not take at least frequency time.
|
|
|
|
>>> import time
|
|
>>> _ = open('start', 'w').write('%s' % time.time())
|
|
|
|
$ hg --profile --config profiling.output=z --config profiling.type=stat --config profiling.freq=0.02 debugshell -c 'a=1'
|
|
|
|
>>> import time
|
|
>>> time.time() - float(open('start').read()) < 50
|
|
True
|