Example #1
0
def apply_lsprofiled(filename, the_callable, *args, **kwargs):
    from bzrlib.lsprof import profile
    ret, stats = profile(the_callable, *args, **kwargs)
    stats.sort()
    if filename is None:
        stats.pprint()
    else:
        stats.save(filename)
        trace.note('Profile data written to "%s".', filename)
    return ret
Example #2
0
 def _file_name_changed ( self, file_name ):
     """ Handles the 'file_name' trait being changed.
     """
     self.hs_stats = hotshot.stats.load( file_name )
     stats         = [ Stats( key, value )
                       for key, value in self.hs_stats.stats.items() ]
     stats.sort( lambda l, r: cmp( r.cumulative_time, l.cumulative_time ) )
     self.stats.stats = stats[ : self.owner.max_rows ]
     self.compute_callers()
     self.compute_callees()
Example #3
0
def apply_lsprofiled(filename, the_callable, *args, **kwargs):
    from bzrlib.lsprof import profile
    ret, stats = profile(the_callable, *args, **kwargs)
    stats.sort()
    if filename is None:
        stats.pprint()
    else:
        stats.save(filename)
        trace.note('Profile data written to "%s".', filename)
    return ret
Example #4
0
def apply_lsprofiled(filename, the_callable, *args, **kwargs):
    from breezy.lsprof import profile
    ret, stats = profile(exception_to_return_code, the_callable,
                         *args, **kwargs)
    stats.sort()
    if filename is None:
        stats.pprint()
    else:
        stats.save(filename)
        trace.note(gettext('Profile data written to "%s".'), filename)
    return ret
Example #5
0
 def _file_name_changed(self, file_name):
     """ Handles the 'file_name' trait being changed.
     """
     self.hs_stats = hotshot.stats.load(file_name)
     stats = [
         Stats(key, value) for key, value in self.hs_stats.stats.items()
     ]
     stats.sort(lambda l, r: cmp(r.cumulative_time, l.cumulative_time))
     self.stats.stats = stats[:self.owner.max_rows]
     self.compute_callers()
     self.compute_callees()
Example #6
0
def _runcommand(ui, options, cmd, cmdfunc):
    def checkargs():
        try:
            return cmdfunc()
        except error.SignatureError:
            raise error.ParseError(cmd, _("invalid arguments"))

    if options['profile']:
        import hotshot, hotshot.stats
        prof = hotshot.Profile("hg.prof")
        try:
            try:
                return prof.runcall(checkargs)
            except:
                try:
                    ui.warn(_('exception raised - generating '
                             'profile anyway\n'))
                except:
                    pass
                raise
        finally:
            prof.close()
            stats = hotshot.stats.load("hg.prof")
            stats.strip_dirs()
            stats.sort_stats('time', 'calls')
            stats.print_stats(40)
    elif options['lsprof']:
        try:
            from mercurial import lsprof
        except ImportError:
            raise util.Abort(_(
                'lsprof not available - install from '
                'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
        p = lsprof.Profiler()
        p.enable(subcalls=True)
        try:
            return checkargs()
        finally:
            p.disable()
            stats = lsprof.Stats(p.getstats())
            stats.sort()
            stats.pprint(top=10, file=sys.stderr, climit=5)
    else:
        return checkargs()
Example #7
0
                try:
                    ui.warn(_('exception raised - generating '
                             'profile anyway\n'))
                except:
                    pass
                raise
        finally:
            prof.close()
            stats = hotshot.stats.load("hg.prof")
            stats.strip_dirs()
            stats.sort_stats('time', 'calls')
            stats.print_stats(40)
    elif options['lsprof']:
        try:
            from mercurial import lsprof
        except ImportError:
            raise util.Abort(_(
                'lsprof not available - install from '
                'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
        p = lsprof.Profiler()
        p.enable(subcalls=True)
        try:
            return checkargs()
        finally:
            p.disable()
            stats = lsprof.Stats(p.getstats())
            stats.sort()
            stats.pprint(top=10, file=sys.stderr, climit=5)
    else:
        return checkargs()