generate profile even when exception raised.
authorVadim Gelfer <vadim.gelfer@gmail.com>
Fri, 03 Mar 2006 13:11:25 -0800
changeset 1832 7a58bf789965
parent 1831 bf118f39afd7
child 1833 fc959d6ffb13
generate profile even when exception raised. otherwise, is not possible to profile hg serve.
mercurial/commands.py
--- a/mercurial/commands.py	Fri Mar 03 09:40:18 2006 -0800
+++ b/mercurial/commands.py	Fri Mar 03 13:11:25 2006 -0800
@@ -2862,13 +2862,21 @@
             if options['profile']:
                 import hotshot, hotshot.stats
                 prof = hotshot.Profile("hg.prof")
-                r = prof.runcall(d)
-                prof.close()
-                stats = hotshot.stats.load("hg.prof")
-                stats.strip_dirs()
-                stats.sort_stats('time', 'calls')
-                stats.print_stats(40)
-                return r
+                try:
+                    try:
+                        return prof.runcall(d)
+                    except:
+                        try:
+                            u.warn(_('exception raised - generating profile '
+                                     'anyway\n'))
+                        except:
+                            pass
+                finally:
+                    prof.close()
+                    stats = hotshot.stats.load("hg.prof")
+                    stats.strip_dirs()
+                    stats.sort_stats('time', 'calls')
+                    stats.print_stats(40)
             else:
                 return d()
         except: