Exemple #1
0
def test_for_mem_leak():
    from calibre.utils.mem import memory, gc_histogram, diff_hists
    import gc
    gc.disable()
    scanner = DeviceScanner()
    scanner.scan()
    memory()  # load the psutil library
    for i in xrange(3):
        gc.collect()

    for reps in (1, 10, 100, 1000):
        for i in xrange(3):
            gc.collect()
        h1 = gc_histogram()
        startmem = memory()
        for i in xrange(reps):
            scanner.scan()
        for i in xrange(3):
            gc.collect()
        usedmem = memory(startmem)
        prints('Memory used in %d repetitions of scan(): %.5f KB'%(reps,
            1024*usedmem))
        prints('Differences in python object counts:')
        diff_hists(h1, gc_histogram())
        prints()
Exemple #2
0
def test_mem():
    from calibre.utils.mem import gc_histogram, diff_hists
    m = Matcher([])
    del m
    def doit(c):
        m = Matcher([c+'im/one.gif', c+'im/two.gif', c+'text/one.html',])
        m('one')
    import gc
    gc.collect()
    h1 = gc_histogram()
    for i in xrange(100):
        doit(str(i))
    h2 = gc_histogram()
    diff_hists(h1, h2)