profiling for web application

Sat Jun 20 20:44:03 2009 +0900

author
hattori@www.hexacosa.net
date
Sat Jun 20 20:44:03 2009 +0900
changeset 6
c6da061b21c4
parent 5
b8def1b74408
child 7
e3fe9920d56c

profiling for web application

web/code-webpyorg-cprof.wsgi file | annotate | diff | revisions
web/code-webpyorg-hotshotline.wsgi file | annotate | diff | revisions
web/code-webpyorg-lineprof.wsgi file | annotate | diff | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/web/code-webpyorg-cprof.wsgi	Sat Jun 20 20:44:03 2009 +0900
     1.3 @@ -0,0 +1,39 @@
     1.4 +import os
     1.5 +import sqlite3
     1.6 +import web
     1.7 +import fapws._evwsgi as evwsgi
     1.8 +from fapws import base
     1.9 +
    1.10 +
    1.11 +DBPATH = '/var/www/app/hello/hello.sqlite'
    1.12 +TEMPLATE_PATH = '/var/www/templates/'
    1.13 +
    1.14 +urls = (
    1.15 +    '/', 'index',
    1.16 +    '/(.*)', 'hello',
    1.17 +)
    1.18 +
    1.19 +render = web.template.render(TEMPLATE_PATH)
    1.20 +application = web.application(urls, globals()).wsgifunc()
    1.21 +db = web.database(dbn='sqlite', db=DBPATH)
    1.22 +
    1.23 +class hello:
    1.24 +    def GET(self, username):
    1.25 +        users = db.select('hellouser', where="name = '%s'" % username)
    1.26 +        isFound = False
    1.27 +        for u in users:
    1.28 +            if u.name == username:
    1.29 +                isFound = True
    1.30 +        if not isFound:
    1.31 +            db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
    1.32 +        return render.hello(username, isFound)
    1.33 +
    1.34 +class index:
    1.35 +    def GET(self):
    1.36 +        return "Hello web.py"
    1.37 +
    1.38 +if __name__ == '__main__':
    1.39 +    import cProfile
    1.40 +    application = web.application(urls, globals())
    1.41 +    cProfile.run("application.run()", 'cprof.prof')
    1.42 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/web/code-webpyorg-hotshotline.wsgi	Sat Jun 20 20:44:03 2009 +0900
     2.3 @@ -0,0 +1,41 @@
     2.4 +import os
     2.5 +import sqlite3
     2.6 +import web
     2.7 +import fapws._evwsgi as evwsgi
     2.8 +from fapws import base
     2.9 +
    2.10 +
    2.11 +DBPATH = '/var/www/app/hello/hello.sqlite'
    2.12 +TEMPLATE_PATH = '/var/www/templates/'
    2.13 +
    2.14 +urls = (
    2.15 +    '/', 'index',
    2.16 +    '/(.*)', 'hello',
    2.17 +)
    2.18 +
    2.19 +render = web.template.render(TEMPLATE_PATH)
    2.20 +application = web.application(urls, globals()).wsgifunc()
    2.21 +db = web.database(dbn='sqlite', db=DBPATH)
    2.22 +
    2.23 +class hello:
    2.24 +    def GET(self, username):
    2.25 +        users = db.select('hellouser', where="name = '%s'" % username)
    2.26 +        isFound = False
    2.27 +        for u in users:
    2.28 +            if u.name == username:
    2.29 +                isFound = True
    2.30 +        if not isFound:
    2.31 +            db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
    2.32 +        return render.hello(username, isFound)
    2.33 +
    2.34 +class index:
    2.35 +    def GET(self):
    2.36 +        return "Hello web.py"
    2.37 +
    2.38 +if __name__ == '__main__':
    2.39 +    import hotshot
    2.40 +    application = web.application(urls, globals())
    2.41 +    prof = hotshot.Profile('hotshot.prof', True)
    2.42 +    prof.runcall(application.run)
    2.43 +    prof.close()
    2.44 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/web/code-webpyorg-lineprof.wsgi	Sat Jun 20 20:44:03 2009 +0900
     3.3 @@ -0,0 +1,44 @@
     3.4 +"""
     3.5 +
     3.6 +[usage] $ kernprof.py -l TARGET.py
     3.7 +        $ python -m line_profiler TARGET.py.lprof
     3.8 +"""
     3.9 +
    3.10 +import web
    3.11 +import fapws._evwsgi as evwsgi
    3.12 +from fapws import base
    3.13 +
    3.14 +
    3.15 +DBPATH = '/var/www/app/hello/hello.sqlite'
    3.16 +TEMPLATE_PATH = '/var/www/templates/'
    3.17 +
    3.18 +urls = (
    3.19 +    '/', 'index',
    3.20 +    '/(.*)', 'hello',
    3.21 +)
    3.22 +
    3.23 +render = web.template.render(TEMPLATE_PATH)
    3.24 +application = web.application(urls, globals()).wsgifunc()
    3.25 +db = web.database(dbn='sqlite', db=DBPATH)
    3.26 +
    3.27 +class hello:
    3.28 +    @profile
    3.29 +    def GET(self, username):
    3.30 +        users = db.select('hellouser', where="name = '%s'" % username)
    3.31 +        isFound = False
    3.32 +        for u in users:
    3.33 +            if u.name == username:
    3.34 +                isFound = True
    3.35 +        if not isFound:
    3.36 +            db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
    3.37 +        return render.hello(username, isFound)
    3.38 +
    3.39 +class index:
    3.40 +    @profile
    3.41 +    def GET(self):
    3.42 +        return "Hello web.py"
    3.43 +
    3.44 +if __name__ == '__main__':
    3.45 +    application = web.application(urls, globals())
    3.46 +    application.run()
    3.47 +

mercurial