2013-05-19 4 views
2

저는 CherryPy 웹 서버 프로파일 링을 시작하려했지만이 문서의 설정 방법에 대한 자세한 내용은 부족합니다. 내 초기 서버를 마운트하기 위해 미들웨어로 cherrypy.lib.profiler을 사용할 수 있어야한다는 것을 이해합니다. 바로 지금, 내가 좋아하는 코드가 다음프로파일 링 CherryPy

server_app = ServerClass() 
cherrypy.tree.mount(server_app, '/', '/path/to/config/file.cfg') 
cherrypy.engine.start() 
cherrypy.engine.block() 

내가 프로파일 미들웨어를 탑재 할, 그것은 보인다 같은 필수입니다 : 어떤 이유로 cherrypy.tree.mount를 들어

from cherrypy.lib import profiler 

server_app = ServerClass() 
server_cpapp = cherrypy.Application(server_app, '/', '/path/to/config/file.cfg') 
server_profile_cpapp = profiler.make_app(server_cpapp, '/home/ken/tmp/cprofile', True) 
#cherrypy.tree.mount(server_profile_cpapp) 
cherrypy.tree.graft(server_profile_cpapp) 

cherrypy.engine.start() 
cherrypy.engine.block() 

하지 않는 내가 cherrypy.tree.graft을 사용하는 경우 작업,하지만 모두 내가 어떻게에 (내가 정상적으로 서버에 요청을 할 수 있습니다)

그러나, 위의 코드는 /home/ken/tmp/cprofile 아래 cp_0001.prof 파일을 생성하고, 나는 확실하지 않다 잘 작동하는 것 같다 그것을 해석하십시오. pyprof2calltree을 사용하여 KCacheGrind로 데이터를 읽으려고 시도했지만 구문 분석 오류가 발생합니다. 내가하고있는 일이 맞는지, 그렇다면 어떻게 출력 파일을 해석 할 수 있습니까?

답변

4

CherryPy에서 생성 된 프로필 파일은 CherryPy의 일부로 제공된 profiler.py 스크립트를 사용하여 해석 할 수 있습니다. 다음과 같이 간단하게 <site-packages>/cherrypy/lib 디렉토리에 profiler.py을 실행

python profiler.py /directory/containing/prof/files 8080 

그런 다음 브라우저에서 localhost:8080로 이동하여 대상 디렉토리에있는 모든 .prof 파일에 대한 프로파일 링 결과는 간단한 텍스트 인터페이스에 표시됩니다.

나는 여전히 KCacheGrind를 사용하여 프로필에 콜 트리로 결과를 내보낼 수있는 것을 선호하지만이 방법은 기본 프로파일 링에 유용합니다. 프로파일 러가 (프로파일을 설정하는 방법을 설명하는 해당 페이지의 다른 세부 사항은 이후되었다하더라도이 사용되지 않음) 도입 때

change log for v2.1 of CherryPy에 설명되어 있습니다

나는 또한 최대 프로파일 및 출마 얻기 위해 노력하고
1

cherrypy 인스턴스입니다. 나는 당신이 초기 질문에 가지고있는 것과 같은 코드를 사용했다. 이것은 폴더에 cp_0001.prof 파일을 생성한다는 점에서 효과가있는 것으로 보인다.

질문에 답하기 위해이 파일을 runsnakerun에서 열어 프로필 출력을 트리보기로 볼 수 있습니다.

내가 가진 문제는 서버에 할 모든 요청은 이제 로그에 다음과 같은 출력을, 실패입니다 :

[29/May/2013:16:39:32] ENGINE AssertionError('Bad call', ('', 0, 'sleep'), <frame object at 0x08522400>, <frame object at 0x08522030>, <frame object at 0x08156748>, <frame object at 0x06D06F10>) 
Traceback (most recent call last): 
    File "<path>\packages\cherrypy\wsgiserver\wsgiserver2.py", line 1302, in communicate 
    req.respond() 
    File "<path>\packages\cherrypy\wsgiserver\wsgiserver2.py", line 831, in respond 
    self.server.gateway(self).respond() 
    File "<path>\packages\cherrypy\wsgiserver\wsgiserver2.py", line 2115, in respond 
    response = self.req.server.wsgi_app(self.env, self.start_response) 
    File "<path>\packages\cherrypy\_cptree.py", line 290, in __call__ 
    return app(environ, start_response) 
    File "<path>\packages\cherrypy\lib\profiler.py", line 188, in __call__ 
    return self.profiler.run(gather) 
    File "<path>\packages\cherrypy\lib\profiler.py", line 147, in run 
    result = self.profiler.runcall(func, *args) 
    File "<path>\python\lib\profile.py", line 472, in runcall 
    return func(*args, **kw) 
    File "<path>\packages\cherrypy\lib\profiler.py", line 183, in gather 
    def gather(): 
    File "<path>\python\lib\profile.py", line 246, in trace_dispatch_i 
    if self.dispatch[event](self, frame, t): 
    File "<path>\python\lib\profile.py", line 301, in trace_dispatch_call 
    frame, frame.f_back) 
AssertionError: ('Bad call', ('', 0, 'sleep'), <frame object at 0x08522400>, <frame object at 0x08522030>, <frame object at 0x08156748>, <frame object at 0x06D06F10>) 

내가 파이썬 2.6.6와 cherrypy 3.2.2

을 사용하고 있습니다

제안 사항이 있으십니까?

+0

이것을 얻으십시오. –