changeset 1381:f374d3f8f7d3

test_ccload: add statistics for received messages
author Thomas Klausner <tk@giga.or.at>
date Wed, 26 Jun 2019 18:11:36 +0200
parents 1fe534395b05
children f62e18dc4800
files extensions/test_ccload/test_ccload.c
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/test_ccload/test_ccload.c	Wed Jun 26 16:33:45 2019 +0200
+++ b/extensions/test_ccload/test_ccload.c	Wed Jun 26 18:11:36 2019 +0200
@@ -66,21 +66,25 @@
 	uint64_t success;
 	uint64_t error;
 	time_t first;
+	time_t first_reply;
 	time_t last;
+	time_t last_reply;
 } statistics;
 
 void print_statistics(void) {
-	uint64_t missing;
+	uint64_t missing, received;
 
 	if (statistics.first == 0 || statistics.last == 0 || statistics.last == statistics.first) {
 		return;
 	}
 
-	missing = statistics.sent - statistics.error - statistics.success;
+	received = statistics.error + statistics.success;
+	missing = statistics.sent - received;
 
-	fd_log_error("%s: %lld CCR messages sent in %llds (%.2f messages/second), %lld success (%.2f%%), %lld errors (%.2f%%), %lld missing (%.2f%%)",
+	fd_log_error("%s: %lld CCR messages sent in %llds (%.2f messages/second), %lld CCA messages received in %llds (%.2f messages/second), %lld success (%.2f%%), %lld errors (%.2f%%), %lld missing (%.2f%%)",
 		     fd_g_config->cnf_diamid,
 		     (long long)statistics.sent, (long long)(statistics.last-statistics.first), (float)statistics.sent / (statistics.last-statistics.first),
+		     (long long)received, (long long)(statistics.last_reply-statistics.first_reply), (float)received / (statistics.last_reply-statistics.first_reply),
 		     (long long)statistics.success,
 		     100*(float)statistics.success/statistics.sent, (long long)statistics.error, 100*(float)statistics.error/statistics.sent,
 		     missing, 100*(float)missing/statistics.sent);
@@ -103,6 +107,9 @@
 		return -1;
 	}
 
+	if (statistics.first_reply == 0) {
+		statistics.first_reply = time(NULL);
+	}
 	/* Answer received, check it */
 	if (fd_msg_search_avp(*msg, rc_avp_do, &rc) < 0 || rc == NULL) {
 		fd_log_error("[%s] Result-Code not found in CCA", MODULE_NAME);
@@ -113,6 +120,7 @@
 		fd_log_error("[%s] error parsing Result-Code in CCA", MODULE_NAME);
 		return -1;
 	}
+	statistics.last_reply = time(NULL);
 	fd_log_debug("Credit-Control-Answer with Result-Code %d received", ahdr->avp_value->i32);
 	switch (ahdr->avp_value->i32/1000) {
 	case 2:
@@ -122,6 +130,9 @@
 		statistics.error++;
 		break;
 	}
+	if (statistics.sent - statistics.error - statistics.success == 0) {
+		print_statistics();
+	}
 
 	return 0;
 }
"Welcome to our mercurial repository"