简体   繁体   English

如何分析 Google App Engine python27 运行时(不是 python)

[英]How to profile Google App Engine python27 runtime (not python)

How to profile python code under Google App Engine runtime python27 ?如何在Google App Engine运行时 python27 下分析python代码?

In runtime python it was done by this code - python runtime :在运行时python中,它是由这段代码完成的 - python 运行时

from google.appengine.ext import webapp

class PageHandler(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    self.response.out.write('Hello, WebApp World!')

def real_main():
  application = webapp.WSGIApplication([('/', PageHandler)], debug=True)
  run_wsgi_app(application)

def profile_main():
  # This is the main function for profiling
  # We've renamed our original main() above to real_main()
  import cProfile, pstats, StringIO
  prof = cProfile.Profile()
  prof = prof.runctx('real_main()', globals(), locals())
  stream = StringIO.StringIO()
  stats = pstats.Stats(prof, stream=stream)
  stats.sort_stats('cumulative')
  logging.info("Profile data:\n%s", stream.getvalue())

if __name__ == "__main__":
    profile_main()

In runtime python27 is has to be done differently since there is no main calls - how to do the same thing - I want to switch to python27 but not without profiling.在运行时python27必须以不同的方式完成,因为没有主调用 - 如何做同样的事情 - 我想切换到 python27 但不是没有分析。 How to attach profiler in python27 - python27 runtime ?如何在python27中附加探查器 - python27 运行时

import webapp2

class PageHandler(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, WebApp World!')

app = webapp2.WSGIApplication([('/', PageHandler)])

You can profile a WSGI app using WSGI middleware by inserting in your appengine_config.py:您可以通过在 appengine_config.py 中插入以下内容来使用 WSGI 中间件分析 WSGI 应用程序:

import cProfile
import cStringIO
import logging
import pstats

def webapp_add_wsgi_middleware(app):

  def profiling_wrapper(environ, start_response):
    profile = cProfile.Profile()
    response = profile.runcall(app, environ, start_response)
    stream = cStringIO.StringIO()
    stats = pstats.Stats(profile, stream=stream)
    stats.sort_stats('cumulative').print_stats()
    logging.info('Profile data:\n%s', stream.getvalue())
    return response

  return profiling_wrapper

You can also just drop in App Engine Mini Profiler, which takes care of this incantation for you and presents the results nicely on each page being profiled.您也可以只放入 App Engine Mini Profiler,它会为您处理这个咒语,并在每个被分析的页面上很好地显示结果。

It provides both API call perf information (via Appstats) and standard profiling data for all function calls (via cProfiler)它提供 API 调用性能信息(通过 Appstats)和所有 function 调用的标准分析数据(通过 cProfiler)

https://github.com/kamens/gae_mini_profiler https://github.com/kamens/gae_mini_profiler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Google App Engine 中调试 gunicorn 和 python? - How to debug gunicorn and python in Google App Engine? 如何在 Google App Engine for Python3 上安装库 - How to install libraries on Google App Engine for Python3 如何停止谷歌云应用引擎重新启动 discord.python 机器人? - How to stop google cloud app engine to restart the discord python bot? 从 App Engine 在 Google Compute Engine 中执行 python 脚本 - Executing a python script in Google Compute Engine from App Engine google app engine-python 的简单 slider 验证码实现 - simple slider captcha implementation for google app engine-python Numpy 在 Python3 Google App Flexible Engine 中失败 - Numpy failing in Python3 Google App Flexible Engine 如何从 Google App Engine (Python) NDB/Datastore 中的子实体查询父实体? - How to query parent entity from child entity in Google App Engine (Python) NDB/Datastore? 如何在 App Engine Flex (Python 3.7) 中本地模拟 Google 云任务服务? - How to emulate Google cloud tasks service locally in app engine flex (Python 3.7)? 我应该使用哪种开发环境来使用 Python 开发 Google App Engine? - Which development environment should I use for developing Google App Engine with Python? Google Cloud App Engine - Eclipse 在 app.yaml 中显示“运行时:java 11”不是 Java - Google Cloud App Engine - Eclipse shows "runtime: java 11" in app.yaml is not Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM