debug.py 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import logging
  2. import time
  3. logger = logging.getLogger(__name__)
  4. class PrintStats:
  5. def __init__(self, parent):
  6. self.startTime = time.monotonic()
  7. def execute(self, values):
  8. counts = {}
  9. dt = time.monotonic() - self.startTime
  10. self.startTime = time.monotonic()
  11. text = ""
  12. warn = False
  13. for meas in values:
  14. id = "{} {}".format(meas.series, meas.source)
  15. if id in counts:
  16. counts[id] += 1
  17. else:
  18. counts[id] = 1
  19. if counts:
  20. ids = list(counts.keys())
  21. ids.sort()
  22. for id in ids:
  23. text += "{}: {:4d} in {:.03f}s, {:.1f}/s ".format(id, counts[id], dt, counts[id] / dt)
  24. else:
  25. text = "0 Messungen in {:.03f}s ".format(dt)
  26. warn = True
  27. if warn:
  28. logger.warning(text)
  29. else:
  30. logger.info(text)
  31. return values
  32. class Warning:
  33. def __init__(self, parent):
  34. pass
  35. def execute(self, values):
  36. for meas in values:
  37. logger.warning(str(meas))
  38. yield meas