#lang racket/base
;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: Copyright © 2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>

(provide report-stats)

(define (report-stats REPORT_EVERY)
  (define start-time (current-inexact-milliseconds))
  (define prev-value 0)
  (lambda (new-value)
    (when (zero? (remainder new-value REPORT_EVERY))
      (define end-time (current-inexact-milliseconds))
      (define delta (/ (- end-time start-time) 1000.0))
      (define count (- new-value prev-value))
      (set! prev-value new-value)
      (set! start-time end-time)
      (log-info "Box got ~a (~a Hz)" new-value (/ count delta)))))
