Skip to content

Commit

Permalink
propagate measurement reset to reporters, closes jketterl#88
Browse files Browse the repository at this point in the history
  • Loading branch information
jketterl committed Mar 25, 2020
1 parent 0bffc2b commit a7345bb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion htdocs/lib/Measurement.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Measurement() {
this.reporters = [];
this.reset();
}

Expand All @@ -21,10 +22,13 @@ Measurement.prototype.getRate = function() {
Measurement.prototype.reset = function() {
this.value = 0;
this.start = new Date();
this.reporters.forEach(function(r){ r.reset(); });
};

Measurement.prototype.report = function(range, interval, callback) {
return new Reporter(this, range, interval, callback);
var reporter = new Reporter(this, range, interval, callback);
this.reporters.push(reporter);
return reporter;
};

function Reporter(measurement, range, interval, callback) {
Expand Down Expand Up @@ -59,4 +63,8 @@ Reporter.prototype.report = function(){
var accumulated = newest.value - oldest.value;
// we want rate per second, but our time is in milliseconds... compensate by 1000
this.callback(accumulated * 1000 / elapsed);
};

Reporter.prototype.reset = function(){
this.samples = [];
};

0 comments on commit a7345bb

Please sign in to comment.