diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-09-02 13:07:43 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-09-02 13:46:19 -0400 |
commit | 8fe8a6deb3b7ea3eca8730d5b1500c2c27c251cd (patch) | |
tree | e9dee0f04913f7f4bb1baff0cc532ee819e98300 /klippy/extras/statistics.py | |
parent | 18b04ffe6815987284130337e5eb4f46f3ba1c69 (diff) | |
download | kutter-8fe8a6deb3b7ea3eca8730d5b1500c2c27c251cd.tar.gz kutter-8fe8a6deb3b7ea3eca8730d5b1500c2c27c251cd.tar.xz kutter-8fe8a6deb3b7ea3eca8730d5b1500c2c27c251cd.zip |
statistics: Move stats handling to new "extras" module
Move the generation of statistics to its own module.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/statistics.py')
-rw-r--r-- | klippy/extras/statistics.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/klippy/extras/statistics.py b/klippy/extras/statistics.py new file mode 100644 index 00000000..639bcad3 --- /dev/null +++ b/klippy/extras/statistics.py @@ -0,0 +1,29 @@ +# Support for logging periodic statistics +# +# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net> +# +# This file may be distributed under the terms of the GNU GPLv3 license. +import logging + +class PrinterStats: + def __init__(self, config): + self.printer = config.get_printer() + reactor = self.printer.get_reactor() + self.stats_timer = reactor.register_timer(self.generate_stats) + self.stats_cb = [] + def printer_state(self, state): + if state == 'ready': + self.stats_cb = [o.stats for n, o in self.printer.lookup_objects() + if hasattr(o, 'stats')] + if self.printer.get_start_args().get('debugoutput') is None: + reactor = self.printer.get_reactor() + reactor.update_timer(self.stats_timer, reactor.NOW) + def generate_stats(self, eventtime): + stats = [cb(eventtime) for cb in self.stats_cb] + if max([s[0] for s in stats]): + logging.info("Stats %.1f: %s", eventtime, + ' '.join([s[1] for s in stats])) + return eventtime + 1. + +def load_config(config): + return PrinterStats(config) |