当前位置: 首页>>代码示例>>Python>>正文


Python profile.Profile方法代码示例

本文整理汇总了Python中profile.Profile方法的典型用法代码示例。如果您正苦于以下问题:Python profile.Profile方法的具体用法?Python profile.Profile怎么用?Python profile.Profile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在profile的用法示例。


在下文中一共展示了profile.Profile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def __call__(self, *args, **kw):
        """Profile a singe call to the function."""
        self.ncalls += 1
        if self.skip > 0:
            self.skip -= 1
            self.skipped += 1
            return self.fn(*args, **kw)
        if FuncProfile.in_profiler:
            # handle recursive calls
            return self.fn(*args, **kw)
        # You cannot reuse the same profiler for many calls and accumulate
        # stats that way.  :-/
        profiler = self.Profile()
        try:
            FuncProfile.in_profiler = True
            return profiler.runcall(self.fn, *args, **kw)
        finally:
            FuncProfile.in_profiler = False
            self.stats.add(profiler)
            if self.immediate:
                self.print_stats()
                self.reset_stats() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:24,代码来源:profilehooks.py

示例2: _exec_main

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def _exec_main(parser, values):
    sconsflags = os.environ.get('SCONSFLAGS', '')
    all_args = sconsflags.split() + sys.argv[1:]

    options, args = parser.parse_args(all_args, values)

    if isinstance(options.debug, list) and "pdb" in options.debug:
        import pdb
        pdb.Pdb().runcall(_main, parser)
    elif options.profile_file:
        # compat layer imports "cProfile" for us if it's available.
        from profile import Profile

        prof = Profile()
        try:
            prof.runcall(_main, parser)
        finally:
            prof.dump_stats(options.profile_file)
    else:
        _main(parser) 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:22,代码来源:Main.py

示例3: run

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def run(self, reactor):
        """
        Run reactor under the standard profiler.
        """
        try:
            import profile
        except ImportError as e:
            self._reportImportError("profile", e)

        p = profile.Profile()
        p.runcall(reactor.run)
        if self.saveStats:
            p.dump_stats(self.profileOutput)
        else:
            tmp, sys.stdout = sys.stdout, open(self.profileOutput, 'a')
            try:
                p.print_stats()
            finally:
                sys.stdout, tmp = tmp, sys.stdout
                tmp.close() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:app.py

示例4: test_profilePrintStatsError

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def test_profilePrintStatsError(self):
        """
        When an error happens during the print of the stats, C{sys.stdout}
        should be restored to its initial value.
        """
        class ErroneousProfile(profile.Profile):
            def print_stats(self):
                raise RuntimeError("Boom")
        self.patch(profile, "Profile", ErroneousProfile)

        config = twistd.ServerOptions()
        config["profile"] = self.mktemp()
        config["profiler"] = "profile"
        profiler = app.AppProfiler(config)
        reactor = DummyReactor()

        oldStdout = sys.stdout
        self.assertRaises(RuntimeError, profiler.run, reactor)
        self.assertIs(sys.stdout, oldStdout) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_twistd.py

示例5: _wrap_profiling

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def _wrap_profiling(self, runner, *args):
    if not self._vars.PEX_PROFILE and self._vars.PEX_PROFILE_FILENAME is None:
      return runner(*args)

    pex_profile_filename = self._vars.PEX_PROFILE_FILENAME
    pex_profile_sort = self._vars.PEX_PROFILE_SORT
    try:
      import cProfile as profile
    except ImportError:
      import profile

    profiler = profile.Profile()

    try:
      return profiler.runcall(runner, *args)
    finally:
      if pex_profile_filename is not None:
        profiler.dump_stats(pex_profile_filename)
      else:
        profiler.print_stats(sort=pex_profile_sort) 
开发者ID:pantsbuild,项目名称:pex,代码行数:22,代码来源:pex.py

示例6: __init__

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def __init__(self, fn, skip=0, filename=None):
            """Creates a profiler for a function.

            Every profiler has its own log file (the name of which is derived
            from the function name).

            HotShotFuncProfile registers an atexit handler that prints
            profiling information to sys.stderr when the program terminates.

            The log file is not removed and remains there to clutter the
            current working directory.
            """
            self.fn = fn
            self.filename = filename
            if self.filename:
                self.logfilename = filename + ".raw"
            else:
                self.logfilename = fn.__name__ + ".prof"
            self.profiler = hotshot.Profile(self.logfilename)
            self.ncalls = 0
            self.skip = skip
            self.skipped = 0
            atexit.register(self.atexit) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:25,代码来源:profilehooks.py

