mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Print out time taken for each report type
This commit is contained in:
parent
a006aed4f1
commit
79f5dff810
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import posixpath, os
|
import posixpath, os, time, types
|
||||||
from collections import namedtuple, defaultdict, Counter
|
from collections import namedtuple, defaultdict, Counter
|
||||||
|
|
||||||
from calibre.ebooks.oeb.polish.container import OEB_DOCS, OEB_STYLES, OEB_FONTS
|
from calibre.ebooks.oeb.polish.container import OEB_DOCS, OEB_STYLES, OEB_FONTS
|
||||||
@ -51,7 +51,7 @@ def safe_img_data(container, name, mt):
|
|||||||
width = height = 0
|
width = height = 0
|
||||||
return width, height
|
return width, height
|
||||||
|
|
||||||
def file_data(container):
|
def files_data(container, book_locale):
|
||||||
for name, path in container.name_path_map.iteritems():
|
for name, path in container.name_path_map.iteritems():
|
||||||
yield File(name, posixpath.dirname(name), posixpath.basename(name), safe_size(container, name),
|
yield File(name, posixpath.dirname(name), posixpath.basename(name), safe_size(container, name),
|
||||||
get_category(name, container.mime_map.get(name, '')))
|
get_category(name, container.mime_map.get(name, '')))
|
||||||
@ -66,7 +66,7 @@ def sort_locations(container, locations):
|
|||||||
return (nmap.get(l.name, len(nmap)), numeric_sort_key(l.name), l.line_number)
|
return (nmap.get(l.name, len(nmap)), numeric_sort_key(l.name), l.line_number)
|
||||||
return sorted(locations, key=sort_key)
|
return sorted(locations, key=sort_key)
|
||||||
|
|
||||||
def link_data(container):
|
def images_data(container, book_locale):
|
||||||
image_usage = defaultdict(set)
|
image_usage = defaultdict(set)
|
||||||
link_sources = OEB_STYLES | OEB_DOCS
|
link_sources = OEB_STYLES | OEB_DOCS
|
||||||
for name, mt in container.mime_map.iteritems():
|
for name, mt in container.mime_map.iteritems():
|
||||||
@ -87,13 +87,13 @@ def link_data(container):
|
|||||||
|
|
||||||
Word = namedtuple('Word', 'id word locale usage')
|
Word = namedtuple('Word', 'id word locale usage')
|
||||||
|
|
||||||
def word_data(container, book_locale):
|
def words_data(container, book_locale):
|
||||||
count, words = get_all_words(container, book_locale, get_word_count=True)
|
count, words = get_all_words(container, book_locale, get_word_count=True)
|
||||||
return (count, tuple(Word(i, word, locale, v) for i, ((word, locale), v) in enumerate(words.iteritems())))
|
return (count, tuple(Word(i, word, locale, v) for i, ((word, locale), v) in enumerate(words.iteritems())))
|
||||||
|
|
||||||
Char = namedtuple('Char', 'id char codepoint usage count')
|
Char = namedtuple('Char', 'id char codepoint usage count')
|
||||||
|
|
||||||
def char_data(container):
|
def chars_data(container, book_locale):
|
||||||
chars = defaultdict(set)
|
chars = defaultdict(set)
|
||||||
counter = Counter()
|
counter = Counter()
|
||||||
def count(codepoint):
|
def count(codepoint):
|
||||||
@ -116,10 +116,13 @@ def char_data(container):
|
|||||||
yield Char(i, safe_chr(codepoint), codepoint, sorted(usage, key=sort_key), counter[codepoint])
|
yield Char(i, safe_chr(codepoint), codepoint, sorted(usage, key=sort_key), counter[codepoint])
|
||||||
|
|
||||||
def gather_data(container, book_locale):
|
def gather_data(container, book_locale):
|
||||||
data = {'files':tuple(file_data(container))}
|
timing = {}
|
||||||
img_data = link_data(container)
|
data = {}
|
||||||
data['images'] = img_data
|
for x in 'files images words chars'.split():
|
||||||
data['words'] = word_data(container, book_locale)
|
st = time.time()
|
||||||
data['chars'] = tuple(char_data(container))
|
data[x] = globals()[x + '_data'](container, book_locale)
|
||||||
return data
|
if isinstance(data[x], types.GeneratorType):
|
||||||
|
data[x] = tuple(data[x])
|
||||||
|
timing[x] = time.time() - st
|
||||||
|
return data, timing
|
||||||
|
|
||||||
|
@ -752,6 +752,12 @@ class Reports(Dialog):
|
|||||||
return error_dialog(self, _('Failed to gather data'), _(
|
return error_dialog(self, _('Failed to gather data'), _(
|
||||||
'Failed to gather data for the report. Click "Show details" for more'
|
'Failed to gather data for the report. Click "Show details" for more'
|
||||||
' information.'), det_msg=data, show=True)
|
' information.'), det_msg=data, show=True)
|
||||||
|
data, timing = data
|
||||||
|
try:
|
||||||
|
for x, t in timing.iteritems():
|
||||||
|
print ('Time for %s data: %.3f seconds' % (x, t))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
self.reports(data)
|
self.reports(data)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user