| 1 |
#!/usr/bin/env python |
| 2 |
# License: GPLv3 Copyright: 2013, Kovid Goyal <kovid at kovidgoyal.net> |
| 3 |
|
| 4 |
import cProfile |
| 5 |
import os |
| 6 |
from tempfile import gettempdir |
| 7 |
|
| 8 |
from calibre.db.legacy import LibraryDatabase |
| 9 |
|
| 10 |
db = None |
| 11 |
|
| 12 |
|
| 13 |
def initdb(path): |
| 14 |
global db |
| 15 |
db = LibraryDatabase(os.path.expanduser(path)) |
| 16 |
|
| 17 |
|
| 18 |
def show_stats(path): |
| 19 |
from pstats import Stats |
| 20 |
|
| 21 |
s = Stats(path) |
| 22 |
s.sort_stats('cumulative') |
| 23 |
s.print_stats(30) |
| 24 |
|
| 25 |
|
| 26 |
def main(): |
| 27 |
stats = os.path.join(gettempdir(), 'read_db.stats') |
| 28 |
pr = cProfile.Profile() |
| 29 |
initdb('~/test library') |
| 30 |
all_ids = db.new_api.all_book_ids() |
| 31 |
pr.enable() |
| 32 |
for book_id in all_ids: |
| 33 |
db.new_api._composite_for('#isbn', book_id) |
| 34 |
db.new_api._composite_for('#formats', book_id) |
| 35 |
pr.disable() |
| 36 |
pr.dump_stats(stats) |
| 37 |
show_stats(stats) |
| 38 |
print('Stats saved to', stats) |
| 39 |
|
| 40 |
|
| 41 |
if __name__ == '__main__': |
| 42 |
main() |