示例7: _run_main

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def _run_main(main, argv):
  """Calls main, optionally with pdb or profiler."""
  if FLAGS.run_with_pdb:
    sys.exit(pdb.runcall(main, argv))
  elif FLAGS.run_with_profiling or FLAGS.profile_file:
    # Avoid import overhead since most apps (including performance-sensitive
    # ones) won't be run with profiling.
    import atexit
    if FLAGS.use_cprofile_for_profiling:
      import cProfile as profile
    else:
      import profile
    profiler = profile.Profile()
    if FLAGS.profile_file:
      atexit.register(profiler.dump_stats, FLAGS.profile_file)
    else:
      atexit.register(profiler.print_stats)
    retval = profiler.runcall(main, argv)
    sys.exit(retval)
  else:
    sys.exit(main(argv)) 
开发者ID:abseil,项目名称:abseil-py,代码行数:23,代码来源:app.py

示例8: profiled

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def profiled(f, outputFile):
    def _(*args, **kwargs):
        if sys.version_info[0:2] != (2, 4):
            import profile
            prof = profile.Profile()
            try:
                result = prof.runcall(f, *args, **kwargs)
                prof.dump_stats(outputFile)
            except SystemExit:
                pass
            prof.print_stats()
            return result
        else: # use hotshot, profile is broken in 2.4
            import hotshot.stats
            prof = hotshot.Profile(outputFile)
            try:
                return prof.runcall(f, *args, **kwargs)
            finally:
                stats = hotshot.stats.load(outputFile)
                stats.strip_dirs()
                stats.sort_stats('cum')   # 'time'
                stats.print_stats(100)
    return _ 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:25,代码来源:util.py

示例9: test_profilePrintStatsError

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def test_profilePrintStatsError(self):
        """
        When an error happens during the print of the stats, C{sys.stdout}
        should be restored to its initial value.
        """
        class ErroneousProfile(profile.Profile):
            def print_stats(self):
                raise RuntimeError("Boom")
        self.patch(profile, "Profile", ErroneousProfile)

        config = twistd.ServerOptions()
        config["profile"] = self.mktemp()
        config["profiler"] = "profile"
        profiler = app.AppProfiler(config)
        reactor = DummyReactor()

        oldStdout = sys.stdout
        self.assertRaises(RuntimeError, profiler.run, reactor)
        self.assertIdentical(sys.stdout, oldStdout) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:test_twistd.py

示例10: run

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def run(self, func, *args, **params):
        """Dump profile data into self.path."""
        global _count
        c = _count = _count + 1
        path = os.path.join(self.path, 'cp_%04d.prof' % c)
        prof = profile.Profile()
        result = prof.runcall(func, *args, **params)
        prof.dump_stats(path)
        return result 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:11,代码来源:profiler.py

示例11: __init__

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def __init__(self, path=None):
        Profiler.__init__(self, path)
        global _count
        self.count = _count = _count + 1
        self.profiler = profile.Profile() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:7,代码来源:profiler.py

示例12: reset_stats

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def reset_stats(self):
        """Reset accumulated profiler statistics."""
        # Note: not using self.Profile, since pstats.Stats() fails then
        self.stats = pstats.Stats(Profile())
        self.ncalls = 0
        self.skipped = 0 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:8,代码来源:profilehooks.py

示例13: print_stats

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def print_stats(self):
            if self.profiler is None:
                self.stats = pstats.Stats(Profile())
            else:
                self.profiler.close()
                self.stats = hotshot.stats.load(self.logfilename)
            super(HotShotFuncProfile, self).print_stats() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:9,代码来源:profilehooks.py

示例14: validate_profile

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def validate_profile(self):
        self.profile = Profile()
        self.profile.validate_configuration() 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:5,代码来源:settings_sanity.py

示例15: __call__

# 需要导入模块: import profile [as 别名]
# 或者: from profile import Profile [as 别名]
def __call__(self, environ, start_response):
        response_body = []

        def catching_start_response(status, headers, exc_info=None):
            start_response(status, headers, exc_info)
            return response_body.append

        def runapp():
            appiter = self._app(environ, catching_start_response)
            response_body.extend(appiter)
            if hasattr(appiter, 'close'):
                appiter.close()

        p = Profile()
        start = time.time()
        p.runcall(runapp)
        body = b''.join(response_body)
        elapsed = time.time() - start

        if self._profile_dir is not None:
            prof_filename = os.path.join(self._profile_dir,
                                         '%s.%s.%06dms.%d.prof' % (
                                             environ['REQUEST_METHOD'],
                                             environ.get('PATH_INFO').strip(
                                                 '/').replace('/', '.') or 'root',
                                             elapsed * 1000.0,
                                             time.time()
                                         ))
            p.dump_stats(prof_filename)

        else:
            stats = Stats(p, stream=self._stream)
            stats.sort_stats(*self._sort_by)

            self._stream.write('-' * 80)
            self._stream.write('\nPATH: %r\n' % environ.get('PATH_INFO'))
            stats.print_stats(*self._restrictions)
            self._stream.write('-' * 80 + '\n\n')

        return [body] 
开发者ID:jpush,项目名称:jbox,代码行数:42,代码来源:profiler.py


注:本文中的profile.Profile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。