Navigation


Changeset 1372:6b1a2405cebb in freeDiameter for extensions/test_cc/test_cc.c


Ignore:
Timestamp:
Jun 12, 2019, 9:54:35 PM (5 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

test_cc, loadtest_cc: write current statistics every second

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/test_cc/test_cc.c

    r1365 r1372  
    4242#define MODULE_NAME "test_cc"
    4343
     44struct statistics {
     45        uint64_t sent;
     46        time_t first;
     47        time_t last;
     48} statistics;
     49
     50void print_statistics(void) {
     51        if (statistics.first == 0 || statistics.last == 0 || statistics.last == statistics.first) {
     52                return;
     53        }
     54
     55        fd_log_error("%s: %lld CCA messages sent in %llds (%.2f messages/second)", fd_g_config->cnf_diamid,
     56                     (long long)statistics.sent, (long long)(statistics.last-statistics.first), (float)statistics.sent / (statistics.last-statistics.first));
     57}
     58
    4459static int ccr_handler(struct msg ** msg, struct avp * avp, struct session * sess, void * data, enum disp_action * act)
    4560{
    4661        struct msg_hdr *hdr = NULL;
     62        time_t now;
    4763
    4864        TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
     
    134150                /* Send the answer */
    135151                CHECK_FCT(fd_msg_send(msg, NULL, NULL));
     152                now = time(NULL);
     153                if (!statistics.first) {
     154                        statistics.first = now;
     155                }
     156                if (statistics.last != now) {
     157                        print_statistics();
     158                }
     159                statistics.last = now;
     160                statistics.sent++;
    136161                fd_log_debug("reply sent");
    137162        } else {
     
    171196}
    172197
     198/* And terminate it */
     199void fd_ext_fini(void)
     200{
     201        /* Unregister the callbacks */
     202        if (ccr_handler_hdl) {
     203                CHECK_FCT_DO( fd_disp_unregister(&ccr_handler_hdl, NULL), );
     204                ccr_handler_hdl = NULL;
     205        }
     206
     207        print_statistics();
     208
     209        return;
     210}
     211
     212
    173213EXTENSION_ENTRY(MODULE_NAME, cc_entry);
Note: See TracChangeset for help on using the changeset viewer.