Mercurial > hg > freeDiameter
diff extensions/test_cc/test_cc.c @ 1372:6b1a2405cebb
test_cc, loadtest_cc: write current statistics every second
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Wed, 12 Jun 2019 14:54:35 +0200 |
parents | 0d951a67648b |
children |
line wrap: on
line diff
--- a/extensions/test_cc/test_cc.c Mon Jun 10 16:56:40 2019 +0200 +++ b/extensions/test_cc/test_cc.c Wed Jun 12 14:54:35 2019 +0200 @@ -41,9 +41,25 @@ #define MODULE_NAME "test_cc" +struct statistics { + uint64_t sent; + time_t first; + time_t last; +} statistics; + +void print_statistics(void) { + if (statistics.first == 0 || statistics.last == 0 || statistics.last == statistics.first) { + return; + } + + fd_log_error("%s: %lld CCA messages sent in %llds (%.2f messages/second)", fd_g_config->cnf_diamid, + (long long)statistics.sent, (long long)(statistics.last-statistics.first), (float)statistics.sent / (statistics.last-statistics.first)); +} + static int ccr_handler(struct msg ** msg, struct avp * avp, struct session * sess, void * data, enum disp_action * act) { struct msg_hdr *hdr = NULL; + time_t now; TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act); @@ -133,6 +149,15 @@ /* Send the answer */ CHECK_FCT(fd_msg_send(msg, NULL, NULL)); + now = time(NULL); + if (!statistics.first) { + statistics.first = now; + } + if (statistics.last != now) { + print_statistics(); + } + statistics.last = now; + statistics.sent++; fd_log_debug("reply sent"); } else { /* We received an answer message, just discard it */ @@ -170,4 +195,19 @@ return 0; } +/* And terminate it */ +void fd_ext_fini(void) +{ + /* Unregister the callbacks */ + if (ccr_handler_hdl) { + CHECK_FCT_DO( fd_disp_unregister(&ccr_handler_hdl, NULL), ); + ccr_handler_hdl = NULL; + } + + print_statistics(); + + return; +} + + EXTENSION_ENTRY(MODULE_NAME, cc_entry);