[ovs-dev] [PATCH ovn v5 1/2] ovn-northd: Add useful stopwatches

Mark Gray mark.d.gray at redhat.com
Wed Jun 30 13:15:01 UTC 2021


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 at redhat.com>
Acked-by: Dumitru Ceara <dceara at redhat.com>
---

Notes:
    v4:  Add common header file for stopwatch names
    v5:  Forgot to `git add` a new file. Added this file.

 lib/automake.mk           |  3 ++-
 lib/stopwatch-names.h     | 25 +++++++++++++++++++++++++
 northd/ovn-northd-ddlog.c | 12 ++++++++++++
 northd/ovn-northd.c       | 17 +++++++++++++++++
 4 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 lib/stopwatch-names.h

diff --git a/lib/automake.mk b/lib/automake.mk
index 917b28e1edf7..f668b791bb81 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -29,7 +29,8 @@ lib_libovn_la_SOURCES = \
 	lib/inc-proc-eng.c \
 	lib/inc-proc-eng.h \
 	lib/lb.c \
-	lib/lb.h
+	lib/lb.h \
+	lib/stopwatch-names.h
 nodist_lib_libovn_la_SOURCES = \
 	lib/ovn-dirs.c \
 	lib/ovn-nb-idl.c \
diff --git a/lib/stopwatch-names.h b/lib/stopwatch-names.h
new file mode 100644
index 000000000000..06b20272e8cf
--- /dev/null
+++ b/lib/stopwatch-names.h
@@ -0,0 +1,25 @@
+/* Copyright (c) 2021 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef STOPWATCH_NAMES_H
+#define STOPWATCH_NAMES_H 1
+
+/* In order to not duplicate names for stopwatches between ddlog and non-ddlog
+ * we define them in a common header file.
+ */
+#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"
+
+#endif
\ No newline at end of file
diff --git a/northd/ovn-northd-ddlog.c b/northd/ovn-northd-ddlog.c
index bc2c75f51bb0..a02949b2d1b7 100644
--- a/northd/ovn-northd-ddlog.c
+++ b/northd/ovn-northd-ddlog.c
@@ -38,6 +38,8 @@
 #include "ovsdb-parser.h"
 #include "ovsdb-types.h"
 #include "simap.h"
+#include "stopwatch.h"
+#include "lib/stopwatch-names.h"
 #include "stream-ssl.h"
 #include "stream.h"
 #include "unixctl.h"
@@ -1267,6 +1269,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) {
@@ -1293,8 +1299,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 &&
@@ -1305,6 +1315,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 e96494ba3c7a..2149c8f60459 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -50,6 +50,8 @@
 #include "smap.h"
 #include "sset.h"
 #include "svec.h"
+#include "stopwatch.h"
+#include "lib/stopwatch-names.h"
 #include "stream.h"
 #include "stream-ssl.h"
 #include "timeval.h"
@@ -13261,6 +13263,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;
@@ -13404,6 +13409,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.
@@ -13996,6 +14003,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);
@@ -14003,6 +14012,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
@@ -14457,6 +14468,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;
 
@@ -14540,6 +14555,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();
-- 
2.27.0



More information about the dev mailing list