summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-05-16 21:28:07 +1200
committerLars Wirzenius <liw@liw.fi>2010-05-16 21:28:07 +1200
commit7dd72021c06803bac66b73f0c8687df0d459fd4a (patch)
treefd0a660552fad67282f8382b503df49c0fa6c48e
parentaf7babe2d8272fae414c4dccbd710ba5ca52a9d2 (diff)
downloadobnam-7dd72021c06803bac66b73f0c8687df0d459fd4a.tar.gz
Add way to run obnam under profiling.
Add script to view profile data.
-rwxr-xr-xobnam35
-rwxr-xr-xviewprof25
2 files changed, 48 insertions, 12 deletions
diff --git a/obnam b/obnam
index c8845fc7..4582304f 100755
--- a/obnam
+++ b/obnam
@@ -16,20 +16,31 @@
import logging
+import os
import sys
import traceback
import obnamlib
-try:
- obnamlib.App().run()
-except obnamlib.AppException, e:
- logging.critical(str(e))
- sys.stderr.write('Error: %s\n' % str(e))
- sys.exit(1)
-except SystemExit, e:
- sys.exit(e.code)
-except BaseException, e:
- logging.critical(traceback.format_exc())
- sys.stderr.write(traceback.format_exc())
- sys.exit(1)
+
+def main():
+ try:
+ obnamlib.App().run()
+ except obnamlib.AppException, e:
+ logging.critical(str(e))
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(1)
+ except SystemExit, e:
+ sys.exit(e.code)
+ except BaseException, e:
+ logging.critical(traceback.format_exc())
+ sys.stderr.write(traceback.format_exc())
+ sys.exit(1)
+
+
+if __name__ == '__main__':
+ if os.environ.get('OBNAM_PROFILE') == 'yes':
+ import cProfile
+ cProfile.run('main()', 'obnam.prof')
+ else:
+ main()
diff --git a/viewprof b/viewprof
new file mode 100755
index 00000000..cecfbcfd
--- /dev/null
+++ b/viewprof
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+# Copyright 2010 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import pstats
+import sys
+
+p = pstats.Stats(sys.argv[1])
+p.strip_dirs()
+p.sort_stats('time')
+p.print_stats()
+p.print_callees()