Add stopwatch counters to track how long the main thread "run()"
function took for each of the types of statistics we track in
ovn-controller.

Today that is FDB and MAC_Binding stats:
  > ovn-appctl stopwatch/show stats_FDB
  Statistics for 'stats_FDB'
    Total samples: 13
    Maximum: 0 msec
    Minimum: 0 msec
    95th percentile: 0.000000 msec
    Short term average: 0.000000 msec
    Long term average: 0.000000 msec
  > ovn-appctl stopwatch/show stats_MAC_BINDING
  Statistics for 'stats_MAC_BINDING'
    Total samples: 19
    Maximum: 0 msec
    Minimum: 0 msec
    95th percentile: 0.000000 msec
    Short term average: 0.000000 msec
    Long term average: 0.000000 msec

Signed-off-by: Dumitru Ceara <[email protected]>
---
 controller/statctrl.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/controller/statctrl.c b/controller/statctrl.c
index d3c70ccba4..d555de36d0 100644
--- a/controller/statctrl.c
+++ b/controller/statctrl.c
@@ -33,6 +33,7 @@
 #include "seq.h"
 #include "socket-util.h"
 #include "statctrl.h"
+#include "stopwatch.h"
 
 VLOG_DEFINE_THIS_MODULE(statctrl);
 
@@ -63,21 +64,27 @@ struct stats_node {
     /* Function to process the parsed stats.
      * This function runs in main thread locked behind mutex. */
     void (*run)(struct ovs_list *stats_list, uint64_t *req_delay, void *data);
+    /* Name of the stats node corresponding stopwatch. */
+    const char *stopwatch_name;
 };
 
 #define STATS_NODE(NAME, REQUEST, DESTROY, PROCESS, RUN)                   \
-    statctrl_ctx.nodes[STATS_##NAME] = (struct stats_node) {               \
-        .request = REQUEST,                                                \
-        .xid = 0,                                                          \
-        .next_request_timestamp = INT64_MAX,                               \
-        .request_delay = 0,                                                \
-        .stats_list =                                                      \
-            OVS_LIST_INITIALIZER(                                          \
-                &statctrl_ctx.nodes[STATS_##NAME].stats_list),             \
-        .destroy = DESTROY,                                                \
-        .process_flow_stats = PROCESS,                                     \
-        .run = RUN                                                         \
-    };
+    do {                                                                   \
+        statctrl_ctx.nodes[STATS_##NAME] = (struct stats_node) {           \
+            .request = REQUEST,                                            \
+            .xid = 0,                                                      \
+            .next_request_timestamp = INT64_MAX,                           \
+            .request_delay = 0,                                            \
+            .stats_list =                                                  \
+                OVS_LIST_INITIALIZER(                                      \
+                    &statctrl_ctx.nodes[STATS_##NAME].stats_list),         \
+            .destroy = DESTROY,                                            \
+            .process_flow_stats = PROCESS,                                 \
+            .run = RUN,                                                    \
+            .stopwatch_name = OVS_STRINGIZE(stats_##NAME),                 \
+        };                                                                 \
+        stopwatch_create(OVS_STRINGIZE(stats_##NAME), SW_MS);              \
+    } while (0)
 
 struct statctrl_ctx {
     /* OpenFlow connection to the switch. */
@@ -168,7 +175,9 @@ statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn,
         struct stats_node *node = &statctrl_ctx.nodes[i];
         uint64_t prev_delay = node->request_delay;
 
+        stopwatch_start(node->stopwatch_name, time_msec());
         node->run(&node->stats_list, &node->request_delay, node_data[i]);
+        stopwatch_stop(node->stopwatch_name, time_msec());
 
         schedule_updated |=
                 statctrl_update_next_request_timestamp(node, now, prev_delay);
-- 
2.48.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to