mercurial/profiling.py
changeset 30664 69acfd2ca11e
parent 30322 189a1030affb
child 30820 6a70cf94d1b5
equal deleted inserted replaced
30663:bb0d5aad761a 30664:69acfd2ca11e
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import, print_function
     8 from __future__ import absolute_import, print_function
     9 
     9 
    10 import contextlib
    10 import contextlib
    11 import os
       
    12 import time
    11 import time
    13 
    12 
    14 from .i18n import _
    13 from .i18n import _
    15 from . import (
    14 from . import (
    16     error,
    15     error,
       
    16     pycompat,
    17     util,
    17     util,
    18 )
    18 )
    19 
    19 
    20 @contextlib.contextmanager
    20 @contextlib.contextmanager
    21 def lsprofile(ui, fp):
    21 def lsprofile(ui, fp):
   118     """Start profiling.
   118     """Start profiling.
   119 
   119 
   120     Profiling is active when the context manager is active. When the context
   120     Profiling is active when the context manager is active. When the context
   121     manager exits, profiling results will be written to the configured output.
   121     manager exits, profiling results will be written to the configured output.
   122     """
   122     """
   123     profiler = os.getenv('HGPROF')
   123     profiler = pycompat.osgetenv('HGPROF')
   124     if profiler is None:
   124     if profiler is None:
   125         profiler = ui.config('profiling', 'type', default='stat')
   125         profiler = ui.config('profiling', 'type', default='stat')
   126     if profiler not in ('ls', 'stat', 'flame'):
   126     if profiler not in ('ls', 'stat', 'flame'):
   127         ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler)
   127         ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler)
   128         profiler = 'stat'
   128         profiler = 'stat'