當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。