मैं Gprof2Dot अत्यंत उपयोगी पाया है। प्रोफाइलिंग मॉड्यूल का आउटपुट मैंने व्याख्या करने के लिए बहुत ही अनजान के रूप में प्रयास किया है।
Gprof2Dot cProfile आउटपुट को एक सुंदर दिखने वाले ग्राफ में बदलता है, जिसमें सबसे धीमी श्रृंखला (?) हाइलाइट किया गया है, और प्रत्येक फ़ंक्शन (फ़ंक्शन नाम, इस फ़ंक्शन पर समय व्यय का प्रतिशत, और कॉल की संख्या) पर कुछ जानकारी है।
An example graph (1429x1896px)
मैं App इंजन के साथ ज्यादा नहीं किया है, लेकिन जब गैर webapp स्क्रिप्ट की रूपरेखा, मैं स्क्रिप्ट है कि सभी unittests है, जो वास्तविक दुनिया के लिए बहुत सही नहीं हो सकता चलाता प्रोफ़ाइल के लिए करते हैं परिस्थितियों
एक (बेहतर?) विधि एक ऐसी स्क्रिप्ट होगी जो नकली डब्लूएसजीआई अनुरोध करे, फिर प्रोफाइल करें।
डब्लूएसजीआई वास्तव में सरल प्रोटोकॉल है, यह मूल रूप से एक फ़ंक्शन है जो दो तर्क लेता है, एक अनुरोध जानकारी के साथ दूसरा और कॉलबैक फ़ंक्शन वाला दूसरा (जिसे अन्य चीजों के साथ हेडर सेट करने के लिए उपयोग किया जाता है)।
से http://code.google.com/appengine/kb/commontasks.html#profiling:
शायद निम्नलिखित की तरह कुछ (जो संभव काम छद्म कोड है) ...
class IndexHandler(webapp.RequestHandler):
"""Your site"""
def get(self):
self.response.out.write("hi")
if __name__ == '__main__':
application = webapp.WSGIApplication([
('.*', IndexHandler),
], debug=True)
# Start fake-request/profiling bit
urls = [
"/",
"/blog/view/hello",
"/admin/post/edit/hello",
"/makeanerror404",
"/makeanerror500"
]
def fake_wsgi_callback(response, headers):
"""Prints heads to stdout"""
print("\n".join(["%s: %s" % (n, v) for n, v in headers]))
print("\n")
for request_url in urls:
html = application({
'REQUEST_METHOD': 'GET',
'PATH_INFO': request_url},
fake_wsgi_callback
)
print html
वास्तव में, App इंजन प्रलेखन आपके आवेदन की रूपरेखा का एक बेहतर तरीका बताते हैं
अपने एप्लिकेशन के प्रदर्शन को प्रोफाइल करने के लिए, पहले अपने एप्लिकेशन के main()
फ़ंक्शन को real_main()
पर पुनर्नामित करें।
def profile_main():
# This is the main function for profiling
# We've renamed our original main() above to real_main()
import cProfile, pstats
prof = cProfile.Profile()
prof = prof.runctx("real_main()", globals(), locals())
print "<pre>"
stats = pstats.Stats(prof)
stats.sort_stats("time") # Or cumulative
stats.print_stats(80) # 80 = how many to print
# The rest is optional.
# stats.print_callees()
# stats.print_callers()
print "</pre>"
[...]
अपने आवेदन के साथ रूपरेखा को सक्षम करने के लिए सेट main = profile_main
: तो फिर, इस तरह के नीचे एक के रूप में अपने आवेदन, profile_main()
नामित करने के लिए एक नया मुख्य कार्य जोड़ें। अपना एप्लिकेशन सामान्य के रूप में चलाने के लिए, बस main = real_main
सेट करें।
अद्यतन: http://googleappengine.blogspot.com/2010/02/app-engine-sdk-131-including-major.html : http: // कोड यह अब GAE SDK का एक भाग है .google.com/appengine/docs/python/tools/appstats.html – Turadg