Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 9c74f16c8bf7408f9fe7b6cdf1769756f334f5be 0 parents
@waywardmonkeys waywardmonkeys authored
2  .gitignore
@@ -0,0 +1,2 @@
+*.hdp
+_build
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Bruce Mitchener, Jr.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+
0  README.rst
No changes.
14 metrics/clock.dylan
@@ -0,0 +1,14 @@
+module: metrics
+synopsis:
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define class <clock> (<object>)
+end;
+
+define method clock-get-ticks (clock :: <clock>)
+ => (ticks :: <integer>)
+ 0
+end;
+
+define constant $default-clock = make(<clock>);
24 metrics/counter.dylan
@@ -0,0 +1,24 @@
+module: metrics
+synopsis:
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define class <counter> (<metric>)
+ slot value :: <integer> = 0;
+end;
+
+define method counter-value (counter :: <counter>)
+ => (count :: <integer>)
+ counter.value
+end;
+
+define method counter-increment (counter :: <counter>,
+ by-value)
+ => ()
+ counter.value := counter.value + by-value;
+end;
+
+define method counter-clear (counter :: <counter>)
+ => ()
+ counter.value := 0;
+end;
14 metrics/gauge.dylan
@@ -0,0 +1,14 @@
+module: metrics
+synopsis:
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define class <gauge> (<metric>)
+ constant slot value-generator :: <function>,
+ required-init-keyword: generator:;
+end;
+
+define method gauge-value (gauge :: <gauge>)
+ => (value :: <integer>)
+ gauge.value-generator()
+end;
27 metrics/library.dylan
@@ -0,0 +1,27 @@
+module: dylan-user
+
+define library metrics
+ use dylan;
+
+ export metrics;
+end library;
+
+define module metrics
+ use dylan;
+ use threads;
+
+ export <clock>, clock-get-ticks,
+ $default-clock;
+
+ export <metric>;
+
+ export <gauge>, gauge-value;
+
+ export <counter>, counter-value,
+ counter-increment, counter-clear;
+
+ export <meter>, meter-mark,
+ meter-counter-value;
+
+ export <timer>;
+end module;
54 metrics/meter.dylan
@@ -0,0 +1,54 @@
+module: metrics
+synopsis:
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+// 5 seconds in nanoseconds.
+define constant $tick-interval = 5000000000;
+
+define class <meter> (<metric>)
+ constant slot meter-counter :: <counter> = make(<counter>);
+ constant slot meter-one-minute-moving-average = make(<moving-average>, minutes: 1);
+ constant slot meter-five-minute-moving-average = make(<moving-average>, minutes: 5);
+ constant slot meter-fifteen-minute-moving-average = make(<moving-average>, minutes: 15);
+ constant slot meter-clock = $default-clock,
+ init-keyword: clock:;
+ //***--- This last-tick should be atomic.
+ slot meter-last-tick :: <integer> = 0;
+end;
+
+define method meter-mark (meter :: <meter>, count :: <integer>)
+ => ()
+ meter-maybe-tick(meter);
+ counter-increment(meter.meter-counter, count);
+ moving-average-update(meter.meter-one-minute-moving-average, count);
+ moving-average-update(meter.meter-five-minute-moving-average, count);
+ moving-average-update(meter.meter-fifteen-minute-moving-average, count);
+end;
+
+define method meter-tick (meter :: <meter>)
+ => ()
+ moving-average-tick(meter.meter-one-minute-moving-average);
+ moving-average-tick(meter.meter-five-minute-moving-average);
+ moving-average-tick(meter.meter-fifteen-minute-moving-average);
+end;
+
+define method meter-maybe-tick (meter :: <meter>)
+ => ()
+ let old-tick = meter.meter-last-tick;
+ let new-tick = clock-get-ticks(meter.meter-clock);
+ let age = new-tick - old-tick;
+ //***--- meter-last-tick assignment to new-tick should be
+ //***--- conditional-update! inside the if test expression.
+ if (age > $tick-interval)
+ meter.meter-last-tick := new-tick;
+ let required-ticks = floor/(age, $tick-interval);
+ for (i from 0 below required-ticks)
+ meter-tick(meter);
+ end for;
+ end if;
+end;
+
+define method meter-counter-value (meter :: <meter>)
+ counter-value(meter.meter-counter)
+end;
7 metrics/metrics.dylan
@@ -0,0 +1,7 @@
+module: metrics
+synopsis:
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define class <metric> (<object>)
+end;
10 metrics/metrics.lid
@@ -0,0 +1,10 @@
+library: metrics
+target-type: dll
+files: library
+ metrics
+ moving-average
+ clock
+ counter
+ gauge
+ meter
+ timer
13 metrics/moving-average.dylan
@@ -0,0 +1,13 @@
+module: metrics
+synopsis:
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define class <moving-average> (<object>)
+end;
+
+define method moving-average-tick (moving-average :: <moving-average>)
+end;
+
+define method moving-average-update (moving-average :: <moving-average>, value :: <integer>)
+end;
13 metrics/tests/metrics-test-suite-app-library.dylan
@@ -0,0 +1,13 @@
+module: dylan-user
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define library metrics-test-suite-app
+ use testworks;
+ use metrics-test-suite;
+end library;
+
+define module metrics-test-suite-app
+ use testworks;
+ use metrics-test-suite;
+end module;
5 metrics/tests/metrics-test-suite-app.dylan
@@ -0,0 +1,5 @@
+module: metrics-test-suite-app
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+run-test-application(metrics-test-suite);
4 metrics/tests/metrics-test-suite-app.lid
@@ -0,0 +1,4 @@
+library: metrics-test-suite-app
+executable: metrics-test-suite-app
+files: metrics-test-suite-app-library
+ metrics-test-suite-app
21 metrics/tests/metrics-test-suite-library.dylan
@@ -0,0 +1,21 @@
+module: dylan-user
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define library metrics-test-suite
+ use common-dylan;
+ use io;
+ use metrics;
+ use testworks;
+
+ export metrics-test-suite;
+end library;
+
+define module metrics-test-suite
+ use common-dylan, exclude: { format-to-string };
+ use format;
+ use metrics;
+ use testworks;
+
+ export metrics-test-suite;
+end module;
38 metrics/tests/metrics-test-suite.dylan
@@ -0,0 +1,38 @@
+module: metrics-test-suite
+synopsis: Test suite for the nanomsg library.
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define suite metrics-test-suite ()
+ test counter-metrics-test;
+ test gauge-metrics-test;
+ test meter-metrics-test;
+end suite;
+
+define test counter-metrics-test ()
+ let counter = make(<counter>);
+ check-equal("counter starts at zero",
+ counter-value(counter), 0);
+ counter-increment(counter, 1);
+ check-equal("counter increments to one",
+ counter-value(counter), 1);
+ counter-clear(counter);
+ check-equal("counter clears to zero",
+ counter-value(counter), 0);
+end test counter-metrics-test;
+
+define test gauge-metrics-test ()
+ let g = method () 3 end;
+ let gauge = make(<gauge>, generator: g);
+ check-equal("gauge returns correct value",
+ gauge-value(gauge), 3);
+end test gauge-metrics-test;
+
+define test meter-metrics-test ()
+ let meter = make(<meter>);
+ check-equal("meter counter starts at zero",
+ meter-counter-value(meter), 0);
+ meter-mark(meter, 1);
+ check-equal("meter counter increments to one on mark",
+ meter-counter-value(meter), 1);
+end test meter-metrics-test;
4 metrics/tests/metrics-test-suite.lid
@@ -0,0 +1,4 @@
+library: metrics-test-suite
+files: metrics-test-suite-library
+ metrics-test-suite
+
7 metrics/timer.dylan
@@ -0,0 +1,7 @@
+module: metrics
+synopsis:
+author: Bruce Mitchener, Jr.
+copyright: See LICENSE file in this distribution.
+
+define class <timer> (<metric>)
+end;
1  registry/generic/metrics
@@ -0,0 +1 @@
+abstract://dylan/metrics/metrics.lid
1  registry/generic/metrics-test-suite
@@ -0,0 +1 @@
+abstract://dylan/metrics/tests/metrics-test-suite.lid
1  registry/generic/metrics-test-suite-app
@@ -0,0 +1 @@
+abstract://dylan/metrics/tests/metrics-test-suite-app.lid
Please sign in to comment.
Something went wrong with that request. Please try again.