Commits

Jason R. Coombs  committed 7c84e7f

Added a log entry to indicate how long it takes to load the feed history

  • Participants
  • Parent commits 6af78c3
  • Tags 1101.7

Comments (0)

Files changed (2)

File pmxbot/rss.py

 from . import botbase
 from . import pmxbot
 from . import storage
+from . import timing
 
 log = logging.getLogger(__name__)
 
 				args = [feed],
 				repeat = True,
 				)(self.parse_feed)
+		timer = timing.Stopwatch()
 		self.seen_feeds = self.store.get_seen_feeds()
+		log.info("Loaded feed history in %s", timer.split())
 		pmxbot._finalizers.append(self.finalize)
 
 	@classmethod

File pmxbot/timing.py

+# copied from jaraco.util.timing
+from __future__ import unicode_literals
+
+import datetime
+
+class Stopwatch(object):
+	"""
+	A simple stopwatch which starts automatically.
+
+	>>> w = Stopwatch()
+	>>> _1_sec = datetime.timedelta(seconds=1)
+	>>> w.split() < _1_sec
+	True
+	>>> import time
+	>>> time.sleep(1.0)
+	>>> w.split() >= _1_sec
+	True
+	>>> w.stop() >= _1_sec
+	True
+	>>> w.reset()
+	>>> w.start()
+	>>> w.split() < _1_sec
+	True
+	"""
+	def __init__(self):
+		self.reset()
+		self.start()
+
+	def reset(self):
+		self.elapsed = datetime.timedelta(0)
+		if hasattr(self, 'start_time'):
+			del self.start_time
+
+	def start(self):
+		self.start_time = datetime.datetime.now()
+
+	def stop(self):
+		stop_time = datetime.datetime.now()
+		self.elapsed += stop_time - self.start_time
+		del self.start_time
+		return self.elapsed
+
+	def split(self):
+		local_duration = datetime.datetime.now() - self.start_time
+		return self.elapsed + local_duration
+
+	# context manager support
+	__enter__ = start
+
+	def __exit__(self, exc_type, exc_value, traceback):
+		self.stop()