From 5ce7afa6e2fb0743e3c7bba2de33d76bd016d687 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Dec 2010 10:57:15 -0700 Subject: [PATCH] ... --- src/calibre/ebooks/metadata/pdf.py | 1 + src/calibre/utils/mem.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/calibre/ebooks/metadata/pdf.py b/src/calibre/ebooks/metadata/pdf.py index 2d1935539e..20a4c4659e 100644 --- a/src/calibre/ebooks/metadata/pdf.py +++ b/src/calibre/ebooks/metadata/pdf.py @@ -17,6 +17,7 @@ pdfreflow, pdfreflow_error = plugins['pdfreflow'] def get_metadata(stream, cover=True): if pdfreflow is None: raise RuntimeError(pdfreflow_error) + stream.seek(0) raw = stream.read() #isbn = _isbn_pat.search(raw) #if isbn is not None: diff --git a/src/calibre/utils/mem.py b/src/calibre/utils/mem.py index f48aec34c6..1f9bff8d63 100644 --- a/src/calibre/utils/mem.py +++ b/src/calibre/utils/mem.py @@ -5,6 +5,8 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' +import gc + ## {{{ http://code.activestate.com/recipes/286222/ (r1) import os @@ -52,4 +54,19 @@ def stacksize(since=0.0): ## end of http://code.activestate.com/recipes/286222/ }}} +def gc_histogram(): + """Returns per-class counts of existing objects.""" + result = {} + for o in gc.get_objects(): + t = type(o) + count = result.get(t, 0) + result[t] = count + 1 + return result + +def diff_hists(h1, h2): + """Prints differences between two results of gc_histogram().""" + for k in h1: + if h1[k] != h2[k]: + print "%s: %d -> %d (%s%d)" % ( + k, h1[k], h2[k], h2[k] > h1[k] and "+" or "", h2[k] - h1[k])