如何评测Google App Engine python27运行时(非python)

如何评测Google App Engine python27运行时(非python),python,google-app-engine,profile,python-2.7,Python,Google App Engine,Profile,Python 2.7,如何在googleappengine运行时python27下分析python代码 在运行时python它是由以下代码完成的-: 在运行时,python27必须以不同的方式执行,因为没有主调用-如何执行相同的操作-我想切换到python27,但不能不进行分析。如何在python27中附加探查器 您可以通过在appengine_config.py中插入以下内容,使用WSGI中间件评测WSGI应用程序: import cProfile import cStringIO import logging i

如何在googleappengine运行时python27下分析python代码

在运行时python它是由以下代码完成的-:

在运行时,python27必须以不同的方式执行,因为没有主调用-如何执行相同的操作-我想切换到python27,但不能不进行分析。如何在python27中附加探查器


您可以通过在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

您也可以直接访问AppEngine Mini Profiler,它会为您处理这个咒语,并在每个被评测的页面上很好地显示结果

它提供API调用性能信息(通过Appstats)和所有函数调用的标准配置数据(通过cProfiler)


您仍然可以在app.yaml中指定CGI脚本处理程序。
如果我理解正确,您仍然可以使用旧方法,如果您不需要
并发请求
,那么很可能使用app.yaml,因为您希望在没有CGI的情况下进行测试,而不是每次测试都编辑app.yaml(速度很慢)。
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)])
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