3 # Copyright 2008 the Melange authors.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """Main Melange module with profiling support.
21 # alphabetical order by last name, please
22 '"Augie Fackler" <durin42@gmail.com>',
23 '"Pawel Solyga" <pawel.solyga@gmail.com>',
29 from google
.appengine
.ext
.webapp
import util
31 # pylint: disable-msg=W0611
35 def profile_main_as_html():
36 """Main program for profiling. Profiling data added as HTML to the page.
42 prof
= cProfile
.Profile()
43 prof
= prof
.runctx('real_main()', globals(), locals())
44 stream
= StringIO
.StringIO()
45 stats
= pstats
.Stats(prof
, stream
=stream
)
46 # stats.strip_dirs() # Don't; too many modules are named __init__.py.
48 # 'time', 'cumulative' or 'calls'
49 stats
.sort_stats('time')
51 # Optional arg: how many to print
53 # The rest is optional.
54 # stats.print_callees()
55 # stats.print_callers()
57 print '<h1>Profile data</h1>'
59 print stream
.getvalue()[:1000000]
63 def profile_main_as_logs():
64 """Main program for profiling. Profiling data logged.
70 prof
= cProfile
.Profile()
71 prof
= prof
.runctx("real_main()", globals(), locals())
72 stream
= StringIO
.StringIO()
73 stats
= pstats
.Stats(prof
, stream
=stream
)
74 stats
.sort_stats('time') # Or cumulative
75 stats
.print_stats(80) # 80 = how many to print
76 # The rest is optional.
77 # stats.print_callees()
78 # stats.print_callers()
79 logging
.info("Profile data:\n%s", stream
.getvalue())
83 """Main program without profiling.
85 import django
.core
.handlers
.wsgi
87 # Create a Django application for WSGI.
88 application
= django
.core
.handlers
.wsgi
.WSGIHandler()
90 from soc
.modules
import callback
91 from soc
.modules
import core
93 callback
.registerCore(core
.Core())
94 callback
.getCore().registerModuleCallbacks()
96 # Run the WSGI CGI handler with that application.
97 util
.run_wsgi_app(application
)
101 if __name__
== '__main__':