From 11918e809c64ed91a61b7a3d0069b99968df88a2 Mon Sep 17 00:00:00 2001
From: Florian Pose <fp@igh-essen.com>
Date: Thu, 3 Aug 2006 20:11:20 +0000
Subject: [PATCH] New statistic outputs to avoid blasting the logs.

---
 master/domain.c | 21 +++++++++++++++++++--
 master/domain.h |  3 +++
 master/master.c | 11 ++++++++---
 master/master.h |  5 ++++-
 4 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/master/domain.c b/master/domain.c
index 4126f077..a5e88d76 100644
--- a/master/domain.c
+++ b/master/domain.c
@@ -106,6 +106,8 @@ int ec_domain_init(ec_domain_t *domain, /**< EtherCAT domain */
     domain->data_size = 0;
     domain->base_address = 0;
     domain->response_count = 0xFFFFFFFF;
+    domain->t_last = 0;
+    domain->working_counter_changes = 0;
 
     INIT_LIST_HEAD(&domain->data_regs);
     INIT_LIST_HEAD(&domain->datagrams);
@@ -511,6 +513,7 @@ void ecrt_domain_process(ec_domain_t *domain /**< EtherCAT domain */)
 {
     unsigned int working_counter_sum;
     ec_datagram_t *datagram;
+    cycles_t t_now = get_cycles();
 
     working_counter_sum = 0;
     list_for_each_entry(datagram, &domain->datagrams, list) {
@@ -520,9 +523,23 @@ void ecrt_domain_process(ec_domain_t *domain /**< EtherCAT domain */)
     }
 
     if (working_counter_sum != domain->response_count) {
+        domain->working_counter_changes++;
         domain->response_count = working_counter_sum;
-        EC_INFO("Domain %i working counter change: %i\n", domain->index,
-                domain->response_count);
+    }
+
+    if (domain->working_counter_changes &&
+        (u32) (t_now - domain->t_last) / cpu_khz > 1000) {
+        domain->t_last = t_now;
+        if (domain->working_counter_changes == 1) {
+            EC_INFO("Domain %i working counter change: %i\n", domain->index,
+                    domain->response_count);
+        }
+        else {
+            EC_INFO("Domain %i: %u WC changes. Current response count: %i\n",
+                    domain->index, domain->working_counter_changes,
+                    domain->response_count);
+        }
+        domain->working_counter_changes = 0;
     }
 
     ec_domain_queue(domain);
diff --git a/master/domain.h b/master/domain.h
index 05fe5278..e8876313 100644
--- a/master/domain.h
+++ b/master/domain.h
@@ -67,6 +67,9 @@ struct ec_domain
     uint32_t base_address; /**< logical offset address of the process data */
     unsigned int response_count; /**< number of responding slaves */
     struct list_head data_regs; /**< PDO data registrations */
+    unsigned int working_counter_changes; /**< working counter changes
+                                             since last notification */
+    cycles_t t_last; /**< time of last notification */
 };
 
 /*****************************************************************************/
diff --git a/master/master.c b/master/master.c
index a2e0b33a..52e16b25 100644
--- a/master/master.c
+++ b/master/master.c
@@ -240,6 +240,7 @@ void ec_master_reset(ec_master_t *master /**< EtherCAT master */)
     master->stats.timeouts = 0;
     master->stats.delayed = 0;
     master->stats.corrupted = 0;
+    master->stats.skipped = 0;
     master->stats.unmatched = 0;
     master->stats.t_last = 0;
 
@@ -287,9 +288,9 @@ void ec_master_queue_datagram(ec_master_t *master, /**< EtherCAT master */
     // check, if the datagram is already queued
     list_for_each_entry(queued_datagram, &master->datagram_queue, queue) {
         if (queued_datagram == datagram) {
+            master->stats.skipped++;
+            ec_master_output_stats(master);
             datagram->state = EC_DATAGRAM_QUEUED;
-            if (unlikely(master->debug_level))
-                EC_WARN("datagram already queued.\n");
             return;
         }
     }
@@ -538,6 +539,10 @@ void ec_master_output_stats(ec_master_t *master /**< EtherCAT master */)
             EC_WARN("%i frame(s) CORRUPTED!\n", master->stats.corrupted);
             master->stats.corrupted = 0;
         }
+        if (master->stats.skipped) {
+            EC_WARN("%i datagram(s) SKIPPED!\n", master->stats.skipped);
+            master->stats.skipped = 0;
+        }
         if (master->stats.unmatched) {
             EC_WARN("%i datagram(s) UNMATCHED!\n", master->stats.unmatched);
             master->stats.unmatched = 0;
@@ -1234,7 +1239,7 @@ void ecrt_master_receive(ec_master_t *master /**< EtherCAT master */)
     ec_device_call_isr(master->device);
 
     t_received = get_cycles();
-    t_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000);
+    t_timeout = EC_IO_TIMEOUT * cpu_khz / 1000;
 
     // dequeue all received datagrams
     list_for_each_entry_safe(datagram, next, &master->datagram_queue, queue)
diff --git a/master/master.h b/master/master.h
index 288665a7..ab6fce20 100644
--- a/master/master.h
+++ b/master/master.h
@@ -74,7 +74,10 @@ typedef struct
     unsigned int timeouts; /**< datagram timeouts */
     unsigned int delayed; /**< delayed datagrams */
     unsigned int corrupted; /**< corrupted frames */
-    unsigned int unmatched; /**< unmatched datagrams */
+    unsigned int skipped; /**< skipped datagrams (the ones that were
+                             requeued when not yet received) */
+    unsigned int unmatched; /**< unmatched datagrams (received, but not
+                               queued any longer) */
     cycles_t t_last; /**< time of last output */
 }
 ec_stats_t;
-- 
GitLab