mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-16 11:17:52 -06:00
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>
This commit is contained in:
parent
18b04ffe68
commit
8fe8a6deb3
3 changed files with 31 additions and 14 deletions
29
klippy/extras/statistics.py
Normal file
29
klippy/extras/statistics.py
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue