Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1408)

Unified Diff: pkg/analysis_server/lib/src/utilities/average.dart

Issue 1489583003: Diagnostic status reporting (#24932). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/status/get_handler.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/utilities/average.dart
diff --git a/pkg/analysis_server/lib/src/utilities/average.dart b/pkg/analysis_server/lib/src/utilities/average.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a738d3976964b71f0f2c775777670074d6ae1a59
--- /dev/null
+++ b/pkg/analysis_server/lib/src/utilities/average.dart
@@ -0,0 +1,30 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library analysis_server.src.utilities.average;
+
+/// Simple rolling average sample counter.
+class Average {
+ num _val;
+ final int _sampleCount;
+
+ /// Create an average with the given (optional) sample count size.
+ Average([this._sampleCount = 20]);
+
+ /// The current average.
+ num get value => _val ?? 0;
+
+ /// Add the given [sample].
+ void addSample(num sample) {
+ if (_val == null) {
+ _val = sample;
+ } else {
+ _val = _val * ((_sampleCount - 1) / _sampleCount) +
+ sample * (1 / _sampleCount);
+ }
+ }
+
+ @override
+ String toString() => 'average: ${value}';
+}
« no previous file with comments | « pkg/analysis_server/lib/src/status/get_handler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698