]> git.proxmox.com Git - mirror_corosync.git/commitdiff
cmapctl: Add option to clear the stats
authorChristine Caulfield <ccaulfie@redhat.com>
Thu, 2 Nov 2017 16:01:36 +0000 (16:01 +0000)
committerJan Friesse <jfriesse@redhat.com>
Fri, 3 Nov 2017 12:41:16 +0000 (13:41 +0100)
Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
man/corosync-cmapctl.8
tools/corosync-cmapctl.c

index a7d967ab51b8b9660872c4825658ebaf9d94fee1..a19eb492e05a725beb255f174ebb0d4df5850791 100644 (file)
@@ -87,6 +87,9 @@ corosync\-cmapctl [\-b] \fB\-t\fR key_name
 .SS "Track changes on keys with key prefix:"
 .IP
 corosync\-cmapctl [\-b] \fB\-T\fR key_prefix
+.SS "Clear statistics (-mstats is implied)"
+.IP
+corosync\-cmapctl \fB\-C\fR [ipc|totem|knet|all]
 
 .SH "SEE ALSO"
 .BR cmap_overview (8),
index 5dadc219ee6b5d5a28a54f5bc898a58ded9d0ccc..1d8bfc4940de06f422bc83dd7bd5cfe8eef5945a 100644 (file)
@@ -56,6 +56,7 @@ enum user_action {
        ACTION_PRINT_PREFIX,
        ACTION_TRACK,
        ACTION_LOAD,
+       ACTION_CLEARSTATS,
 };
 
 struct name_to_type_item {
@@ -739,6 +740,14 @@ static void read_in_config_file(cmap_handle_t handle, char * filename)
        fclose (fh);
 }
 
+static void clear_stats(cmap_handle_t handle, char *clear_opt)
+{
+       char key_name[CMAP_KEYNAME_MAXLEN + 1];
+
+       sprintf(key_name, "stats.clear.%s", clear_opt);
+       cmap_set_uint32(handle, key_name, 1);
+}
+
 int main(int argc, char *argv[])
 {
        enum user_action action;
@@ -752,12 +761,13 @@ int main(int argc, char *argv[])
        int track_prefix;
        int map_set = 0;
        int no_retries;
+       char * clear_opt = NULL;
        char * settings_file = NULL;
 
        action = ACTION_PRINT_PREFIX;
        track_prefix = 1;
 
-       while ((c = getopt(argc, argv, "m:hgsdDtTbp:")) != -1) {
+       while ((c = getopt(argc, argv, "m:hgsdDtTbp:C:")) != -1) {
                switch (c) {
                case 'h':
                        return print_help();
@@ -781,6 +791,22 @@ int main(int argc, char *argv[])
                        settings_file = optarg;
                        action = ACTION_LOAD;
                        break;
+               case 'C':
+                       if (strcmp(optarg, "knet") == 0 ||
+                           strcmp(optarg, "totem") == 0 ||
+                           strcmp(optarg, "ipc") == 0 ||
+                           strcmp(optarg, "all") == 0) {
+                               action = ACTION_CLEARSTATS;
+                               clear_opt = optarg;
+
+                               /* Force the map to be STATS */
+                               map = CMAP_MAP_STATS;
+                       }
+                       else {
+                               fprintf(stderr, "argument to -C should be 'knet', 'totem', 'ipc' or 'all'\n");
+                               return (EXIT_FAILURE);
+                       }
+                       break;
                case 't':
                        action = ACTION_TRACK;
                        track_prefix = 0;
@@ -817,6 +843,7 @@ int main(int argc, char *argv[])
 
        if (argc == 0 &&
            action != ACTION_LOAD &&
+           action != ACTION_CLEARSTATS &&
            action != ACTION_PRINT_PREFIX) {
                fprintf(stderr, "Expected key after options\n");
                return (EXIT_FAILURE);
@@ -883,6 +910,9 @@ int main(int argc, char *argv[])
 
                set_key(handle, argv[0], argv[1], argv[2]);
                break;
+       case ACTION_CLEARSTATS:
+               clear_stats(handle, clear_opt);
+               break;
 
        }