ovsdb-monitor: rename jsonrpc_monitor_compose_table_update()
[cascardo/ovs.git] / ovsdb / ovsdb-server.c
index 13dfa68..cd13b0d 100644 (file)
@@ -26,7 +26,6 @@
 #include "command-line.h"
 #include "daemon.h"
 #include "dirs.h"
-#include "dummy.h"
 #include "dynamic-string.h"
 #include "fatal-signal.h"
 #include "file.h"
@@ -54,7 +53,8 @@
 #include "trigger.h"
 #include "util.h"
 #include "unixctl.h"
-#include "vlog.h"
+#include "perf-counter.h"
+#include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(ovsdb_server);
 
@@ -77,6 +77,8 @@ static bool bootstrap_ca_cert;
 static unixctl_cb_func ovsdb_server_exit;
 static unixctl_cb_func ovsdb_server_compact;
 static unixctl_cb_func ovsdb_server_reconnect;
+static unixctl_cb_func ovsdb_server_perf_counters_clear;
+static unixctl_cb_func ovsdb_server_perf_counters_show;
 
 struct server_config {
     struct sset *remotes;
@@ -98,7 +100,7 @@ static void close_db(struct db *db);
 static void parse_options(int *argc, char **argvp[],
                           struct sset *remotes, char **unixctl_pathp,
                           char **run_command);
-static void usage(void) NO_RETURN;
+OVS_NO_RETURN static void usage(void);
 
 static char *reconfigure_remotes(struct ovsdb_jsonrpc_server *,
                                  const struct shash *all_dbs,
@@ -212,7 +214,7 @@ main(int argc, char *argv[])
     char *error;
     int i;
 
-    proctitle_init(argc, argv);
+    ovs_cmdl_proctitle_init(argc, argv);
     set_program_name(argv[0]);
     service_start(&argc, &argv);
     fatal_ignore_sigpipe();
@@ -293,6 +295,8 @@ main(int argc, char *argv[])
 
     daemonize_complete();
 
+    perf_counters_init();
+
     if (!run_command) {
         /* ovsdb-server is usually a long-running process, in which case it
          * makes plenty of sense to log the version, but --run makes
@@ -319,6 +323,10 @@ main(int argc, char *argv[])
                              ovsdb_server_remove_database, &server_config);
     unixctl_command_register("ovsdb-server/list-dbs", "", 0, 0,
                              ovsdb_server_list_databases, &all_dbs);
+    unixctl_command_register("ovsdb-server/perf-counters-show", "", 0, 0,
+                             ovsdb_server_perf_counters_show, NULL);
+    unixctl_command_register("ovsdb-server/perf-counters-clear", "", 0, 0,
+                             ovsdb_server_perf_counters_clear, NULL);
 
     main_loop(jsonrpc, &all_dbs, unixctl, &remotes, run_process, &exiting);
 
@@ -339,7 +347,7 @@ main(int argc, char *argv[])
                       run_command, process_status_msg(status));
         }
     }
-
+    perf_counters_destroy();
     service_stop();
     return 0;
 }
@@ -429,7 +437,7 @@ find_db(const struct shash *all_dbs, const char *db_name)
     return NULL;
 }
 
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
 parse_db_column__(const struct shash *all_dbs,
                   const char *name_, char *name,
                   const struct db **dbp,
@@ -483,7 +491,7 @@ parse_db_column__(const struct shash *all_dbs,
 
 /* Returns NULL if successful, otherwise a malloc()'d string describing the
  * error. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
 parse_db_column(const struct shash *all_dbs,
                 const char *name_,
                 const struct db **dbp,
@@ -499,7 +507,7 @@ parse_db_column(const struct shash *all_dbs,
 
 /* Returns NULL if successful, otherwise a malloc()'d string describing the
  * error. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
 parse_db_string_column(const struct shash *all_dbs,
                        const char *name,
                        const struct db **dbp,
@@ -540,6 +548,7 @@ query_db_string(const struct shash *all_dbs, const char *name,
                                         &db, &table, &column);
         if (retval) {
             ds_put_format(errors, "%s\n", retval);
+            free(retval);
             return NULL;
         }
 
@@ -1021,6 +1030,26 @@ ovsdb_server_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
     unixctl_command_reply(conn, NULL);
 }
 
+static void
+ovsdb_server_perf_counters_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                                const char *argv[] OVS_UNUSED,
+                                void *arg_ OVS_UNUSED)
+{
+    char *s = perf_counters_to_string();
+
+    unixctl_command_reply(conn, s);
+    free(s);
+}
+
+static void
+ovsdb_server_perf_counters_clear(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                                 const char *argv[] OVS_UNUSED,
+                                 void *arg_ OVS_UNUSED)
+{
+    perf_counters_clear();
+    unixctl_command_reply(conn, NULL);
+}
+
 static void
 ovsdb_server_compact(struct unixctl_conn *conn, int argc,
                      const char *argv[], void *dbs_)
@@ -1223,7 +1252,6 @@ parse_options(int *argcp, char **argvp[],
         OPT_UNIXCTL,
         OPT_RUN,
         OPT_BOOTSTRAP_CA_CERT,
-        OPT_ENABLE_DUMMY,
         VLOG_OPTION_ENUMS,
         DAEMON_OPTION_ENUMS
     };
@@ -1241,10 +1269,9 @@ parse_options(int *argcp, char **argvp[],
         {"private-key", required_argument, NULL, 'p'},
         {"certificate", required_argument, NULL, 'c'},
         {"ca-cert",     required_argument, NULL, 'C'},
-        {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
         {NULL, 0, NULL, 0},
     };
-    char *short_options = long_options_to_short_options(long_options);
+    char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
     int argc = *argcp;
     char **argv = *argvp;
 
@@ -1298,10 +1325,6 @@ parse_options(int *argcp, char **argvp[],
             bootstrap_ca_cert = true;
             break;
 
-        case OPT_ENABLE_DUMMY:
-            dummy_enable(optarg && !strcmp(optarg, "override"));
-            break;
-
         case '?':
             exit(EXIT_FAILURE);