| 1 | #! /usr/bin/python -tt
|
|---|
| 2 |
|
|---|
| 3 | # Do either:
|
|---|
| 4 | # ./yum-leak-test.py
|
|---|
| 5 | # ./yum-leak-test.py zip
|
|---|
| 6 |
|
|---|
| 7 | import yum, os, time, gc, sys
|
|---|
| 8 | from urlgrabber.progress import format_number
|
|---|
| 9 |
|
|---|
| 10 | def out_mem(pid):
|
|---|
| 11 | ps = {}
|
|---|
| 12 | for line in open("/proc/%d/status" % pid):
|
|---|
| 13 | if line[-1] != '\n':
|
|---|
| 14 | continue
|
|---|
| 15 | data = line[:-1].split(':\t', 1)
|
|---|
| 16 | if data[1].endswith(' kB'):
|
|---|
| 17 | data[1] = data[1][:-3]
|
|---|
| 18 | ps[data[0].strip().lower()] = data[1].strip()
|
|---|
| 19 | if 'vmrss' in ps and 'vmsize' in ps:
|
|---|
| 20 | print "* Memory : %5s RSS (%5sB VSZ)" % \
|
|---|
| 21 | (format_number(int(ps['vmrss']) * 1024),
|
|---|
| 22 | format_number(int(ps['vmsize']) * 1024))
|
|---|
| 23 |
|
|---|
| 24 | print "Running:", yum.__version__
|
|---|
| 25 |
|
|---|
| 26 | def _leak_tst_yb():
|
|---|
| 27 | print "Doing YumBase leak test. "
|
|---|
| 28 | out_mem(os.getpid())
|
|---|
| 29 | while True:
|
|---|
| 30 | yb = yum.YumBase()
|
|---|
| 31 | yb.preconf.debuglevel = 0
|
|---|
| 32 | yb.preconf.errorlevel = 0
|
|---|
| 33 | yb.repos.setCacheDir(yum.misc.getCacheDir())
|
|---|
| 34 | yb.rpmdb.returnPackages()
|
|---|
| 35 | yb.pkgSack.returnPackages()
|
|---|
| 36 | out_mem(os.getpid())
|
|---|
| 37 | time.sleep(4)
|
|---|
| 38 |
|
|---|
| 39 | if False:
|
|---|
| 40 | del yb
|
|---|
| 41 | print len(gc.garbage)
|
|---|
| 42 | if gc.garbage:
|
|---|
| 43 | print gc.garbage[0]
|
|---|
| 44 | print gc.get_referrers(gc.garbage[0])
|
|---|
| 45 | # print "DBG:", gc.get_referrers(yb)
|
|---|
| 46 |
|
|---|
| 47 | def _leak_tst_cl():
|
|---|
| 48 | print "Doing closeRpmDB and .up test. "
|
|---|
| 49 | yb = yum.YumBase()
|
|---|
| 50 | yb.preconf.debuglevel = 0
|
|---|
| 51 | yb.preconf.errorlevel = 0
|
|---|
| 52 | yb.repos.setCacheDir(yum.misc.getCacheDir())
|
|---|
| 53 | while True:
|
|---|
| 54 | out_mem(os.getpid())
|
|---|
| 55 | print "up:",
|
|---|
| 56 | yb.up
|
|---|
| 57 | print "done"
|
|---|
| 58 | out_mem(os.getpid())
|
|---|
| 59 |
|
|---|
| 60 | print "rpmdb pkgs:",
|
|---|
| 61 | yb.rpmdb.returnPackages()
|
|---|
| 62 | print "done"
|
|---|
| 63 | out_mem(os.getpid())
|
|---|
| 64 |
|
|---|
| 65 | print "pkgSack pkgs:",
|
|---|
| 66 | yb.pkgSack.returnPackages()
|
|---|
| 67 | print "done"
|
|---|
| 68 | out_mem(os.getpid())
|
|---|
| 69 |
|
|---|
| 70 | print "close:",
|
|---|
| 71 | yb.closeRpmDB()
|
|---|
| 72 | print "done"
|
|---|
| 73 |
|
|---|
| 74 | def _leak_tst_ir():
|
|---|
| 75 | print "Doing install/remove leak test. "
|
|---|
| 76 |
|
|---|
| 77 | def _init():
|
|---|
| 78 | yb = cli.YumBaseCli() # Need doTransaction() etc.
|
|---|
| 79 | yb.preconf.debuglevel = 0
|
|---|
| 80 | yb.preconf.errorlevel = 0
|
|---|
| 81 | yb.repos.setCacheDir(yum.misc.getCacheDir())
|
|---|
| 82 | yb.conf.assumeyes = True
|
|---|
| 83 | return yb
|
|---|
| 84 |
|
|---|
| 85 | sys.path.append('/usr/share/yum-cli')
|
|---|
| 86 | import cli
|
|---|
| 87 | yb = _init()
|
|---|
| 88 | out_mem(os.getpid())
|
|---|
| 89 |
|
|---|
| 90 | def _run(yb):
|
|---|
| 91 | print " Run"
|
|---|
| 92 | (code, msgs) = yb.buildTransaction()
|
|---|
| 93 | if code == 1:
|
|---|
| 94 | print "ERROR:", core, msgs
|
|---|
| 95 | sys.exit(1)
|
|---|
| 96 | returnval = yb.doTransaction()
|
|---|
| 97 | if returnval != 0: # We could allow 1 too, but meh.
|
|---|
| 98 | print "ERROR:", returnval
|
|---|
| 99 | sys.exit(1)
|
|---|
| 100 | yb.closeRpmDB()
|
|---|
| 101 |
|
|---|
| 102 | last = None
|
|---|
| 103 | while True:
|
|---|
| 104 | if True:
|
|---|
| 105 | yb = _init()
|
|---|
| 106 | out_mem(os.getpid())
|
|---|
| 107 | print " Install:", sys.argv[1:]
|
|---|
| 108 | for pat in sys.argv[1:]:
|
|---|
| 109 | yb.install(pattern=pat)
|
|---|
| 110 | out_mem(os.getpid())
|
|---|
| 111 | _run(yb)
|
|---|
| 112 | out_mem(os.getpid())
|
|---|
| 113 |
|
|---|
| 114 | print " Remove:", sys.argv[1:]
|
|---|
| 115 | for pat in sys.argv[1:]:
|
|---|
| 116 | yb.remove(pattern=pat)
|
|---|
| 117 | out_mem(os.getpid())
|
|---|
| 118 | _run(yb)
|
|---|
| 119 |
|
|---|
| 120 | if len(sys.argv) == 2 and sys.argv[1] == 'closeRpmDB':
|
|---|
| 121 | _leak_tst_cl()
|
|---|
| 122 | elif sys.argv[1:]:
|
|---|
| 123 | _leak_tst_ir()
|
|---|
| 124 | else:
|
|---|
| 125 | _leak_tst_yb()
|
|---|