summaryrefslogtreecommitdiffstats
path: root/nserver/src/protocol.c
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2019-11-02 10:41:52 -0400
committerrsiddharth <s@ricketyspace.net>2020-04-17 20:56:34 -0400
commit71768c6233d8249425e2a3ae34993be84f245e0a (patch)
treed41aa2752b0e230114cf1ad98d4185c0c23a9d7d /nserver/src/protocol.c
parent2811735e12d0352e93120bee6be9e114bc474830 (diff)
nserver: protocol: Define sssample.
* nserver/src/protocol.c (sssample): New function. * nserver/tests/protocol_tests.c (test_sssample): New test. (all_tests): Add test_sssample.
Diffstat (limited to 'nserver/src/protocol.c')
-rw-r--r--nserver/src/protocol.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c
index 6963116..a174caf 100644
--- a/nserver/src/protocol.c
+++ b/nserver/src/protocol.c
@@ -36,3 +36,24 @@ int sscreate(char *key)
error:
return -1;
}
+
+int sssample(char *key, double s)
+{
+ check(hash != NULL, "hash not initialized");
+
+ // 1. create bstring from 'key'.
+ bstring k = bfromcstr(key);
+ check(k != NULL, "key creation failed");
+
+ // 2. try to get Stats for key.
+ Stats *st = (Stats *) Hashmap_get(hash, k);
+ check(st != NULL, "stats not found for key");
+
+ // 3. sample!
+ Stats_sample(st, s);
+
+ return 0;
+ error:
+ return -1;
+}
+