diff mbox series

[ovs-dev,v2,2/3] ovn-northd: Add useful stopwatches

Message ID 20210617174253.3459548-3-mark.d.gray@redhat.com
State Superseded, archived
Headers show
Series tests: Add check-perf target | expand

Commit Message

Mark Gray June 17, 2021, 5:42 p.m. UTC
For performance measurement, it is useful to understand the
length of time required to complete a number of key code paths
in ovn-northd.c. Add stopwatches to measure these timings.

Signed-off-by: Mark Gray <mark.d.gray@redhat.com>
---
 northd/ovn-northd-ddlog.c | 15 +++++++++++++++
 northd/ovn-northd.c       | 20 ++++++++++++++++++++
 2 files changed, 35 insertions(+)
diff mbox series

Patch

diff --git a/northd/ovn-northd-ddlog.c b/northd/ovn-northd-ddlog.c
index a4f2960bdcb8..7c552d516550 100644
--- a/northd/ovn-northd-ddlog.c
+++ b/northd/ovn-northd-ddlog.c
@@ -37,6 +37,7 @@ 
 #include "ovsdb-parser.h"
 #include "ovsdb-types.h"
 #include "simap.h"
+#include "stopwatch.h"
 #include "stream-ssl.h"
 #include "stream.h"
 #include "unixctl.h"
@@ -50,6 +51,10 @@  VLOG_DEFINE_THIS_MODULE(ovn_northd);
 #include "northd/ovn-northd-ddlog-nb.inc"
 #include "northd/ovn-northd-ddlog-sb.inc"
 
+#define NORTHD_LOOP_STOPWATCH_NAME "ovn-northd-loop"
+#define OVNNB_DB_RUN_STOPWATCH_NAME "ovnnb_db_run"
+#define OVNSB_DB_RUN_STOPWATCH_NAME "ovnsb_db_run"
+
 struct northd_status {
     bool locked;
     bool pause;
@@ -1259,6 +1264,10 @@  main(int argc, char *argv[])
 
     daemonize_complete();
 
+    stopwatch_create(NORTHD_LOOP_STOPWATCH_NAME, SW_MS);
+    stopwatch_create(OVNNB_DB_RUN_STOPWATCH_NAME, SW_MS);
+    stopwatch_create(OVNSB_DB_RUN_STOPWATCH_NAME, SW_MS);
+
     /* Main loop. */
     exiting = false;
     while (!exiting) {
@@ -1285,8 +1294,12 @@  main(int argc, char *argv[])
         status.locked = has_lock;
         status.pause = sb_ctx->paused;
 
+        stopwatch_start(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec());
         northd_run(nb_ctx);
+        stopwatch_stop(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec());
+        stopwatch_start(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec());
         northd_run(sb_ctx);
+        stopwatch_stop(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec());
         northd_update_probe_interval(nb_ctx, sb_ctx);
         if (ovsdb_cs_has_lock(sb_ctx->cs) &&
             sb_ctx->state == S_UPDATE &&
@@ -1297,6 +1310,8 @@  main(int argc, char *argv[])
             northd_send_deltas(sb_ctx);
         }
 
+        stopwatch_stop(NORTHD_LOOP_STOPWATCH_NAME, time_msec());
+        stopwatch_start(NORTHD_LOOP_STOPWATCH_NAME, time_msec());
         unixctl_server_run(unixctl);
 
         northd_wait(nb_ctx);
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index d872f6a3cc1d..bffa18de5c2d 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -49,6 +49,7 @@ 
 #include "smap.h"
 #include "sset.h"
 #include "svec.h"
+#include "stopwatch.h"
 #include "stream.h"
 #include "stream-ssl.h"
 #include "timeval.h"
@@ -59,6 +60,10 @@ 
 
 VLOG_DEFINE_THIS_MODULE(ovn_northd);
 
+#define NORTHD_LOOP_STOPWATCH_NAME "ovn-northd-loop"
+#define OVNNB_DB_RUN_STOPWATCH_NAME "ovnnb_db_run"
+#define OVNSB_DB_RUN_STOPWATCH_NAME "ovnsb_db_run"
+
 static unixctl_cb_func ovn_northd_exit;
 static unixctl_cb_func ovn_northd_pause;
 static unixctl_cb_func ovn_northd_resume;
@@ -13238,6 +13243,9 @@  ovnnb_db_run(struct northd_context *ctx,
     if (!ctx->ovnsb_txn || !ctx->ovnnb_txn) {
         return;
     }
+
+    stopwatch_start(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec());
+
     struct hmap port_groups;
     struct hmap mcast_groups;
     struct hmap igmp_groups;
@@ -13379,6 +13387,8 @@  ovnnb_db_run(struct northd_context *ctx,
      * as well.
      */
     cleanup_macam();
+
+    stopwatch_stop(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec());
 }
 
 /* Stores the list of chassis which references an ha_chassis_group.
@@ -13970,6 +13980,8 @@  ovnsb_db_run(struct northd_context *ctx,
         return;
     }
 
+    stopwatch_start(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec());
+
     struct shash ha_ref_chassis_map = SHASH_INITIALIZER(&ha_ref_chassis_map);
     handle_port_binding_changes(ctx, ports, &ha_ref_chassis_map);
     update_northbound_cfg(ctx, sb_loop, loop_start_time);
@@ -13977,6 +13989,8 @@  ovnsb_db_run(struct northd_context *ctx,
         update_sb_ha_group_ref_chassis(&ha_ref_chassis_map);
     }
     shash_destroy(&ha_ref_chassis_map);
+
+    stopwatch_stop(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec());
 }
 
 static void
@@ -14425,6 +14439,10 @@  main(int argc, char *argv[])
     char *ovn_internal_version = ovn_get_internal_version();
     VLOG_INFO("OVN internal version is : [%s]", ovn_internal_version);
 
+    stopwatch_create(NORTHD_LOOP_STOPWATCH_NAME, SW_MS);
+    stopwatch_create(OVNNB_DB_RUN_STOPWATCH_NAME, SW_MS);
+    stopwatch_create(OVNSB_DB_RUN_STOPWATCH_NAME, SW_MS);
+
     /* Main loop. */
     exiting = false;
 
@@ -14508,6 +14526,8 @@  main(int argc, char *argv[])
             ovsdb_idl_wait(ovnsb_idl_loop.idl);
         }
 
+        stopwatch_stop(NORTHD_LOOP_STOPWATCH_NAME, time_msec());
+        stopwatch_start(NORTHD_LOOP_STOPWATCH_NAME, time_msec());
         unixctl_server_run(unixctl);
         unixctl_server_wait(unixctl);
         memory_wait();