jenkins-bot has submitted this change and it was merged.
Change subject: Print additional statistics when script terminates
......................................................................
Print additional statistics when script terminates
Change-Id: I71be8b199f04cc754c99d3a58255476eb3c48a89
---
M pywikibot/bot.py
1 file changed, 19 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 722670e..61b9ab0 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -48,7 +48,7 @@
ListOption, HighlightContextOption,
ChoiceException, QuitKeyboardInterrupt,
)
-from pywikibot.tools import deprecated, deprecated_args, PY2
+from pywikibot.tools import deprecated, deprecated_args, PY2, PYTHON_VERSION
if not PY2:
unicode = str
@@ -1498,6 +1498,23 @@
pywikibot.output("\n%i pages read"
"\n%i pages written"
% (self._treat_counter, self._save_counter))
+ if hasattr(self, '_start_ts'):
+ delta = (pywikibot.Timestamp.now() - self._start_ts)
+ if PYTHON_VERSION >= (2, 7):
+ seconds = int(delta.total_seconds())
+ else:
+ seconds = delta.seconds + delta.days * 86400
+ if delta.days:
+ pywikibot.output("Execution time: %d days, %d seconds"
+ % (delta.days, delta.seconds))
+ else:
+ pywikibot.output("Execution time: %d seconds" % delta.seconds)
+ if self._treat_counter:
+ pywikibot.output("Read operation time: %d seconds"
+ % (seconds / self._treat_counter))
+ if self._save_counter:
+ pywikibot.output("Write operation time: %d seconds"
+ % (seconds / self._save_counter))
# exc_info contains exception from self.run() while terminating
exc_info = sys.exc_info()
@@ -1518,6 +1535,7 @@
def run(self):
"""Process all pages in generator."""
+ self._start_ts = pywikibot.Timestamp.now()
if not hasattr(self, 'generator'):
raise NotImplementedError('Variable %s.generator not set.'
% self.__class__.__name__)
--
To view, visit
https://gerrit.wikimedia.org/r/221656
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I71be8b199f04cc754c99d3a58255476eb3c48a89
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>