comparison mercurial/hgweb/hgwebdir_mod.py @ 29787:80df04266a16

hgweb: profile HTTP requests Currently, running `hg serve --profile` doesn't yield anything useful: when the process is terminated the profiling output displays results from the main thread, which typically spends most of its time in select.select(). Furthermore, it has no meaningful results from mercurial.* modules because the threads serving HTTP requests don't actually get profiled. This patch teaches the hgweb wsgi applications to profile individual requests. If profiling is enabled, the profiler kicks in after HTTP/WSGI environment processing but before Mercurial's main request processing. The profile results are printed to the configured profiling output. If running `hg serve` from a shell, they will be printed to stderr, just before the HTTP request line is logged. If profiling to a file, we only write a single profile to the file because the file is not opened in append mode. We could add support for appending to files in a future patch if someone wants it. Per request profiling doesn't work with the statprof profiler because internally that profiler collects samples from the thread that *initially* requested profiling be enabled. I have plans to address this by vendoring Facebook's customized statprof and then improving it.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 14 Aug 2016 18:37:24 -0700
parents fc2442492606
children d83ca854fa21
comparison
equal deleted inserted replaced
29786:fc2442492606 29787:80df04266a16
29 29
30 from .. import ( 30 from .. import (
31 encoding, 31 encoding,
32 error, 32 error,
33 hg, 33 hg,
34 profiling,
34 scmutil, 35 scmutil,
35 templater, 36 templater,
36 ui as uimod, 37 ui as uimod,
37 util, 38 util,
38 ) 39 )
215 return True 216 return True
216 217
217 return False 218 return False
218 219
219 def run_wsgi(self, req): 220 def run_wsgi(self, req):
220 return self._runwsgi(req) 221 with profiling.maybeprofile(self.ui):
222 for r in self._runwsgi(req):
223 yield r
221 224
222 def _runwsgi(self, req): 225 def _runwsgi(self, req):
223 try: 226 try:
224 self.refresh() 227 self.refresh()
225 228