Tim Lauridsen wrote:
Florian Festi wrote:
Hi!
The attached patch adds profiling to yummain.py. It's not that
beautiful as it replaces all kind of system.exit() calls by returns. I
don't like all these exit calls. But if anyone really likes them we
can just catch the SystemExit exceptions...
The patches look fine to me.
I'd also like to add command line switch to enable profiling. May be
--profile=(main|main-hot|depsolve|depsolve-hot|...)
I don't like adding the --profile= to the default yum cli the newest
yum-utils inherit the yum cli command line switches and the --profile,
will not work there and it also is to not use to the normal yum user.
what about making a special yumprof.py there is importing the main from
yummain.py and run the selected profiler on the main imported from
yummain.py.
Example:
sudo ./yumprof.py (main|main-hot|depsolve|depsolve-hot|...) install *.i386
Tim
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel
Here is a patch to move the profile code to yumprof.py
Comments please.
Tim
diff --git a/yummain.py b/yummain.py
index e3eb396..daf0024 100755
--- a/yummain.py
+++ b/yummain.py
@@ -195,36 +195,10 @@ def main(args):
if unlock(): return 200
return 0
-def hotshot(func, *args, **kwargs):
- import hotshot.stats, os.path
- fn = os.path.expanduser("~/yum.prof")
- prof = hotshot.Profile(fn)
- rc = prof.runcall(func, *args, **kwargs)
- prof.close()
- print_stats(hotshot.stats.load(fn))
- return rc
-
-def cprof(func, *args, **kwargs):
- import cProfile, pstats, os.path
- fn = os.path.expanduser("~/yum.prof")
- prof = cProfile.Profile()
- rc = prof.runcall(func, *args, **kwargs)
- prof.dump_stats(fn)
- print_stats(pstats.Stats(fn))
- return rc
-
-def print_stats(stats):
- stats.strip_dirs()
- stats.sort_stats('time', 'calls')
- stats.print_stats(20)
- stats.sort_stats('cumulative')
- stats.print_stats(40)
if __name__ == "__main__":
try:
errcode = main(sys.argv[1:])
- #errcode = cprof(main, sys.argv[1:])
- #errcode = hotshot(main, sys.argv[1:])
sys.exit(errcode)
except KeyboardInterrupt, e:
print >> sys.stderr, "\n\nExiting on user cancel."
diff --git a/yumprof.py b/yumprof.py
new file mode 100755
index 0000000..af58723
--- /dev/null
+++ b/yumprof.py
@@ -0,0 +1,67 @@
+#!/usr/bin/python -t
+# 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 2 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 Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Copyright 2005 Duke University
+
+import sys
+from yummain import main
+
+def hotshot(func, *args, **kwargs):
+ import hotshot.stats, os.path
+ fn = os.path.expanduser("~/yum.prof")
+ prof = hotshot.Profile(fn)
+ rc = prof.runcall(func, *args, **kwargs)
+ prof.close()
+ print_stats(hotshot.stats.load(fn))
+ return rc
+
+def cprof(func, *args, **kwargs):
+ import cProfile, pstats, os.path
+ fn = os.path.expanduser("~/yum.prof")
+ prof = cProfile.Profile()
+ rc = prof.runcall(func, *args, **kwargs)
+ prof.dump_stats(fn)
+ print_stats(pstats.Stats(fn))
+ return rc
+
+def print_stats(stats):
+ stats.strip_dirs()
+ stats.sort_stats('time', 'calls')
+ stats.print_stats(20)
+ stats.sort_stats('cumulative')
+ stats.print_stats(40)
+
+def usage():
+ print "Usage : yumprof.py [main|main-hot] <yum command> <yum options>"
+ sys.exit(1)
+
+
+if __name__ == "__main__":
+ try:
+ if len(sys.argv) < 3:
+ usage()
+ cmd = sys.argv[1]
+ del sys.argv[1]
+ print sys.argv[2:]
+ if cmd == 'main':
+ errcode = cprof(main, sys.argv[1:])
+ elif cmd == 'main-hot':
+ errcode = hotshot(main, sys.argv[1:])
+ else:
+ usage()
+
+ sys.exit(errcode)
+ except KeyboardInterrupt, e:
+ print >> sys.stderr, "\n\nExiting on user cancel."
+ sys.exit(1)
\ No newline at end of file
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel