]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add both sdev and mdev, it was so confused most time
authorSeven Du <dujinfang@gmail.com>
Thu, 26 Sep 2013 23:38:32 +0000 (07:38 +0800)
committerSeven Du <dujinfang@gmail.com>
Thu, 26 Sep 2013 23:38:32 +0000 (07:38 +0800)
ref: http://www.plug.org/pipermail/plug/2005-June/002144.html

src/mod/applications/mod_sonar/mod_sonar.c

index 183a9884d1fa2af7dec8f1d97d023fe47aae3e41..446319b2a8a5795488f5f5f74a584c69e963ed4a 100644 (file)
@@ -103,7 +103,7 @@ SWITCH_STANDARD_APP(sonar_app)
        int loops;
        int lost = 0;
        int x;
-       int avg = 0, mdev = 0;
+       int avg = 0, sdev = 0, mdev = 0;
        int sum2;
        switch_event_t *event;
        sonar_ping_helper_t ph = { 0 };
@@ -157,18 +157,28 @@ SWITCH_STANDARD_APP(sonar_app)
 
        if (ph.received > 0) avg = ph.sum / ph.received;
 
+       sum2 = 0;
+       for(x = 0; x < ph.received; x++) {
+               sum2 += abs(ph.samples[x] - avg);
+       }
+
+       if (ph.received > 0) {
+               mdev = sum2 / ph.received;
+       }
+
+
        sum2 = 0;
        for(x = 0; x < ph.received; x++) {
                sum2 += (ph.samples[x] - avg) * (ph.samples[x] - avg);
        }
 
        if (ph.received > 1) {
-               mdev = sqrt(sum2 / (ph.received - 1));
+               sdev = sqrt(sum2 / (ph.received - 1));
        }
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
-               "Sonar Ping (in ms): min:%d max:%d avg:%d mdev:%d sent:%d recv: %d lost:%d lost/send:%2.2f%%\n",
-               ph.min, ph.max, avg, mdev, loops, ph.received, lost, lost * 1.0 / loops);
+               "Sonar Ping (in ms): min:%d max:%d avg:%d sdev:%d mdev:%d sent:%d recv: %d lost:%d lost/send:%2.2f%%\n",
+               ph.min, ph.max, avg, sdev, mdev, loops, ph.received, lost, lost * 1.0 / loops);
 
        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "sonar::ping") == SWITCH_STATUS_SUCCESS) {
                const char *verbose_event;
@@ -176,6 +186,7 @@ SWITCH_STANDARD_APP(sonar_app)
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_min", "%d", ph.min);
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_max", "%d", ph.max);
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_avg", "%d", avg);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_sdev", "%d", sdev);
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_mdev", "%d", mdev);
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_sent", "%d", loops);
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_recv", "%d", ph.received);