<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>profiling/__init__.py</filename>
    </added>
    <added>
      <filename>profiling/lsprofcalltree.py</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -544,6 +544,8 @@ class PootleOptionParser(simplewebserver.WebOptionParser):
     psycomodes=[&quot;none&quot;, &quot;full&quot;, &quot;profile&quot;]
     self.add_option('', &quot;--statsdb_file&quot;, action=&quot;store&quot;, type=&quot;string&quot;, dest=&quot;statsdb_file&quot;,
                     default=None, help=&quot;Specifies the location of the SQLite stats db file.&quot;)
+    self.add_option('', &quot;--profile&quot;, action=&quot;store&quot;, type=&quot;string&quot;, dest=&quot;profile&quot;,
+                    help=&quot;Perform profiling, storing the result to the supplied filename.&quot;)
     try:
       import psyco
       self.add_option('', &quot;--psyco&quot;, dest=&quot;psyco&quot;, default=None, choices=psycomodes, metavar=&quot;MODE&quot;,
@@ -577,6 +579,34 @@ def usepsyco(options):
   import encodings
   psyco.cannotcompile(encodings.search_function)
 
+def profile_runner(server, options):
+  import cProfile
+  import profiling.lsprofcalltree as lsprofcalltree
+
+  def write_cache_grind(profiler, file):
+    k_cache_grind = lsprofcalltree.KCacheGrind(profiler)
+    k_cache_grind.output(file)
+    file.close()
+
+  def do_profile_run(file):
+    profiler = cProfile.Profile()
+    try:
+      profiler.runcall(simplewebserver.run, server, options)
+    finally:
+      write_cache_grind(profiler, file)
+  
+  try:
+    profile_file = open(options.profile, &quot;w+&quot;)
+    do_profile_run(profile_file)
+  except IOError, _e:
+    print &quot;Could not open profiling file %s&quot; % (options.profile,)
+
+def get_runner(options):
+  if getattr(options, &quot;profile&quot;, None) != None:
+    return profile_runner
+  else:
+    return simplewebserver.run
+
 def main():
   # run the web server
   checkversions()
@@ -590,7 +620,8 @@ def main():
   server = parser.getserver(options)
   server.options = options
   if options.action == &quot;runwebserver&quot;:
-    simplewebserver.run(server, options)
+    run = get_runner(options)
+    run(server, options)  
   elif options.action == &quot;refreshstats&quot;:
     server.refreshstats(args)
 </diff>
      <filename>pootle.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b725e864428039f9db7dd72dbd377c693ffeee1a</id>
    </parent>
  </parents>
  <author>
    <name>winterstream</name>
    <email>winterstream@54714841-351b-0410-a198-e36a94b762f5</email>
  </author>
  <url>http://github.com/julen/pootle/commit/e3f8306568cfa0c6ff3d1c3a72e8cc6daf2d38c1</url>
  <id>e3f8306568cfa0c6ff3d1c3a72e8cc6daf2d38c1</id>
  <committed-date>2008-07-29T06:13:15-07:00</committed-date>
  <authored-date>2008-07-29T06:13:15-07:00</authored-date>
  <message>This adds some profiling code to Poolte. The output can be viewed with
kcachegrind.


git-svn-id: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/Pootle@7926 54714841-351b-0410-a198-e36a94b762f5</message>
  <tree>14daa3fbb821f72894cec848e0d82d9f7d194a3a</tree>
  <committer>
    <name>winterstream</name>
    <email>winterstream@54714841-351b-0410-a198-e36a94b762f5</email>
  </committer>
</commit>
