tracing: extract tracing-active logic to separate function
I'm about to add support for counters, and want to avoid duplicating this
logic.
Differential Revision: https://phab.mercurial-scm.org/D6525
demandimport: add tracing coverage for Python 3
This makes things feel a little less mysterious when modules are being
imported.
Differential Revision: https://phab.mercurial-scm.org/D6523