##// END OF EJS Templates
profiling: add --no-profile to disable profiling enabled via config...
Kyle Lippincott -
r47787:a2bf93ab default
parent child Browse files
Show More
@@ -1064,6 +1064,16 b' def _dispatch(req):'
1064 1064 if req.earlyoptions[b'profile']:
1065 1065 for ui_ in uis:
1066 1066 ui_.setconfig(b'profiling', b'enabled', b'true', b'--profile')
1067 elif req.earlyoptions[b'profile'] is False:
1068 # Check for it being set already, so that we don't pollute the config
1069 # with this when using chg in the very common case that it's not
1070 # enabled.
1071 if lui.configbool(b'profiling', b'enabled'):
1072 # Only do this on lui so that `chg foo` with a user config setting
1073 # profiling.enabled=1 still shows profiling information (chg will
1074 # specify `--no-profile` when `hg serve` is starting up, we don't
1075 # want that to propagate to every later invocation).
1076 lui.setconfig(b'profiling', b'enabled', b'false', b'--no-profile')
1067 1077
1068 1078 profile = lui.configbool(b'profiling', b'enabled')
1069 1079 with profiling.profile(lui, enabled=profile) as profiler:
@@ -468,3 +468,72 b" Test that chg works (sets to the user's "
468 468 LC_ALL=
469 469 LC_CTYPE=
470 470 LANG=
471
472 Profiling isn't permanently enabled or carried over between chg invocations that
473 share the same server
474 $ cp $HGRCPATH.orig $HGRCPATH
475 $ hg init $TESTTMP/profiling
476 $ cd $TESTTMP/profiling
477 $ filteredchg() {
478 > CHGDEBUG=1 chg "$@" 2>&1 | egrep 'Sample count|start cmdserver' || true
479 > }
480 $ newchg() {
481 > chg --kill-chg-daemon
482 > filteredchg "$@" | egrep -v 'start cmdserver' || true
483 > }
484 (--profile isn't permanently on just because it was specified when chg was
485 started)
486 $ newchg log -r . --profile
487 Sample count: * (glob)
488 $ filteredchg log -r .
489 (enabling profiling via config works, even on the first chg command that starts
490 a cmdserver)
491 $ cat >> $HGRCPATH <<EOF
492 > [profiling]
493 > type=stat
494 > enabled=1
495 > EOF
496 $ newchg log -r .
497 Sample count: * (glob)
498 $ filteredchg log -r .
499 Sample count: * (glob)
500 (test that we aren't accumulating more and more samples each run)
501 $ cat > $TESTTMP/debugsleep.py <<EOF
502 > import time
503 > from mercurial import registrar
504 > cmdtable = {}
505 > command = registrar.command(cmdtable)
506 > @command(b'debugsleep', [], b'', norepo=True)
507 > def debugsleep(ui):
508 > start = time.time()
509 > x = 0
510 > while time.time() < start + 0.5:
511 > time.sleep(.1)
512 > x += 1
513 > ui.status(b'%d debugsleep iterations in %.03fs\n' % (x, time.time() - start))
514 > EOF
515 $ cat >> $HGRCPATH <<EOF
516 > [extensions]
517 > debugsleep = $TESTTMP/debugsleep.py
518 > EOF
519 $ newchg debugsleep > run_1
520 $ filteredchg debugsleep > run_2
521 $ filteredchg debugsleep > run_3
522 $ filteredchg debugsleep > run_4
523 FIXME: Run 4 should not be >3x Run 1's number of samples.
524 $ "$PYTHON" <<EOF
525 > r1 = int(open("run_1", "r").read().split()[-1])
526 > r4 = int(open("run_4", "r").read().split()[-1])
527 > print("Run 1: %d samples\nRun 4: %d samples\nRun 4 > 3 * Run 1: %s" %
528 > (r1, r4, r4 > (r1 * 3)))
529 > EOF
530 Run 1: * samples (glob)
531 Run 4: * samples (glob)
532 Run 4 > 3 * Run 1: True
533 (Disabling with --no-profile on the commandline still works, but isn't permanent)
534 $ newchg log -r . --no-profile
535 $ filteredchg log -r .
536 Sample count: * (glob)
537 $ filteredchg log -r . --no-profile
538 $ filteredchg log -r .
539 Sample count: * (glob)
General Comments 0
You need to be logged in to leave comments. Login now