diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-08-22 08:56:53 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-09-03 22:57:23 -0400 |
| commit | d83b96faeb02d7a3574e63880141d6b23f31ced1 (patch) | |
| tree | b6cd2feca3513dccba012b9da2ac230e94d09ac0 /tests/stats.c | |
| parent | 1b2a93503e0ed108f7c4add4bcf4b201a363bb80 (diff) | |
| download | nng-d83b96faeb02d7a3574e63880141d6b23f31ced1.tar.gz nng-d83b96faeb02d7a3574e63880141d6b23f31ced1.tar.bz2 nng-d83b96faeb02d7a3574e63880141d6b23f31ced1.zip | |
fixes #4 Statistics support
This introduces new public APIs for obtaining statistics,
and adds some generic stats for dialers, listeners, pipes, and
sockets. Also added are stats for inproc and pairv1 protocol.
The other protocols and transports will have stats added
incrementally as time goes on.
A simple test program, and man pages are provided for this.
Start by looking at nng_stat(5).
Statistics does have some impact, and they can be disabled by
using the advanced NNG_ENABLE_STATS (setting it to OFF, it's
ON by default) if you need to build a minimized configuration.
Diffstat (limited to 'tests/stats.c')
| -rw-r--r-- | tests/stats.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/stats.c b/tests/stats.c new file mode 100644 index 00000000..b8ca8da8 --- /dev/null +++ b/tests/stats.c @@ -0,0 +1,78 @@ +// +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#include "convey.h" +#include "nng.h" +#include "trantest.h" + +#include "protocol/pubsub0/sub.h" + +#include "protocol/pair1/pair.h" + +#include "supplemental/util/platform.h" + +#include "stubs.h" + +#include <string.h> + +#define SECONDS(x) ((x) *1000) + +TestMain("Stats Test", { + atexit(nng_fini); + + Convey("We are able to open a PAIR socket", { + nng_socket s1; + + So(nng_pair_open(&s1) == 0); + + Reset({ nng_close(s1); }); + + Convey("We can send and receive messages", { + nng_socket s2; + int len; + size_t sz; + nng_duration to = SECONDS(3); + char * buf; + char * a = "inproc://stats"; + nng_stat * stats; + + So(nng_pair_open(&s2) == 0); + Reset({ nng_close(s2); }); + + So(nng_setopt_int(s1, NNG_OPT_RECVBUF, 1) == 0); + So(nng_getopt_int(s1, NNG_OPT_RECVBUF, &len) == 0); + So(len == 1); + + So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 1) == 0); + So(nng_setopt_int(s2, NNG_OPT_SENDBUF, 1) == 0); + + So(nng_setopt_ms(s1, NNG_OPT_SENDTIMEO, to) == 0); + So(nng_setopt_ms(s1, NNG_OPT_RECVTIMEO, to) == 0); + So(nng_setopt_ms(s2, NNG_OPT_SENDTIMEO, to) == 0); + So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, to) == 0); + + So(nng_listen(s1, a, NULL, 0) == 0); + So(nng_dial(s2, a, NULL, 0) == 0); + + So(nng_send(s1, "abc", 4, 0) == 0); + So(nng_recv(s2, &buf, &sz, NNG_FLAG_ALLOC) == 0); + So(buf != NULL); + So(sz == 4); + So(memcmp(buf, "abc", 4) == 0); + nng_free(buf, sz); + + Convey("We can collect stats", { + So(nng_stats_get(&stats) == 0); + nng_stats_dump(stats); + nng_stats_free(stats); + }); + }); + }); +}) |
