def doit(num_loops=-1): if "-v" in sys.argv: # Hack the verbose flag for the server xpcom.verbose = 1 # Do the test lots of times - can help shake-out ref-count bugs. print "Testing the Python.TestComponent component" if num_loops == -1: num_loops = 10 for i in xrange(num_loops): test_all() if i == 0: # First loop is likely to "leak" as we cache things. # Leaking after that is a problem. if gc is not None: gc.collect() num_refs = gettotalrefcount() mem_usage = getmemusage() if num_errors: break if gc is not None: gc.collect() lost = gettotalrefcount() - num_refs # Sometimes we get spurious counts off by 1 or 2. # This can't indicate a real leak, as we have looped # more than twice! if abs(lost) > 2: print "*** Lost %d references" % (lost, ) # sleep to allow the OS to recover time.sleep(1) mem_lost = getmemusage() - mem_usage # working set size is fickle, and when we were leaking strings, this test # would report a leak of 100MB. So we allow a 2MB buffer - but even this # may still occasionally report spurious warnings. If you are really # worried, bump the counter to a huge value, and if there is a leak it will # show. if mem_lost > 2000000: print "*** Lost %.6f MB of memory" % (mem_lost / 1000000.0, ) if num_errors: print "There were", num_errors, "errors testing the Python component :-(" else: print "The Python test component worked!"
def doit(num_loops = -1): if "-v" in sys.argv: # Hack the verbose flag for the server xpcom.verbose = 1 # Do the test lots of times - can help shake-out ref-count bugs. print "Testing the Python.TestComponent component" if num_loops == -1: num_loops = 10 for i in xrange(num_loops): test_all() if i==0: # First loop is likely to "leak" as we cache things. # Leaking after that is a problem. if gc is not None: gc.collect() num_refs = gettotalrefcount() mem_usage = getmemusage() if num_errors: break if gc is not None: gc.collect() lost = gettotalrefcount() - num_refs # Sometimes we get spurious counts off by 1 or 2. # This can't indicate a real leak, as we have looped # more than twice! if abs(lost)>2: print "*** Lost %d references" % (lost,) # sleep to allow the OS to recover time.sleep(1) mem_lost = getmemusage() - mem_usage # working set size is fickle, and when we were leaking strings, this test # would report a leak of 100MB. So we allow a 2MB buffer - but even this # may still occasionally report spurious warnings. If you are really # worried, bump the counter to a huge value, and if there is a leak it will # show. if mem_lost > 2000000: print "*** Lost %.6f MB of memory" % (mem_lost/1000000.0,) if num_errors: print "There were", num_errors, "errors testing the Python component :-(" else: print "The Python test component worked!"